Skip to content

Commit

Permalink
add - doc - Added encoding and rate lists
Browse files Browse the repository at this point in the history
---

You can now list all the supported encodings and rates, as well as encoding names and descriptions.

---

Type: add
Breaking: False
Doc Required: True
Backport Required: False
Part: 1/1
  • Loading branch information
AptiviCEO committed Sep 18, 2024
1 parent c4b3e7d commit 14844ae
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 4 deletions.
100 changes: 100 additions & 0 deletions BassBoom.Basolia/Format/FormatTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
using SpecProbe.Software.Platform;
using BassBoom.Native;
using BassBoom.Basolia.Exceptions;
using BassBoom.Basolia.Helpers;
using System.Linq;

namespace BassBoom.Basolia.Format
{
Expand Down Expand Up @@ -60,6 +62,104 @@ public static (long rate, int channels, int encoding) GetFormatInfo(BasoliaMedia
// We're now entering the safe zone
return (fileRate, fileChannel, fileEncoding);
}

/// <summary>
/// Gets the rate list supported by the library
/// </summary>
public static int[] GetRates()
{
InitBasolia.CheckInited();
int[] rates;

// We're now entering the dangerous zone
unsafe
{
// Get the rates
var @delegate = MpgNative.GetDelegate<NativeOutput.mpg123_rates>(MpgNative.libManagerMpg, nameof(NativeOutput.mpg123_rates));
@delegate.Invoke(out IntPtr ratesPtr, out int count);
rates = ArrayVariantLength.GetIntegersKnownLength(ratesPtr, count);
}

// We're now entering the safe zone
return rates;
}

/// <summary>
/// Gets the encoding list supported by the library
/// </summary>
public static int[] GetEncodings()
{
InitBasolia.CheckInited();
int[] encodings = [];

// We're now entering the dangerous zone
unsafe
{
// Get the encodings
var @delegate = MpgNative.GetDelegate<NativeOutput.mpg123_encodings>(MpgNative.libManagerMpg, nameof(NativeOutput.mpg123_encodings));
@delegate.Invoke(out IntPtr encodingsPtr, out int count);
encodings = ArrayVariantLength.GetIntegersKnownLength(encodingsPtr, count);
}

// We're now entering the safe zone
return encodings;
}

/// <summary>
/// Gets the encoding name
/// </summary>
/// <param name="encoding">Encoding ID</param>
/// <returns>Name of the encoding in short form</returns>
public static string GetEncodingName(int encoding)
{
InitBasolia.CheckInited();
string encodingName = "";

// Check the encoding
int[] encodings = GetEncodings();
if (!encodings.Contains(encoding))
throw new BasoliaException($"Encoding {encoding} not found.", mpg123_errors.MPG123_BAD_TYPES);

// We're now entering the dangerous zone
unsafe
{
// Get the encodings
var @delegate = MpgNative.GetDelegate<NativeOutputLib.out123_enc_name>(MpgNative.libManagerOut, nameof(NativeOutputLib.out123_enc_name));
IntPtr namePtr = @delegate.Invoke(encoding);
encodingName = Marshal.PtrToStringAnsi(namePtr);
}

// We're now entering the safe zone
return encodingName;
}

/// <summary>
/// Gets the encoding description
/// </summary>
/// <param name="encoding">Encoding ID</param>
/// <returns>Description of the encoding in short form</returns>
public static string GetEncodingDescription(int encoding)
{
InitBasolia.CheckInited();
string encodingDescription = "";

// Check the encoding
int[] encodings = GetEncodings();
if (!encodings.Contains(encoding))
throw new BasoliaException($"Encoding {encoding} not found.", mpg123_errors.MPG123_BAD_TYPES);

// We're now entering the dangerous zone
unsafe
{
// Get the encodings
var @delegate = MpgNative.GetDelegate<NativeOutputLib.out123_enc_longname>(MpgNative.libManagerOut, nameof(NativeOutputLib.out123_enc_longname));
IntPtr descriptionPtr = @delegate.Invoke(encoding);
encodingDescription = Marshal.PtrToStringAnsi(descriptionPtr);
}

// We're now entering the safe zone
return encodingDescription;
}

/// <summary>
/// Gets the supported formats
Expand Down
12 changes: 12 additions & 0 deletions BassBoom.Basolia/Helpers/ArrayVariantLength.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,17 @@ internal static string[] GetStringsUnknownLength(IntPtr arrayPointer)
}
return [.. strings];
}

internal static int[] GetIntegersKnownLength(IntPtr arrayPointer, int elements)
{
List<int> ints = [];
for (int i = 0; i < elements; i++)
{
IntPtr elementPtr = arrayPointer + i * sizeof(int);
int value = Marshal.ReadInt32(elementPtr);
ints.Add(value);
}
return [.. ints];
}
}
}
19 changes: 19 additions & 0 deletions BassBoom.Cli/CliBase/Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,17 @@ Available devices and drivers

internal static void ShowSpecs()
{
var encodingsBuilder = new StringBuilder();
int[] encodings = FormatTools.GetEncodings();
foreach (int encoding in encodings)
{
// Get the name and the description
string name = FormatTools.GetEncodingName(encoding);
string desc = FormatTools.GetEncodingDescription(encoding);

encodingsBuilder.AppendLine($" - {name} [{encoding}]: {desc}");
}

InfoBoxColor.WriteInfoBox(
$$"""
BassBoom specifications
Expand All @@ -160,6 +171,14 @@ BassBoom specifications
All decoders:
- {{string.Join("\n - ", DecodeTools.GetDecoders(false))}}
Encodings and Rates
===================
Encodings:
{{encodingsBuilder}}
Rates:
- {{string.Join("\n - ", FormatTools.GetRates())}}
System specifications
=====================
Expand Down
4 changes: 2 additions & 2 deletions BassBoom.Native/Interop/Output/NativeOutputLib.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,12 @@ internal delegate int out123_devices(out123_handle* ao,
/// <summary>
/// MPG123_EXPORT const char* out123_enc_name(int encoding);
/// </summary>
internal delegate string out123_enc_name(int encoding);
internal delegate IntPtr out123_enc_name(int encoding);

/// <summary>
/// MPG123_EXPORT const char* out123_enc_longname(int encoding);
/// </summary>
internal delegate string out123_enc_longname(int encoding);
internal delegate IntPtr out123_enc_longname(int encoding);

/// <summary>
/// MPG123_EXPORT int out123_start( out123_handle *ao
Expand Down
5 changes: 3 additions & 2 deletions BassBoom.Native/Interop/Play/NativeOutput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
//

using BassBoom.Native.Interop.Init;
using System;
using System.Runtime.InteropServices;

namespace BassBoom.Native.Interop.Play
Expand All @@ -36,12 +37,12 @@ internal static unsafe class NativeOutput
/// <summary>
/// MPG123_EXPORT void mpg123_rates(const long **list, size_t *number);
/// </summary>
internal delegate void mpg123_rates(long[] list, int* number);
internal delegate void mpg123_rates(out IntPtr list, out int number);

/// <summary>
/// MPG123_EXPORT void mpg123_encodings(const int **list, size_t *number);
/// </summary>
internal delegate void mpg123_encodings(int[] list, int* number);
internal delegate void mpg123_encodings(out IntPtr list, out int number);

/// <summary>
/// MPG123_EXPORT int mpg123_encsize(int encoding);
Expand Down

0 comments on commit 14844ae

Please sign in to comment.