Author Topic: BASS for Android  (Read 429615 times)

gicci

  • Posts: 48
Re: BASS for Android
« Reply #1375 on: 4 Apr '18 - 07:45 »
The BASSWV update posted above is the 2.4.6 release version minus the armv7 optimizations. If it turns out that the armv7 optimizations are indeed causing the crashes, I will replace the current release version (in the 1st post) with the update. Let me know what you find with your app.

I have fully released the app with the BASSWV without optimizations and no crashes have been reported. Users with devices crashing with previous version are reporting it is working again.
So it seems that somehow those optimizations are not working properly with Android 6.0 (at least on some devices).

Ian @ un4seen

  • Administrator
  • Posts: 21133
Re: BASS for Android
« Reply #1376 on: 4 Apr '18 - 17:01 »
Thanks Ian, I hear sound now.
However, do I need to create a AudioTrack object directly and write a buffer to it and invoke audioTrack.play()?

No, BASS handles the AudioTrack stuff; you only need to specify the BASS_DEVICE_AUDIOTRACK flag to enable it.

I have fully released the app with the BASSWV without optimizations and no crashes have been reported. Users with devices crashing with previous version are reporting it is working again.
So it seems that somehow those optimizations are not working properly with Android 6.0 (at least on some devices).

OK. I have now moved the BASSWV update to the package in the 1st post.

denis_shakinov

  • Posts: 3
Re: BASS for Android
« Reply #1377 on: 5 Apr '18 - 12:35 »
Thanks Ian, I hear sound now.
However, do I need to create a AudioTrack object directly and write a buffer to it and invoke audioTrack.play()?

No, BASS handles the AudioTrack stuff; you only need to specify the BASS_DEVICE_AUDIOTRACK flag to enable it.

Actually, I'm trying to record video/audio with Everyplay sdk https://developers.everyplay.com/. Everyplay only works with audiotrack API. When I just use
Code: [Select]
BASS.BASS_Init(-1, 44100, BASS.BASS_DEVICE_AUDIOTRACK)then I notice some lag when playing midi events with soundfont, and Everyplay sdk recorded just noise instead of notes sound. When I created audiotrack explicitly
Code: [Select]
...
res = BASS.BASS_ChannelGetData(channel, buffer, bufferSize)
audioTrack.write(buffer.array(), 0, res)
...
then I hear doubled sounds apparently, and Everyplay sdk recorded noise along with normal notes sound
also I've noticed such a logcat output:
Code: [Select]
W/AudioTrack: Use of stream types is deprecated for operations other than volume control
    See the documentation of AudioTrack() for what to use instead with android.media.AudioAttributes to qualify your playback use case
Do you know something about how to deal with Everyplay sdk, audiotrack and BASS?
« Last Edit: 5 Apr '18 - 12:40 by denis_shakinov »

Ian @ un4seen

  • Administrator
  • Posts: 21133
Re: BASS for Android
« Reply #1378 on: 5 Apr '18 - 17:39 »
I'm not familiar with that SDK, but if it's currently capturing noise from your app then perhaps it's a matter of floating-point vs 16-bit output? BASS will use floating-point by default when available (Andriod 5+) but you can request 16-bit output by adding the BASS_DEVICE_16BITS flag to your BASS_Init call:

Code: [Select]
BASS.BASS_Init(-1, 44100, BASS.BASS_DEVICE_AUDIOTRACK | BASS.BASS_DEVICE_16BITS);

Regarding the "lag", that is probably due to the MIDI stream's playback buffering. You can try disabling playback buffering via the BASS_ATTRIB_BUFFER option:

Code: [Select]
BASS.BASS_ChannelSetAttribute(midihandle, BASS.BASS_ATTRIB_BUFFER, 0);

chadr

  • Guest
Re: BASS for Android
« Reply #1379 on: 12 Apr '18 - 15:18 »
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.


When will you add arm64-v8a architecture builds to official Android BASS package?
You said that it will be added in this early year.  :)

Ian @ un4seen

  • Administrator
  • Posts: 21133
Re: BASS for Android
« Reply #1380 on: 12 Apr '18 - 17:26 »
Soon, hopefully :)

otherside

  • Posts: 35
Re: BASS for Android
« Reply #1381 on: 14 Apr '18 - 11:32 »
Hello.
Question related to new BASS_DEVICE_AUDIOTRACK.
How to get audioSessionId? (it is necessary in order to use System equalizer)

It is available as field in AudioTrack and MediaPlayer.

Ian @ un4seen

  • Administrator
  • Posts: 21133
Re: BASS for Android
« Reply #1382 on: 16 Apr '18 - 17:12 »
The latest build (not yet up in the 1st post) does provide that option. You can get it here:

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

It adds this BASS_GetConfig option to get the audio session ID:

Code: [Select]
public static final int BASS_CONFIG_ANDROID_SESSIONID = 62;

otherside

  • Posts: 35
Re: BASS for Android
« Reply #1383 on: 18 Apr '18 - 21:43 »
I tried. Thanks! It works as I expect and there's no bugs at first glance.

otherside

  • Posts: 35
Re: BASS for Android
« Reply #1384 on: 19 Apr '18 - 18:27 »
Another question:

I have a channel which is created from a file and is currently playing.
Plus I need to analyze levels of the whole channel. I create separate channel because I use seekToPosition in order to analyze track from beginnig until end. Playing channel has different position.

Currently I create 2 streams, like this:
for play - BASS.BASS_StreamCreateFile(url, 0, 0, 0)
for analyzing - BASS.BASS_StreamCreateFile(url, 0, 0, BASS.BASS_STREAM_DECODE)

is there a way to optimize it by avoding creation of the duplicate stream?

Ian @ un4seen

  • Administrator
  • Posts: 21133
Re: BASS for Android
« Reply #1385 on: 20 Apr '18 - 16:42 »
One option is to decode the file to memory during the analysis and play it from there, but unless you're having performance problems with it, I would probably stick with using 2 streams instead. The CUSTLOOP example included in the Win32/OSX/Linux BASS packages does that too.

diystar

  • Posts: 45
Re: BASS for Android
« Reply #1386 on: 25 Apr '18 - 07:02 »
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.
When i use BASS_DEVICE_AUDIOTRACK flag:
BASS_Init(-1, 44100, BASS_DEVICE_16BITS or BASS_DEVICE_FREQ or BASS_DEVICE_AUDIOTRACK, handle, nil);

It causes error:

Ian @ un4seen

  • Administrator
  • Posts: 21133
Re: BASS for Android
« Reply #1387 on: 25 Apr '18 - 13:34 »
What programming language are you using? The AudioTrack support requires a Java VM. If you happen to be using Xamarin, you can use JavaSystem.LoadLibrary to load the BASS library so that it gets a Java VM:

   https://developer.xamarin.com/api/member/Java.Lang.JavaSystem.LoadLibrary/p/System.String/

diystar

  • Posts: 45
Re: BASS for Android
« Reply #1388 on: 26 Apr '18 - 03:12 »
I use delphi 10.1

Ian @ un4seen

  • Administrator
  • Posts: 21133
Re: BASS for Android
« Reply #1389 on: 26 Apr '18 - 15:01 »
I haven't tried it myself, but it looks like you can access Delphi's JavaVM via "System.JavaMachine". You could try using that with this latest BASS build, which adds a BASS_CONFIG_ANDROID_JAVAVM config option that allows you to provide a JavaVM when not using Java:

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

BASS_CONFIG_ANDROID_JAVAVM is defined as 63, so something like this:

Code: [Select]
BASS_SetConfigPtr(63, System.JavaMachine);

otherside

  • Posts: 35
Re: BASS for Android
« Reply #1390 on: 26 Apr '18 - 19:57 »
One option is to decode the file to memory during the analysis and play it from there, but unless you're having performance problems with it, I would probably stick with using 2 streams instead. The CUSTLOOP example included in the Win32/OSX/Linux BASS packages does that too.
Yes, I have performance problems, because I play tracks from internet, so loading a track twice is a waste. Is there a way to copy buffer from one channel to another?

diystar

  • Posts: 45
Re: BASS for Android
« Reply #1391 on: 27 Apr '18 - 05:18 »
I haven't tried it myself, but it looks like you can access Delphi's JavaVM via "System.JavaMachine". You could try using that with this latest BASS build, which adds a BASS_CONFIG_ANDROID_JAVAVM config option that allows you to provide a JavaVM when not using Java:

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

BASS_CONFIG_ANDROID_JAVAVM is defined as 63, so something like this:

Code: [Select]
BASS_SetConfigPtr(63, System.JavaMachine);
Thank, i'll try it.
« Last Edit: 27 Apr '18 - 05:34 by diystar »

Ian @ un4seen

  • Administrator
  • Posts: 21133
Re: BASS for Android
« Reply #1392 on: 27 Apr '18 - 14:01 »
One option is to decode the file to memory during the analysis and play it from there, but unless you're having performance problems with it, I would probably stick with using 2 streams instead. The CUSTLOOP example included in the Win32/OSX/Linux BASS packages does that too.
Yes, I have performance problems, because I play tracks from internet, so loading a track twice is a waste. Is there a way to copy buffer from one channel to another?

Yes, you can copy sample data from one stream to another, by setting a DSPPROC function on the source stream. A demonstration of this can be found in the MULTI example (see the "clone" option) that's included in the BASS package. I'm not sure that will be ideal when there may be a large time difference between the streams though, as it will mean a lot of buffered data. If you're playing a file from the internet, perhaps you could write a local copy of it (in a DOWNLOADPROC function) and play that.

alexanderbaars

  • Posts: 8
Re: BASS for Android
« Reply #1393 on: 3 May '18 - 19:35 »
Hello,

Our Android app crashes on newer Android versions (on android 6 it runs fine) because the libbass_fx.so is 32bit.
Do you have a 64bit version for us?

Here's the snippet of the crashlog:
Code: [Select]
05-03 18:15:02.990 27388 27388 E AndroidRuntime:
Caused by: java.lang.UnsatisfiedLinkError:
dlopen failed: "/data/app/nl.dedicon.daisylezer2-j-J2SdDWvPr-KhGrdzKutw==/lib/arm64/libbass_fx.so" is 32-bit instead of 64-bit

best regards

Ian @ un4seen

  • Administrator
  • Posts: 21133
Re: BASS for Android
« Reply #1394 on: 4 May '18 - 14:17 »
The arm64-v8a architecture isn't fully supported currently but should be soon, perhaps as soon as next week. In the meantime, you should remove the arm64-v8a library directory from your app's project, so that the armeabi-v7a libraries get used instead. From the log message, I guess you're currently using the arm64-v8a BASS library that was posted a while ago, and copied the armeabi-v7a BASS_FX library into the same directory? Unfortunately, it isn't possible to mix architectures like that.

teq

  • Posts: 8
Re: BASS for Android
« Reply #1395 on: 5 May '18 - 12:02 »
Hi there! I'am using bass with Unity.
Here is my basic Play() method
Code: [Select]

if (stream != 0)
            {
                Bass.BASS_ChannelStop(stream);
                Bass.BASS_StreamFree(stream);
            }

            if (streamTempoFX != 0)
            {
                Bass.BASS_ChannelStop(streamTempoFX);
                Bass.BASS_StreamFree(streamTempoFX);
            }
           
            if (_hGCFile.IsAllocated)
            {
                _hGCFile.Free();
            }

            _hGCFile = GCHandle.Alloc(data, GCHandleType.Pinned);
            stream = Bass.BASS_StreamCreateFile(_hGCFile.AddrOfPinnedObject(), 0, data.Length, BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_STREAM_PRESCAN);
 if (stream != 0)
            {
streamTempoFX = BassFx.BASS_FX_TempoCreate(stream, BASSFlag.BASS_FX_FREESOURCE | BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_SAMPLE_LOOP);
            }

if (streamTempoFX != 0 && Bass.BASS_ChannelPlay(streamTempoFX, false))
            {
                // real-time beat position
                BPMBEATPROC beatProc = new BPMBEATPROC(MyBeatProc);
                BassFx.BASS_FX_BPM_BeatCallbackSet(streamTempoFX, beatProc, IntPtr.Zero);
            }

So my quistion is : can i somehow reduce GC invoke every time i need to play track? I have 15mb tracks and it's entails 1-2s delay before playing starts.
Also i noticed that on device (nexus 5) app has memory leaking, which i can't reproduce in Unity editor. Am i using library in proper way ?
Thanks!

« Last Edit: 5 May '18 - 18:02 by teq »

teq

  • Posts: 8
Re: BASS for Android
« Reply #1396 on: 13 May '18 - 08:53 »
So after a week my problem still unsolved. I've tried byte[] pre allocation, passing data byte[] by ref, call GC.Collect() here and there and i still have memory leaks with growing ManagedHeap on Android. In Unity editor is ok

teq

  • Posts: 8
Re: BASS for Android
« Reply #1397 on: 13 May '18 - 09:41 »
OK seems to be stable now, I removed the    BASS.BASS_StreamFree(chan);   from the callback and delayed the fres until the next track finished, obviously it can not freed at the exact end of track. Thanks for the support!
           
My be problem that i'am loading all the file in byte[], so if i'll loading it into the chunks for reducing heap growing, can i create stream in this way ?

Ian @ un4seen

  • Administrator
  • Posts: 21133
Re: BASS for Android
« Reply #1398 on: 14 May '18 - 17:44 »
I'm not a .Net user myself, so I'm not sure how you should best manage memory allocation with that, but you could try using BASS_StreamCreateFileUser (with system=STREAMFILE_NOBUFFER) instead of BASS_StreamCreateFile to play the data from memory. The data won't need to all be in one continuous block then.

Regarding the 1-2s delay you mention, the BASS_STREAM_PRESCAN flag may also be contributing to that if you're playing MP3 files. Unless you absolutely need a precise length value and seeking, you might not really need that flag.

alexanderbaars

  • Posts: 8
Re: BASS for Android
« Reply #1399 on: 17 May '18 - 13:13 »
The arm64-v8a architecture isn't fully supported currently but should be soon, perhaps as soon as next week. In the meantime, you should remove the arm64-v8a library directory from your app's project, so that the armeabi-v7a libraries get used instead.

Any change on getting an arm64-v8a version of the BASS_FX library?