Sorry in advance if I posted this in the wrong place!
I'm currently trying to implement BASSloud in a popular rhythm game,
osu!. However, I'm coming across an issue. Our game uses
ManagedBass for c# to use bass. To implement bassloud, I made a
PR for ManagedBass to add bindings for BASSloud. Using the code from my PR (my branch), and using it to make a very rough proof of concept design (excuse the variable names) for applying loudness normalization, I use the following code in a fresh isolated console application:
// See https://aka.ms/new-console-template for more information
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Runtime.InteropServices;
using ManagedBass.Loud;
using ManagedBass;
namespace AudioNormalization
{
public class AudioNormalization
{
public AudioNormalization(string file)
{
Bass.Free();
Bass.Init();
Console.WriteLine("bassloud version: " + BassLoud.Version);
var idk = Bass.CreateStream(file, 0, 0, BassFlags.Decode | BassFlags.Float);
Console.WriteLine("idk: " + idk);
if (idk == 0)
{
Console.WriteLine("cant decode stream");
Console.WriteLine(Bass.LastError);
return;
}
var loudness = BassLoud.BASS_Loudness_Start(idk, BassFlags.BassLoudnessIntegrated, 0);
Console.WriteLine("loudness: " + loudness);
if (loudness == 0)
{
Console.WriteLine("cant start loudness measurement");
Console.WriteLine(Bass.LastError);
}
int data;
while (true)
{
IntPtr buffer = new IntPtr();
data = Bass.ChannelGetData(idk, buffer,Marshal.SizeOf(buffer));
if (data < 0) break;
}
Bass.StreamFree(idk);
bool gotlevel = BassLoud.BASS_Loudness_GetLevel(loudness, BassFlags.BassLoudnessIntegrated, out float level);
Console.WriteLine("level: " + level);
Console.WriteLine("gotlevel: " + gotlevel);
if (gotlevel == false)
{
Console.WriteLine("failed to get level");
Console.WriteLine(Bass.LastError);
}
}
}
}
internal static class Program
{
public static void Main(string[] args)
{
var audioNormalization = new AudioNormalization.AudioNormalization("/Users/smallketchup/Downloads/Origami Angel - Doctor Whomst.mp3");
}
}
However, I come across a very bizarre issue. When I try to do
Bass_Loudness_Start(). The return value of the function is 0, but printing
Bass.LastError returns OK. I've spent a while debugging this and can't seem to come to a solution.
To reproduce, clone my branch in the ManagedBass PR. Then pack ManagedBass and ManagedBass.Loud into a nuget package. Create a new console application using .NET 8, and overwrite Program.cs with my code. Change it to use a random mp3 file. Make sure you install ManagedBass and ManagedBass.Loud in the new console application, and make sure that you're using the local nuget packages that you made using my branch. When you run the code, it'll print out `Bass_Loudness_Start()` returning 0 (cant start loudness measurement), but will also state that `Bass_Loudness_Start()` supposedly ran without issue (OK). I'm not sure if its a problem with my implementation, or with the code in my ManagedBass PR.
Do you have any suggestions?