Author Topic: BASS for Android  (Read 645150 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: 22170
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: 22170
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: 22170
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: 22170
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: 8
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: 22170
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: 22170
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.

Ryota

  • Posts: 20
Re: BASS for Android
« Reply #1587 on: 20 May '19 - 09:12 »
Hi Ian and JOBnik,

When I use BASS_FX_BFX_ECHO4, the app crash occurred.

Is there any solution?

Here is the code excerpted.

Code: [Select]
mFxEcho = BASS.BASS_ChannelSetFX(sStream, BASS_FX.BASS_FX_BFX_ECHO4, 2);
echo = new BASS_FX.BASS_BFX_ECHO4();
echo.fDryMix = 0.95f;
echo.fWetMix = 0.1f;
echo.fFeedback = 0.55f;
echo.fDelay = 0.4f;
echo.bStereo = TRUE;
echo.lChannel = BASS_FX.BASS_BFX_CHANALL;
BASS.BASS_FXSetParameters(mFxEcho, echo);

And here is the error log.

Code: [Select]
java_vm_ext.cc:542] JNI DETECTED ERROR IN APPLICATION: attempt to access field boolean com.un4seen.bass.BASS_FX$BASS_BFX_ECHO4.bStereo of type boolean with the wrong type int: 0xe150e98c
    java_vm_ext.cc:542]     in call to GetIntField
    java_vm_ext.cc:542]     from boolean com.un4seen.bass.BASS.BASS_FXSetParameters(int, java.lang.Object)
    java_vm_ext.cc:542] "main" prio=5 tid=1 Runnable
    java_vm_ext.cc:542]   | group="main" sCount=0 dsCount=0 flags=0 obj=0x7421cee0 self=0xe4b5f000
    java_vm_ext.cc:542]   | sysTid=3359 nice=-4 cgrp=default sched=0/0 handle=0xe97d7494
    java_vm_ext.cc:542]   | state=R schedstat=( 5518793483 476951570 2865 ) utm=383 stm=168 core=1 HZ=100
    java_vm_ext.cc:542]   | stack=0xff1f9000-0xff1fb000 stackSize=8MB
    java_vm_ext.cc:542]   | held mutexes= "mutator lock"(shared held)

Regards,
Ryota.

Ian @ un4seen

  • Administrator
  • Posts: 22170
Re: BASS for Android
« Reply #1588 on: 21 May '19 - 16:18 »
There is indeed a little JNI issue in the BASS_BFX_ECHO4.bStereo parameter handling. A BASS_FX update to fix that will hopefully be available shortly.

(: JOBnik! :)

  • Posts: 1080
Re: BASS for Android
« Reply #1589 on: 30 May '19 - 21:57 »

Ryota

  • Posts: 20
Re: BASS for Android
« Reply #1590 on: 2 Jun '19 - 04:08 »
Hi Ian and JOBnik,

The new version of BASS_FX works perfectly.

Thank you for fixing :)

Newbie4Ever

  • Guest
Re: BASS for Android
« Reply #1591 on: 4 Jun '19 - 13:10 »
Hello, I'd like to know if it is possible to balance sound using this library, if not, do you know a way to do it using AudioTrack?

I need that feature in order to provide accessibility on an app.

Thanks in  advance

Ian @ un4seen

  • Administrator
  • Posts: 22170
Re: BASS for Android
« Reply #1592 on: 4 Jun '19 - 16:13 »
Do you mean you want to adjust the left/right balance of the output, and if so, do you mean for the entire system, not just the app that's using BASS? It is possible for a BASS-based app to adjust the balance of its own output (via BASS_ATTRIB_PAN) but that won't affect other apps.

hexise

  • Posts: 8
Re: BASS for Android
« Reply #1593 on: 24 Jun '19 - 06:43 »
Hi Ian,

I found a music file with 3F1R channels, when I play it using BASS and earphones, right earphone has much louder sound than left earphone, left earphone is nearly muted, which is a bad stereo sound. Android native players do not have this issue. Is there any special configuration to play multi-channel music files?

The test file is as following:

https://drive.google.com/open?id=1NaAIV6Ff08z8wfAEjjKPMhe9lGbT175F

The media info for the source file:

Code: [Select]
General
CompleteName                     : E:\Music\Examples\Test\You're A No Good.m4a
Format/String                    : MPEG-4
Format_Profile                   : Apple audio with iTunes info
CodecID/String                   : M4A  (isom/iso2)
FileSize/String                  : 162 KiB
Duration/String                  : 10 s 43 ms
OverallBitRate_Mode/String       : Constant
OverallBitRate/String            : 132 kb/s
Album                            : Scientist Rids The World Of The Evil Curse Of The Vampires
Track                            : You're A No Good
Track/Position                   : 2
Performer                        : Scientist
Recorded_Date                    : 1981
Encoded_Application/String       : Lavf58.20.100
Comment                          : Greensleeves Rec.

Audio
ID/String                        : 1
Format/String                    : AAC LC
Format/Info                      : Advanced Audio Codec Low Complexity
CodecID                          : mp4a-40-2
Duration/String                  : 10 s 43 ms
Duration_LastFrame/String        : -5 ms
BitRate_Mode/String              : Constant
BitRate/String                   : 132 kb/s
Channel(s)/String                : 4 channels
ChannelLayout                    : C L R Cb
SamplingRate/String              : 48.0 kHz
FrameRate/String                 : 46.875 FPS (1024 SPF)
Compression_Mode/String          : Lossy
StreamSize/String                : 159 KiB (98%)
Default/String                   : Yes
AlternateGroup/String            : 1

My minimal code to reproduce the problem:

Code: [Select]
if (!BASS.BASS_Init(-1, 44100, 0)) {
    throw new IllegalStateException("Cannot initialize device with error code: " + BASS.BASS_ErrorGetCode());
} else {
    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/You're A No Good.m4a";
int chan = BASS.BASS_StreamCreateFile(path, 0, 0, 0);
BASS.BASS_ChannelPlay(chan, false);

Thank you!
« Last Edit: 24 Jun '19 - 07:13 by hexise »

Ian @ un4seen

  • Administrator
  • Posts: 22170
Re: BASS for Android
« Reply #1594 on: 24 Jun '19 - 16:31 »
The issue there is that BASS (and the BASS_AAC add-on) assumes that 4 channel output will be 2F2R, so the channels end up in the wrong order (AAC/MP4 puts the center channel first when it's present). Unless the output device supports multi-channel (unlikely on Android), it's a good idea to use the BASS_AAC_STEREO flag to have BASS_AAC downmix to stereo. Unfortunately, that flag can only be used with the BASS_AAC stream creation functions, eg. BASS_MP4_StreamCreateFile rather than BASS_StreamCreateFile. I will look into adding a config option to automatically apply the STEREO flag.

For comparison, what happens if you don't load the BASS_AAC add-on (via BASS_PlugnLoad), to let the OS's AAC/MP4 codec handle the file instead?

hexise

  • Posts: 8
Re: BASS for Android
« Reply #1595 on: 24 Jun '19 - 17:57 »
The issue there is that BASS (and the BASS_AAC add-on) assumes that 4 channel output will be 2F2R, so the channels end up in the wrong order (AAC/MP4 puts the center channel first when it's present). Unless the output device supports multi-channel (unlikely on Android), it's a good idea to use the BASS_AAC_STEREO flag to have BASS_AAC downmix to stereo. Unfortunately, that flag can only be used with the BASS_AAC stream creation functions, eg. BASS_MP4_StreamCreateFile rather than BASS_StreamCreateFile. I will look into adding a config option to automatically apply the STEREO flag.

For comparison, what happens if you don't load the BASS_AAC add-on (via BASS_PlugnLoad), to let the OS's AAC/MP4 codec handle the file instead?

I removed libbass_aac.so and now it works well. Is it safe to do so? Will OS's AAC/MP4 codec always work with BASS? My app is based on Android 5.0 and above.

I know that currently BASS can use OS's MP3 codec. But Android system official support many other formats such as FLAC, OPUS, etc. Should I use BASS codec or OS native codec for these formats? What are the differences? Thank you!

Ian @ un4seen

  • Administrator
  • Posts: 22170
Re: BASS for Android
« Reply #1596 on: 24 Jun '19 - 18:21 »
Good to hear that it's working well with the OS's AAC/MP4 decoder. Out of interest, how many channels does the created stream have? You can check that with BASS_ChannelGetInfo.

Using the OS's codecs requires Android 4.1, so you should be fine with Android 5.0 and above. BASS includes built-in support for MP4 tags, so you shouldn't miss out on much by using the OS's AAC/MP4 decoder instead of BASS_AAC (doing that also avoids the need for AAC patent licensing). BASS doesn't include support for FLAC or OPUS tags though, so I would still use the BASSFLAC and BASSOPUS add-ons for those formats.

gicci

  • Posts: 67
Re: BASS for Android
« Reply #1597 on: 24 Jun '19 - 19:00 »
Hi Ian,

I have seen that it has been already reported in the other thread, but BassFX is missing the x86_64 library. This causes all Bass to fail if the x86_64 version is included, as the versions cannot be mixed.

hexise

  • Posts: 8
Re: BASS for Android
« Reply #1598 on: 24 Jun '19 - 19:44 »
Hi Ian,

I have seen that it has been already reported in the other thread, but BassFX is missing the x86_64 library. This causes all Bass to fail if the x86_64 version is included, as the versions cannot be mixed.

I found there is the beta version of BassFx which contains x86_64 support:

http://jobnik.org/BASS_FX/beta/

hexise

  • Posts: 8
Re: BASS for Android
« Reply #1599 on: 25 Jun '19 - 17:22 »
Good to hear that it's working well with the OS's AAC/MP4 decoder. Out of interest, how many channels does the created stream have? You can check that with BASS_ChannelGetInfo.

Using the OS's codecs requires Android 4.1, so you should be fine with Android 5.0 and above. BASS includes built-in support for MP4 tags, so you shouldn't miss out on much by using the OS's AAC/MP4 decoder instead of BASS_AAC (doing that also avoids the need for AAC patent licensing). BASS doesn't include support for FLAC or OPUS tags though, so I would still use the BASSFLAC and BASSOPUS add-ons for those formats.

The created stream using OS decoder has 4 channels for the testing(3F1R) file.

Code: [Select]
info = {BASS$BASS_CHANNELINFO@14195}
chans = 4
ctype = 65545
filename = null
flags = 2097408
freq = 48000
origres = 0
plugin = 0
sample = 0
shadow$_klass_ = {Class@12540} "class com.un4seen.bass.BASS$BASS_CHANNELINFO"
shadow$_monitor_ = 0
« Last Edit: 28 Jun '19 - 07:14 by hexise »