Author Topic: BASS for Android  (Read 634195 times)

gicci

  • Posts: 67
Re: BASS for Android
« Reply #1550 on: 12 Mar '19 - 16:28 »
I will try to investigate a bit more, and I am not sure if it was introduced yesterday or not, I was still using the test version you sent me. If you want please send the link to a version you want to be tested and I can check if the problem was already there.
Consider that I am using the MIDI channel in decode mode and feeding it into a mixer, it could be that the issue is due to this configuration.

Ian @ un4seen

  • Administrator
  • Posts: 22121
Re: BASS for Android
« Reply #1551 on: 13 Mar '19 - 14:03 »
The Android version of the BASSHLS 2.4.2 release is up now in the 1st post.

gicci

  • Posts: 67
Re: BASS for Android
« Reply #1552 on: 16 Mar '19 - 11:19 »
Hi Ian,

so I repeated my testing, and I can confirm that after changing the playback position the audio on the MIDI file stops playing. Sync events and all the rest continues to work properly. It is quite difficult for me to modify the example code to behave exactly as mine, I would keep this as a last resort.

I have attached anyway a log of all the calls I am performing until the problem happens. At the timestamp "11:56:29.383" I changed the play position on the player but after that no sound is heard.
The channel [-2147483641] is the decoding MIDI file, [-2147483644] is the mixer which outputs it.

Let me know if you need me to perform some other testing.

Ian @ un4seen

  • Administrator
  • Posts: 22121
Re: BASS for Android
« Reply #1553 on: 19 Mar '19 - 18:00 »
OK. Please also try logging the number of active voices by calling BASS_ChannelGetAttribute with BASS_ATTRIB_MIDI_VOICES_ACTIVE on the MIDI stream. If that's 0 then also try setting a MIDIFILTERPROC callback on the MIDI stream (via BASS_MIDI_StreamSetFilter) and see if that's still getting called when you have no sound. Also, does it make a difference what position you seek to? Does it happen even with pos=0, or if you use BASS_POS_BYTE instead of BASS_POS_TICK?

gicci

  • Posts: 67
Re: BASS for Android
« Reply #1554 on: 19 Mar '19 - 23:10 »
I have added the BASS_ChannelGetAttribute call for BASS_ATTRIB_MIDI_VOICES_ACTIVE in the note sync proc of the MIDI, both with the old and new libraries, and attached the logs. In both cases I see the value of playing notes, but in the new library no sound is heard after seek. The result does not change with the seek position, it happens also with 0.
I have tested also replacing the set position call of the MIDI channel with BASS_Mixer_ChannelSetPosition using BASS_POS_BYTE always to 0, but the result is the same.

Ian @ un4seen

  • Administrator
  • Posts: 22121
Re: BASS for Android
« Reply #1555 on: 20 Mar '19 - 12:31 »
That looks the MIDI stream is still playing samples then, but you don't hear them for some reason. To narrow down where the problem is, please try attaching WAV writers to both the MIDI stream and mixer after seeking, and then check whether the 2 WAV files contain sound or silence. You can use the BASSenc add-on to do that, like this:

Code: [Select]
BASSenc.BASS_Encode_Start(midi, "/sdcard/midi.wav", BASSenc.BASS_ENCODE_PCM | BASSenc.BASS_ENCODE_AUTOFREE, null, null);
BASSenc.BASS_Encode_Start(mixer, "/sdcard/mixer.wav", BASSenc.BASS_ENCODE_PCM | BASSenc.BASS_ENCODE_AUTOFREE, null, null);

Make sure your app has the WRITE_EXTERNAL_STORAGE permission.

gicci

  • Posts: 67
Re: BASS for Android
« Reply #1556 on: 21 Mar '19 - 20:42 »
The midi.wav contains music, mixer.wav is instead silent.

Ian @ un4seen

  • Administrator
  • Posts: 22121
Re: BASS for Android
« Reply #1557 on: 22 Mar '19 - 13:01 »
When the problem began, had you updated the BASSmix library too or only BASS? If you did update BASSmix too, what happens if you put back the old BASSmix but keep the latest BASS?

gicci

  • Posts: 67
Re: BASS for Android
« Reply #1558 on: 22 Mar '19 - 20:52 »
I always update everything together.
Reverting only the BASSmix library to the version I was using before, it works properly.
At least we understood where the problem is located  ;D

rafal.haly

  • Guest
Re: BASS for Android
« Reply #1559 on: 25 Mar '19 - 08:41 »
Hi Ian
We are using Bass Audio Library for Xamarin.Android type of project.
For decoding playback stream we are using method Bass.BASS_StreamCreateFileUser because our source stream is encrypted.
We have noticed that during playback some file bass.pcm is created in external storage when method
Bass.BASS_ChannelPlay(stream, restart) is invoked.
We are also using bass_fx to change tempo of playback.
I guess its some temporary file for some kind of convertion of streams, but this file keeps growing up to GB's.

I've created gist to illustrate the problem and to give you more details.
https://gist.github.com/rhaly/7fb802430656975d5fcb3a73bb449a19

Can you have a look maybe it is something wrong in our configuration or we are setting wrong flag somewhere.
I will be grateful for your help.

Ian @ un4seen

  • Administrator
  • Posts: 22121
Re: BASS for Android
« Reply #1560 on: 25 Mar '19 - 12:39 »
I always update everything together.
Reverting only the BASSmix library to the version I was using before, it works properly.
At least we understood where the problem is located  ;D

I don't seem to be able to reproduce the problem here, so I will send you a debug BASSmix version to get some more info on what's happening there.

We are using Bass Audio Library for Xamarin.Android type of project.
For decoding playback stream we are using method Bass.BASS_StreamCreateFileUser because our source stream is encrypted.
We have noticed that during playback some file bass.pcm is created in external storage when method

That sounds like you may have a debug BASS version. Perhaps I sent it to you previously to look into a problem, and it has accidentally been included in a release of your app? Please download the latest release from the first post and see if you still get the bass.pcm file written with that.

Ian @ un4seen

  • Administrator
  • Posts: 22121
Re: BASS for Android
« Reply #1561 on: 28 Mar '19 - 12:54 »
There was a bug in the recent BASSmix 2.4.9.8 update that could result in a mixer source being muted after calling BASS_Mixer_ChannelSetPosition on it. Another update (2.4.9.9) is up now in the 1st post to fix that. The 2.4.9.8 update was only posted for Android and iOS, so other platforms are unaffected.

RevG

  • Posts: 457
Re: BASS for Android
« Reply #1562 on: 3 Apr '19 - 21:54 »
Hi Ian,

It's been a long time, I hope you are doing well :) I have decided to play around with BASS for Android that last few days.

I have found a bug I wanted to report. I have an audio file that will consistently crackle while playing it using BASS. It does not crackle when playing it through the standard Android MediaPlayer. I have only been able to reproduce this problem on my Samsung Galaxy S8 running Android 9.0. This bug does not occur on my Google Pixel or Google Nexus devices. Also, strangely, this crackling does not occur in all mp3 files either. It doesn't sound like a buffering issue, but I adjusted the BASS_CONFIG_DEV_BUFFER and BASS_CONFIG_DEV_PERIOD anyway and also hard reset my device but none of this fixed the issue. Do you have any idea what may be causing this?

Here is the code I am using and the file I am playing
http://cubesol.com/Files/clouds.mp3

Code: [Select]
@Override
 protected void onCreate(Bundle savedInstanceState) {

        if(!BASS.BASS_Init(-1, 44100, 0)){
            Log.d("@@@", "onCreate: error initializing bass");
        }

       int hAudioStream = BASS.BASS_StreamCreateFile(new BASS.Asset(getAssets(), "clouds.mp3"), 0, 0, 0);
       BASS.BASS_ChannelPlay(hAudioStream, false);
}

kenumir

  • Posts: 18
Re: BASS for Android
« Reply #1563 on: 4 Apr '19 - 07:06 »
Exception when start play local file:

Code: [Select]
java.lang.IllegalStateException        at android.media.MediaCodec.native_flush(MediaCodec.java:-2)
        at android.media.MediaCodec.flush(MediaCodec.java:1948)
        at com.un4seen.bass.BASS.BASS_StreamCreateFileUser(BASS.java:-2)

Device: HTC Desire 820
Android: 6.0.1
Abi: arm64-v8a

Exception comes from production app, logged into exception handler system.

Alex K

  • Guest
Re: BASS for Android
« Reply #1564 on: 4 Apr '19 - 10:09 »
Hi Ian,

It's been a long time, I hope you are doing well :) I have decided to play around with BASS for Android that last few days.

I have found a bug I wanted to report. I have an audio file that will consistently crackle while playing it using BASS. It does not crackle when playing it through the standard Android MediaPlayer. I have only been able to reproduce this problem on my Samsung Galaxy S8 running Android 9.0. This bug does not occur on my Google Pixel or Google Nexus devices. Also, strangely, this crackling does not occur in all mp3 files either. It doesn't sound like a buffering issue, but I adjusted the BASS_CONFIG_DEV_BUFFER and BASS_CONFIG_DEV_PERIOD anyway and also hard reset my device but none of this fixed the issue. Do you have any idea what may be causing this?

Hi Ian,
I have the same issue on the same Samsung Galaxy S8 running Android 9.0.
I can solve it by by initializing BASS this way:
BASS.BASS_Init(-1, 44100, BASS.BASS_DEVICE_AUDIOTRACK)
but it involves several other issues on other phones.

Thank you.

Ian @ un4seen

  • Administrator
  • Posts: 22121
Re: BASS for Android
« Reply #1565 on: 4 Apr '19 - 15:19 »
Hi Ian,

It's been a long time, I hope you are doing well :) I have decided to play around with BASS for Android that last few days.

I have found a bug I wanted to report. I have an audio file that will consistently crackle while playing it using BASS. It does not crackle when playing it through the standard Android MediaPlayer. I have only been able to reproduce this problem on my Samsung Galaxy S8 running Android 9.0. This bug does not occur on my Google Pixel or Google Nexus devices. Also, strangely, this crackling does not occur in all mp3 files either. It doesn't sound like a buffering issue, but I adjusted the BASS_CONFIG_DEV_BUFFER and BASS_CONFIG_DEV_PERIOD anyway and also hard reset my device but none of this fixed the issue. Do you have any idea what may be causing this?

Hi Ian,
I have the same issue on the same Samsung Galaxy S8 running Android 9.0.
I can solve it by by initializing BASS this way:
BASS.BASS_Init(-1, 44100, BASS.BASS_DEVICE_AUDIOTRACK)
but it involves several other issues on other phones.

Thank you.

Perhaps AAudio will work better on that device. Here's an update for both of you to try:

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

It adds support for using AAudio instead of OpenSLES when available (on Android 8 and above). That will eventually be the default (after more testing), but for now it can be enabled like this (before calling BASS_Init):

Code: [Select]
BASS.BASS_SetConfig(67, 1); // enable AAudio

Let me know if you still get the crackles (or any other problems) happening with that.

Exception when start play local file:

Code: [Select]
java.lang.IllegalStateException        at android.media.MediaCodec.native_flush(MediaCodec.java:-2)
        at android.media.MediaCodec.flush(MediaCodec.java:1948)
        at com.un4seen.bass.BASS.BASS_StreamCreateFileUser(BASS.java:-2)

Device: HTC Desire 820
Android: 6.0.1
Abi: arm64-v8a

Exception comes from production app, logged into exception handler system.

The update above contains a little change that will hopefully help. Please give it a try and let me know if the problem still happens.

RevG

  • Posts: 457
Re: BASS for Android
« Reply #1566 on: 4 Apr '19 - 16:18 »
Quote
Perhaps AAudio will work better on that device. Here's an update for both of you to try:

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

It adds support for using AAudio instead of OpenSLES when available (on Android 8 and above). That will eventually be the default (after more testing), but for now it can be enabled like this (before calling BASS_Init):

Code: [Select]
BASS.BASS_SetConfig(67, 1); // enable AAudio

Let me know if you still get the crackles (or any other problems) happening with that.

I have updated the libs from the zip you provided and used BASS.BASS_SetConfig(67, 1); before calling BASS.BASS_Init, however I am still experiencing the crackling and pops.

I tried, as Alex K had mentioned, adding the BASS.BASS_DEVICE_AUDIOTRACK flag and that fixed the crackling issue for me too although Alex said there are some other issues that come along with that (not sure what he meant).

Thanks,
Greg

Ian @ un4seen

  • Administrator
  • Posts: 22121
Re: BASS for Android
« Reply #1567 on: 4 Apr '19 - 17:40 »
There doesn't appear to be anything special about your MP3 file (eg. no corruption), so I'm not sure why that would be affected and not others. Perhaps the problem is just less noticeable with other files?

Just to be sure that the BASS update is being used, please check that the BASS_SetConfig call is returning true.

One thing the BASS_DEVICE_AUDIOTRACK flag usually does is enlarge the device buffer. If you compare the "latency" values from BASS_GetInfo with and without the BASS_DEVICE_AUDIOTRACK flag, what do you see? How high did you go when you tried changing the BASS_CONFIG_DEV_BUFFER setting?

You could also try playing the same file on the same device with the VLC app when its "Audio output" option is set to "OpenSL ES" and see if that's affected too.

RevG

  • Posts: 457
Re: BASS for Android
« Reply #1568 on: 4 Apr '19 - 18:12 »
I tried setting the BASS_CONFIG_DEV_BUFFER to 500ms with the old libs and the crackling still occurs.

Without BASS_DEVICE_AUDIOTRACK flag latency is 35ms
With BASS_DEVICE_AUDIOTRACK flag latency is 85ms

However, I discovered that if I use the new libs with the code below AND set  BASS_CONFIG_DEV_BUFFER to a number >= 100ms then the crackling problem is solved.
Code: [Select]
BASS.BASS_SetConfig(67, 1); // enable AAudio

Alex K

  • Guest
Re: BASS for Android
« Reply #1569 on: 5 Apr '19 - 07:56 »
Thank you, Ian.
Updated lib plus next line
BASS.BASS_SetConfig(67, 1); // enable AAudio
fixes crackling issue!
By the way, for the long time I use
DEV_BUFFER_LENGTH = 90;

But still have issue (that exists for a long time) when BASS sound is quieter than Android MediaPlayer sound.
I had this issue on Samsung Galaxy S8 with Android 8 and with Android 9.
If you will have chance to test it - please test on different audio files with headset and through phone speaker.

Concerning issues with BASS.BASS_DEVICE_AUDIOTRACK:
Bluetooth playback control, stutters, play button blinking and unexpected stops.
I never had this issues on any of my phones but several customers reported them.
Most possible that they may be specific to app code and will never exist in other apps.

Thank you again!

Alex K

  • Guest
Re: BASS for Android
« Reply #1570 on: 5 Apr '19 - 10:20 »
The miracle happens!
When I change
BASS.BASS_SetConfig(BASS.BASS_CONFIG_DEV_BUFFER, 90);
to
BASS.BASS_SetConfig(BASS.BASS_CONFIG_DEV_BUFFER, 100);

Sound volume became as loud as with Android MediaPlayer.
I recompiled and tested 3 times.

So now there is no need to use BASS.BASS_DEVICE_AUDIOTRACK.
BASS works great without it.

Thank you, Ian!

Ian @ un4seen

  • Administrator
  • Posts: 22121
Re: BASS for Android
« Reply #1571 on: 5 Apr '19 - 13:34 »
I tried setting the BASS_CONFIG_DEV_BUFFER to 500ms with the old libs and the crackling still occurs.

Without BASS_DEVICE_AUDIOTRACK flag latency is 35ms
With BASS_DEVICE_AUDIOTRACK flag latency is 85ms

However, I discovered that if I use the new libs with the code below AND set  BASS_CONFIG_DEV_BUFFER to a number >= 100ms then the crackling problem is solved.
Code: [Select]
BASS.BASS_SetConfig(67, 1); // enable AAudio

Interesting. The update enables low latency mode for AAudio below 100ms, and OpenSL ES enables it automatically whenever possible, so it looks like the problem is related to that. I'll send you a debug version to get more info.

The miracle happens!
When I change
BASS.BASS_SetConfig(BASS.BASS_CONFIG_DEV_BUFFER, 90);
to
BASS.BASS_SetConfig(BASS.BASS_CONFIG_DEV_BUFFER, 100);

Sound volume became as loud as with Android MediaPlayer.
I recompiled and tested 3 times.

Low latency mode bypasses system effects processing, so it looks like it is those effects that are boosting the level on that device.

In light of this, I think the BASS_CONFIG_DEV_BUFFER threshold for enabling low latency AAudio should probably be reduced and/or an option to totally disable it. I'll look into that.

Alex K

  • Guest
Re: BASS for Android
« Reply #1572 on: 5 Apr '19 - 15:55 »
With new BASS lib and new settings I found that
sound can stop playing.

It happened 2 times.
Not sure is it related to it or no but both times it happened after some period of inactivity.
No sound was from the phone and playback position didn't move.
Only rebooting helped (maybe reinitialization of BASS would also help but I don't have this in my app).

Unfortunately I can't reproduce it anymore.

Ian @ un4seen

  • Administrator
  • Posts: 22121
Re: BASS for Android
« Reply #1573 on: 5 Apr '19 - 16:30 »
AAudio includes a new failure callback system, which will make BASS stop the output. Perhaps that's getting triggered. To find out, please try setting a BASS_SYNC_DEV_FAIL sync on your stream and see if that gets called. If it does, you could then try calling BASS_Start and see if that gets it going again. Otherwise, you will probably need to reinitialize the output, ie. call BASS_Free and BASS_Init again.

Alex K

  • Guest
Re: BASS for Android
« Reply #1574 on: 7 Apr '19 - 07:47 »
AAudio includes a new failure callback system, which will make BASS stop the output. Perhaps that's getting triggered. To find out, please try setting a BASS_SYNC_DEV_FAIL sync on your stream and see if that gets called. If it does, you could then try calling BASS_Start and see if that gets it going again. Otherwise, you will probably need to reinitialize the output, ie. call BASS_Free and BASS_Init again.

Unfortunately this bug never happened since that time.
But if they will - I will try your advice.
Thank you, Ian.