Author Topic: Help with Unity + BASS Audio Library on Android: Issue with `libbass_fx.so`  (Read 291 times)

afsanchez001

  • Posts: 115
Hi everyone,

I'm using Unity 3D with C# and testing my app on a Samsung Galaxy Tab A.  :)

The mp3 files and SHOUTcast play fine. The C# for my Bass implementation to play audio works.

I'm developing the app to support both `arm64-v8a` and `armeabi-v7a` architectures. Here’s the directory structure I have for the libraries:

\Assets\Plugins\Android\libs\arm64-v8a
    libbass.so
    libbass_fx.so

\Assets\Plugins\Android\libs\armeabi-v7a
    libbass.so
    libbass_fx.so


Device Details
Here’s the device info from my logs:

SystemInfo CPU = ARMv7 VFPv3 NEON, Cores = 8, Memory = 1896mb
SystemInfo ARM big.LITTLE configuration: 2 big (mask: 0xc0), 6 little (mask: 0x3f)
ApplicationInfo com.***.*** version 0.1
Built from '2022.1/staging' branch, Version '2022.1.23f1 (9636b062134a)'
Build type 'Release', Scripting Backend 'il2cpp', CPU 'armeabi-v7a', Stripping 'Enabled'
Device Name: Galaxy Tab A


Current Status
- Audio playback works perfectly. 🎉
  - MP3 files play fine.
  - SHOUTcast streams work great.
- The problem arises when I try to use `libbass_fx.so` for effects like reverb and echo.

Code Overview
I’m using a simple C# class (`BassMp3.cs`) to manage audio. Initialization via `BASS_Init` works without issues:

Code: [Select]
if (!BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero, IntPtr.Zero))
{
    Debug.LogError("BASS Init failed.");
}

The logs confirm successful initialization:

BASS Init succeeded.
BASS_SetConfig succeeded.


The Issue with `libbass_fx.so`

When I attempt to load the `libbass_fx.so` plugin with the following code:

Code: [Select]
int pluginHandle = BASS_PluginLoad(Path.Combine(Application.persistentDataPath, "libbass_fx.so"));
if (pluginHandle == 0)
{
    Debug.LogError($"Failed to load libbass_fx.so: {BASS_ErrorGetCode()}");
}

I get the following error in the log:  :-\

Failed to load libbass_fx.so: BASS_ERROR_FILEOPEN

Subsequently, when I try to use the plugin, I encounter errors like this:  ???

ArgumentNullException: Value cannot be null.
Parameter name: obj
at System.Threading.Monitor.ReliableEnterTimeout (System.Object obj, System.Int32 timeout, System.Boolean& lockTaken) ...


What Works

- `libbass.so` loads and works perfectly for both MP3 playback and SHOUTcast streams.
- Audio playback is smooth without any issues.

What Doesn’t Work

- Loading `libbass_fx.so` results in the `BASS_ERROR_FILEOPEN` error.
- Trying to apply effects like reverb or echo via `BASS_FXSetParameters` leads to crashes or null reference errors.

Key Questions

1. Am I missing something in the setup for `libbass_fx.so`?
2. Does the `libbass_fx.so` library need to be manually loaded differently than `libbass.so` on Android?
3. Could this be a permissions issue, or is there something specific to Android that I need to address?

I’ve double-checked the library placement, and the `libbass.so` file works as expected. I also ensured that the `INTERNET` permission is enabled in Unity's Player Settings.

I’m stuck on this and would really appreciate any advice or insights! Thank you in advance for your help.  :)
« Last Edit: 8 Dec '24 - 06:21 by afsanchez001 »

Ian @ un4seen

  • Administrator
  • Posts: 26223
BASS_PluginLoad is currently only for plugging add-ons into the stream/sample creation functions (eg. BASS_StreamCreateFile) for additional file format support. That doesn't apply to BASS_FX because it doesn't add support for any file formats. Instead, you generally need to call a BASS_FX function to have it loaded, eg. you could call BASS_FX_GetVersion in your initialization code.

afsanchez001

  • Posts: 115
Hi Ian,

Thank you for getting back to me.

Yes, I was already doing `BASS_FX_GetVersion()` earlier in the code.

But because I keep getting the error, `Value cannot be null` when doing `BASS_FXSetParameters`, that is why I tried `BASS_PluginLoad()`, just to be sure that the .so file was indeed there.

And it is, the file is there.

The thing is, when I do NOT do `BASS_FXSetParameters`, the mp3 plays fine.  :)

But when I apply it, I get the error.  :-\


MY INIT CODE:

Code: [Select]
// Apply global settings
        try
        {
            BASS_SetConfig(BASSConfig.BASS_CONFIG_BUFFER, 3000); // increasing the device buffer length, default is 30ms
            BASS_SetConfig(BASSConfig.BASS_CONFIG_DEV_BUFFER, 30); // increasing the device buffer length, default is 30ms
            BASS_SetConfig(BASSConfig.BASS_CONFIG_FLOATDSP, true); // Pass 32-bit floating-point sample data to all DSP functions.
            Debug.Log("BASS_SetConfig succeeded.");
        }
        catch (Exception ex)
        {
            Debug.LogError($"BASS_SetConfig: {ex.Message}");
        }


// Initialize the BASS library
        if (!BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero, IntPtr.Zero))
        {
            Debug.Log("BASS initialized successfully.");

            // Check BASS version
            if ((BASS_GetVersion() & 0xFFFF0000) != (BASSVERSION << 16))
            {
                Debug.LogError($"BASS version mismatch: {BASS_ErrorGetCode()}");
                return;
            }

            // Check BASS_FX version
            if ((BASS_FX_GetVersion() & 0xFFFF0000) != (BASSFXVERSION << 16))
            {
                Debug.LogError($"BASS_FX version mismatch: {BASS_ErrorGetCode()}");
                return;
            }

            Debug.Log("BASS and BASS_FX versions match and are loaded.");
        }
        else
        {
            Debug.LogError($"Failed to initialize BASS: {BASS_ErrorGetCode()}");
        }

AND ELSEWHERE, PlayMp3 method:

Code: [Select]
FxHandleReverb = BASS_ChannelSetFX(mp3StreamHandle, BASSFXType.BASS_FX_BFX_FREEVERB, 1);

BASS_BFX_FREEVERB reverbParams = new BASS_BFX_FREEVERB
{
fDryMix = 1f,
fWetMix = 1.5f
};

reverbParams.fRoomSize = 0.50f;
reverbParams.fDamp = 0.5f;
reverbParams.fWidth = 1.0f;

if (reverbParams == null)
{
Debug.LogError("Reverb parameters are null.");
yield return 0;
}

try
{
if (!BASS_FXSetParameters(FxHandleReverb, reverbParams))
{
throw new Exception($"Failed to set BASS FX Reverb parameters. Error code: {BASS_ErrorGetCode()}");
}
}
catch (Exception ex)
{
Debug.LogError($"Exception while setting BASS FX Reverb parameters: {ex.Message}");
}


THE ERROR I GET:

12-09 10:16:31.938   789  1362 E Unity   : Exception while setting BASS FX Reverb parameters: Value cannot be null.
12-09 10:16:31.938   789  1362 E Unity   : Parameter name: obj
12-09 10:16:31.938   789  1362 E Unity   : UnityEngine.Logger:Log(LogType, Object)


Here is the full logging in my PlayMp3 method:

12-09 10:16:31.923   789  1362 I Unity   : doReverb is enabled. Starting reverb effect setup.
12-09 10:16:31.924   789  1362 I Unity   : Removing existing reverb effect. FxHandleReverb: -2147483643
12-09 10:16:31.928   789  1362 I Unity   : Reverb effect removed: False
12-09 10:16:31.929   789  1362 I Unity   : Stream handle: -2147483639
12-09 10:16:31.931   789  1362 I Unity   : New FxHandleReverb: -2147483638
12-09 10:16:31.932   789  1362 I Unity   : FxHandleReverb: -2147483638
12-09 10:16:31.933   789  1362 I Unity   : Setting reverb preset values.
12-09 10:16:31.934   789  1362 I Unity   : Reverb preset values applied. RoomSize: 1
12-09 10:16:31.935   789  1362 I Unity   : Reverb settings - Damp: 0.5, Width: 1
12-09 10:16:31.936   789  1362 I Unity   : Applying reverb parameters using BASS_FXSetParameters.
12-09 10:16:31.938   789  1362 E Unity   : Exception while setting BASS FX Reverb parameters: Value cannot be null.
12-09 10:16:31.939   789  1362 I Unity   : FxVolume: 1
12-09 10:16:31.940   789  1362 I Unity   : FxPitch: 0
12-09 10:16:31.941   789  1362 I Unity   : FxTempo: 0
12-09 10:16:31.942   789  1362 I Unity   : FxTempo PREVENT_CLICK: 0
12-09 10:16:31.954   789  1362 I Unity   : Playing: /storage/emulated/0/Android/data/com.***.***app/files/63d3b8f5-31d3-44fb-8447-96fe966f7bcf.mp3
12-09 10:16:31.957   789  1362 I Unity   : streamHandleMp3: -2147483639
12-09 10:16:34.980   789  1362 I Unity   : Stopping active Shoutcast stream.

I am not sure why this is happening?  :-\

Thanks for your help.
« Last Edit: 9 Dec '24 - 18:51 by afsanchez001 »

afsanchez001

  • Posts: 115
Hi Ian,

A strange update... although I am still getting the error:

Exception while setting BASS FX Reverb parameters: Value cannot be null.

The Reverb effect seems to be working.   :-\ Which is good?

So, I am not sure why, but it is operating. As are the other effects like pitch and tempo.

Any ideas?


Ian @ un4seen

  • Administrator
  • Posts: 26223
When you're unable to set the effect's parameters, it'll be left with the default parameters, so that'll be why you still hear a reverb effect. I'm not sure what could be causing the exception in the BASS_FXSetParameters call, so I've asked Bernd to have a look at the BASS_BFX_FREEVERB support in BASS.Net to see if he can spot anything there.

Ian @ un4seen

  • Administrator
  • Posts: 26223
One thing you could check to perhaps narrow-down what the problem is, is whether it affects BASS_FXGetParameters too?

Code: [Select]
BASS_BFX_FREEVERB reverbParams = new BASS_BFX_FREEVERB();
BASS.BASS_FXSetParameters(FxHandleReverb, reverbParams);

If that works, you could then also try passing the same parameters (reverbParams) back to BASS_FXSetParameters.

Ian @ un4seen

  • Administrator
  • Posts: 26223
Bernd has posted a BASS.Net 2.4.17.6 update. Please give that a try and see if you still have the problem.

radio42

  • Posts: 4841
Any News?
Does the new version work out fine?