Skip to content

Commit

Permalink
add - doc - You can now get SPF
Browse files Browse the repository at this point in the history
---

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
  • Loading branch information
AptiviCEO committed Sep 18, 2024
1 parent 415a435 commit c49ee1d
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
31 changes: 31 additions & 0 deletions BassBoom.Basolia/Format/AudioInfoTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,37 @@ public static int GetSamplesPerFrame(BasoliaMedia? basolia)
return getStatus;
}

/// <summary>
/// Gets the number of seconds per frame
/// </summary>
/// <param name="basolia">Basolia instance that contains a valid handle</param>
/// <returns>Number of seconds per frame</returns>
/// <exception cref="BasoliaException"></exception>
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<NativeStatus.mpg123_tpf>(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;
}

/// <summary>
/// Gets the buffer size from the currently open music file.
/// </summary>
Expand Down
20 changes: 19 additions & 1 deletion BassBoom.Cli/CliBase/Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
$"""
Expand All @@ -195,7 +213,7 @@ Encodings and Rates
Buffer info
-----------
Generic buffer size: {AudioInfoTools.GetGenericBufferSize()}
Generic buffer size: {AudioInfoTools.GetGenericBufferSize()}{playingBuilder}
""");
}

Expand Down

0 comments on commit c49ee1d

Please sign in to comment.