Author Topic: BASS for Android  (Read 831235 times)

helri

  • Posts: 10
Re: BASS for Android
« Reply #50 on: 4 Jan '12 - 14:29 »
Thank you Ian.

I tried your code and I keep getting the same error (i'm testing in a Samsung Galaxy, SDK version 2.2 and in a Sony Ericsson Xperia, SDK version 2.3)

This is my entire code, url included:

Code: [Select]
String url= "http://ia700401.us.archive.org/33/items/another007/01-allthelivingandthedead-IntheMoon.ogg";
BASS.BASS_StreamFree(chan); // free old stream before opening new
chan=BASS.BASS_StreamCreateURL(url, 0, BASS.BASS_STREAM_DECODE, null, null);
track = new AudioTrack( AudioManager.STREAM_MUSIC, 44100,
    AudioFormat.CHANNEL_CONFIGURATION_STEREO, AudioFormat.ENCODING_PCM_16BIT,
    AudioTrack.getMinBufferSize(44100, AudioFormat.CHANNEL_CONFIGURATION_STEREO, AudioFormat.ENCODING_PCM_16BIT), AudioTrack.MODE_STREAM);

track.play();

new Thread(new Runnable(){
public void run() {
ByteBuffer buffer = ByteBuffer.allocate(20000); // allocate buffer for decoded data
int res=BASS.BASS_ChannelGetData(chan, buffer, buffer.capacity()); // decode some data
while (res!=-1){
if (res>0)
track.write(buffer.array(), 0, res); // feed it to AudioTrack
else
try {
Thread.sleep(50);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} // wait a bit for more data to arrive
res=BASS.BASS_ChannelGetData(chan, buffer, buffer.capacity()); // decode some data
}


Log.e("MidiTest", "finished");
}
}).start();

note that Log.e("MidiTest", "finished"); is never called nor the thread is interrupted.
The error occurs calling  BASS.BASS_ChannelGetData(chan, buffer, buffer.capacity()); inside the loop.

That thread you see in the code is the only explicit thread i'm using.

I'm using the MidiTest modified with that code. If you want I can send you the .apk or even the source code.

It's weird that SIGBUS error happening...

Thank you.
« Last Edit: 4 Jan '12 - 15:11 by helri »

Ian @ un4seen

  • Administrator
  • Posts: 26095
Re: BASS for Android
« Reply #51 on: 4 Jan '12 - 16:50 »
Ah yes, I can reproduce the problem too with your test URL. It's actually crashing in the download thread rather than the BASS_ChannelGetData call. Once an OGG download is finished, BASS will look at the downloaded data to get the decoded length, and there was a memory alignment issue in that (ARM is fussy about alignment). An update to fix that is up now in the 1st post. Let me know if you have any more trouble with it.

helri

  • Posts: 10
Re: BASS for Android
« Reply #52 on: 4 Jan '12 - 17:30 »
Great! it's working!

Thank you Ian!

helri

  • Posts: 10
Re: BASS for Android
« Reply #53 on: 6 Jan '12 - 09:39 »
Ian, I keep noticing some glitches when playing the song, looks like either the write of bytes to the AudioTrack isn't fast enough or the decoding is leaving some "blanks" in the song. I changed the code a bit so I could write some bytes before starting the audioTrack but I still get a lot of glitches (like when someone scratches a disc). It seems rather deterministic, the glitches happen with some frequency...

Do you have any idea why this can be happening and ways to improve this (I need to use AudioTrack to support older versions of Android)?

thank you!
« Last Edit: 6 Jan '12 - 09:50 by helri »

Ian @ un4seen

  • Administrator
  • Posts: 26095
Re: BASS for Android
« Reply #54 on: 6 Jan '12 - 15:27 »
What number are you getting from the "AudioTrack.getMinBufferSize" call? Perhaps that isn't large enough; the documentation states "Note that this size doesn't guarantee a smooth playback". You could try increasing it and see if that helps.

Brannon

  • Posts: 16
Re: BASS for Android
« Reply #55 on: 8 Jan '12 - 05:09 »
Can you explain your fixed-point format a little more? Are you using ones or twos compliment? And that's only on the whole number portion? Or you're using a sign bit? Or it's unsigned or biased? Which byte is the high byte?

helri

  • Posts: 10
Re: BASS for Android
« Reply #56 on: 9 Jan '12 - 14:38 »
What number are you getting from the "AudioTrack.getMinBufferSize" call? Perhaps that isn't large enough; the documentation states "Note that this size doesn't guarantee a smooth playback". You could try increasing it and see if that helps.
8
yeah, that was the issue. I'm now passing getMinBufferSize*2 as buffer size and it's playing well.

Thanks!
« Last Edit: 9 Jan '12 - 15:05 by helri »

Ian @ un4seen

  • Administrator
  • Posts: 26095
Re: BASS for Android
« Reply #57 on: 9 Jan '12 - 14:47 »
Can you explain your fixed-point format a little more? Are you using ones or twos compliment? And that's only on the whole number portion? Or you're using a sign bit? Or it's unsigned or biased? Which byte is the high byte?

The fixed-point sample data (and FFT data) is in native endian 8.24 fixed-point form, ie. 8 bits for the integer part and 24 bits for the fractional part. The relationship between fixed-point and floating-point is this: fixed=float*16777216.0 (or float=fixed/16777216.0)

What number are you getting from the "AudioTrack.getMinBufferSize" call? Perhaps that isn't large enough; the documentation states "Note that this size doesn't guarantee a smooth playback". You could try increasing it and see if that helps.

yeah, that was the issue. I'm now passing 32678 as buffer size and it's playing very well.

Jolly good :)

helri

  • Posts: 10
Re: BASS for Android
« Reply #58 on: 10 Jan '12 - 12:45 »
Ian, I'm getting a segmentation fault after doing BASS_StreamCreateURL

The use case where i'm getting this is the following:

I play a song using the same process we talked above.
After a little while I seek to the end of the song using setPosition.
The seek is successful and audio track plays the song at that position.
I let the song play until it finishes.
As I have a SYNCPROC to be triggered at BASS_SYNC_END I start playing a new song from a new URL when the SYNCPROC method is called.

I do BASS_StreamFree and then BASS_StreamCreateURL and then I set again BASS_ChannelSetSync to BASS_SYNC_END.
Before even starting writing bytes to audiotrack using BASS_ChannelGetData I get the error below:

Code: [Select]
01-10 12:32:39.534: I/DEBUG(30369): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0404030b
01-10 12:32:39.534: I/DEBUG(30369):  r0 00000001  r1 afd4734c  r2 00000000  r3 00000001
01-10 12:32:39.534: I/DEBUG(30369):  r4 00348fa0  r5 04040303  r6 00006f60  r7 80006f60
01-10 12:32:39.534: I/DEBUG(30369):  r8 00000001  r9 00006f60  10 00018000  fp 00018000
01-10 12:32:39.534: I/DEBUG(30369):  ip 00000000  sp 46e6c9d8  lr afd10e04  pc 80725f96  cpsr 20000030
01-10 12:32:39.534: I/DEBUG(30369):  d0  0000000000000033  d1  002d003100300000
01-10 12:32:39.534: I/DEBUG(30369):  d2  0031005400300039  d3  00320033003a0000
01-10 12:32:39.534: I/DEBUG(30369):  d4  00690062006f006d  d5  0061006d0065006c
01-10 12:32:39.534: I/DEBUG(30369):  d6  002e006300690067  d7  00730075006d006e
01-10 12:32:39.534: I/DEBUG(30369):  d8  405a61ad3f285eef  d9  3ff0000000000000
01-10 12:32:39.534: I/DEBUG(30369):  d10 3ff0000000000000  d11 0000000000000000
01-10 12:32:39.534: I/DEBUG(30369):  d12 0000000000000000  d13 0000000000000000
01-10 12:32:39.534: I/DEBUG(30369):  d14 0000000000000000  d15 0000000000000000
01-10 12:32:39.534: I/DEBUG(30369):  d16 0000002740648668  d17 3ff0000000000000
01-10 12:32:39.534: I/DEBUG(30369):  d18 3fe0000000000000  d19 4000000000000000
01-10 12:32:39.534: I/DEBUG(30369):  d20 3ff0000000000000  d21 4197d78400000000
01-10 12:32:39.534: I/DEBUG(30369):  d22 bf656ac020000000  d23 b5b5b5b5b5b5b5b5
01-10 12:32:39.534: I/DEBUG(30369):  d24 e6e6e6e6e6e6e6e6  d25 e6e6e6e6e6e6e6e6
01-10 12:32:39.534: I/DEBUG(30369):  d26 e6e6e6e6e6e6e6e6  d27 ffffffffffffffff
01-10 12:32:39.534: I/DEBUG(30369):  d28 0100010001000100  d29 4042c055a0000000
01-10 12:32:39.534: I/DEBUG(30369):  d30 4042c055a0000000  d31 3ff0000000000000
01-10 12:32:39.534: I/DEBUG(30369):  scr 60000012
01-10 12:32:39.745: I/DEBUG(30369):          #00  pc 00025f96  /data/data/com.example.miditest/lib/libbass.so
01-10 12:32:39.745: I/DEBUG(30369):          #01  lr afd10e04  /system/lib/libc.so
01-10 12:32:39.745: I/DEBUG(30369): code around pc:
01-10 12:32:39.745: I/DEBUG(30369): 80725f74 bf0c0f00 f0022200 b16a0201 20009906
01-10 12:32:39.753: I/DEBUG(30369): 80725f84 2300e9d1 90004629 f7f14620 682dff51
01-10 12:32:39.753: I/DEBUG(30369): 80725f94 68abb1ad d0e42b00 bf142b02 f0082300
01-10 12:32:39.753: I/DEBUG(30369): 80725fa4 2b000301 9906d0f3 e9d1980b 46292300
01-10 12:32:39.753: I/DEBUG(30369): 80725fb4 46209000 ff3cf7f1 2d00682d f1b8d1e9
01-10 12:32:39.753: I/DEBUG(30369): code around lr:
01-10 12:32:39.753: I/DEBUG(30369): afd10de4 e20c1001 ebffffe8 e1a00005 e8bd8070
01-10 12:32:39.753: I/DEBUG(30369): afd10df4 e92d4070 e1a05000 e5904000 ebffeee1
01-10 12:32:39.753: I/DEBUG(30369): afd10e04 e2044a02 e3843001 e1500003 08bd8070
01-10 12:32:39.753: I/DEBUG(30369): afd10e14 e5854000 e1a00005 e1a01004 e3a02001
01-10 12:32:39.753: I/DEBUG(30369): afd10e24 e8bd4070 eaffffd8 e2502000 e92d40f0
01-10 12:32:39.753: I/DEBUG(30369): stack:
01-10 12:32:39.753: I/DEBUG(30369):     46e6c998  00018000  
01-10 12:32:39.753: I/DEBUG(30369):     46e6c99c  80716517  /data/data/com.example.miditest/lib/libbass.so
01-10 12:32:39.753: I/DEBUG(30369):     46e6c9a0  002d02e8  
01-10 12:32:39.753: I/DEBUG(30369):     46e6c9a4  b0000001  
01-10 12:32:39.753: I/DEBUG(30369):     46e6c9a8  00000000  
01-10 12:32:39.753: I/DEBUG(30369):     46e6c9ac  80717e67  /data/data/com.example.miditest/lib/libbass.so
01-10 12:32:39.753: I/DEBUG(30369):     46e6c9b0  00018000  
01-10 12:32:39.753: I/DEBUG(30369):     46e6c9b4  8070e1bf  /data/data/com.example.miditest/lib/libbass.so
01-10 12:32:39.753: I/DEBUG(30369):     46e6c9b8  00348fa0  
01-10 12:32:39.753: I/DEBUG(30369):     46e6c9bc  80729569  /data/data/com.example.miditest/lib/libbass.so
01-10 12:32:39.753: I/DEBUG(30369):     46e6c9c0  00348fa0  
01-10 12:32:39.753: I/DEBUG(30369):     46e6c9c4  00348fa0  
01-10 12:32:39.753: I/DEBUG(30369):     46e6c9c8  002d02e8  
01-10 12:32:39.761: I/DEBUG(30369):     46e6c9cc  00006f60  
01-10 12:32:39.761: I/DEBUG(30369):     46e6c9d0  df002777  
01-10 12:32:39.761: I/DEBUG(30369):     46e6c9d4  e3a070ad  
01-10 12:32:39.761: I/DEBUG(30369): #00 46e6c9d8  00000000  
01-10 12:32:39.761: I/DEBUG(30369):     46e6c9dc  00000004  
01-10 12:32:39.761: I/DEBUG(30369):     46e6c9e0  00000000  
01-10 12:32:39.761: I/DEBUG(30369):     46e6c9e4  00018000  
01-10 12:32:39.761: I/DEBUG(30369):     46e6c9e8  033f7b00  
01-10 12:32:39.761: I/DEBUG(30369):     46e6c9ec  407136e0  
01-10 12:32:39.761: I/DEBUG(30369):     46e6c9f0  003491e0  
01-10 12:32:39.761: I/DEBUG(30369):     46e6c9f4  807116b9  /data/data/com.example.miditest/lib/libbass.so
01-10 12:32:39.761: I/DEBUG(30369):     46e6c9f8  80754f10  
01-10 12:32:39.761: I/DEBUG(30369):     46e6c9fc  00000000  
01-10 12:32:39.761: I/DEBUG(30369):     46e6ca00  0034a240  
01-10 12:32:39.761: I/DEBUG(30369):     46e6ca04  00000000  
01-10 12:32:39.761: I/DEBUG(30369):     46e6ca08  00000000  
01-10 12:32:39.761: I/DEBUG(30369):     46e6ca0c  0034a240  
01-10 12:32:39.761: I/DEBUG(30369):     46e6ca10  00000000  
01-10 12:32:39.761: I/DEBUG(30369):     46e6ca14  00000001  
01-10 12:32:39.761: I/DEBUG(30369):     46e6ca18  fff00000  
01-10 12:32:39.761: I/DEBUG(30369):     46e6ca1c  00348fa0  


This is probably some error in the download thread as I didn't even start doing BASS_ChannelGetData.

Is there any other thing I should do when I want to start playing a new song besides calling streamFree before creating a new stream?

Thank you
« Last Edit: 10 Jan '12 - 14:17 by helri »

Ian @ un4seen

  • Administrator
  • Posts: 26095
Re: BASS for Android
« Reply #59 on: 10 Jan '12 - 15:35 »
Are you making the BASS_StreamFree call from within the SYNCPROC? If so, that will be a problem as the BASS_SYNC_END sync will automatically be "mixtime" (due to the BASS_STREAM_DECODE flag), which means that there are some restrictions on what can be done in the SYNCPROC. Please see the SYNCPROC/STREAMPROC docs for details. If that is indeed what is happening, you could move the call to another thread, eg. via runOnUiThread.

helri

  • Posts: 10
Re: BASS for Android
« Reply #60 on: 10 Jan '12 - 16:36 »
Yeah that seemed to be the issue. started the new song on a new thread and didn't get the crash. also removed the loop flag so ensure the player stops in the end of the stream.

thanks.

Gnanaoly

  • Guest
Re: BASS for Android
« Reply #61 on: 13 Jan '12 - 11:45 »
How to calculate audio BPM using the BASS android lib.  Please give me a any possibility solution.

gnag

  • Posts: 160
Re: BASS for Android
« Reply #62 on: 13 Jan '12 - 14:26 »
How to calculate audio BPM using the BASS android lib.  Please give me a any possibility solution.

Hello Gnanaoly,

Well, BPM Detection sounds easy, there are BPM Tap Counters, you just have to manually Press A Button when there is a Beat and then it can calculate the BPM Count, works better than expected and is easy to implement!
But since you use the Bass Library and modern CPUs which can process enourmous numbers of calculations, have more power than humans it would be stupid to make a manual BPM Counter.
There is the Open Source "SoundTouch" Library which the Bass Extension BASSFX has implemented but I dont like that one much, the BPM is inaccurate even if you set a very small range for min/max. The most reliable BPM Counter is "BPMCounter" from AbyssMedia, almost always gets it right.

If have been working on a BPM Detection for weeks because the one from BASSFX doesnt meet my requirements even if it is using multiple complicated and dynamic calculations. I started from scratch and my BPM Detection is not so complex as for example SoundTouch but it classify my hardstyle tracks already as 150BPM and "Katy Perry - Last Friday Night" as 125BPM.

If you are interested how it works, it is a basic beat detection scheme involving the PCM Data Samples (Sound Waves),RMS,A Circular Array and some basic BPM Formulas.
If you are interested in the source code you could join my interesting music analyzer project to improve it or give me a reason why I should give out more than 2 weeks of daily, multiple hourly and nightly work which gave me lot of headaches for free to a stranger.

Gnanaoly

  • Guest
Re: BASS for Android
« Reply #63 on: 13 Jan '12 - 15:10 »
Hello gnag,

Yes you are correct I have used the sound touch library already.  The output is inaccurate bpm value.  bass_fx24.zip is having the bpm detect code for windows.  They are provide the dll files.   Windows application is giving the nearest value.  Please check it.  I am working on currently bpm detection only  if I will find any reasonable solution I will update you.

Note: Which platform your need for calculation?


Thanks,
Gnanaoly A.

gnag

  • Posts: 160
Re: BASS for Android
« Reply #64 on: 13 Jan '12 - 17:19 »
SoundTouch is what BassFX uses, I checked the BassFX Beat Detection Applications but it still returns different values, both arent really useable.

I havent used the Bass Library on Android yet but I am using just Bass Included Functions and some Calculating so it shouldnt be to hard to port it to I think Java you use.
You can search a lot on the internet like I did too you wont find some working and modern sample code to detect BPM using Bass Library, its mostly theoretical papers and containing things that could possibly work and complicated formulas.

It is mostly a theoretical problem not a problem if which programming languag to use, once you have a good, proven algorithm it can be ported to other platforms.

Code: [Select]
Note: Which platform your need for calculation?You mean me? I use C# but if you have something working in any other language thas has proven I can port it too.

Edit: Gnanaoly please check your E-Mails, I wrote you something
« Last Edit: 13 Jan '12 - 17:39 by gnag »

SimonH

  • Posts: 9
Re: BASS for Android
« Reply #65 on: 1 Feb '12 - 09:45 »
Hi, How are things progressing with the Android version of BASS_FX?

(: JOBnik! :)

  • Posts: 1080
Re: BASS for Android
« Reply #66 on: 1 Feb '12 - 10:47 »
Hi ;D

I'm so sorry for delay with the BASS_FX port to Android, been busy with other things in my life for latest month...

Brannon

  • Posts: 16
Re: BASS for Android
« Reply #67 on: 2 Feb '12 - 00:25 »
For the Android, when I use BASS.BASS_Init(0, 44100, 0) my call to BASS_StreamCreateFile
always returns 0. I have to pass -1 as the first param on BASS_Init or she doesn't work. Is this expected? I'm using a 2.3.3 emulator.

Ian @ un4seen

  • Administrator
  • Posts: 26095
Re: BASS for Android
« Reply #68 on: 2 Feb '12 - 15:54 »
When a BASS call fails, you can use BASS_ErrorGetCode and lookup its return value in the documentation to find out why. In this case, I suspect it is BASS_ERROR_NOTAVAIL, which means that only "decoding channels" (created with the BASS_STREAM_DECODE flag) are supported on the "no sound" device (device number 0). Device number 1 is the real output device, and -1 maps to that.

gigi0ne

  • Posts: 40
Re: BASS for Android
« Reply #69 on: 4 Feb '12 - 07:15 »
Hi Ian..

you think to bring bassmix in Android?

i need this..  ;D

thank's
Luigi

Ian @ un4seen

  • Administrator
  • Posts: 26095
Re: BASS for Android
« Reply #70 on: 6 Feb '12 - 15:05 »
An Android version of the BASSmix add-on is now up in the package (in the 1st post). It hasn't been tested very much yet, so please report if you encounter any problems.

gigi0ne

  • Posts: 40
Re: BASS for Android
« Reply #71 on: 7 Feb '12 - 16:11 »
if you not  were a man I'd give you a kiss

Brannon

  • Posts: 16
Re: BASS for Android
« Reply #72 on: 8 Feb '12 - 13:25 »
By chance, does anyone have a Mono-for-Android wrapper file for this project that they would be willing to share? Thanks.

Brannon

  • Posts: 16
Re: BASS for Android
« Reply #73 on: 9 Feb '12 - 17:35 »
Does your v7a version of the library take advantage of the FPU available on that platform? In particular, I'm wondering if we could support the FLOAT flags on armeabi-v7a and x86 targets for PCM and FFT data but not the earlier armeabi?

Also, there is probably something to be gained in this library through the NEON instruction set? Thanks for your time.

Ian @ un4seen

  • Administrator
  • Posts: 26095
Re: BASS for Android
« Reply #74 on: 9 Feb '12 - 18:14 »
Fixed-point is used for the more performance-critical parts (eg. sample decoding/processing) in both the armeabi and armeabi-v7a build. In my tests, although floating-point operations were faster in armeabi-v7a than armeabi, fixed-point was still significantly faster. Using floating-point in one and fixed-point in the other would also complicate matters for users, ie. apps would need 2 code paths for some things. If you would prefer to deal with floating-point data (eg. in FFT results), the fixed-point numbers can be converted to floating-point (-1 to +1) by dividing each by 16777216.0 (224).