Author Topic: BASS for Android  (Read 392188 times)

Sebastian

  • Guest
Re: BASS for Android
« Reply #1025 on: 7 Feb '16 - 18:58 »
Hello,

nice library, but i have a problem with the function on Android:
BASS_MIDI_StreamCreateEvents

The library works fine when I create the stream with a file, but when I want to create it with
an array of BASS_MIDI_EVENT it doesn't work. I always get the BASS_ERROR_POSITION.
I manually create midi event files and set the time tick but the library is still returning the same error.

Is it possible that there is a bug? I use the latest library from the first post.

thanks for your help.


Ian @ un4seen

  • Administrator
  • Posts: 20437
Re: BASS for Android
« Reply #1026 on: 8 Feb '16 - 12:55 »
BASS_ERROR_POSITION indicates that the provided events aren't in chronological order. Please note that the event positions ("tick" values) must be absolute. Perhaps you're currently using deltas? If so, you can add the preceding event's position to each delta to make it absolute.

Sebastian

  • Guest
Re: BASS for Android
« Reply #1027 on: 8 Feb '16 - 13:43 »
I'm not using deltas.
Event if I do this the same error appears:

BASSMIDI.BASS_MIDI_EVENT e = new BASSMIDI.BASS_MIDI_EVENT();
e.tick = 1;
e.event = BASSMIDI.MIDI_EVENT_NOTE;
e.chan = 0;
e.param = BASS.Utils.MAKEWORD(60,100);
BASSMIDI.BASS_MIDI_EVENT[] eventArray = new BASSMIDI.BASS_MIDI_EVENT[1];
eventArray[0] = e;
BASSMIDI.BASS_MIDI_StreamCreateEvents(eventArray, mPPQN, 0, 0)

StreamCreateEvents only returns a valid handle if all Ticks from the events passed to this functions is set to 0.


Ian @ un4seen

  • Administrator
  • Posts: 20437
Re: BASS for Android
« Reply #1028 on: 8 Feb '16 - 14:15 »
The event array needs to end with a MIDI_EVENT_END event, which tells BASSMIDI the end position. For example, to have the note play for a while, the MIDI_EVENT_END event should be positioned some time after the MIDI_EVENT_NOTE event. An example code snippet can be found in the BASS_MIDI_StreamCreateEvents documentation.

Sebastian

  • Guest
Re: BASS for Android
« Reply #1029 on: 8 Feb '16 - 16:21 »
The event array needs to end with a MIDI_EVENT_END event, which tells BASSMIDI the end position. For example, to have the note play for a while, the MIDI_EVENT_END event should be positioned some time after the MIDI_EVENT_NOTE event. An example code snippet can be found in the BASS_MIDI_StreamCreateEvents documentation.

thank you, that was my problem. Forgot about the MIDI_EVENT_END always used MIDI_EVENT_NOTE...

bracken

  • Posts: 9
Re: BASS for Android
« Reply #1030 on: 9 Feb '16 - 04:05 »
What is the proper way to check if a file is supported?  Specifically, I'm wanting to know if a file is an m4a file with MPEG DASH, which cannot be decoded by BASS.  I'm using the BASS.BASS_STREAM_DECODE flag to decode the bytes, not streaming directly.  I'm currently checking if 0 bytes are returned by BASS_ChannelGetData to see if it's supported, which works most of the time, but occasionally this causes a crash in native code: "A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr...."

So.. what's the safe and proper way to check if a file is supported?

Ian @ un4seen

  • Administrator
  • Posts: 20437
Re: BASS for Android
« Reply #1031 on: 9 Feb '16 - 17:19 »
I think the current Android BASS_AAC add-on version should fail (with a BASS_ERROR_FILEFORM error) to create streams from MPEG DASH files, but just to be sure, I have put up a build of the latest code in the 1st post. If you still get the problem with it, please upload an affected file to have a look at here:

   ftp.un4seen.com/incoming/

If you would like to detect an MPEG DASH file yourself, you can look for "ftypdash" in bytes 4-11 of the file.

norbert

  • Posts: 122
Re: BASS for Android
« Reply #1032 on: 9 Feb '16 - 17:51 »
A user is reporting that on an Android 5.1.1 device he's always getting this error:
BASS_ERROR_FORMAT.

Currently the first call I use  is:

BASS.BASS_Init(-1, 0, 0)  // -1 = default device, freq is ignored because I did not specify the BASS_DEVICE_FREQ flag

If this returns false then I try

BASS.BASS_Init(1, 0, 0) //   //1 = first real output device

Any idea what could be the problem, and what could be tried instead (flags,...) ?

bracken

  • Posts: 9
Re: BASS for Android
« Reply #1033 on: 10 Feb '16 - 02:29 »
I think the current Android BASS_AAC add-on version should fail (with a BASS_ERROR_FILEFORM error) to create streams from MPEG DASH files, but just to be sure, I have put up a build of the latest code in the 1st post. If you still get the problem with it, please upload an affected file to have a look at here:

   ftp.un4seen.com/incoming/

If you would like to detect an MPEG DASH file yourself, you can look for "ftypdash" in bytes 4-11 of the file.

Thanks Ian, that's what I needed to know. :)

Ian @ un4seen

  • Administrator
  • Posts: 20437
Re: BASS for Android
« Reply #1034 on: 10 Feb '16 - 13:46 »
A user is reporting that on an Android 5.1.1 device he's always getting this error:
BASS_ERROR_FORMAT.

Currently the first call I use  is:

BASS.BASS_Init(-1, 0, 0)  // -1 = default device, freq is ignored because I did not specify the BASS_DEVICE_FREQ flag

If this returns false then I try

BASS.BASS_Init(1, 0, 0) //   //1 = first real output device

Any idea what could be the problem, and what could be tried instead (flags,...) ?

Does the BASS_Init call still fail if you include a sample rate (eg. 44100 or 48000) in it? BASS_Init will try to get and use the device's native rate (if BASS_DEVICE_FREQ isn't used), but perhaps it wasn't able to for some reason in this case.

norbert

  • Posts: 122
Re: BASS for Android
« Reply #1035 on: 10 Feb '16 - 16:39 »
Yes, actually the original call contained the 44100 instead of 0 (I have only removed this number for this post because it is without any meaning as the BASS_Freq flag is not specified)

Ian @ un4seen

  • Administrator
  • Posts: 20437
Re: BASS for Android
« Reply #1036 on: 11 Feb '16 - 13:02 »
OK. I will send you a debug version to get some more info on what's happening.

UserAlexandr

  • Posts: 37
Re: BASS for Android
« Reply #1037 on: 13 Feb '16 - 13:20 »
Hello, how to remove the downsampling? (android 5.0)

And how to check current sample rate?
Im try AudioTrack.getNativeOutputSampleRate(AudioManager.STREAM_MUSIC) and BASS.BASS_GetInfo(); // (get 48000)

There is a way to get 24bit/96000Hz?

Its work?
Code: [Select]
if (!BASS.BASS_Init(-1, 96000, 0))  {
DEBUG.Log("BASS", "Init Error!");
return;
}

And if im use this flag:
Quote
BASS.BASS_StreamCreateFile(path, 0, 0, BASS.BASS_SAMPLE_FLOAT))
BASS.BASS_MusicLoad(path, 0, 0, BASS.BASS_SAMPLE_FLOAT|BASS.BASS_MUSIC_RAMP, 1))

waveform from LiveSpec dont work correct:
Code: [Select]
ByteBuffer bbuf=ByteBuffer.allocateDirect(width*2); // allocate a buffer for the sample data
bbuf.order(null); // little-endian byte order
BASS.BASS_ChannelGetData(chan, bbuf, width*2); // get the sample data
short[] pcm=new short[width]; // allocate a "short" array for the sample data
bbuf.asShortBuffer().get(pcm); // get the data from the buffer into the array
for (int x=0, y=0; x<width; x++) {
int v=(32767-pcm[x])*height/65536; // invert and scale to fit display
if (x==0) y=v;
do { // draw line from previous sample...
if (y<v) y++;
else if (y>v) y--;
specbuf[y*width+x]=palette[1];
} while (y!=v);
}
« Last Edit: 15 Feb '16 - 13:53 by UserAlexandr »

truefedex

  • Posts: 3
Re: BASS for Android
« Reply #1038 on: 13 Feb '16 - 23:35 »
Quote
An "mp3-free" BASS version (using the OS's MP3 decoder) is included, which requires Android 4.1 or above
I tryed it on emulators (from 4.1 to 5.0) and on my Nexus 7 (with android 6.0.1) and it worked, but not on my Lenovo A369i (android 4.2.2 stock) - on A369i BASS_StreamCreateFile of mp3free version lead to crash((

Also seems flag BASS.BASS_ASYNCFILE leads to sigsegv if used with function BASS_StreamCreateFile on android

truefedex

  • Posts: 3
Re: BASS for Android
« Reply #1039 on: 14 Feb '16 - 18:31 »
One yet - BASS.BASS_ChannelGetTags(currentStream, BASS.BASS_TAG_ID3) returns BASS.TAG_ID3 with java.lang.String fields. But java.lang.String internally UTF-16 encoded, but seems BASS placed inside it raw string from ID3 which can be randomly encoded. I think this is wrong - in this case better to use byte[] arrays so user of BASS.BASS_TAG_ID3 can do simply: new String(tags.artist, "Win-1251") etc., or guess encoding.

Ian @ un4seen

  • Administrator
  • Posts: 20437
Re: BASS for Android
« Reply #1040 on: 15 Feb '16 - 17:14 »
And how to check current sample rate?
Im try AudioTrack.getNativeOutputSampleRate(AudioManager.STREAM_MUSIC) and BASS.BASS_GetInfo(); // (get 48000)

There is a way to get 24bit/96000Hz?

Its work?
Code: [Select]
if (!BASS.BASS_Init(-1, 96000, 0))  {
DEBUG.Log("BASS", "Init Error!");
return;
}

You can use the BASS_DEVICE_FREQ flag in the BASS_Init call to request BASS to output at the specified rate. Note that most devices don't support 96000 Hz, so you should be prepared for the BASS_Init call to fail, and retry with a lower rate (or without the BASS_DEVICE_FREQ flag).

To play 24-bit files in full quality, you should use the BASS_SAMPLE_FLOAT flag in your BASS_StreamCreateFile calls. To hear the difference, you will also need to be using Android 5 or above, as older Android versions are limited to 16-bit output.

Quote
An "mp3-free" BASS version (using the OS's MP3 decoder) is included, which requires Android 4.1 or above
I tryed it on emulators (from 4.1 to 5.0) and on my Nexus 7 (with android 6.0.1) and it worked, but not on my Lenovo A369i (android 4.2.2 stock) - on A369i BASS_StreamCreateFile of mp3free version lead to crash((

Also seems flag BASS.BASS_ASYNCFILE leads to sigsegv if used with function BASS_StreamCreateFile on android

Oops! There is indeed a problem with the BASS_ASYNCFILE support in the current Android version. An update to fix that is now up in the 1st post. Let me know if you still get the mp3-free crashing with it, and I'll send you a debug version to get some info on that.

One yet - BASS.BASS_ChannelGetTags(currentStream, BASS.BASS_TAG_ID3) returns BASS.TAG_ID3 with java.lang.String fields. But java.lang.String internally UTF-16 encoded, but seems BASS placed inside it raw string from ID3 which can be randomly encoded. I think this is wrong - in this case better to use byte[] arrays so user of BASS.BASS_TAG_ID3 can do simply: new String(tags.artist, "Win-1251") etc., or guess encoding.

BASS will convert ID3v1 tags from ISO 8859-1 to UTF-8 strings in the TAG_ID3 class. If you need to convert from some other codepage, you can use the BASS_TAG_BYTEBUFFER flag in the BASS_ChannelGetTags call and you will then receive a ByteBuffer containing the file's original ID3 tag block, which you can process as you want.

UserAlexandr

  • Posts: 37
Re: BASS for Android
« Reply #1041 on: 15 Feb '16 - 18:44 »
And how to check current sample rate?
Im try AudioTrack.getNativeOutputSampleRate(AudioManager.STREAM_MUSIC) and BASS.BASS_GetInfo(); // (get 48000)

There is a way to get 24bit/96000Hz?

Its work?
Code: [Select]
if (!BASS.BASS_Init(-1, 96000, 0))  {
DEBUG.Log("BASS", "Init Error!");
return;
}

You can use the BASS_DEVICE_FREQ flag in the BASS_Init call to request BASS to output at the specified rate. Note that most devices don't support 96000 Hz, so you should be prepared for the BASS_Init call to fail, and retry with a lower rate (or without the BASS_DEVICE_FREQ flag).

To play 24-bit files in full quality, you should use the BASS_SAMPLE_FLOAT flag in your BASS_StreamCreateFile calls. To hear the difference, you will also need to be using Android 5 or above, as older Android versions are limited to 16-bit output.

Thanks for the answer. Im use BASS_SAMPLE_FLOAT, but because of it I have not worked waveform of your example "LiveSpec.java"  :-\

truefedex

  • Posts: 3
Re: BASS for Android
« Reply #1042 on: 15 Feb '16 - 21:17 »
Quote
An update to fix that is now up in the 1st post.
Thank you! Now BASS_ASYNCFILE seems working well!
Quote
Let me know if you still get the mp3-free crashing with it
Yes, unfortunately it still crashes on Lenovo A369i while trying to play mp3((

Ian @ un4seen

  • Administrator
  • Posts: 20437
Re: BASS for Android
« Reply #1043 on: 16 Feb '16 - 14:19 »
OK. I've sent you a debug "mp3-free" BASS version to get some more info on that.

UserAlexandr

  • Posts: 37
Re: BASS for Android
« Reply #1044 on: 17 Feb '16 - 10:55 »
Hello, I'm trying to make a waveform (LiveSpec.java) with flag BASS.BASS_SAMPLE_FLOAT.

Code: [Select]
Arrays.fill(specbuf, 0);
ByteBuffer bbuf=ByteBuffer.allocateDirect(width*4);
bbuf.order(null);
BASS.BASS_ChannelGetData(chan, bbuf, width*4);
float[] pcm=new float[width];
bbuf.asFloatBuffer().get(pcm);

But i can't understand this part of code:
Code: [Select]
int v=(32767-pcm[x])*height/65536;
32767 max short value?
65536 ?

And if floating-point is not supported for device, its be 16 bits anyway?

Thx.

Ian @ un4seen

  • Administrator
  • Posts: 20437
Re: BASS for Android
« Reply #1045 on: 17 Feb '16 - 13:04 »
But i can't understand this part of code:
Code: [Select]
int v=(32767-pcm[x])*height/65536;

You can replace that with this:

Code: [Select]
int v=(int)((1-pcm[x])*height/2);
if (v<0) v=0;
if (v>=height) v=height-1;

And if floating-point is not supported for device, its be 16 bits anyway?

You can add the BASS_DATA_FLOAT flag to the BASS_ChannelGetData call to use the same code with 8/16-bit channels:

Code: [Select]
BASS.BASS_ChannelGetData(chan, bbuf, (width*4)|BASS.BASS_DATA_FLOAT);

UserAlexandr

  • Posts: 37
Re: BASS for Android
« Reply #1046 on: 17 Feb '16 - 15:45 »
But i can't understand this part of code:
Code: [Select]
int v=(32767-pcm[x])*height/65536;

You can replace that with this:

Code: [Select]
int v=(int)((1-pcm[x])*height/2);
if (v<0) v=0;
if (v>=height) v=height-1;

And if floating-point is not supported for device, its be 16 bits anyway?

You can add the BASS_DATA_FLOAT flag to the BASS_ChannelGetData call to use the same code with 8/16-bit channels:

Code: [Select]
BASS.BASS_ChannelGetData(chan, bbuf, (width*4)|BASS.BASS_DATA_FLOAT);

Thx, you verry help me.  ;)

UserAlexandr

  • Posts: 37
Re: BASS for Android
« Reply #1047 on: 24 Feb '16 - 11:15 »
Hello, I'm trying to play 96Khz but DEVICEINFO.freq is only 44100, why?

BASS.BASS_Init(-1, 96000, 0) - > return true
info.freq from BASS_ChannelGetInfo -> return 96000
info.freq from BASS_GetInfo -> return 44100

Device:
OS: Android 5.1
DAC: ESS Sabre ESS9018K2M (32bit/384Khz)
« Last Edit: 24 Feb '16 - 13:18 by UserAlexandr »

Ian @ un4seen

  • Administrator
  • Posts: 20437
Re: BASS for Android
« Reply #1048 on: 24 Feb '16 - 15:27 »
Try adding the BASS_DEVICE_FREQ flag to your BASS_Init call. If you don't use that flag, then BASS_Init will use the native output rate (according to getNativeOutputSampleRate).

UserAlexandr

  • Posts: 37
Re: BASS for Android
« Reply #1049 on: 24 Feb '16 - 15:36 »
Try adding the BASS_DEVICE_FREQ flag to your BASS_Init call. If you don't use that flag, then BASS_Init will use the native output rate (according to getNativeOutputSampleRate).

BASS.BASS_Init(-1, 96000, BASS.BASS_DEVICE_FREQ) - > return false.

Only 44100 and 48000 return true. Why? :\

Its my code:
Init:
Code: [Select]
BASS.BASS_SetConfig(BASS.BASS_CONFIG_FLOATDSP, 1);
fixedDSP = (BASS.BASS_GetConfig(BASS.BASS_CONFIG_FLOAT) != 1);

if (!BASS.BASS_Init(-1, SAMPLE_RATE96, BASS.BASS_DEVICE_FREQ))  {
DEBUG.Log("BASS", "Init: "
.concat(String.valueOf(SAMPLE_RATE96))
.concat("Hz Failed!"));

if (!BASS.BASS_Init(-1, SAMPLE_RATE44, 0))  {
DEBUG.Log("BASS", "Init Error!");
return;
}
} else {
DEBUG.Log("BASS", "Init: "
.concat(String.valueOf(SAMPLE_RATE96))
.concat("Hz"));
}

Open:
Code: [Select]
BASS.BASS_MusicFree(channelHandle);
BASS.BASS_StreamFree(channelHandle);

if((channelHandle = BASS.BASS_StreamCreateFile(path, 0, 0, BASS.BASS_SAMPLE_FLOAT)) == 0 && (channelHandle = BASS.BASS_MusicLoad(path, 0, 0, BASS.BASS_SAMPLE_FLOAT|BASS.BASS_MUSIC_RAMP, 1)) == 0) {
DEBUG.Log("BASS", "Can't Play the File!");
DEBUG.Log("BASS", path);
return ERROR;
}

BASS.BASS_ChannelSetSync(channelHandle, BASS.BASS_SYNC_END, 0, EndSync, 0);
BASS.BASS_ChannelPlay(channelHandle, restart);
« Last Edit: 24 Feb '16 - 16:55 by UserAlexandr »