Author Topic: BASS for Android  (Read 683779 times)

Ian @ un4seen

  • Administrator
  • Posts: 22959
Re: BASS for Android
« Reply #1700 on: 9 Mar '20 - 16:57 »
I tried using BASS_Start() instead of BASS_Init() but I'm still getting the same behavior. When I plug in the headphones, the audio stops briefly but it doesn't route to the headphones.

Ah, so the BASS output is still working but just not being rerouted? In that case, those log entries you posted seem a bit strange. Perhaps they're unrelated to BASS?

Does disabling AAudio low-latency mode (by setting BASS_CONFIG_ANDROID_AAUDIO to 2) make any difference?

Do you think the problem could be related to this?: https://github.com/google/oboe/blob/master/docs/notes/disconnect.md

Do you mean the "Workaround for not Disconnecting Properly" part? BASS does try to reinitialize the output when it receives an error callback from AAudio, but it doesn't do that workaround bit. That looks like something that would need to be implemented by the app (rather than BASS as a native library). The "onReceive" method could move the stream(s) to the "No Sound" device, reinitialize the real output device, and then move the streams back to that. Not ideal, but at least you won't need to recreate the streams.

JL

  • Guest
Re: BASS for Android
« Reply #1701 on: 10 Mar '20 - 18:29 »
Does disabling AAudio low-latency mode (by setting BASS_CONFIG_ANDROID_AAUDIO to 2) make any difference?

Setting BASS_CONFIG_ANDROID_AAUDIO to 2 does fix the problem. So it's definitely a problem with low-latency mode.

Do you mean the "Workaround for not Disconnecting Properly" part? BASS does try to reinitialize the output when it receives an error callback from AAudio, but it doesn't do that workaround bit. That looks like something that would need to be implemented by the app (rather than BASS as a native library)

This does look like something that may need to be fixed in app. If all else fails I could always provide a setting to disable low-latency mode.

The "onReceive" method could move the stream(s) to the "No Sound" device, reinitialize the real output device, and then move the streams back to that. Not ideal, but at least you won't need to recreate the streams.

Thanks for the advice, I'll give that a try and let you know how it goes!





Pedro Leonardo

  • Posts: 81
Re: BASS for Android
« Reply #1702 on: 14 Mar '20 - 15:25 »
Hi,
I'm having trouble sending my Android App. Use Delphi Rio 10.3.3. When I generate apk and send it directly to my device, it works well, but when I generate aab file and send it to Google Play and download it directly from the google store the app does not work. Freezes on the splash scren. Does anyone know which folders should I place the dlls? I use only libbass.so and libbass_aac.so. Should I deploy 32 and 64 bits in deployment? Do armeabi-v7a dlls work on 64 bits too?

Regards

teq

  • Posts: 61
Re: BASS for Android
« Reply #1703 on: 15 Mar '20 - 15:21 »
Hi there! I'm using bass with Unity and bass.net. Stream creation from bassfx streamfx docs.
With the latest bass for android, i faced with noticeable issues: little lag on play, which is freezes the ui, and click sound on pause. This happens while both stream and local file replays.
With old version(i don't know number, but v8a version libbass.so has 302kb size opposite to 310 in new one) it works fine.
Here is my init:
Code: [Select]
Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);
Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_NET_PREBUF_WAIT, false);


And another one moment regarding
BASS.BASS_SetConfig(BASS.BASS_CONFIG_ANDROID_AAUDIO, 1);
You said, that i should use (BASSInit)0x20000, but it can't be found here. I can only use "Bass.BASS_SetConfig((BASSConfig)0x20000, 0);", but BASSConfig enum does not contain 0x20000 value.


Bass.BASS_SetConfig((BASSConfig)0x20000, 0);
« Last Edit: 15 Mar '20 - 17:37 by teq »

jnyang

  • Guest
Re: BASS for Android
« Reply #1704 on: 16 Mar '20 - 13:13 »
Hi Ian,

I really appreciate your recent work that make BASS support ParcelFileDescriptor directly to align with the upcoming changes on Android (scoped storages).
However, I am facing the following problems right now...

1) It seems that BASS does not support the internal audio codecs when ParcelFileDescriptor is given instead of the original file path.
For example, when I try to play a FLAC file via the Android's internal FLAC codec, it outputs the following Logcat log:
Code: [Select]
E/ClearFileSource: Failed to open file '/storage/emulated/0/Musics/test.flac'. (Permission denied)
2) There is no BASS_StreamCreateFile function on each plugin (e.g., BASSFLAC, BASSOPUS, BASS_APE, etc.).

I tried to implement my own BASS_FILEPROCS that handles the ParcelFileDescriptor directly, but BASS still fails to employ the internal audio codecs.
Is there any way to solve this? Thanks in advance for your help! :)

MB_SOFT

  • Posts: 384
Re: BASS for Android
« Reply #1705 on: 16 Mar '20 - 13:31 »
my guess:

1) add android.permission.READ_EXTERNAL_STORAGE to your app

2) there is BASS_FLAC_StreamCreateFile but it's better to sue the plugin system works very well on Android as well

Ian @ un4seen

  • Administrator
  • Posts: 22959
Re: BASS for Android
« Reply #1706 on: 16 Mar '20 - 14:04 »
I'm having trouble sending my Android App. Use Delphi Rio 10.3.3. When I generate apk and send it directly to my device, it works well, but when I generate aab file and send it to Google Play and download it directly from the google store the app does not work. Freezes on the splash scren. Does anyone know which folders should I place the dlls? I use only libbass.so and libbass_aac.so. Should I deploy 32 and 64 bits in deployment? Do armeabi-v7a dlls work on 64 bits too?

I'm not familiar with Delphi, so I'm afraid I'm unable to advise on setting that up to use BASS, but if you open your AAB file in ZIP software, you should see a "lib" folder containing a subfolder for each supported architecture. Any libraries that you're using (including BASS) should be present in all of them.

armeabi-v7a libraries will indeed work on 64-bit devices too. They will be used if you leave out arm64-v8a libraries.

Hi there! I'm using bass with Unity and bass.net. Stream creation from bassfx streamfx docs.
With the latest bass for android, i faced with noticeable issues: little lag on play, which is freezes the ui, and click sound on pause. This happens while both stream and local file replays.
With old version(i don't know number, but v8a version libbass.so has 302kb size opposite to 310 in new one) it works fine.
Here is my init:
Code: [Select]
Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);
Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_NET_PREBUF_WAIT, false);

If the UI is freezing then that sounds like a call in the main thread is taking some time. Are you calling BASS_StreamCreateFile and/or BASS_ChannelPlay in the main thread? If so, which is the delay in? If you're unsure, please time them to confirm. In either case, I don't recall any recent changes in BASS that could make those calls take longer. Approximately how old was your previous BASS version? One difference may be that the old version didn't use AAudio. That shouldn't affect how long BASS_StreamCreateFile or BASS_ChannelPlay takes, but does disabling it prevent the problem anyway?

BASS.BASS_SetConfig(BASS.BASS_CONFIG_ANDROID_AAUDIO, 1);
You said, that i should use (BASSInit)0x20000, but it can't be found here. I can only use "Bass.BASS_SetConfig((BASSConfig)0x20000, 0);", but BASSConfig enum does not contain 0x20000 value.


Bass.BASS_SetConfig((BASSConfig)0x20000, 0);

BASS_CONFIG_ANDROID_AAUDIO is defined as 67. So to disable AAudio, you would do this (before calling BASS_Init):

Code: [Select]
Bass.BASS_SetConfig((BASSConfig)67, 0);

1) It seems that BASS does not support the internal audio codecs when ParcelFileDescriptor is given instead of the original file path.
For example, when I try to play a FLAC file via the Android's internal FLAC codec, it outputs the following Logcat log:
Code: [Select]
E/ClearFileSource: Failed to open file '/storage/emulated/0/Musics/test.flac'. (Permission denied)

Are BASS-supported file formats (eg. WAV or MP3) playing OK from the same storage? If not, please check that your app has the READ_EXTERNAL_STORAGE permission, as MB_SOFT mentioned. If that isn't the problem then I will look into it further.

Note it is generally better to use the BASS add-ons rather than Android's decoders whenever possible, eg. for better performance and tag support.

I tried to implement my own BASS_FILEPROCS that handles the ParcelFileDescriptor directly, but BASS still fails to employ the internal audio codecs.

Only Android's AAC decoder is currently supported when using BASS_StreamCreateFileUser, so using that won't be a solution in this case.

jnyang

  • Guest
Re: BASS for Android
« Reply #1707 on: 16 Mar '20 - 14:33 »
Are BASS-supported file formats (eg. WAV or MP3) playing OK from the same storage? If not, please check that your app has the READ_EXTERNAL_STORAGE permission, as MB_SOFT mentioned. If that isn't the problem then I will look into it further.

Note it is generally better to use the BASS add-ons rather than Android's decoders whenever possible, eg. for better performance and tag support.
Yes, there is the READ_EXTERNAL_STORAGE permission in the Android manifest and also permitted by the requestPermission function.

The BASS-supported file formats work, but the Android codec-based formats (e.g., WMA, FLAC) don't work with the "permission denied" error.
It seems that BASS tries to load the song from its raw file path, but there is no permission because Android does not allow the direct access to the files outside the scoped storage via the raw file paths.

Please note that I tested on Galaxy S10 running Android 10. Target SDK level is also set to 29.

Ian @ un4seen

  • Administrator
  • Posts: 22959
Re: BASS for Android
« Reply #1708 on: 18 Mar '20 - 13:52 »
Here's an update for you to try:

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

Let me know if you have any trouble with it. Besides fixing your problem (hopefully), it has also switched to using the Android codecs via the native API instead of the Java API to improve performance a bit. BASS has up to now been using the Java API because it works on Android 4.1, while the native API requires Android 5, but there can't be many people still using Android 4.x now? BASS will still work on those (and older) Android versions but Android's codecs won't be used on them.

jnyang

  • Guest
Re: BASS for Android
« Reply #1709 on: 18 Mar '20 - 17:08 »
Here's an update for you to try:

   www.un4seen.com/stuff/bass-android-test.zip
It works really well at the moment. Thank you for your quick fixes! :) I'll let you know if I find any issue from deeper tests on the other various devices and conditions.

BASS has up to now been using the Java API because it works on Android 4.1, while the native API requires Android 5, but there can't be many people still using Android 4.x now? BASS will still work on those (and older) Android versions but Android's codecs won't be used on them.
Recently, I've changed the minimum supported Android version of my projects (that both use and do not use BASS) from 4.1 to 5.0. It seems that many cross-platform tools have changed the requirements as well, e.g.,
- Qt (Android 5.0 or higher): https://doc.qt.io/qt-5/android.html; and
- Delphi (Android 5.1 or higher): http://docwiki.embarcadero.com/RADStudio/Rio/en/Android_Devices_Supported_for_Application_Development.

Ian @ un4seen

  • Administrator
  • Posts: 22959
Re: BASS for Android
« Reply #1710 on: 20 Mar '20 - 16:29 »
The Android version of the BASSmix 2.4.10 release is up now in the 1st post.

max_xt

  • Posts: 8
Re: BASS for Android
« Reply #1711 on: 5 Apr '20 - 09:45 »
BASS_SetVolume is not working on last versions of bass, isn't it? Is it related with AAUDIO or something? I tried BASS_ChannelSetAttribute(streamHandle, BASS_ATTRIB_VOL, volume) but is not the same.

mix1009

  • Posts: 10
Re: BASS for Android
« Reply #1712 on: 6 Apr '20 - 13:17 »
Hello I'm trying to play files from dropbox using

int chan = BASS.BASS_StreamCreateURL(url, 0, flags, StatusProc, 0);

Url's from netradio example works fine. But when I use (temporary) links from dropbox, function returns 0.

When I check BASS_ErrorGetCode() it returns 10. (I don't think the error code is documented).

dropbox links looks like below, and I've used other methods to download file and it works fine within the same android app.

https://dl.dropboxusercontent.com/apitl/1/AXcwQjtYlWgRSPsFqA9K1bU9nsuyXiu9cxFiYgq6jXuy2H5sj8IjSdETqAcY93gro3mR8kAaqcteUMAg1r_JUkfiRHdRlJXmPwppL5nr_noxCPqmWP72Dqmwq1rJRUs77rxbFBPhEf6sshxT0wmjiC9iEMuAgHpLncEcRefGwQ0LBMsvRQdfqtKiaw7cjLsQOllM0C3D9FLZzlUFzWzXq3_c-FBGAYoNw1rSnZug4y2UAG8wBFbmtFxahorIwA45v5-pDLqOwBdetPJ1S0tjdp2MCqhaL1R0X73iVlfB__3K3qdYsYD7oDLfamEd8AkjTgVUdxHfqWZ75Jn-xhd3tvrJu9K6rGNQPru3jcsIhAWZaA

I also tried URLDecoder.decode(url) but that also didn't work.

Ian @ un4seen

  • Administrator
  • Posts: 22959
Re: BASS for Android
« Reply #1713 on: 6 Apr '20 - 14:44 »
BASS_SetVolume is not working on last versions of bass, isn't it? Is it related with AAUDIO or something? I tried BASS_ChannelSetAttribute(streamHandle, BASS_ATTRIB_VOL, volume) but is not the same.

Yes, AAudio doesn't have volume control. BASS_SetVolume is actually meant to adjust the device's volume level (not just the app's volume level), but it is allowing the app's volume level to be set when using OpenSLES or AudioTrack output on Android, so perhaps it should emulate that for AAudio too.

Another way to adjust the app's volume level is via the BASS_CONFIG_GVOL_STREAM/SAMPLE/MUSIC options. Please see the documentation for details on them.

Hello I'm trying to play files from dropbox using

int chan = BASS.BASS_StreamCreateURL(url, 0, flags, StatusProc, 0);

Url's from netradio example works fine. But when I use (temporary) links from dropbox, function returns 0.

When I check BASS_ErrorGetCode() it returns 10. (I don't think the error code is documented).

Error code 10 is BASS_ERROR_SSL, which means SSL/HTTPS support isn't available. BASS will use the system's SSL library when possible (when the app targets Android 7 or lower), otherwise you will need the BASS_SSL add-on from the 1st post.

JL

  • Posts: 4
Re: BASS for Android
« Reply #1714 on: 7 May '20 - 18:43 »
I tried using BASS_Start() instead of BASS_Init() but I'm still getting the same behavior. When I plug in the headphones, the audio stops briefly but it doesn't route to the headphones.

Ah, so the BASS output is still working but just not being rerouted? In that case, those log entries you posted seem a bit strange. Perhaps they're unrelated to BASS?

Does disabling AAudio low-latency mode (by setting BASS_CONFIG_ANDROID_AAUDIO to 2) make any difference?

Do you think the problem could be related to this?: https://github.com/google/oboe/blob/master/docs/notes/disconnect.md

Do you mean the "Workaround for not Disconnecting Properly" part? BASS does try to reinitialize the output when it receives an error callback from AAudio, but it doesn't do that workaround bit. That looks like something that would need to be implemented by the app (rather than BASS as a native library). The "onReceive" method could move the stream(s) to the "No Sound" device, reinitialize the real output device, and then move the streams back to that. Not ideal, but at least you won't need to recreate the streams.

I finally got around to trying this and this is the code I run when the headphones are plugged in or out:

Code: [Select]
BASS_ChannelSetDevice(stream, BASS_NODEVICE)
BASS_Free()
BASS_Init(1, 44100, 0)
BASS_ChannelSetDevice(stream, 1)
BASS_ChannelPlay(stream, false)

I'm having some problems though... The first line, BASS_ChannelSetDevice(stream, BASS_NODEVICE), fails with BASS_ERROR_NOTAVAIL.
I'm assuming BASS_NODEVICE is not available on Android?

So I tried BASS_ChannelSetDevice(stream, 0) but that fails with BASS_ERROR_INIT.
I'm a bit confused though because if I change the first line to BASS_ChannelSetDevice(stream, 1) it fails with BASS_ERROR_ALREADY.

I checked the code and BASS_Free() is definitely not being called before this point. Any ideas?

Ian @ un4seen

  • Administrator
  • Posts: 22959
Re: BASS for Android
« Reply #1715 on: 8 May '20 - 13:48 »
I'm having some problems though... The first line, BASS_ChannelSetDevice(stream, BASS_NODEVICE), fails with BASS_ERROR_NOTAVAIL.
I'm assuming BASS_NODEVICE is not available on Android?

BASS_NODEVICE can only be used with "decoding channels" (BASS_STREAM_DECODE set).

So I tried BASS_ChannelSetDevice(stream, 0) but that fails with BASS_ERROR_INIT.

You need to initialize device 0 (via BASS_Init) before you can move streams to it. Then you could modify your code above like this:

Code: [Select]
BASS_ChannelSetDevice(stream, 0)
if (BASS_SetDevice(1)) // set device for BASS_Free
BASS_Free()
BASS_Init(1, 44100, 0)
BASS_ChannelSetDevice(stream, 1)

I'm a bit confused though because if I change the first line to BASS_ChannelSetDevice(stream, 1) it fails with BASS_ERROR_ALREADY.

BASS_ERROR_ALREADY indicates that the stream is already on device 1. Note a description of each error code can be found in the failing function's documentation.

The BASS_ERROR_ALREADY error code is fairly pointless in this case, so for the next BASS release, BASS_ChannelSetDevice (and BASS_ChannelPause/SetLink) has been changed to just report success instead. That won't make any real difference, but if you would like to have it, you can get the latest build with the change here:

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

JL

  • Posts: 4
Re: BASS for Android
« Reply #1716 on: 8 May '20 - 21:15 »
You need to initialize device 0 (via BASS_Init) before you can move streams to it. Then you could modify your code above like this:

Code: [Select]
BASS_ChannelSetDevice(stream, 0)
if (BASS_SetDevice(1)) // set device for BASS_Free
BASS_Free()
BASS_Init(1, 44100, 0)
BASS_ChannelSetDevice(stream, 1)

That worked perfectly! Tested it on some phones that were having issues and it's now working as it should.
If anyone else is having AAudio (Low-latency mode) problems when connecting/disconnecting headphones, this will fix it.
If it helps, I'm calling the above code in onAudioDevicesAdded() and onAudioDevicesRemoved() using the Android AudioManager.

BASS_ERROR_ALREADY indicates that the stream is already on device 1. Note a description of each error code can be found in the failing function's documentation.

The BASS_ERROR_ALREADY error code is fairly pointless in this case, so for the next BASS release, BASS_ChannelSetDevice (and BASS_ChannelPause/SetLink) has been changed to just report success instead. That won't make any real difference, but if you would like to have it, you can get the latest build with the change here:

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

I should have realised that I needed to init device 0 before moving streams to that device. My mistake. Thank you for the clarification on the errors.

Anyway, thanks again for your help Ian, really chuffed the headphone issue is solved :)

JL

  • Posts: 4
Re: BASS for Android
« Reply #1717 on: 10 May '20 - 22:14 »
Anyway, thanks again for your help Ian, really chuffed the headphone issue is solved :)

So the headphone issue is solved but during my testing this weekend I found another related issue :(

My app was losing audio when I moved to other apps and then returned to my app again. I couldn't reproduce this consistently but by turning on Android 10's "Live Caption" mode, I experience the same behavior.
If I have my app open and then turn this on, the audio stops working.

I would apply the same fix as I did to solve the headphone issue but I don't know of a way to listen for this event (I'm assuming it's some sort of audio routing change), so I can't re-initialize BASS when this happens.
However, as with the headphone issue, if I disable AAudio low-latency mode, then it works as expected.

Here is the log when turning the "Live Caption" mode on while my app is running without setting the BASS_CONFIG_ANDROID_AAUDIO flag:

Code: [Select]
D/AudioStreamInternal_Client: onEventFromServer - got AAUDIO_SERVICE_EVENT_STOPPED
W/AudioStreamInternal_Client: onEventFromServer - AAUDIO_SERVICE_EVENT_DISCONNECTED - FIFO cleared
D/AudioStreamInternalPlay_Client: callbackLoop() exiting, result = -899, isActive() = 0 <<<<<<<<<<<<<<
I/AAudio: AAudioStreamBuilder_openStream() called ----------------------------------------
I/AudioStreamBuilder: rate   =      0, channels  = 0, format   = 0, sharing = SH, dir = OUTPUT
I/AudioStreamBuilder: device =      0, sessionId = -1, perfMode = 12, callback: ON with frames = 0
I/AudioStreamBuilder: usage  =      1, contentType = 0, inputPreset = 0, allowedCapturePolicy = 0
D/AudioStreamInternal_Client: open() original HW burst = 96, minMicros = 2000 => SW burst = 96
I/AAudio: AAudioStreamBuilder_openStream() returns 0 = AAUDIO_OK for s#3 ----------------
D/AAudio: AAudioStream_close(s#3) called ---------------
D/AAudio: AAudioStream_close(s#3) returned 0 ---------
I/AAudio: AAudioStreamBuilder_openStream() called ----------------------------------------
I/AudioStreamBuilder: rate   =      0, channels  = 0, format   = 0, sharing = SH, dir = OUTPUT
I/AudioStreamBuilder: device =      0, sessionId = -1, perfMode = 12, callback: ON with frames = 480
I/AudioStreamBuilder: usage  =      1, contentType = 0, inputPreset = 0, allowedCapturePolicy = 0
D/AudioStreamInternal_Client: open() original HW burst = 96, minMicros = 2000 => SW burst = 96
I/AAudio: AAudioStreamBuilder_openStream() returns 0 = AAUDIO_OK for s#4 ----------------
D/AAudio: AAudioStream_requestStop(s#2) called
D/IsochronousClockModel: stop(nanos = 754449056560) max lateness = 2000 micros
E/AAudioStream: setState(2) tried to set to 9 but already DISCONNECTED
D/AAudio: AAudioStream_close(s#2) called ---------------
E/AAudioStream: joinThread() - but has no thread
E/AAudioStream: setState(2) tried to set to 11 but already DISCONNECTED
D/AAudio: AAudioStream_close(s#2) returned 0 ---------
D/AAudio: AAudioStream_requestStart(s#4) called --------------
D/AAudio: AAudioStream_requestStart(s#4) returned -898 ---------

This was the same sort of log I was seeing when plugging in headphones.

Here is the log when turning the "Live Caption" mode on and BASS_CONFIG_ANDROID_AAUDIO is set to 2 (This works):

Code: [Select]
W/AudioTrack: restoreTrack_l(205): dead IAudioTrack, PCM, creating a new one from obtainBuffer()
D/AudioStreamLegacy: processCallbackCommon() stream disconnected
W/AudioStreamLegacy: processCallbackCommon() data, stream disconnected
E/AudioTrack: processAudioBuffer(217): EVENT_MORE_DATA requested 3840 bytes but callback returned -1 bytes
I/AAudio: AAudioStreamBuilder_openStream() called ----------------------------------------
I/AudioStreamBuilder: rate   =      0, channels  = 0, format   = 0, sharing = SH, dir = OUTPUT
I/AudioStreamBuilder: device =      0, sessionId = -1, perfMode = 10, callback: ON with frames = 0
I/AudioStreamBuilder: usage  =      1, contentType = 0, inputPreset = 0, allowedCapturePolicy = 0
D/AudioStreamBuilder: build() MMAP not available because AAUDIO_PERFORMANCE_MODE_LOW_LATENCY not used.
D/AudioStreamTrack: open(), request notificationFrames = 0, frameCount = 0
W/AudioStreamTrack: open() sampleRate changed from 0 to 48000
I/AAudio: AAudioStreamBuilder_openStream() returns 0 = AAUDIO_OK for s#3 ----------------
D/AAudio: AAudioStream_close(s#3) called ---------------
D/AAudio: AAudioStream_close(s#3) returned 0 ---------
I/AAudio: AAudioStreamBuilder_openStream() called ----------------------------------------
I/AudioStreamBuilder: rate   =      0, channels  = 0, format   = 0, sharing = SH, dir = OUTPUT
I/AudioStreamBuilder: device =      0, sessionId = -1, perfMode = 10, callback: ON with frames = 480
I/AudioStreamBuilder: usage  =      1, contentType = 0, inputPreset = 0, allowedCapturePolicy = 0
D/AudioStreamBuilder: build() MMAP not available because AAUDIO_PERFORMANCE_MODE_LOW_LATENCY not used.
D/AudioStreamTrack: open(), request notificationFrames = 480, frameCount = 1920
W/AudioStreamTrack: open() sampleRate changed from 0 to 48000
I/AAudio: AAudioStreamBuilder_openStream() returns 0 = AAUDIO_OK for s#4 ----------------
D/AAudio: AAudioStream_requestStop(s#2) called
E/AAudioStream: setState(2) tried to set to 9 but already DISCONNECTED
D/AudioTrack: stop(217): called with 532320 frames delivered
D/AAudio: AAudioStream_close(s#2) called ---------------
D/AAudio: AAudioStream_close(s#2) returned 0 ---------
D/AAudio: AAudioStream_requestStart(s#4) called --------------
D/AAudio: AAudioStream_requestStart(s#4) returned 0 ---------
D/AudioStreamLegacy: onAudioDeviceUpdate() devId 3 => 3

I tested a few devices and I lost audio on a Pixel 2, Pixel 2XL and Pixel 3 when low-latency was enabled. I think the common denominator is that they all use AAudio's MMAP, so this is likely to affect some other phone brands as well.

After this happens, BASS_MIDI_StreamEvents() still gives a BASS_OK when I call BASS_ErrorGetCode(), so I'm not sure if there's another way to see from BASS that there is a problem?

At this point it might be easier to just turn off low-latency mode but ideally I'd like to use it. Any ideas?
« Last Edit: 10 May '20 - 22:31 by JL »

Ian @ un4seen

  • Administrator
  • Posts: 22959
Re: BASS for Android
« Reply #1718 on: 11 May '20 - 13:34 »
That worked perfectly! Tested it on some phones that were having issues and it's now working as it should.
If anyone else is having AAudio (Low-latency mode) problems when connecting/disconnecting headphones, this will fix it.
If it helps, I'm calling the above code in onAudioDevicesAdded() and onAudioDevicesRemoved() using the Android AudioManager.

Good to hear that you've got it working now. Out of interest, can you try setting a BASS_SYNC_DEV_FAIL sync on the stream (via BASS_ChannelSetSync) and then see if that gets called, and when it gets called in relation to the onAudioDevicesAdded and onAudioDevicesRemoved calls? The onAudioDevicesAdded and onAudioDevicesRemoved functions should do nothing while checking that, so that they don't affect the sync call.

After this happens, BASS_MIDI_StreamEvents() still gives a BASS_OK when I call BASS_ErrorGetCode(), so I'm not sure if there's another way to see from BASS that there is a problem?

Yes, BASS_MIDI_StreamEvents will be unaffected by whether or not the stream is playing. The event will be heard when the stream resumes if it's currently stopped.

Please see if a BASS_SYNC_DEV_FAIL sync gets called in this case too.

JL

  • Posts: 4
Re: BASS for Android
« Reply #1719 on: 11 May '20 - 22:58 »
Good to hear that you've got it working now. Out of interest, can you try setting a BASS_SYNC_DEV_FAIL sync on the stream (via BASS_ChannelSetSync) and then see if that gets called, and when it gets called in relation to the onAudioDevicesAdded and onAudioDevicesRemoved calls? The onAudioDevicesAdded and onAudioDevicesRemoved functions should do nothing while checking that, so that they don't affect the sync call.

Yes, BASS_MIDI_StreamEvents will be unaffected by whether or not the stream is playing. The event will be heard when the stream resumes if it's currently stopped.

Please see if a BASS_SYNC_DEV_FAIL sync gets called in this case too.

I tried the BASS_SYNC_DEV_FAIL flag like this:

Code: [Select]
BASS_ChannelSetSync(stream, BASS_SYNC_DEV_FAIL or BASS_SYNC_MIXTIME, 0, proc, null)
But I didn't get a callback when plugging/unplugging headphones or when activating "Live Caption".

Some other things I have found:

When I open a fresh instance of the app with "Live Caption" on, there is no sound from the beginning.

If I play some BASS_MIDI_StreamEvents (There is no sound at this point), then background and resume the app, there's a short burst of sound before the audio stops working again. It sounds as if the notes I played while there was no audio were buffered and then play out at the same time when I resume the app. The curious thing is that I'm only getting this burst of sound every second time I resume the app.

I'm calling BASS_Start() in onResume() and if I don't call BASS_Start(), then I don't get this burst of audio.

Ian @ un4seen

  • Administrator
  • Posts: 22959
Re: BASS for Android
« Reply #1720 on: 12 May '20 - 15:13 »
I will send you a debug BASS version to get more information.

Tyler Durden

  • Guest
Re: BASS for Android
« Reply #1721 on: 17 May '20 - 09:06 »
Hi. Is it possible to cut part of the track with crossfade in the beginning and end, add eq and save at as another mp3? If it is possible, then may you give some resources to read about it?

Ian @ un4seen

  • Administrator
  • Posts: 22959
Re: BASS for Android
« Reply #1722 on: 18 May '20 - 16:40 »
You can use the BASSmix add-on for the mixing/crossfading part, and the BASSenc add-on (with BASSenc_MP3 for MP3) for the file writing part. Here's some example code:

   www.un4seen.com/forum/?topic=13508.msg94274#msg94274

For the EQ, you can use the BASS_FX_DX8_PARAMEQ or BASS_FX_BFX_PEAKEQ effect on the mixer via BASS_ChannelSetFX. BASS_FX_BFX_PEAKEQ will also require the BASS_FX add-on. You can use the forum's search option to find example code for each effect. For example, here:

   www.un4seen.com/forum/?topic=18629.msg130560#msg130560

Ryota

  • Posts: 25
Re: BASS for Android
« Reply #1723 on: 27 May '20 - 06:12 »
Hi Ian and JOBnik,

I'm using BASS_FX 2.4.12.2 beta for Android app development.

When I use BASS_FX_BFX_DISTORTION, there is no sound.

Is there any solution?

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);

Regards,
Ryota.

Ian @ un4seen

  • Administrator
  • Posts: 22959
Re: BASS for Android
« Reply #1724 on: 27 May '20 - 13:57 »
There is a newer BASS_FX beta (2.4.12.3) available here:

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

If the problem happens with that too, do you get sound if you leave the default parameters, ie. don't call BASS_FXSetParameters? Are you only having the problem on Android, ie. you've successfully tried the same on other platform(s)?