Author Topic: BASS for Android  (Read 556471 times)

Alex K

  • Guest
Re: BASS for Android
« Reply #1575 on: 8 Apr '19 - 08:37 »
I was able to reproduce this bug.
First we play file using phone speaker.
Then we connect to Bluetooth headset.
BASS_SYNC_DEV_FAIL sync will be called.
Calling BASS_Start() doesn't help.
But calling BASS_Free() and then BASS_Init() helps.
As expected to continue playback we need to reopen file using BASS_StreamCreateFile();

It will be great if you will be able to overcome this issue.

Thank you, Ian!

Ian @ un4seen

  • Administrator
  • Posts: 21731
Re: BASS for Android
« Reply #1576 on: 8 Apr '19 - 15:18 »
I will send you a debug version to find out what the internal error code from AAudio is.

hexise

  • Guest
Re: BASS for Android
« Reply #1577 on: 14 Apr '19 - 08:53 »
Hello, Ian,

I am new to this library. I have developed an Android player which can play many audio formats using BASS without problem, except MIDI currently.

I am using latest BASS library from 1st post in this thread, with libbassmidi.so. I am using following code to play a new music file, when playing the ape file, there is no problem, when playing the mid file, there is no sound. When I switched to the BASS_MIDI_StreamCreateFile, the result is the same.

Code: [Select]
BASS.BASS_Init(-1, 44100, 0);
String nativePath = getApplicationInfo().nativeLibraryDir;
String[] plugins = new File(nativePath).list();
for (String plugin : plugins) {
     if (!"libbass.so".equals(plugin))
         BASS.BASS_PluginLoad(nativePath + "/" + plugin, 0);
}

String path = "/storage/emulated/0/Music/MIDI/EverQuest.mid";
// String path = "/storage/emulated/0/Music/APE/Adiemus.ape";
int chan = BASS.BASS_StreamCreateFile(path, 0, 0, BASS.BASS_SAMPLE_FLOAT);
// int chan = BASSMIDI.BASS_MIDI_StreamCreateFile(path, 0, 0, 0, 1);
BASS.BASS_ChannelPlay(chan , false);

I am trying to encode the midi file to flac using BASSenc_FLAC.BASS_Encode_FLAC_StartFile() method, the result flac file has no sound.

Currently I can make this work while removing libbassmidi.so from native libraries. Then midi music can be played, it seems using Android native decoder, but sometimes it takes more than 3000ms to play(it only takes 30ms for ape file), which may cause ANR(Application Not Responding) problems.

I still want to use libbassmidi.so, since it is much faster than Android native one while loading. What is the problem of my code? Please advice.

I am using following midi file for testing, if you need more information, please let me know.

https://drive.google.com/file/d/1KKpuxA-TrL-k9R8qHbMtPaVzvtYGAoB3/view

Thank you!


hexise

  • Guest
Re: BASS for Android
« Reply #1578 on: 14 Apr '19 - 09:03 »
Hello, Ian,

I have another question. Currently my app is using 4 FX effects: BASS_FX_BFX_VOLUME, BASS_FX_BFX_PEAKEQ, BASS_FX_BFX_DAMP, BASS_FX_BFX_FREEVERB.

What is the suggested sequence(priority) for them? Currently my priorities from high to low is BASS_FX_BFX_PEAKEQ > BASS_FX_BFX_DAMP > BASS_FX_BFX_VOLUME > BASS_FX_BFX_FREEVERB, EQ will be applied first and freeverb will be applied last. I am also considering to move DAMP and VOLUME to the front of EQ.

Please give me some advice, thanks!

Ian @ un4seen

  • Administrator
  • Posts: 21731
Re: BASS for Android
« Reply #1579 on: 15 Apr '19 - 13:10 »
I am new to this library. I have developed an Android player which can play many audio formats using BASS without problem, except MIDI currently.

I am using latest BASS library from 1st post in this thread, with libbassmidi.so. I am using following code to play a new music file, when playing the ape file, there is no problem, when playing the mid file, there is no sound. When I switched to the BASS_MIDI_StreamCreateFile, the result is the same.

Code: [Select]
BASS.BASS_Init(-1, 44100, 0);
String nativePath = getApplicationInfo().nativeLibraryDir;
String[] plugins = new File(nativePath).list();
for (String plugin : plugins) {
     if (!"libbass.so".equals(plugin))
         BASS.BASS_PluginLoad(nativePath + "/" + plugin, 0);
}

String path = "/storage/emulated/0/Music/MIDI/EverQuest.mid";
// String path = "/storage/emulated/0/Music/APE/Adiemus.ape";
int chan = BASS.BASS_StreamCreateFile(path, 0, 0, BASS.BASS_SAMPLE_FLOAT);
// int chan = BASSMIDI.BASS_MIDI_StreamCreateFile(path, 0, 0, 0, 1);
BASS.BASS_ChannelPlay(chan , false);

An SF2 soundfont (or SFZ) is needed to provide the instrument sounds for BASSMIDI to play. If you don't already have one, a couple are available from the BASS webpage (next to the BASSMIDI download). If you will be using a single soundfont in your app, you can activate it by setting the BASS_CONFIG_MIDI_DEFFONT option to its path via BASS_SetConfigPtr. BASS_MIDI_FontInit and BASS_MIDI_StreamSetFonts can be used for more complex soundfont arrangements.

I have another question. Currently my app is using 4 FX effects: BASS_FX_BFX_VOLUME, BASS_FX_BFX_PEAKEQ, BASS_FX_BFX_DAMP, BASS_FX_BFX_FREEVERB.

What is the suggested sequence(priority) for them? Currently my priorities from high to low is BASS_FX_BFX_PEAKEQ > BASS_FX_BFX_DAMP > BASS_FX_BFX_VOLUME > BASS_FX_BFX_FREEVERB, EQ will be applied first and freeverb will be applied last. I am also considering to move DAMP and VOLUME to the front of EQ.

I would suggest removing the BASS_FX_BFX_VOLUME effect and use BASS_ATTRIB_VOL (via BASS_ChannelSetAttribute) instead. For the other 3 effects, you could try playing around with them and see what sounds best to you. I think I would probably try BASS_FX_BFX_PEAKEQ > BASS_FX_BFX_FREEVERB > BASS_FX_BFX_DAMP first.

hexise

  • Guest
Re: BASS for Android
« Reply #1580 on: 15 Apr '19 - 16:28 »

An SF2 soundfont (or SFZ) is needed to provide the instrument sounds for BASSMIDI to play. If you don't already have one, a couple are available from the BASS webpage (next to the BASSMIDI download). If you will be using a single soundfont in your app, you can activate it by setting the BASS_CONFIG_MIDI_DEFFONT option to its path via BASS_SetConfigPtr. BASS_MIDI_FontInit and BASS_MIDI_StreamSetFonts can be used for more complex soundfont arrangements.


Thanks very much for your reply. It really helps a lot.

I found that the sf2 files are too large for my android app, even the smallest sf2 file need more than 1MB which will increase my app size a lot. Since midi support is not the key value to my app, I will remove libbassmidi.so from my app. The midi files still can be played, is it using the native android decoder? Thanks.

Ian @ un4seen

  • Administrator
  • Posts: 21731
Re: BASS for Android
« Reply #1581 on: 15 Apr '19 - 16:58 »
Yes, BASS would be using Android's MIDI decoder then. You can confirm that with the stream's "ctype" value (being BASS_CTYPE_STREAM_AM), which you can get from BASS_ChannelGetInfo.

hexise

  • Guest
Re: BASS for Android
« Reply #1582 on: 15 Apr '19 - 17:31 »
Yes, BASS would be using Android's MIDI decoder then. You can confirm that with the stream's "ctype" value (being BASS_CTYPE_STREAM_AM), which you can get from BASS_ChannelGetInfo.

Sorry to bother you again.

If I use Android MIDI decoder, BASS.BASS_StreamCreateFile() method for mid files will sometimes cost more than 3000ms, other formats like mp3 and ape do not have this long loading time. Do you know why this cost so long? Is there any solution to reduce the loading time? Currently I am using another thread to prepare song before play. Thanks.

Ian @ un4seen

  • Administrator
  • Posts: 21731
Re: BASS for Android
« Reply #1583 on: 16 Apr '19 - 14:47 »
I don't think all devices support MIDI, so that delay could be device specific. Do you get the same delay with all MIDI files on all devices and Android versions? Also check the BASS_TAG_AM_MIME and BASS_TAG_AM_NAME tags with BASS_ChannelGetTags.

hexise

  • Posts: 1
Re: BASS for Android
« Reply #1584 on: 19 Apr '19 - 15:58 »
Hello, Ian,

You are correct that there are some devices does not support midi format, even android has mentioned midi in the official supported audio format, my user with Honor 5X mentioned that midi is not supported on his device.
https://developer.android.com/guide/topics/media/media-formats

I have another question, is there a way to check the min and max sample rate supported by Android device?

Currently I am using following code to check whether the sample rate is supported by device, and when I tested it on Galaxy S10, 192KHz is supported but 384KHz is failed.

Code: [Select]
boolean supported = AudioTrack.getMinBufferSize(sampleRate, AudioFormat.CHANNEL_OUT_STEREO, AudioFormat.ENCODING_PCM_FLOAT) > 0;
I tried to use following code to get min and max supported sample rate, but minrate and maxrate always be 0, this method seems not working for this scenario.

Code: [Select]
BASS.BASS_INFO info = new BASS.BASS_INFO();
BASS.BASS_GetInfo(info);

So is there a way in BASS to check the min and max sample rate supported by Android device? Or AudioTrack.getMinBufferSize() method is the correct way? Please advice, thanks!
« Last Edit: 19 Apr '19 - 16:19 by hexise »

Ian @ un4seen

  • Administrator
  • Posts: 21731
Re: BASS for Android
« Reply #1585 on: 22 Apr '19 - 17:08 »
I think the success of AudioTrack.getMinBufferSize will just tell you whether Android is able to handle the sample rate rather than whether the device actually supports the rate, ie. Android can convert the sample data to the device's rate. You can get the native sample rate from the AudioManager.PROPERTY_OUTPUT_SAMPLE_RATE property. I don't think it's possible to change the native sample rate, except perhaps when using exclusive mode with the new AAudio API (I haven't checked to confirm that).

Note Android's support or not of a sample rate won't affect playback through BASS, which supports conversion to/from pretty much any sample rate.

The BASS_INFO minrate/maxrate values are only available when using DirectSound output on Windows.

Ian @ un4seen

  • Administrator
  • Posts: 21731
Re: BASS for Android
« Reply #1586 on: 8 May '19 - 13:30 »
A BASSmix update is up in the 1st post, to fix an envelope processing bug that was introduced in 2.4.9.8.