Author Topic: BASS for Android  (Read 390437 times)

norbert

  • Posts: 122
Re: BASS for Android
« Reply #325 on: 31 Mar '13 - 17:42 »
What is the Android equivalent of BASS_MIDI_StreamGetTrackCount ? At least in BASS.NET this method exists.

radio42

  • Posts: 4574
Re: BASS for Android
« Reply #326 on: 31 Mar '13 - 19:22 »
It internally calls "BASS_ChannelGetTags" with the "BASS_TAG_MIDI_TRACK" flag to get the total number of tracks contained in the MIDI stream.

Nalpaco

  • Posts: 2
Re: BASS for Android
« Reply #327 on: 15 Apr '13 - 08:56 »
Hi guys,

I like to use this library for my music app that I am making for Android and IOS Platform so could you please guide me ?
As i am not able to get any running example for playing music and recording.
Is this library is still working?


Ian @ un4seen

  • Administrator
  • Posts: 20400
Re: BASS for Android
« Reply #328 on: 15 Apr '13 - 17:22 »
Please give some detail on the problem you are having, eg. are you having trouble building the examples included in the BASS package (in the 1st post), or are you having trouble running the built examples, or something else?

Nalpaco

  • Posts: 2
Re: BASS for Android
« Reply #329 on: 16 Apr '13 - 06:25 »
Hi Ian

Thanks for your respond,
I am playing on example that you shared in post 1.May be need your help in future while working proper coding part.
Meanwhile could you please let me know can I use Cordova(http://cordova.apache.org/) with this library?
Also I want to know how many tracks of music file I can play simultaneously?

Thanks again!

« Last Edit: 16 Apr '13 - 06:28 by Nalpaco »

Ian @ un4seen

  • Administrator
  • Posts: 20400
Re: BASS for Android
« Reply #330 on: 16 Apr '13 - 15:06 »
Meanwhile could you please let me know can I use Cordova(http://cordova.apache.org/) with this library?

I'm unfamiliar with Cordova, so I'm afraid I can't really comment on that, but if it permits the use of 3rd-party native libraries, then I guess it should be possible to use BASS with it on supported platforms.

Also I want to know how many tracks of music file I can play simultaneously?

There is no fixed limit. The number of files that can be successfully played simultaneously will depend on the file format and how powerful the CPU is. The BASS_GetCPU function can be used to check whether BASS is struggling.

jackraymund

  • Posts: 4
Re: BASS for Android
« Reply #331 on: 19 Apr '13 - 12:59 »
Hi guys, i use this code, its work but music isnt play well, its very slow
i try to use audiotrack because bass_init calling error when i use !BASS.BASS_Init(-1, 44100, 0)
Code: [Select]
if (!BASS.BASS_Init(0, 44100, 0)) {
Log.i("TAG","Can't initialize device");
return;
}
String url = "...";
chan=BASS_AAC.BASS_AAC_StreamCreateURL(url, 0, BASS.BASS_STREAM_DECODE, null, null);
int aInt = BASS.BASS_ErrorGetCode();
   String aString = Integer.toString(aInt);
   Log.e("MidiTest", aString);
track = new AudioTrack( AudioManager.STREAM_MUSIC, 44100,
    AudioFormat.CHANNEL_OUT_STEREO, AudioFormat.ENCODING_PCM_16BIT,
    AudioTrack.getMinBufferSize(44100, AudioFormat.CHANNEL_OUT_STEREO, AudioFormat.ENCODING_PCM_16BIT), AudioTrack.MODE_STREAM);

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
track.play();
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

}

int aInt = BASS.BASS_ErrorGetCode();
   String aString = Integer.toString(aInt);
   Log.e("MidiTest", aString);
Log.e("MidiTest", "finished");
}
}).start();
« Last Edit: 19 Apr '13 - 13:07 by jackraymund »

Ian @ un4seen

  • Administrator
  • Posts: 20400
Re: BASS for Android
« Reply #332 on: 19 Apr '13 - 15:10 »
You should use the stream's sample rate when initializing the AudioTrack output, like this...

Code: [Select]
chan=BASS_AAC.BASS_AAC_StreamCreateURL(url, 0, BASS.BASS_STREAM_DECODE, null, null);
BASS_CHANNELINFO ci;
BASS_ChannelGetInfo(chan, &ci);
track = new AudioTrack( AudioManager.STREAM_MUSIC, ci.freq,
     AudioFormat.CHANNEL_OUT_STEREO, AudioFormat.ENCODING_PCM_16BIT,
     AudioTrack.getMinBufferSize(ci.freq, AudioFormat.CHANNEL_OUT_STEREO, AudioFormat.ENCODING_PCM_16BIT), AudioTrack.MODE_STREAM);

Regarding the failed BASS_Init call, what was the error code from that? Please also confirm what Android version your device is running.

jackraymund

  • Posts: 4
Re: BASS for Android
« Reply #333 on: 19 Apr '13 - 15:48 »
Code: [Select]
public static final int BASS_ERROR_DX = 39; // a sufficient DirectX version is not installed
error code from init
ci.freq calls the same(44100) and sometimes return 0
i change that line
Code: [Select]
track = new AudioTrack( AudioManager.STREAM_MUSIC, 44100,AudioFormat.CHANNEL_OUT_STEREO, AudioFormat.ENCODING_PCM_16BIT,
    AudioTrack.getMinBufferSize(44100, AudioFormat.CHANNEL_OUT_STEREO, AudioFormat.ENCODING_PCM_16BIT)*6, AudioTrack.MODE_STREAM);
its work only well when i run this on phone without debugger
its freezing when phone is on idle, running from avd, and when phone is connected to debugger and sometimes getting this errors
Quote
04-19 15:01:49.072: W/AudioTrack(274): obtainBuffer timed out (is the CPU pegged?) 0x22bdc8 user=00033000, server=0002e000
test on htc wildfire 2.2.1 and avd 2.2
« Last Edit: 19 Apr '13 - 16:06 by jackraymund »

Ian @ un4seen

  • Administrator
  • Posts: 20400
Re: BASS for Android
« Reply #334 on: 19 Apr '13 - 16:30 »
OK. On Android, BASS_ERROR_DX from BASS_Init indicates that OpenSL ES is not available, and indeed that would appear to be the case there (OpenSL ES was introduced in Android 2.3).

Regarding the poor performance under the debugger, the debugger does appear to delay some things, eg. buffer/array manipulation. Here's an old post on that subject...

   www.un4seen.com/forum/?topic=13225.msg95360#msg95360

jackraymund

  • Posts: 4
Re: BASS for Android
« Reply #335 on: 19 Apr '13 - 16:36 »
ok, but what with "phone is on idle" or when app is in background
« Last Edit: 19 Apr '13 - 16:38 by jackraymund »

Ian @ un4seen

  • Administrator
  • Posts: 20400
Re: BASS for Android
« Reply #336 on: 19 Apr '13 - 17:23 »
Background apps get lower CPU priority. To get around that, you need to implement a "foreground service". Here's a previous post on that, including a little example...

   www.un4seen.com/forum/?topic=13225.msg99418#msg99418

jackraymund

  • Posts: 4
Re: BASS for Android
« Reply #337 on: 23 Apr '13 - 18:54 »
Code: [Select]
public void onCreate() {
super.onCreate();
SharedPreferences settings = getSharedPreferences(PREFS_NAME,Context.MODE_PRIVATE);
acc = settings.getBoolean("acc", true);
Log.i("TAG","service created");
Log.w(getClass().getName(), "Got to play()!");

     Notification note=new Notification(R.drawable.ikona, "Can you hear the music?", System.currentTimeMillis());
     Intent i=new Intent(this, MainActivity.class);
   
     i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|
                Intent.FLAG_ACTIVITY_SINGLE_TOP);
   
     PendingIntent pi=PendingIntent.getActivity(this, 0,
                                                 i, 0);
     
     note.setLatestEventInfo(this, "Fake Player",
                             "Now Playing: \"Ummmm, Nothing\"",
                             pi);
     note.flags|=Notification.FLAG_NO_CLEAR;

     startForeground(15, note);
if(acc)
{

if (!BASS.BASS_Init(0, 44100, 0)) {
Log.i("TAG","Can't initialize device");
return;
}
String url = "xxxx";
chan=BASS_AAC.BASS_AAC_StreamCreateURL(url, 0, BASS.BASS_STREAM_DECODE, null, null);
int aInt = AudioTrack.getMinBufferSize(44100, AudioFormat.CHANNEL_OUT_STEREO, AudioFormat.ENCODING_PCM_16BIT);
   String aString = Integer.toString(aInt);
   Log.e("MidiTest", aString);
track = new AudioTrack( AudioManager.STREAM_MUSIC, 44100,
    AudioFormat.CHANNEL_OUT_STEREO, AudioFormat.ENCODING_PCM_16BIT,
    AudioTrack.getMinBufferSize(44100, AudioFormat.CHANNEL_OUT_STEREO, AudioFormat.ENCODING_PCM_16BIT)*10, AudioTrack.MODE_STREAM);

new Thread(new Runnable(){
public void run() {
ByteBuffer buffer = ByteBuffer.allocate(10000); // allocate buffer for decoded data
res=BASS.BASS_ChannelGetData(chan, buffer, buffer.capacity()); // decode some data
track.play();
while (res!=-1){
if (res>0)
track.write(buffer.array(), 0, res); // feed it to AudioTrack
else
try {
Thread.sleep(100);
} 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

}

int aInt = BASS.BASS_ErrorGetCode();
   String aString = Integer.toString(aInt);
   Log.e("MidiTest", aString);
Log.e("MidiTest", "finished");
}
}).start();



//stop();
            //aacPlayer = new ArrayAACPlayer( ArrayDecoder.create( Decoder.DECODER_OPENCORE ), this,1500, 700 );
            //aacPlayer.playAsync("xxx");
}
}
service
in activity i use
Code: [Select]
startService(new Intent(MainActivity.this,XXXService.class));what i do wrong?(still freezing)
still getting
Quote
04-24 11:52:05.989: W/AudioTrack(16177): obtainBuffer timed out (is the CPU pegged?) 0x212698 user=0000fa00, server=00007d00
« Last Edit: 27 Apr '14 - 09:04 by jackraymund »

Ian @ un4seen

  • Administrator
  • Posts: 20400
Re: BASS for Android
« Reply #338 on: 24 Apr '13 - 13:12 »
Please try starting with the example in the post I linked, and then modify it to use AudioTrack output while leaving the rest (eg. service-related stuff) as it is.

norbert

  • Posts: 122
Re: BASS for Android
« Reply #339 on: 29 Apr '13 - 09:08 »
I was just wondering whether playing a midi file using a wavpack lossy compressed (256 kbit) soundfont could result in a significant higher cpu usage compared to an uncompressed soundfont, at least on slower Android devices.

But after using BASS_MIDI_StreamLoadSamples there should be no more difference between a packed and an unpacked soundfont regarding cpu usage for reading the sample data because all preloading AND decoding is done only once ? Is this correct ?

Ian @ un4seen

  • Administrator
  • Posts: 20400
Re: BASS for Android
« Reply #340 on: 29 Apr '13 - 16:59 »
The only difference in CPU usage between a packed and non-packed version of the same soundfont is in loading the samples. A packed sample will require more CPU to load, so there could be a spike in CPU usage when a new sample is first played, but there would be no such spike for subsequent playbacks of the sample (unless it gets unloaded via BASS_MIDI_FontUnload/Compact). Sample-loading CPU spikes during playback can be avoided by using BASS_MIDI_StreamLoadSamples to pre-load the samples.

mrjoey

  • Posts: 31
Re: BASS for Android
« Reply #341 on: 30 Apr '13 - 14:50 »
Sir IAN can u post me a clean and fast waveform display for the whole song using channel_getdata? i tried getposition and get level i got a nice waveform but not accurate. 10x

Ian @ un4seen

  • Administrator
  • Posts: 20400
Re: BASS for Android
« Reply #342 on: 3 May '13 - 17:31 »
The Android version of BASSMIDI 2.4.8 is now up in the 1st post.

toob

  • Posts: 133
Re: BASS for Android
« Reply #343 on: 18 May '13 - 19:35 »
put this in proguard.cfg:
-keep class com.un4seen.bass.** {
  public protected private *;
}

Thanks - this was driving me nuts!  :P

MrGreen

  • Guest
Re: BASS for Android
« Reply #344 on: 27 May '13 - 01:36 »
Guys, you have some issues with performance in the last version of the library.

I had previos version which was released before 30 October 2012. But when I updated to new one from 3 May 2013 the I receive some lags in the beginning of some MP3 tracks. Maybe it's a problem with buffering or something like that.

Bitrate of the song is 320K. Android version is 4.2.2. Device is Samsung Galaxy Nexus.

I can send you music sample to test it if you need it.

Ian @ un4seen

  • Administrator
  • Posts: 20400
Re: BASS for Android
« Reply #345 on: 28 May '13 - 15:19 »
When you say "lags in the beginning", do you mean there is a delay before playback starts, or is the playback stuttering at the start? Do you still have the old BASS library version to compare with, ie. are you able to switch between that and the current version and notice a difference? If so, please monitor and report what BASS_GetCPU says, ie. does it show higher CPU usage with the current version? If the problem is happening with a particular file, please do upload that to have a look at here...

   ftp.un4seen.com/incoming/

Dodge

  • Posts: 32
Re: BASS for Android
« Reply #346 on: 31 May '13 - 12:11 »
Hey there,

i got a question about licensing.

I plan to release an app using BASS for android. The App will be free, but later maybe there will be an option to buy some features per in app purchase.
would a shareware license be OK, if all features stay less than 10? As it allows non shareware products with a price limit of 10?
or does a app with in app purchase even count as shareware?


thanks

Ian @ un4seen

  • Administrator
  • Posts: 20400
Re: BASS for Android
« Reply #347 on: 31 May '13 - 17:47 »
If you are creating the app yourself as an individual (eg. not working for a company), then that sounds perfectly fine with a Shareware BASS licence. Regarding what qualifies as "shareware", it's basically anything that's made available on a "try before you buy" basis. Your case sounds like it would qualify as that.

mrjoey

  • Posts: 31
Re: BASS for Android
« Reply #348 on: 3 Jun '13 - 21:44 »
Sir IAN same question here as Dodge's
i want to publish my music app on play store as a paid app..so what license do i need?

Ian @ un4seen

  • Administrator
  • Posts: 20400
Re: BASS for Android
« Reply #349 on: 4 Jun '13 - 16:51 »
If you are creating the app yourself as an individual (eg. not working for a company), then the Shareware BASS licence is what you would want for that. If the price of your app exceeds the licence's price limit, you can purchase multiple licences to raise the limit.