Author Topic: BASS for Android  (Read 390098 times)

Andeee

  • Guest
Re: BASS for Android
« Reply #125 on: 12 Apr '12 - 08:01 »
Apologies if the answer to this question is somewhat obvious  :)

I am using BASS for Android in a Marmalde application. When marmalade builds the .apk file it puts assets (such as audio) in an assets folder in the apk. How can I play these audio files using BASS? The problem I see is that you can only pass a string to the BASS_StreamCreateFile call.

I have tried passing in '/data/data/my.app.name/assets/mysong.mp3' which didn't work - I received error code 2 back.

I realise this may not entirely be a BASS question but I just wondered if anyone had solved anything similar. For example, I think you'd have the same problem if you wanted to play a file out of the res/raw folder in a standard android application - is this possible? Or is it only possible to play files off an sd card?

Thanks

Andeee

  • Guest
Re: BASS for Android
« Reply #126 on: 12 Apr '12 - 15:42 »
Nevermind, achieved it by passing a ByteBuffer to BASS instead of a string :)

Ian @ un4seen

  • Administrator
  • Posts: 20389
Re: BASS for Android
« Reply #127 on: 12 Apr '12 - 17:24 »
Yep, you could read the asset into a ByteBuffer and pass that to BASS_StreamCreateFile (as you have done), or wrap the asset access in BASS_FILEPROCS functions and pass that to BASS_StreamCreateFileUser. I'll see if some built-in asset support can be added to BASS for greater convenience.

Ian @ un4seen

  • Administrator
  • Posts: 20389
Re: BASS for Android
« Reply #128 on: 13 Apr '12 - 16:01 »
An update is now up in the 1st post, including support for passing assets to the stream/sample/music creation functions. An example snippet for that has also been added to the post.

Mr.Green2

  • Guest
Re: BASS for Android
« Reply #129 on: 14 Apr '12 - 00:33 »
From the quoted text, it sounds like you/they want to use the Replaygain peak level to normalize the stream, so that the level is just short of clipping. To do that, you can set the pre-amp gain to 1/peak. Note that applying EQ (and most other effects) will affect the level though, pretty much invalidating the Replaygain information.

Meanwhile... a BASS_FX update is up in the first post, which adds support for the BASS_FX_BFX_VOLUME effect. That can be used instead of a DSP function (eg. the one I posted earlier) to implement a pre-amp control. A BASS library update is also up, which is needed by the BASS_FX update (for Java effect parameter support). The BASSWV add-on has also been updated to the latest version (2.4.3).
BASS_FX_BFX_VOLUME effect works exectly the same as DSP function. Is it possible to make dinamic preamp to reduce only too high volume on some frequencies and not affect other frequences with correct volume?

Mr.Green2

  • Guest
Re: BASS for Android
« Reply #130 on: 15 Apr '12 - 22:19 »
Did you test last bass and bass_fx release on Android < 2.3 ? I have error:

java.lang.UnsatisfiedLinkError: Library bass not found
  at java.lang.Runtime.loadLibrary(Runtime.java:461)
  at java.lang.System.loadLibrary(System.java:557)


Mr.Green2

  • Guest
Re: BASS for Android
« Reply #131 on: 15 Apr '12 - 22:20 »
And libbass.so is present in apk

Ian @ un4seen

  • Administrator
  • Posts: 20389
Re: BASS for Android
« Reply #132 on: 16 Apr '12 - 14:45 »
BASS_FX_BFX_VOLUME effect works exectly the same as DSP function. Is it possible to make dinamic preamp to reduce only too high volume on some frequencies and not affect other frequences with correct volume?

It sounds like a multiband compressor is what you want. BASS doesn't provide that, but perhaps there are 3rd-party implementations available. If so, that could be applied via a DSP function; you would want to give it a low "priority" in the BASS_ChannelSetDSP call so that it's applied last (after any other effects).

Did you test last bass and bass_fx release on Android < 2.3 ? I have error:

java.lang.UnsatisfiedLinkError: Library bass not found
  at java.lang.Runtime.loadLibrary(Runtime.java:461)
  at java.lang.System.loadLibrary(System.java:557)

Make sure the BASS library is loaded before the BASS_FX library by making a BASS call before you make a BASS_FX call. For example, you could do this first thing in your app to enforce the correct load order...

Code: [Select]
BASS.BASS_GetVersion();
BASS_FX.BASS_FX_GetVersion();

gnag

  • Posts: 160
Re: BASS for Android
« Reply #133 on: 17 Apr '12 - 10:44 »
Hello, I want to generate a Sine Wave Tone using Bass for Android (2.2.3) , I use a similar Code in C#, it works there. Can you give me a Tip what I could have made wrong?
All I hear from the Speakers is some strange Noise, it is not the generated Wave.

The Code makes the ByteBuffer an ShortBuffer (2 Byte per 16 Bit Number), fills the Buffer and puts it back as far as I understand and returns the number of Bytes written, what did I overlook here?
I am using a StreamProc because I want to change the Frequency while playing.

Code: [Select]
int loopChannel;
float theta = 0;
float angle = 0;
int _sampleRate = 44100;
public double frequency = 440.0;

private void StartLoopChan() {
// Init Theta
theta = (float) (Math.PI * frequency * 2) / (float) (_sampleRate);

// LoopChan

STREAMPROC streamProc = new STREAMPROC() {
public int STREAMPROC(int handle, ByteBuffer buffer, int length,
Object user) {

// Sine Wave Test (16Bit = 2Bytes for 1Short Value)
ShortBuffer ibuffer = buffer.asShortBuffer();
short[] b = new short[length / 2]; // allocate an "short" array
// for the sample data

// Sine Init
double amplitude = 32767.0;

for (int a = 0; a < length / 2; a++) {
b[a] = (short) ((amplitude * Math.sin(angle)));
angle += theta;

}

// Buffer Operations
ibuffer.put(b); // put the array back into the buffer

return length * 2;
}
};

//Set Buffer Size (default 30ms) -- BASS.BASS_SetConfig(BASS.BASS_CONFIG_DEV_BUFFER, 10000);
loopChannel = BASS.BASS_StreamCreate(_sampleRate, 1,
BASS.BASS_SAMPLE_LOOP, streamProc, 0);

// int err = BASS.BASS_ErrorGetCode();
BASS.BASS_ChannelPlay(loopChannel, false);

}

gnag

  • Posts: 160
Re: BASS for Android
« Reply #134 on: 17 Apr '12 - 15:38 »
I was able to solve my Problem by adding "buffer.order(null);" to the first line of the StreamProc, however I am still NOT getting the correct Results, I now have some kind of Pause/Break in my Sine Waves, can anyone tell me why is that so, is there some kind of unfilled Space or Buffer Problem ?

Again it must be Java/Android specific since on Windows I dont have the Problem.

Sound Waves look like this (Recorded via Line In/Speaker Loop)


Ian @ un4seen

  • Administrator
  • Posts: 20389
Re: BASS for Android
« Reply #135 on: 17 Apr '12 - 16:40 »
I was able to solve my Problem by adding "buffer.order(null);" to the first line of the StreamProc

Yep, that is necessary because Android is natively little-endian while Java's default is big-endian, so it needs to be told that the data in the buffer is little-endian.

Regarding the other problem, it may be due to this line...

Code: [Select]
return length * 2;

The "length" value shouldn't be multiplied, as it hasn't previously been divided :)

gnag

  • Posts: 160
Re: BASS for Android
« Reply #136 on: 17 Apr '12 - 18:40 »
Thanks Ian for this suggestion, my Code looks now like this and I still get the Pauses/Breaks, what could be the Problem ?


Ian @ un4seen

  • Administrator
  • Posts: 20389
Re: BASS for Android
« Reply #137 on: 18 Apr '12 - 15:39 »
Do you happen to be running your app under the debugger, ie. using Eclipse's "Debug" option? If so, you could try using the "Run" option instead, or "Disconnect" the debugger once it is started. I have noticed that array/buffer manipulation (perhaps other things too) seems to be quite a bit slower when running under the debugger, and perhaps that is causing your gaps, ie. the STREAMPROC function is taking too long to sustain playback.

gnag

  • Posts: 160
Re: BASS for Android
« Reply #138 on: 18 Apr '12 - 18:46 »
Thanks, I just found out the same thing before I read your post by just trying out things, it seems that the Eclipse Debugger slows the Process down too much and the Playback gets "Gaps", when just using "Run" it works almost without gaps, only very short ones.

It is amazing how Ian can always find all the Bugs, I needed hours of wild trying out Stuff  ;D

Mr.Green2

  • Guest
Re: BASS for Android
« Reply #139 on: 19 Apr '12 - 09:46 »
Make sure the BASS library is loaded before the BASS_FX library by making a BASS call before you make a BASS_FX call. For example, you could do this first thing in your app to enforce the correct load order...

Code: [Select]
BASS.BASS_GetVersion();
BASS_FX.BASS_FX_GetVersion();
It didn't help. But if I just replace libbass.so with older one then everything start working. Could you test it on Android < 2.3, please?

Ian @ un4seen

  • Administrator
  • Posts: 20389
Re: BASS for Android
« Reply #140 on: 19 Apr '12 - 14:48 »
That's strange. If you look at the call stack in the debugger, what function call is the error message coming up on?

gnag

  • Posts: 160
Re: BASS for Android
« Reply #141 on: 23 Apr '12 - 19:18 »
Hello,
again I am facing a Problem with things that work in the Windows Version but don't work in the Android/Java Version. Currently I want to use a SYNCPROC to call a Loop every X Seconds (1 Second currently) which produces a Tone.

After playing the Stream loopchannel which is feed from a STREAMPROC I can alread hear Sounds but when I try to set an SYNCPROC with 1 Second of Data as the Time to call it just doesn't get called, the debugger never steps into the line that says FreqChange(...), in Windows a similar Code works without Problem.

Maybe there is something special on Java again I missed.
Maybe something is getting Garbage collected or anything else is different?
If you need the full Code let me know, I can send it via PM because I don't want to post it all here.

Code: [Select]
private void DoSyncProc() {
// SyncProc
BASS.SYNCPROC mySync=new BASS.SYNCPROC() {
    public void SYNCPROC(int handle, int channel, int data, Object user) {
    //Play Next Tone
    // float freq_new = note_stack.iterator().next().Frequency;
    FreqChange(frequency+100);
    //Reset Channel
    BASS.BASS_ChannelSetPosition(handle, 0, BASS.BASS_POS_BYTE);
   
    }
   };
long nextPos = BASS.BASS_ChannelSeconds2Bytes(loopChannel, 1);
BASS.BASS_ChannelSetSync(loopChannel, BASS.BASS_SYNC_POS | BASS.BASS_SYNC_MIXTIME, nextPos, mySync, 0);
// int err = BASS.BASS_ErrorGetCode();
BASS.BASS_ChannelPlay(loopChannel, false);
}

Edit: I got the first problem solved (now it gets called after I called the SetSync before the ChannelPlay, on Windows the order of this calls doesn't have to be in that way, both ways work) however it does only get called once, does anyone know why?
« Last Edit: 24 Apr '12 - 17:07 by gnag »

Ian @ un4seen

  • Administrator
  • Posts: 20389
Re: BASS for Android
« Reply #142 on: 24 Apr '12 - 17:16 »
Are you sure that the "nextPos" position is ahead of the current decoding position? Note it needs to be ahead of the decoding position, not just the currently heard position (which will be behind the decoding due to buffering). You can get the decoding position by using the BASS_POS_DECODE flag in a BASS_ChannelGetPosition call. If that is fine and the sync is still not working properly, please confirm how you're creating the "loopChannel" stream and what CONFIG settings you're using.

gnag

  • Posts: 160
Re: BASS for Android
« Reply #143 on: 24 Apr '12 - 17:28 »
Thanks for your answer, yes I think it wasn't ahead of the current decoding Position because I was playing first and then calling the BASS_ChannelSetSync, I changed the order and it works now.

Also I was able to solve my second problem, the problem was that I was calling BASS_ChannelSetPosition with the handle of/from the SYNCPROC callback function instead of the channel handle so it didn't get reset and therefore was called only once, it works now like it should.

Ian @ un4seen

  • Administrator
  • Posts: 20389
Re: BASS for Android
« Reply #144 on: 24 Apr '12 - 17:55 »
Oh yes, looking at your code again, it should be the "channel" handle that is used in the BASS_ChannelSetPosition call. Should have spotted that 1st time round :)

Ian @ un4seen

  • Administrator
  • Posts: 20389
Re: BASS for Android
« Reply #145 on: 4 May '12 - 14:49 »
The latest BASS version (2.4.9) is now up in the 1st post.

Mr.Green2

  • Guest
Re: BASS for Android
« Reply #146 on: 4 May '12 - 19:46 »
Android < 2.3 still doesn't see bass lib=(

Here is log:
Code: [Select]
05-04 22:42:34.909: D/dalvikvm(26812): Trying to load lib /data/data/app.name/lib/libbass.so 0x47ff68f8
05-04 22:42:34.926: I/dalvikvm(26812): Unable to dlopen(/data/data/app.name/lib/libbass.so): Cannot load library: link_image[1995]: failed to link libbass.so
05-04 22:42:34.926: W/dalvikvm(26812): Exception Ljava/lang/UnsatisfiedLinkError; thrown during Lcom/un4seen/bass/BASS;.<clinit>
05-04 22:42:34.926: D/AndroidRuntime(26812): Shutting down VM
05-04 22:42:34.926: W/dalvikvm(26812): threadid=1: thread exiting with uncaught exception (group=0x4001d7d0)
05-04 22:42:34.926: D/FlurryAgent(26812): Ending session

and then:

Code: [Select]
05-04 22:42:34.987: E/AndroidRuntime(26812): FATAL EXCEPTION: main
05-04 22:42:34.987: E/AndroidRuntime(26812): java.lang.ExceptionInInitializerError
...
05-04 22:42:34.987: E/AndroidRuntime(26812): Caused by: java.lang.UnsatisfiedLinkError: Library bass not found
05-04 22:42:34.987: E/AndroidRuntime(26812): at java.lang.Runtime.loadLibrary(Runtime.java:461)
05-04 22:42:34.987: E/AndroidRuntime(26812): at java.lang.System.loadLibrary(System.java:557)
05-04 22:42:34.987: E/AndroidRuntime(26812): at com.un4seen.bass.BASS.<clinit>(BASS.java:670)
05-04 22:42:34.987: E/AndroidRuntime(26812): ... 18 more

If I just change libbass.so to the old version - everything become allright.

Ian @ un4seen

  • Administrator
  • Posts: 20389
Re: BASS for Android
« Reply #147 on: 5 May '12 - 13:55 »
Ah. That was probably introduced with the asset support, which appears to require Android 2.3. An update is now up in the 1st post, which should still work when asset support is unavailable (asset support will just be disabled then). Let me know if you still have any trouble loading it.

Mr.Green2

  • Guest
Re: BASS for Android
« Reply #148 on: 5 May '12 - 20:18 »
Ah. That was probably introduced with the asset support, which appears to require Android 2.3. An update is now up in the 1st post, which should still work when asset support is unavailable (asset support will just be disabled then). Let me know if you still have any trouble loading it.
Thanks. Everything is working now!

Ian @ un4seen

  • Administrator
  • Posts: 20389
Re: BASS for Android
« Reply #149 on: 8 May '12 - 15:22 »
The latest BASSmix version (2.4.7) is now up in the Android package, in the 1st post.