Author Topic: BASS for Android  (Read 830636 times)

sg

  • Posts: 4
Re: BASS for Android
« Reply #1925 on: 20 Jan '23 - 19:56 »
Hi,
what would be the best option to load (user selected) soundfonts on Android?

I use the ACTION_OPEN_DOCUMENT Intent to let the user select the soundfont.
As a result I get an Uri object from which I can retrieve a ParcelFileDescriptor object.

Is there any way to convert this Uri / ParcelFileDescriptor into a parameter that is compatible with the available BASS_MIDI_FontInit methods?


(I don't want to copy the whole soundfont into the app's storage.
This is my current temporary solution, because I have direct access to the file and file name there, but isn't perfect for very large soundfonts.
And loading it through a ByteBuffer results in an OutOfMemoryError for larger files)


Thanks!

Ian @ un4seen

  • Administrator
  • Posts: 26079
Re: BASS for Android
« Reply #1926 on: 23 Jan '23 - 16:32 »
When you don't have a filename to give, you can use BASS_MIDI_FontInitUser with BASS_FILEPROCS callback functions instead of BASS_MIDI_FontInit to load a soundfont. BASSMIDI will call your functions to get the file data as needed then.

sg

  • Posts: 4
Re: BASS for Android
« Reply #1927 on: 23 Jan '23 - 20:43 »
Ok thanks, I will try that!

sg

  • Posts: 4
Re: BASS for Android
« Reply #1928 on: 23 Jan '23 - 21:48 »
It seems that I am not able to implement the callback function FILESEEKPROC because InputStreams which I can open from URIs do not support seeking.

Apparently the only option to load user selected soundfonts is to copy them into a new file (in the app's storage), which is not perfect, but it works.

(If I'm wrong or there are other ways, feel free to share them, thanks!)

Ian @ un4seen

  • Administrator
  • Posts: 26079
Re: BASS for Android
« Reply #1929 on: 24 Jan '23 - 13:49 »
If you use a FileInputStream instead of InputStream then you should be able to seek via the getChannel().position method.

Looking at BASS_MIDI_FontInit again now, I think it should actually already support ParcelFileDescriptor, but the BASSMIDI.JAVA file doesn't contain the required overload yet. Please try adding this line to that file:

Code: [Select]
public static native int BASS_MIDI_FontInit(ParcelFileDescriptor file, int flags);

Also "import android.os.ParcelFileDescriptor;" at the top. And then try using your ParcelFileDescriptor with BASS_MIDI_FontInit.

sg

  • Posts: 4
Re: BASS for Android
« Reply #1930 on: 24 Jan '23 - 19:58 »
Thanks a lot for the info and help,
this works and is the best solution for my implementation!

Ian @ un4seen

  • Administrator
  • Posts: 26079
Re: BASS for Android
« Reply #1931 on: 25 Jan '23 - 13:17 »
Good to hear the BASSMIDI.JAVA update got things working for you. I have now put an updated BASSMIDI.JAVA file in the Android BASSMIDI package. Note a ParcelFileDescriptor overload is also available for BASS_MIDI_StreamCreateFile.

gicci

  • Posts: 117
Re: BASS for Android
« Reply #1932 on: 31 Jan '23 - 13:28 »
It seems that I am not able to implement the callback function FILESEEKPROC because InputStreams which I can open from URIs do not support seeking.

Apparently the only option to load user selected soundfonts is to copy them into a new file (in the app's storage), which is not perfect, but it works.

(If I'm wrong or there are other ways, feel free to share them, thanks!)

It seems that Ian solved your problem, but anyway I was able to implement a BASS_FILEPROCS that reads from a file the user selected with SAF. You should have done something like this:
Code: [Select]
        ContentResolver resolver = getApplication().getContentResolver();
        ParcelFileDescriptor parcelFileDescriptor = resolver.openFileDescriptor(document.getUri(), "r");
        fileDescriptor = parcelFileDescriptor.getFileDescriptor();
        FileChannel channel = new FileInputStream(fileDescriptor).getChannel();
You can then use the FileChannel to read the data and on it the position() operation should work. Be sure to store the fileDescriptor in a variable of the object to retain it: if it gets garbage collected the channel will be closed.

The difficult thing is to open a SFZ file because you need to fix the paths, but also this can be done.

teq

  • Posts: 80
Re: BASS for Android
« Reply #1933 on: 18 Feb '23 - 14:06 »
Hi there!
I use Unity with BASS and it works ok, except some cases usually with Samsung devices.
Recently received a message from user that he switched his device to Galaxy a53 and "All tracks crackle and pop while playing visibly in the app gui interface.  Soon as I minimize the app it starts playing perfectly smooth".
I don't have Samsung device yet so maybe there are some suggestions how to solve this?
I suspect hat i should offer audio output methods in the settings(OpenSL, AudioTrack, AAduio).
Currently i use default behavior.
« Last Edit: 22 Feb '23 - 12:07 by teq »

Ian @ un4seen

  • Administrator
  • Posts: 26079
Re: BASS for Android
« Reply #1934 on: 20 Feb '23 - 11:29 »
Do you know what Android version the device is running? It looks like the official latest is Android 8.0, which means OpenSLES would be the default output system used but AAudio may also be available. If you can send a test version of your app to the user, please try setting the BASS_CONFIG_ANDROID_AAUDIO option to 1 before calling BASS_Init to enable AAudio, and if that doesn't help, also try raising the BASS_CONFIG_DEV_BUFFER setting (again before BASS_Init).

teq

  • Posts: 80
Re: BASS for Android
« Reply #1935 on: 22 Feb '23 - 12:07 »
Do you know what Android version the device is running? It looks like the official latest is Android 8.0, which means OpenSLES would be the default output system used but AAudio may also be available. If you can send a test version of your app to the user, please try setting the BASS_CONFIG_ANDROID_AAUDIO option to 1 before calling BASS_Init to enable AAudio, and if that doesn't help, also try raising the BASS_CONFIG_DEV_BUFFER setting (again before BASS_Init).
Thanks for the feedback! Sorry, it was a typo, not Galaxy A5, it was Samsung Galaxy A53 5G with Android 13.
Can i change output method or BASS_CONFIG_DEV_BUFFER after BASS_Init, so if user would like to change this option several times for finding the best sound?
« Last Edit: 22 Feb '23 - 12:25 by teq »

Ian @ un4seen

  • Administrator
  • Posts: 26079
Re: BASS for Android
« Reply #1936 on: 22 Feb '23 - 13:50 »
You will need to call BASS_Init again to apply the changes, but you can use the BASS_DEVICE_REINIT flag when doing so, to retain the existing channels/handles. You can also toggle the BASS_DEVICE_AUDIOTRACK flag that way, to enable/disable using AudioTrack output instead of AAudio or OpenSLES.

hexise

  • Posts: 9
Re: BASS for Android
« Reply #1937 on: 31 Jan '24 - 23:40 »
Hello,

I found a new problem when a user reported a file which my app cannot support.

It is a voicemail wav file, and after I test it, I found the encoding is PCM MU-LAW. Does BASS support this encoding?

I have tested that Android default music player can support this encoding. Am I missing any add-on to support it? If BASS does not support it, will it handover to Android to play it?

Currently from my testing, the format is not supported and when use BASS to parse the file, it throws BASS_ERROR_FORMAT error.

Thanks.

Ian @ un4seen

  • Administrator
  • Posts: 26079
Re: BASS for Android
« Reply #1938 on: 1 Feb '24 - 17:13 »
BASS doesn't have built-in support for mu-law, but it may be supported via the OS's codecs, eg. it is on Windows. Checking an mu-law WAV file on Android just now, it is detected as "g711-mlaw" by Android's media codecs but then they fail to parse/decode the data. Android's list of supported formats only mentions linear PCM, so it may be that mu-law isn't supported:

   https://developer.android.com/media/platform/supported-formats

OnePeople

  • Guest
Re: BASS for Android
« Reply #1939 on: 24 Sep '24 - 10:53 »
Hi.
How play file in AudioManager.STREAM_RING?

Ian @ un4seen

  • Administrator
  • Posts: 26079
Re: BASS for Android
« Reply #1940 on: 26 Sep '24 - 13:12 »
BASS doesn't currently include an option for STREAM_RING output. I believe that's intended for ringtones, so not really applicable?