From c49ee1d3060424c89bf83ff624bb57476750bdec Mon Sep 17 00:00:00 2001 From: Aptivi CEO Date: Wed, 18 Sep 2024 22:35:19 +0300 Subject: [PATCH] add - doc - You can now get SPF --- You can now get seconds per frame value in double-precision floating point! --- Type: add Breaking: False Doc Required: True Backport Required: False Part: 1/1 --- BassBoom.Basolia/Format/AudioInfoTools.cs | 31 +++++++++++++++++++++++ BassBoom.Cli/CliBase/Common.cs | 20 ++++++++++++++- 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/BassBoom.Basolia/Format/AudioInfoTools.cs b/BassBoom.Basolia/Format/AudioInfoTools.cs index af38a3d..627589a 100644 --- a/BassBoom.Basolia/Format/AudioInfoTools.cs +++ b/BassBoom.Basolia/Format/AudioInfoTools.cs @@ -236,6 +236,37 @@ public static int GetSamplesPerFrame(BasoliaMedia? basolia) return getStatus; } + /// + /// Gets the number of seconds per frame + /// + /// Basolia instance that contains a valid handle + /// Number of seconds per frame + /// + public static double GetSecondsPerFrame(BasoliaMedia? basolia) + { + double getStatus; + InitBasolia.CheckInited(); + if (basolia is null) + throw new BasoliaException("Basolia instance is not provided", mpg123_errors.MPG123_BAD_HANDLE); + + // Check to see if the file is open + if (!FileTools.IsOpened(basolia)) + throw new BasoliaException("Can't query a file that's not open", mpg123_errors.MPG123_BAD_FILE); + + unsafe + { + var handle = basolia._mpg123Handle; + + // Get the seconds per frame + var @delegate = MpgNative.GetDelegate(MpgNative.libManagerMpg, nameof(NativeStatus.mpg123_tpf)); + getStatus = @delegate.Invoke(handle); + if (getStatus < 0) + throw new BasoliaException($"Can't get the seconds per frame.", mpg123_errors.MPG123_ERR); + Debug.WriteLine($"Got frame tpf {getStatus}"); + } + return getStatus; + } + /// /// Gets the buffer size from the currently open music file. /// diff --git a/BassBoom.Cli/CliBase/Common.cs b/BassBoom.Cli/CliBase/Common.cs index cd33157..ceecdec 100644 --- a/BassBoom.Cli/CliBase/Common.cs +++ b/BassBoom.Cli/CliBase/Common.cs @@ -173,6 +173,24 @@ Extra specs (for developers) foreach (int rate in rates) ratesBuilder.AppendLine($" - {rate} hertz"); + // For playing files (not radio stations), add even more values + var playingBuilder = new StringBuilder(); + if (FileTools.IsOpened(BassBoomCli.basolia) && !isRadioMode) + { + int durationSamples = AudioInfoTools.GetDuration(BassBoomCli.basolia, true); + int frameLength = AudioInfoTools.GetFrameLength(BassBoomCli.basolia); + int samplesFrame = AudioInfoTools.GetSamplesPerFrame(BassBoomCli.basolia); + double secondsFrame = AudioInfoTools.GetSecondsPerFrame(BassBoomCli.basolia); + playingBuilder.Append( + $""" + + Duration in samples: {durationSamples} + Frame length: {frameLength} + Samples/frame: {samplesFrame} + Seconds/frame: {secondsFrame} + """); + } + // Now, grab the necessary values and add them, too. devSpecs.Append( $""" @@ -195,7 +213,7 @@ Encodings and Rates Buffer info ----------- - Generic buffer size: {AudioInfoTools.GetGenericBufferSize()} + Generic buffer size: {AudioInfoTools.GetGenericBufferSize()}{playingBuilder} """); }