Author Topic: BASS for Android  (Read 683778 times)

Muzzy

  • Guest
Re: BASS for Android
« Reply #1725 on: 30 May '20 - 18:15 »
I'm a little ignorant when it comes to setting up android projects.  But, I have an Android Native Activity project in visual studio and I'm trying to get BASS set up with it.  In my Visual Studio project directory I created a "lib" folder and that's where I put the BASS .so files.

I referenced my Native Activity Project to that lib folder in the Project Properties->Linker->General->Additional Library Directories.  Then I referenced the 'libbass.so' under Project Properties->Linker->Input->Library Dependencies.

When I compile I get a linker error  "cannot find -llibbass.so" or "cannot find -llibbass" if I remove the '.so'.  It's looking in my AndroidNDK directory for the file and doesn't look in the lib folder I created for it.

How do I correctly link the libs in a Visual Studio project?

Ian @ un4seen

  • Administrator
  • Posts: 22959
Re: BASS for Android
« Reply #1726 on: 1 Jun '20 - 15:54 »
I have never used Visual Studio for Android stuff myself, so I'm not familiar with the specifics of that, but did you keep the architecture folder structure, eg. lib/armeabi-v7a/libbass.so? It looks like that should work, according to this:

   https://docs.microsoft.com/en-us/xamarin/android/platform/native-libraries

Ryota

  • Posts: 25
Re: BASS for Android
« Reply #1727 on: 2 Jun '20 - 04:34 »
There is a newer BASS_FX beta (2.4.12.3) available here:

   www.jobnik.org/BASS_FX/beta/bass_fx24123-android-beta.zip

Thank you, Ian.

But is this really 2.4.12.3?
It seems that files are the same of 2.4.12.2.

Ian @ un4seen

  • Administrator
  • Posts: 22959
Re: BASS for Android
« Reply #1728 on: 2 Jun '20 - 14:00 »
I haven't actually tried it myself. Are you having the problem with it too? If so, does it still happen if you leave the default parameters, ie. don't call BASS_FXSetParameters? Please also try on another platform if possible, to see if it's only affecting the Android version.

max_xt

  • Posts: 8
Re: BASS for Android
« Reply #1729 on: 2 Jun '20 - 18:35 »
I have weird behavior of BASS.BASS_ChannelGetData(handle, bbuf, BASS.BASS_DATA_FFT4096) after connection to bluetooth speaker. Seems like it drop refresh rate of data. I can't hear any changes in audio, and frame rate of app is still 60fps, so is not glitch of view.
Xiaomi MI A1, Android 9:
https://youtu.be/0lpmzUj8sFk
Also I have same issue on Pixel XL with Android 10.
Also on Amazon Fire 8 it work with slow rate always, but I thought this is old device specific.
Both OpenSL and AAudio have this problem.

Ryota

  • Posts: 25
Re: BASS for Android
« Reply #1730 on: 3 Jun '20 - 00:09 »
I haven't actually tried it myself. Are you having the problem with it too? If so, does it still happen if you leave the default parameters, ie. don't call BASS_FXSetParameters? Please also try on another platform if possible, to see if it's only affecting the Android version.

Thank you, Ian.

There is no sound when I use the default parameters too.

Here is the code excerpted.

Code: [Select]
int fxDistortion = BASS.BASS_ChannelSetFX(stream, BASS_FX.BASS_FX_BFX_DISTORTION, 2);
/*
BASS_FX.BASS_BFX_DISTORTION distortion = new BASS_FX.BASS_BFX_DISTORTION();
distortion.fDrive = 1f;
distortion.fDryMix = 0f;
distortion.fWetMix = 1f;
distortion.fFeedback = 0f;
distortion.fVolume = 1f;
distortion.lChannel = BASS_FX.BASS_BFX_CHANALL;
BASS.BASS_FXSetParameters(fxDistortion, distortion);
*/

I tried on iOS platform, but this problem doen not occured.

Muzzy

  • Guest
Re: BASS for Android
« Reply #1731 on: 3 Jun '20 - 00:23 »
I have never used Visual Studio for Android stuff myself, so I'm not familiar with the specifics of that, but did you keep the architecture folder structure, eg. lib/armeabi-v7a/libbass.so? It looks like that should work, according to this:

   https://docs.microsoft.com/en-us/xamarin/android/platform/native-libraries

The link you sent helped.  I was able to manually link the .so file by manually adding the link in the project settings file.  Now I just need to figure out how to include the java code in C++.

Ian @ un4seen

  • Administrator
  • Posts: 22959
Re: BASS for Android
« Reply #1732 on: 3 Jun '20 - 17:19 »
There is no sound when I use the default parameters too.

Here is the code excerpted.

Code: [Select]
int fxDistortion = BASS.BASS_ChannelSetFX(stream, BASS_FX.BASS_FX_BFX_DISTORTION, 2);
/*
BASS_FX.BASS_BFX_DISTORTION distortion = new BASS_FX.BASS_BFX_DISTORTION();
distortion.fDrive = 1f;
distortion.fDryMix = 0f;
distortion.fWetMix = 1f;
distortion.fFeedback = 0f;
distortion.fVolume = 1f;
distortion.lChannel = BASS_FX.BASS_BFX_CHANALL;
BASS.BASS_FXSetParameters(fxDistortion, distortion);
*/

I tried on iOS platform, but this problem doen not occured.

OK. I tried it now, and there was sound with your parameters and the defaults, so I'm not sure why it wouldn't be working for you. What architecture are you running on? I tried it on arm64-v8a and armeabi-v7a. If you still have no luck with it, perhaps you could try the BASS_FX_DX8_DISTORTION effect instead. Although it has "DX8" in the name, it is also available on Android.

Now I just need to figure out how to include the java code in C++.

If you're using C++, you can use the BASS.H header instead of BASS.JAVA. You can get that header from the Windows/OSX/Linux packages on the BASS webpage.

Ryota

  • Posts: 25
Re: BASS for Android
« Reply #1733 on: 5 Jun '20 - 06:13 »
OK. I tried it now, and there was sound with your parameters and the defaults, so I'm not sure why it wouldn't be working for you. What architecture are you running on? I tried it on arm64-v8a and armeabi-v7a. If you still have no luck with it, perhaps you could try the BASS_FX_DX8_DISTORTION effect instead. Although it has "DX8" in the name, it is also available on Android.
Thank you, Ian. I tried it on x86, and there is no sound. As you said, there is sound on arm64-v8a and armeabi-v7a.

Ian @ un4seen

  • Administrator
  • Posts: 22959
Re: BASS for Android
« Reply #1734 on: 5 Jun '20 - 14:06 »
Oh yes, I see there is no sound when running on x86. Strange. Simply rebuilding the library seems to get it working somehow, so here that is for you to try:

   www.un4seen.com/stuff/bass_fx-android.zip

Ryota

  • Posts: 25
Re: BASS for Android
« Reply #1735 on: 6 Jun '20 - 04:53 »
Oh yes, I see there is no sound when running on x86. Strange. Simply rebuilding the library seems to get it working somehow, so here that is for you to try:

   www.un4seen.com/stuff/bass_fx-android.zip
Thank you, Ian! I tried your rebuilding version, and that works perfectly.

norbert

  • Posts: 135
Re: BASS for Android
« Reply #1736 on: 7 Jun '20 - 09:49 »
Using the BASSENC_MP3  in an commercial app - do I have to care about the restrictions of the LGPL which are still valid for LAME itself  - since the doc states for BASSENC_MP3:  "MP3 encoding is based on libmp3lame" ?  "Based on" vs "using"  - not sure...

max_xt

  • Posts: 8
Re: BASS for Android
« Reply #1737 on: 7 Jun '20 - 16:05 »
I have weird behavior of BASS.BASS_ChannelGetData(handle, bbuf, BASS.BASS_DATA_FFT4096) after connection to bluetooth speaker. Seems like it drop refresh rate of data. I can't hear any changes in audio, and frame rate of app is still 60fps, so is not glitch of view.
Xiaomi MI A1, Android 9:
https://youtu.be/0lpmzUj8sFk
Also I have same issue on Pixel XL with Android 10.
Also on Amazon Fire 8 it work with slow rate always, but I thought this is old device specific.
Both OpenSL and AAudio have this problem.
Also I checked previous version of lib BASS_GetVersion: 33820161 it don't have this problem.
BASS_GetVersion: 33820416 - problem exists

Ian @ un4seen

  • Administrator
  • Posts: 22959
Re: BASS for Android
« Reply #1738 on: 8 Jun '20 - 17:25 »
Using the BASSENC_MP3  in an commercial app - do I have to care about the restrictions of the LGPL which are still valid for LAME itself  - since the doc states for BASSENC_MP3:  "MP3 encoding is based on libmp3lame" ?  "Based on" vs "using"  - not sure...

Yes, BASSenc_MP3 includes the LAME library (libmp3lame). I'm just double-checking the requirements, and then I'll get back to you.

I have weird behavior of BASS.BASS_ChannelGetData(handle, bbuf, BASS.BASS_DATA_FFT4096) after connection to bluetooth speaker. Seems like it drop refresh rate of data. I can't hear any changes in audio, and frame rate of app is still 60fps, so is not glitch of view.
Xiaomi MI A1, Android 9:
https://youtu.be/0lpmzUj8sFk
Also I have same issue on Pixel XL with Android 10.
Also on Amazon Fire 8 it work with slow rate always, but I thought this is old device specific.
Both OpenSL and AAudio have this problem.
Also I checked previous version of lib BASS_GetVersion: 33820161 it don't have this problem.
BASS_GetVersion: 33820416 - problem exists

An apparent refresh rate drop could be caused by a drop in the smoothness of the stream's position advancement, ie. if it starts advancing in larger steps. You can use BASS_ChannelGetPosition to check that.

If the problem began with BASS 2.4.15 then it may be related to AAudio, which BASS 2.4.15 uses by default. Are you sure the problem is happening with OpenSL too? I would expect the old version to be affected too then. Please try this latest build:

   www.un4seen.com/stuff/bass-android-test.zip

If the problem still happens with that, then try disabling AAudio's low-latency mode like this (before calling BASS_Init):

Code: [Select]
BASS.BASS_SetConfig(BASS.BASS_CONFIG_ANDROID_AAUDIO, 2);

And if the problem still happens, then try disabling AAudio all together like this (again before calling BASS_Init):

Code: [Select]
BASS.BASS_SetConfig(BASS.BASS_CONFIG_ANDROID_AAUDIO, 0);

You could also try AudioTrack, like this:

Code: [Select]
BASS.BASS_Init(-1, 44100, BASS.BASS_DEVICE_AUDIOTRACK);

max_xt

  • Posts: 8
Re: BASS for Android
« Reply #1739 on: 8 Jun '20 - 21:11 »
An apparent refresh rate drop could be caused by a drop in the smoothness of the stream's position advancement, ie. if it starts advancing in larger steps. You can use BASS_ChannelGetPosition to check that.

If the problem began with BASS 2.4.15 then it may be related to AAudio, which BASS 2.4.15 uses by default. Are you sure the problem is happening with OpenSL too? I would expect the old version to be affected too then. Please try this latest build:

   www.un4seen.com/stuff/bass-android-test.zip
Thanks Ian. I tried all your ask configurations and it all worked the same -  start dropping after on/off bluetooth. Then if bluetooth on and app restart - is still glitching. I checked BASS_ChannelGetPosition every drawing frame and the difference between frames: if glitching or not it looks the same.
Also I tried setting different buffer params in BASS_SetConfig - nothing helped.
Then I rollback to working version and compare BASS_GetInfo with latest, I see only difference in "Enable AAudio output on Android: -1" so i decided to set BASS.BASS_SetConfig(BASS.BASS_CONFIG_ANDROID_AAUDIO, -1); on your test build and it start glitching in some other way:
1. bluetooth is off, start app, all ok
2. turn on bluetooth(and it connects to speaker Sony gtk-x1bt), SpectrumView freeze for a second then starts dropping output
3. turn off bluetooth, and here difference : it may become normal again or I hear little sound glitch and it keep dropping

Ian @ un4seen

  • Administrator
  • Posts: 22959
Re: BASS for Android
« Reply #1740 on: 9 Jun '20 - 16:58 »
Thanks Ian. I tried all your ask configurations and it all worked the same -  start dropping after on/off bluetooth. Then if bluetooth on and app restart - is still glitching. I checked BASS_ChannelGetPosition every drawing frame and the difference between frames: if glitching or not it looks the same.

That's strange. Perhaps there's a buffering/latency difference then. I will probably need to send you a debug version to get more info. But first, as well as BASS_ChannelGetPosition, please also try comparing the BASS_ChannelGetData(BASS_DATA_AVAILABLE) return values with the 2.4.15 and 2.4.14 BASS versions.

Does the display still look in sync with the sound when it's sluggish, or is it ahead or behind? Does using a smaller FFT make a difference?

Then I rollback to working version and compare BASS_GetInfo with latest, I see only difference in "Enable AAudio output on Android: -1"

-1 indicates that BASS_GetConfig failed (the BASS_CONFIG_ANDROID_AAUDIO option wasn't present in BASS 2.4.14).

Btw, are the BASS_GetInfo values identical with BASS 2.4.14 and BASS 2.4.15?

max_xt

  • Posts: 8
Re: BASS for Android
« Reply #1741 on: 10 Jun '20 - 01:18 »
Added flag BASS_DATA_AVAILABLE - nothing changed;
Tried BASS_DATA_FFT1024 - lower resolution but same dropped rate
Does the display still look in sync with the sound when it's sluggish, or is it ahead or behind?
Bluetooth speaker has delay, I think nothing special here. When it play via phone speaker delay is minimum.

View is rendering in 60fps, so I call BASS_ChannelGetData 60 times per second and new data return every 15ms, when it start drop rate time between data changes increase up to 80ms.

BASS_GetInfo:
Quote
    Total device hardware memory: 0
    Free device hardware memory: 0
    Number of free sample slots in the hardware: 0
    Number of free 3D sample slots in the hardware: 0
    Min sample rate supported by the hardware: 0
    Max sample rate supported by the hardware: 0
    Device supports EAX?: 0
    Recommended minimum buffer length in ms: 10
    Delay (in ms) before start of playback: 36
    Number of speakers available: 2
    Current output rate: 44100 <-- when start with bluetooth on, if is off AudioTrack.getNativeOutputSampleRate(AudioManager.STREAM_MUSIC) return 48000
    Flags: 0
    Output device buffer length: 40
    Playback buffer length: 500
    Output device update period: 10
    Floating-point sample data is supported: 1
    Pass 32-bit floating-point sample data to all DSP functions: 1
    Number of existing handles: 0
    Default sample rate conversion quality: 1
    Default sample rate conversion quality for samples: 0
    Update period of playback buffers: 100
    Number of update threads: 1
    Enable AAudio output on Android: 0 <-- depended on BASS.BASS_CONFIG_ANDROID_AAUDIO settings, I tried 0,2,-1, old version return -1;

P.S. Video with sound https://www.youtube.com/watch?v=GBDRK4W2l38

Ian @ un4seen

  • Administrator
  • Posts: 22959
Re: BASS for Android
« Reply #1742 on: 10 Jun '20 - 16:49 »
Using the BASSENC_MP3  in an commercial app - do I have to care about the restrictions of the LGPL which are still valid for LAME itself  - since the doc states for BASSENC_MP3:  "MP3 encoding is based on libmp3lame" ?  "Based on" vs "using"  - not sure...

It looks like it will be a bit tricky to use BASSenc_MP3 in a commercial (or any closed source) Android app. The issue is that LGPL requires that the end-user will be able to modify the BASSenc_MP3 library that you include in your app. That's pretty simple on Windows/Linux/OSX as they can replace the DLL, but it's not so simple on Android (or iOS). I haven't tried it myself, but perhaps Apktool can help?

   https://ibotpeaches.github.io/Apktool/

If that allows the user to replace the LIBBASSENC_MP3.SO file(s) in your app's APK then that seems like it would satisfy that LGPL requirement. You will also need to satisfy the other LGPL (v2) requirements, eg. crediting LAME.

View is rendering in 60fps, so I call BASS_ChannelGetData 60 times per second and new data return every 15ms, when it start drop rate time between data changes increase up to 80ms.

I will send you a debug BASS version to get more info.

norbert

  • Posts: 135
Re: BASS for Android
« Reply #1743 on: 10 Jun '20 - 17:21 »
If that allows the user to replace the LIBBASSENC_MP3.SO file(s) in your app's APK then that seems like it would satisfy that LGPL requirement. You will also need to satisfy the other LGPL (v2) requirements, eg. crediting LAME.

I assume the "LIBBASSENC_MP3.so" is some wrapper/container that contains the original liblame that needs to be replaceable for the user ?
So I unzipped the .so file, and got many tiny files and the largest with size 80KB named ".text" - Is this is the original  liblame ? However I guess this would be a bit too obfuscated for a user.

Ian @ un4seen

  • Administrator
  • Posts: 22959
Re: BASS for Android
« Reply #1744 on: 10 Jun '20 - 17:55 »
No, the user would need to rebuild BASSenc_MP3 to change the libmp3lame code that's used. The BASSenc_MP3 source code is available here:

   www.un4seen.com/files/bassenc_mp3-source.zip

elan

  • Posts: 47
Re: BASS for Android
« Reply #1745 on: 11 Jun '20 - 10:30 »
We've noticed that when using AAudio, audio ducking doesn't seem to work properly (e.g. Maps will speak over the app audio without ducking it). When using OpenSL, it all works properly and the audio is ducked by the system. Is there anything additional needed when using AAudio to get system ducking to work? Thanks!

AAudio doesn't appear to have any functions for controlling that, so I would expect it to behave the same as the other output APIs. Checking with the BASS examples, they don't seem to be ducking when using any of AAudio/OpenSLES/AudioTrack :) ... Perhaps the AudioFocusRequest class needs to be used:

   https://developer.android.com/guide/topics/media-apps/audio-focus

Are you already using that in your app?

Ian, just following up on this:

- We tried low-latency mode and regular mode and neither do the auto-ducking one would expect with AAudio, as explained in the auto-ducking section of your link above.
- OpenSL does auto-ducking perfectly.
- We test by switching to Google Maps and starting a route and seeing if the voice ends up ducking the BASS output.
- We do have a focus listener setup, and if we call setWillPauseWhenDucked(true) we do get called when the system wants us to duck and we can take action there, as per the Android docs.
- However, it seems fairly odd that ducking doesn't work automatically, as that would appear to be the right and easy way.
- Random thought, any chance this has anything to do with AAUDIO_SHARING_MODE_SHARED vs exclusive mode?

Otherwise, just wondering if you have any other thoughts...

Ian @ un4seen

  • Administrator
  • Posts: 22959
Re: BASS for Android
« Reply #1746 on: 11 Jun '20 - 18:09 »
Logically speaking, ducking can't apply to exclusive mode, but BASS uses shared mode, so I don't think the ducking issue will be related to that. I can't find anything regarding ducking in the AAudio documentation, so it seems like there isn't anything special to configure for that. Did you try disabling AAudio's low-latency mode by setting BASS_CONFIG_ANDROID_AAUDIO to 2 before calling BASS_Init? Doesn't seem like that should affect ducking, but worth a try. Similarly, you could also try using the "Default (alarm)" and "Default (voice)" devices (number 2 and 3) in your BASS_Init call, and see if that makes any difference. Another random thing you could try is generating a session ID for BASS to use (before calling BASS_Init), like this:

Code: [Select]
AudioManager am = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
int sid = am.generateAudioSessionId();
BASS.BASS_SetConfig(BASS.BASS_CONFIG_ANDROID_SESSIONID, sid);

elan

  • Posts: 47
Re: BASS for Android
« Reply #1747 on: 12 Jun '20 - 02:07 »
Logically speaking, ducking can't apply to exclusive mode, but BASS uses shared mode, so I don't think the ducking issue will be related to that.

Thanks for the quick reply! I tried:

  • Low latency and normal modes (verified by logcat). Only difference was in volume level, no ducking.
  • Using devices 2 and 3. Lower sample rates on at least 3, but no ducking.
  • Generated an audio session and set it. No ducking.

For now we'll just move on and handle it manually, but I suspect there's something weird going on. Maybe others using AAudio can share their experiences.

saga

  • Posts: 2419
Re: BASS for Android
« Reply #1748 on: 25 Jun '20 - 08:58 »
I figured that if our app didn't request the RECORD_AUDIO permission, BASS_RecordStart returns 0 and BASS_ErrorGetCode() returns -1. Would it be technically possible to return a more specific error code so that we can e.g. remind the user that they denied the permission? Otherwise we'd have to do that with every unknown error when starting recording, which might be misleading.

Ian @ un4seen

  • Administrator
  • Posts: 22959
Re: BASS for Android
« Reply #1749 on: 25 Jun '20 - 16:58 »
The OpenSLES initialization is failing with a SL_RESULT_CONTENT_UNSUPPORTED error when permission is denied. That's on all of the devices I checked, which is promising for possible detection, but the name doesn't look like it's specific to permission issues, so I'm not sure if it can be reliably used to detect that. Probably best for the app to check its permissions itself.