Author Topic: BASS for Android  (Read 478747 times)

Ian @ un4seen

  • Administrator
  • Posts: 21358
Re: BASS for Android
« Reply #1325 on: 19 Oct '17 - 16:11 »
A BASS update that adds support for using AudioTrack output (instead of OpenSL ES) is up now in the 1st post. See the post for details.

otherside

  • Posts: 35
Re: BASS for Android
« Reply #1326 on: 22 Oct '17 - 10:47 »

Ian @ un4seen

  • Administrator
  • Posts: 21358
Re: BASS for Android
« Reply #1327 on: 7 Nov '17 - 14:52 »
The Android version of the new BASSenc_FLAC add-on is now up in the 1st post.

dieppa

  • Posts: 33
Re: BASS for Android
« Reply #1328 on: 28 Nov '17 - 11:04 »
Hi. I am trying to play songs but it always returns 0 to the channel. Can someone tell me what am I doing wrong? Thanks!

int channel =222;
BASS.BASS_MusicFree(channel);
                BASS.BASS_StreamFree(channel);


                channel = BASS.BASS_StreamCreateFile(choosedSong, 0, 0, BASS.BASS_SAMPLE_LOOP);
                channel = BASS.BASS_MusicLoad(choosedSong, 0, 0, BASS.BASS_SAMPLE_LOOP | BASS.BASS_MUSIC_RAMP, 1);
                BASS.BASS_ChannelPlay(channel, false);

Edit:

I forgot to initialize the device  8) 8) 8) 8)
« Last Edit: 28 Nov '17 - 12:02 by dieppa »

dieppa

  • Posts: 33
Re: BASS for Android
« Reply #1329 on: 29 Nov '17 - 09:52 »
Hello, is there a way to set Bass boost and gain levels using FX? Thanks in advance.

Ian @ un4seen

  • Administrator
  • Posts: 21358
Re: BASS for Android
« Reply #1330 on: 30 Nov '17 - 14:02 »
You can use the BASS_FX_DX8_PARAMEQ effect via BASS_ChannelSetFX to apply a bass boost. For example, something like this:

Code: [Select]
int bboostfx = BASS.BASS_ChannelSetFX(channel, BASS.BASS_FX_DX8_PARAMEQ, 0); // set an EQ effect on a BASS channel
BASS.BASS_DX8_PARAMEQ param = new BASS.BASS_DX8_PARAMEQ();
param.fCenter = 100;
param.fBandwidth = 12;
param.fGain = 6;
BASS.BASS_FXSetParamters(bboostfx, param); // apply the parameters

You can play around with the parameters to find something that you like.

The BASS_ATTRIB_VOL option can be used (via BASS_ChannelSetAttribute) to control overall level, but it currently doesn't allow amplification with standard playback (it does with a mixer). For that, you can use the BASS_FX add-on's BASS_FX_BFX_VOLUME effect, again via BASS_ChannelSetFX. For example:

Code: [Select]
int volfx = BASS.BASS_ChannelSetFX(channel, BASS_FX.BASS_FX_BFX_VOLUME, 0);
BASS_FX.BASS_BFX_VOLUME param = new BASS_FX.BASS_BFX_VOLUME();
param.lChannel = 0;
param.fVolume = Math.pow(10.0, gaindb / 20.0);
BASS.BASS_FXSetParameters(volfx, param);

Note that the BASS_FX library needs to loaded before you can use its effects. You can force it to be loaded by calling a function from it, eg. BASS_FX_GetVersion during initialization.

dejan

  • Guest
Re: BASS for Android
« Reply #1331 on: 19 Dec '17 - 13:11 »
Is there a Bass support for playing MOD/IT/XM on Android?

Ian @ un4seen

  • Administrator
  • Posts: 21358
Re: BASS for Android
« Reply #1332 on: 19 Dec '17 - 17:16 »
Yes, the BASS library includes built-in support for those file formats. You would use the BASS_MusicLoad function to load them. Please see the BASS_MusicLoad documentation for details.

Ian @ un4seen

  • Administrator
  • Posts: 21358
Re: BASS for Android
« Reply #1333 on: 19 Dec '17 - 18:10 »
The Android version of the new BASS 2.4.13 release is up in the 1st post.

gicci

  • Posts: 48
Re: BASS for Android
« Reply #1334 on: 20 Dec '17 - 09:32 »
In August 2019 we will be forced to include the 64 bit version of the native libraries when publishing on Google Play (see https://android-developers.googleblog.com/2017/12/improving-app-security-and-performance.html). It seems a lot of time, but preparing ahead will help in troubleshooting possible problems and give better performance already now. Will it be possible to have 64 bit versions of the BASS libraries included in the Android release? Thank you for the excellent work.

dejan

  • Guest
Re: BASS for Android
« Reply #1335 on: 20 Dec '17 - 15:48 »
I have tried using BASS.BASS_MusicLoad() to play any MOD/IT/XM file, unfortunately it does not work, I am using new Android Studio 3.0.
I have tried all three method variants of MusicLoad(), file, asset, bytebuffer that is -- file and asset just do not work while passing the song bytebuffer actually crashes the app.

Is there any available example of doing it on Android?

Ian @ un4seen

  • Administrator
  • Posts: 21358
Re: BASS for Android
« Reply #1336 on: 20 Dec '17 - 16:41 »
In August 2019 we will be forced to include the 64 bit version of the native libraries when publishing on Google Play (see https://android-developers.googleblog.com/2017/12/improving-app-security-and-performance.html). It seems a lot of time, but preparing ahead will help in troubleshooting possible problems and give better performance already now. Will it be possible to have 64 bit versions of the BASS libraries included in the Android release? Thank you for the excellent work.

Yes, I think arm64-v8a architecture builds will probably added to be Android BASS package early next year.

I have tried using BASS.BASS_MusicLoad() to play any MOD/IT/XM file, unfortunately it does not work, I am using new Android Studio 3.0.
I have tried all three method variants of MusicLoad(), file, asset, bytebuffer that is -- file and asset just do not work while passing the song bytebuffer actually crashes the app.

Please check the error code by calling BASS_ErrorGetCode straight after the failed BASS_MusicLoad call.

Is there any available example of doing it on Android?

The DSPTEST and FXTEST examples in the Android BASS package include support for MOD files. They try to open the user's selected file like this:

Code: [Select]
if ((chan=BASS.BASS_StreamCreateFile(file, 0, 0, BASS.BASS_SAMPLE_LOOP))==0
&& (chan=BASS.BASS_MusicLoad(file, 0, 0, BASS.BASS_SAMPLE_LOOP|BASS.BASS_MUSIC_RAMP, 1))==0) {

dejan

  • Guest
Re: BASS for Android
« Reply #1337 on: 20 Dec '17 - 17:09 »
Thanks for your help Ian.

I am trying to load a module from the application asset folder. When I try to pass the ByteBuffer to MusicLoad() native crash happens and I do not know how to catch that one. :(

Anyhow here is the log of an error if that would be of any help:
https://hastebin.com/fivuqovexi

Also, what is the proper way of doing MusicLoad() with BASS.Asset? Where the module file should be exactly stored?

Ian @ un4seen

  • Administrator
  • Posts: 21358
Re: BASS for Android
« Reply #1338 on: 20 Dec '17 - 18:11 »
I think the "BASS.Asset" method will unfortunately only work with non-compressed assets. Already compressed audio (MP3/etc) is likely to be just stored in the app's APK file, but MOD files will probably be compressed. In that case, you could read the asset into a ByteBuffer and pass that to BASS_MusicLoad. When doing that, make sure you pass the length of the file in the "length" parameter.

El_Diablo

  • Posts: 2
Re: BASS for Android
« Reply #1339 on: 29 Jan '18 - 00:52 »
I've updated the code for your BASS wrapper here: https://github.com/War3Evo/FMX.Radio to work for Delphi 10.2.2 for Android.

The issue I think I'm having is to due with multi threading.

It seems that when I put the android application into the background and open another application while it is streaming audio... your bass library begins to "skip" a lot!   I am wondering if there is a fix for this in your library?

Much Thanks for any ideas if I can do something about this or if your library needs an update,


Sincerely,


El Diablo
https://github.com/War3Evo/FMX.Radio


p.s.
I would have done a pull request, but I'm not going to pull request something that doesn't fully work yet due to the "skipping" issue.


Ian @ un4seen

  • Administrator
  • Posts: 21358
Re: BASS for Android
« Reply #1340 on: 29 Jan '18 - 15:10 »
Background apps get lower priority on Android. You can avoid that by implementing a "foreground service". Here is some info on that:

   http://developer.android.com/guide/components/services.html#Foreground

Also, here is a modified version of the PLUGINS example that another user has provided:

   www.un4seen.com/stuff/android-service.zip
   
By the way, please note that FMX.Radio GitHub project was created by a third-party (not un4seen).

Ian @ un4seen

  • Administrator
  • Posts: 21358
Re: BASS for Android
« Reply #1341 on: 1 Feb '18 - 17:50 »
The Android version of the BASSHLS 2.4.1 release is up now in the package in the 1st post.

El_Diablo

  • Posts: 2
Re: BASS for Android
« Reply #1342 on: 1 Feb '18 - 23:05 »
Background apps get lower priority on Android. You can avoid that by implementing a "foreground service". Here is some info on that:

   http://developer.android.com/guide/components/services.html#Foreground

Also, here is a modified version of the PLUGINS example that another user has provided:

   www.un4seen.com/stuff/android-service.zip
   
By the way, please note that FMX.Radio GitHub project was created by a third-party (not un4seen).

Okay Sweet!  I updated the third-party wrapper by adding "AndroidServiceRadio" @ https://github.com/War3Evo/FMX.Radio and I also included instructions for other Delphi 10.2.2 Tokyo Developers in using it.

gicci

  • Posts: 48
Re: BASS for Android
« Reply #1343 on: 2 Feb '18 - 22:46 »
Hi,

I just realized I am getting a crash when closing a SoundFont I open from a memory buffer, when the service I use for playback is destroyed. The problem was not present before and I didn't changed my code (at least that part of it), only the BASS library since it was working.

The font is open with

Code: [Select]
soundFontId = BASSMIDI.BASS_MIDI_FontInit(data, 0);
and closed with

Code: [Select]
BASSMIDI.BASS_MIDI_FontFree(soundFontId)
but as soon as the previous call gets invoked I get:

Code: [Select]
02-02 23:32:27.989 29440-29440/<package> A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0xd0 in tid 29440 (<package>)
                                                       
                                                       [ 02-02 23:32:27.991  3142: 3142 W/         ]
                                                       debuggerd: handling request: pid=29440 uid=10374 gid=10374 tid=29440

No other stack trace is present. I open and close other SoundFonts while the app is running from files, and no problem is present.

As I am going to call BASS.BASS_Free() probably I could avoid the release of the SoundFont, but it is not supposed to crash.  ::)

astrohoff

  • Posts: 4
Re: BASS for Android
« Reply #1344 on: 3 Feb '18 - 21:18 »
I'm building a MIDI visualizer with Unity, and I'm having a strange problem: sending a program change seems to silence the channel it's sent to.
I'm working with the real-time event stream. With the program-change-sending code commented out, everything seems to play normally (with piano notes). I tried only sending the 1st program change and just the 1st channel was silenced.

Here is my C# function in Unity a for program change:
Code: [Select]
public void ProgramChange(byte channel, byte programNum)
{
    //                   Function name, parameters...
    bassMidiDevice.Call("ProgramChange", (int)channel, (int)programNum);       
}
And here is my Java library function the above calls:
Code: [Select]
public void ProgramChange(int channel, int programNum){
    BASSMIDI.BASS_MIDI_StreamEvent(midiStreamHandle, BASSMIDI.MIDI_EVENT_PROGRAM, channel, programNum);
}
I have no idea what's going on, but at this point I'm suspecting it might be something with the soundfont (using FluidR3), so here's that code too:
Code: [Select]
soundfontHandle = BASSMIDI.BASS_MIDI_FontInit(soundfontPath, 0);
if(soundfontHandle == 0){
    throw new Exception("Soundfont initialization error: " + BASS.BASS_ErrorGetCode());
}
BASSMIDI.BASS_MIDI_FONT[] sf = {new BASSMIDI.BASS_MIDI_FONT()};
sf[0].font = soundfontHandle;
sf[0].preset = -1;
sf[0].bank = 0;
if(!BASSMIDI.BASS_MIDI_StreamSetFonts(midiStreamHandle, sf, 1)){
    throw new Exception("Error setting soundfont to stream: " + BASS.BASS_ErrorGetCode());
}

If anyone can shed any light on what might be happening here, it would be greatly appreciated.
« Last Edit: 3 Feb '18 - 21:22 by astrohoff »

diystar

  • Posts: 45
Re: BASS for Android
« Reply #1345 on: 5 Feb '18 - 06:49 »
Background apps get lower priority on Android. You can avoid that by implementing a "foreground service". Here is some info on that:

   http://developer.android.com/guide/components/services.html#Foreground

Also, here is a modified version of the PLUGINS example that another user has provided:

   www.un4seen.com/stuff/android-service.zip
   
By the way, please note that FMX.Radio GitHub project was created by a third-party (not un4seen).

Delphi example of foreground service:
https://sourceforge.net/projects/mcool/

Ian @ un4seen

  • Administrator
  • Posts: 21358
Re: BASS for Android
« Reply #1346 on: 5 Feb '18 - 17:52 »
I just realized I am getting a crash when closing a SoundFont I open from a memory buffer, when the service I use for playback is destroyed. The problem was not present before and I didn't changed my code (at least that part of it), only the BASS library since it was working.

Did the problem begin after upgrading to BASS 2.4.13, and do you happen to be using a soundfont with encoded samples? There is a known issue in the BASS 2.4.13 release with the BASS_NODEVICE option, which BASSMIDI uses internally with encoded samples. A BASS update to fix that should be released tomorrow.

I'm building a MIDI visualizer with Unity, and I'm having a strange problem: sending a program change seems to silence the channel it's sent to.
I'm working with the real-time event stream. With the program-change-sending code commented out, everything seems to play normally (with piano notes). I tried only sending the 1st program change and just the 1st channel was silenced.

That sounds strange. Are already playing notes suddenly silenced, or only subsequently played notes? A MIDI_EVENT_PROGRAM event should only immediately silence the channel if it is switching the channel from melodic to percussive or vice versa (in XG or GM2 mode). I don't suppose that is what you're doing? Are you sure MIDI_EVENT_NOTESOFF or MIDI_EVENT_SOUNDOFF events aren't being sent too?

To confirm whether it is soundfont specific, you could also try the soundfonts available from the BASS page.

Okay Sweet!  I updated the third-party wrapper by adding "AndroidServiceRadio" @ https://github.com/War3Evo/FMX.Radio and I also included instructions for other Delphi 10.2.2 Tokyo Developers in using it.

Delphi example of foreground service:
https://sourceforge.net/projects/mcool/

Nice :)

astrohoff

  • Posts: 4
Re: BASS for Android
« Reply #1347 on: 6 Feb '18 - 00:44 »
I created a test midi file to play events from, and the notes are cut off immediately on a MIDI_EVENT_PROGRAM event. I'm unfamiliar with switching percussive/melodic modes, so unless that is something that can be done unintentionally I don't think that's it. The test file I used is just 6 notes on 1 channel with a program change just after the 3rd note. The 3rd note is cut off and none of the last 3 sound. I also tried disabling all events except MIDI_EVENT_NOTE and MIDI_EVENT_PROGRAM in my code and I'm getting the same behavior. I will try a different soundfont next.

Edit: I get the same behavior with ChoriumRevA.
« Last Edit: 6 Feb '18 - 00:52 by astrohoff »

Ian @ un4seen

  • Administrator
  • Posts: 21358
Re: BASS for Android
« Reply #1348 on: 6 Feb '18 - 16:51 »
I don't seem to be able to reproduce that, so please upload your test MIDI file to have a look at here:

   ftp.un4seen.com/incoming/

Please also confirm that you are using the latest BASS and BASSMIDI library versions.

Ian @ un4seen

  • Administrator
  • Posts: 21358
Re: BASS for Android
« Reply #1349 on: 6 Feb '18 - 16:52 »
The Android version of the BASS 2.4.13.8 release is up in the 1st post.