Author Topic: BASS for Android  (Read 704661 times)

jnyang

  • Guest
Re: BASS for Android
« Reply #1800 on: 5 Jan '21 - 10:55 »
Here's an update for you to try:

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

Let me know if you have any trouble with it. Besides fixing your problem (hopefully), it has also switched to using the Android codecs via the native API instead of the Java API to improve performance a bit. BASS has up to now been using the Java API because it works on Android 4.1, while the native API requires Android 5, but there can't be many people still using Android 4.x now? BASS will still work on those (and older) Android versions but Android's codecs won't be used on them.

Hi Ian, I recently updated the BASS library to the latest version, but it seems that the above bug fix is not included. When my app tries to open a file that should be handled by Android's native codec (e.g., WMA, M4A), BASS throws BASS_ERROR_FILEFORM error and the log outputs like "E/ClearFileSource: Failed to open file '/mnt/media_rw/3D9F-BC89/Musics/test.wma'. (Permission denied)".

I tried to re-download the fixed version of BASS library from above link, but it seems that the link does not work anymore.
Can you check this bug again? Thanks!

Ian @ un4seen

  • Administrator
  • Posts: 23563
Re: BASS for Android
« Reply #1801 on: 5 Jan '21 - 14:33 »
Yes, that change isn't in the release version yet, which is still 2.4.15. It will be in 2.4.16, which should be released fairly soon. In the meantime, the latest build's URL has changed slightly to this:

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

The old bass-android-test.zip URL has now been re-enabled too (pointing to the same file), for anyone that's monitoring it for updates.

jnyang

  • Guest
Re: BASS for Android
« Reply #1802 on: 6 Jan '21 - 04:43 »
Yes, that change isn't in the release version yet, which is still 2.4.15. It will be in 2.4.16, which should be released fairly soon. In the meantime, the latest build's URL has changed slightly to this:

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

The old bass-android-test.zip URL has now been re-enabled too (pointing to the same file), for anyone that's monitoring it for updates.

Thank you for your reply. Happy new year!

Ian @ un4seen

  • Administrator
  • Posts: 23563
Re: BASS for Android
« Reply #1803 on: 6 Jan '21 - 17:03 »
The Android version of the BASSALAC 2.4.0.2 release is up now in the 1st post.

gicci

  • Posts: 76
Re: BASS for Android
« Reply #1804 on: 7 Jan '21 - 01:50 »
Hi Ian,

I am testing some files with drums configured on multiple channels, but I am getting param=2 in the corresponding MIDI_EVENT_DRUMS events, not 1 as stated in the documentation.
Shall any value != 0 be interpreted as drums? Does this values carry any additional information?

Thank you.

Ian @ un4seen

  • Administrator
  • Posts: 23563
Re: BASS for Android
« Reply #1805 on: 7 Jan '21 - 17:14 »
That's strange. Please upload one of the MIDI files to have a look at here:

   ftp.un4seen.com/incoming/

Also confirm that you're using the latest BASSMIDI version.

gicci

  • Posts: 76
Re: BASS for Android
« Reply #1806 on: 7 Jan '21 - 18:22 »
I have sent a sample file. Tested with the latest version with the same results. I am using BASS_MIDI_StreamGetEvents(), not looking for them during the playback.

Serg

  • Posts: 7
Re: BASS for Android
« Reply #1807 on: 7 Jan '21 - 20:08 »
Good day! Please tell me, on the android you need to output sound with a slight delay, without using a remote microphone. However, there is strong background audio and noise (unless a separate external microphone is used) :'( .
How to get rid of the squeak, noise?
I am using the following code:

BASS.BASS_SetConfig (BASS. BASS_CONFIG_DEV_BUFFER , 2000);
BASS.BASS_Init(-1, FREQ, 0);
..........

record=BASS.BASS_RecordStart(FREQ, chan, 0, null, null);

output=BASS.BASS_StreamCreate(FREQ, chan, 0, StreamProc, null);
BASS.BASS_ChannelSetAttribute(output, BASS.BASS_ATTRIB_NOBUFFER, 1);
BASS.BASS_ChannelPlay(output, false);
.......

BASSAMPROC(int handle, ByteBuffer buffer, int length, Object user) {
         int r=BASS.BASS_ChannelGetData(record, buffer, length); // get data from the recording
         return r;
      }
   };

Ian @ un4seen

  • Administrator
  • Posts: 23563
Re: BASS for Android
« Reply #1808 on: 8 Jan '21 - 16:49 »
I have sent a sample file. Tested with the latest version with the same results. I am using BASS_MIDI_StreamGetEvents(), not looking for them during the playback.

Ah, I see what it is now. In GS files (like the one you uploaded), the "USE FOR RHYTHM PART" sysex translates to a MIDI_EVENT_DRUMS event, and it can be set to 2 to request the 2nd drum map (GS allows up to 2). BASSMIDI doesn't have a limited number of global drum maps, rather each drum channel has its own map (with its own MIDI_EVENT_DRUM_XXX settings), so it will treat any non-0 setting as 1.

Good day! Please tell me, on the android you need to output sound with a slight delay, without using a remote microphone. However, there is strong background audio and noise (unless a separate external microphone is used) :'( .
How to get rid of the squeak, noise?
I am using the following code:
...

That sounds like what you're hearing is feedback, ie. the speaker is playing the sound from the microphone and the microphone is capturing it again. That can be avoided by using headphones. Otherwise, you will need some AEC (Acoustic Echo Cancellation). Unfortunately, BASS doesn't include that feature but if you would like to give it a try, Android has an AcousticEchoCanceler effect (note you will need to use the AudioRecord API instead of BASS_RecordInit/etc for recording then):

   https://developer.android.com/reference/android/media/audiofx/AcousticEchoCanceler.html

If that doesn't work for you, there is also the libspeex library that includes AEC processing (speex_echo_xxx functions), but I'm not sure whether there is a ready-made Android build of that available.

Serg

  • Posts: 7
Re: BASS for Android
« Reply #1809 on: 8 Jan '21 - 19:08 »
Thank you very much! I will try

Serg

  • Posts: 7
Re: BASS for Android
« Reply #1810 on: 17 Jan '21 - 09:11 »
I'm trying to use "audioRecord", but something doesn't work. The following code doesn't work, the crash occurs on "Output = BASS.BASS_StreamCreateFile (recbuf, 0, recbuf.limit (), 0);" ... Please tell me what I'm doing wrong?

  readCount = audioRecord.read(myBuffer, 0, myBufferSize);

  ByteBuffer recbuf = ByteBuffer.wrap(myBuffer,0,myBuffer.length);

  Output  = BASS.BASS_StreamCreateFile(recbuf, 0, recbuf.limit(), 0); //Falling
  BASS.BASS_ChannelPlay(Output, true);

Ian @ un4seen

  • Administrator
  • Posts: 23563
Re: BASS for Android
« Reply #1811 on: 18 Jan '21 - 13:56 »
BASS_StreamCreateFile will need a WAVE header in front of the sample data (to describe the format of it). You can use BASS_StreamCreate instead to play raw PCM data.

Serg

  • Posts: 7
Re: BASS for Android
« Reply #1812 on: 21 Jan '21 - 05:47 »
BASS_StreamCreateFile will need a WAVE header in front of the sample data (to describe the format of it). You can use BASS_StreamCreate instead to play raw PCM data.

Nothing works with BASS_StreamCreate (), can you give an example with BASS_StreamCreate ()?

Ian @ un4seen

  • Administrator
  • Posts: 23563
Re: BASS for Android
« Reply #1813 on: 21 Jan '21 - 13:05 »
You would use BASS_StreamCreate something like this:

Code: [Select]
stream = BASS.BASS_StreamCreate(freq, chans, 0, StreamProc, null); // create stream
BASS.BASS_ChannelPlay(stream, false); // start it

BASS.STREAMPROC StreamProc = new BASS.STREAMPROC() {
public int STREAMPROC(int handle, ByteBuffer buffer, int length, Object user) {
// put up to "length" bytes of data in "buffer" here and return the amount
}
};

Another option is to create a "push" stream, where you use BASS_StreamPutData instead of a STREAMPROC to provide the data. Something like this:

Code: [Select]
stream = BASS.BASS_StreamCreate(freq, chans, 0, BASS.STREAMPROC_PUSH, null); // create stream
BASS.BASS_StreamPutData(stream, buffer, length); // give it data to play
BASS.BASS_ChannelPlay(stream, false); // start it

Please see the BASS_StreamCreate documentation for details.

rrhh_fx

  • Posts: 21
Re: BASS for Android
« Reply #1814 on: 24 Jan '21 - 19:21 »
When i use   Bassmidi      boolean b = BASSMIDI.BASS_MIDI_StreamSetFilter(chan, false, MIDIFILTER, null);  APP  is crash   but Playing sf2 files is OK

    BASSMIDI.MIDIFILTERPROC MIDIFILTER = new BASSMIDI.MIDIFILTERPROC() {
        @Override
        public boolean MIDIFILTERPROC(int handle, int track, BASSMIDI.BASS_MIDI_EVENT event, boolean seeking, Object user) {
            BASSMIDI.BASS_MIDI_EVENT event1 = event;

            return true;
        }
    };


And  i dont load 

   BASS.BASS_PluginLoad(libpath + "/libbassflac.so", 0);
   BASS.BASS_PluginLoad(libpath + "/libbasswv.so", 0);



crash report:

JNI DETECTED ERROR IN APPLICATION: JNI GetMethodID called with pending exception java.lang.ClassNotFoundException: Didn't find class "com.un4seen.bass.BASSMIDI$BASS_MIDI_EVENT" on path: DexPathList[[directory "."],nativeLibraryDirectories=[/system/lib, /system/product/lib, /system/lib, /system/product/lib]]
2020-02-10 14:36:53.006 17846-17909/com.tuolu.drum A/com.tuolu.drum: java_vm_ext.cc:570]   at java.lang.Class dalvik.system.BaseDexClassLoader.findClass(java.lang.String) (BaseDexClassLoader.java:230)
2020-02-10 14:36:53.006 17846-17909/com.tuolu.drum A/com.tuolu.drum: java_vm_ext.cc:570]   at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String, boolean) (ClassLoader.java:379)
2020-02-10 14:36:53.006 17846-17909/com.tuolu.drum A/com.tuolu.drum: java_vm_ext.cc:570]   at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String) (ClassLoader.java:312)
2020-02-10 14:36:53.006 17846-17909/com.tuolu.drum A/com.tuolu.drum: java_vm_ext.cc:570]
2020-02-10 14:36:53.006 17846-17909/com.tuolu.drum A/com.tuolu.drum: java_vm_ext.cc:570]     in call to GetMethodID

I am experiencing the same problem. Did you solve it?

Ian @ un4seen

  • Administrator
  • Posts: 23563
Re: BASS for Android
« Reply #1815 on: 25 Jan '21 - 18:04 »
Ah, I think I see what that is now (the filtering thread is unable to get the BASS_MIDI_EVENT Java class). Here's an update that should fix it:

   www.un4seen.com/stuff/bassmidi-android.zip

Let me know if you still see the problem happening with that.

rrhh_fx

  • Posts: 21
Re: BASS for Android
« Reply #1816 on: 25 Jan '21 - 18:24 »
Ah, I think I see what that is now (the filtering thread is unable to get the BASS_MIDI_EVENT Java class). Here's an update that should fix it:

   www.un4seen.com/stuff/bassmidi-android.zip

Let me know if you still see the problem happening with that.

Impressive! You saved my day. Thanks a lot :)

rrhh_fx

  • Posts: 21
Re: BASS for Android
« Reply #1817 on: 26 Jan '21 - 12:25 »
In BASSMidi, When changing the playback speed through
                           
Code: [Select]
BASSMIDI.BASS_MIDI_StreamEvent(stream, channel, BASSMIDI.MIDI_EVENT_SPEED, newSpeed);
is there a way to know the playback position in the stream after the change (for example, in percentage, or respect the new length? Since BASS_ChannelGetLength returns the same value

Ian @ un4seen

  • Administrator
  • Posts: 23563
Re: BASS for Android
« Reply #1818 on: 26 Jan '21 - 14:29 »
Impressive! You saved my day. Thanks a lot :)

Great! The BASSMIDI update has now been moved to the main package in the first post.

In BASSMidi, When changing the playback speed through
                           
Code: [Select]
BASSMIDI.BASS_MIDI_StreamEvent(stream, channel, BASSMIDI.MIDI_EVENT_SPEED, newSpeed);
is there a way to know the playback position in the stream after the change (for example, in percentage, or respect the new length? Since BASS_ChannelGetLength returns the same value

BASSMIDI doesn't keep track of what the new time/byte length will be after speed changes, but the tick length isn't affected by them, so you could use that (BASS_POS_MIDI_TICK) for a percentage:

Code: [Select]
percentage = 100 * BASS_ChannelGetPosition(handle, BASS_POS_MIDI_TICK) /  BASS_ChannelGetLength(handle, BASS_POS_MIDI_TICK);

If you want the time/byte position, you could calculate it by retaining the position of the speed change and then scaling the reported position beyond that. To precisely track multiple speed changes, you would need an array of speed change records, but you can perhaps get away with just something like this (untested):

Code: [Select]
float speed = 1;
int64_t speedpos = 0, speedposdiff = 0; // position of last speed change, and difference to real position

...

// changing the speed
BASS_ChannelSetAttribute(handle, BASS_ATTRIB_MIDI_SPEED, newspeed); // apply speed change
int64_t pos = BASS_ChannelGetPosition(handle, BASS_POS_BYTE | BASS_POS_DECODE); // get position of speed change
speedposdiff += (pos - speedpos) * (speed - 1); // update difference to real position
speed = newspeed;
speedpos = pos;

...

// getting the position
int64_t pos = BASS_ChannelGetPosition(handle, BASS_POS_BYTE); // get current position
if (pos > speedpos) pos = speedpos + (pos - speedpos) * speed; // apply speed change
pos += speedposdiff; // add the starting difference

"speedposdiff" should be reset to 0 at the start of playback, including after seeking. "speedpos" should also be reset to the new position then.

rrhh_fx

  • Posts: 21
Re: BASS for Android
« Reply #1819 on: 26 Jan '21 - 17:19 »
Thanks! Both alternatives are useful

rrhh_fx

  • Posts: 21
Re: BASS for Android
« Reply #1820 on: 29 Jan '21 - 10:51 »
Hi again,

I am trying to change the volume of MIDI file stream , before encoding to MP3. As it uses BASS_STREAM_DECODE, from documentation I cannot use BASS_ChannelSetAttribute, so I think I need to use Bass_Mixer, but I am trying to do it with no results. Here is the code:

Code: [Select]
String file=getActivity().getFilesDir()+"/"+fileTmp+".mid";
int streamMidi= BASSMIDI.BASS_MIDI_StreamCreateFile(file, 0, 0, BASS_STREAM_DECODE,0);

BASS.BASS_CHANNELINFO info = new BASS.BASS_CHANNELINFO();
boolean b = BASS.BASS_ChannelGetInfo(streamMidi, info);
int compressionStream = BASSmix.BASS_Mixer_StreamCreate(info.freq, info.chans, BASS.BASS_STREAM_DECODE|BASSmix.BASS_MIXER_END);
BASSmix.BASS_Mixer_StreamAddChannel(compressionStream,streamMidi,BASSmix.BASS_MIXER_NORAMPIN);

//f returns error
float [][] matrixA= {{.75f,0f},{0f,0.75f}};
boolean f=BASSmix.BASS_Mixer_ChannelSetMatrix(compressionStream,matrixA);

//These two lines does not work, because it is in DECODE mode
//BASS.BASS_ChannelSetAttribute(compressionStream,BASS_ATTRIB_VOL,.15f);
//BASS.BASS_SetConfig(BASS_CONFIG_GVOL_STREAM,4000);

BASSenc_MP3.BASS_Encode_MP3_StartFile(compressionStream, null, 0,file.replace(".mid",".mp3") );
               
while (true) {
     int got = BASS.BASS_ChannelGetData(compressionStream, buffer, 20000);
     if (got < 0) break; // end or error
 }

BASSenc.BASS_Encode_Stop(compressionStream);

Any help is appreciated. Thanks

Ian @ un4seen

  • Administrator
  • Posts: 23563
Re: BASS for Android
« Reply #1821 on: 29 Jan '21 - 14:39 »
A simpler way to change the level is with the BASS_FX_VOLUME effect. For example, something like this:

Code: [Select]
int volfx = BASS.BASS_ChannelSetFX(streamMidi, BASS.BASS_FX_VOLUME, 0);
BASS.BASS_FX_VOLUME_PARAM param = new BASS.BASS_FX_VOLUME_PARAM();
param.fTarget = volume;
param.fTime = 0;
BASS.BASS_FXSetParamters(volfx, param);

Please see the BASS_FX_VOLUME_PARAM documentation for details.

rrhh_fx

  • Posts: 21
Re: BASS for Android
« Reply #1822 on: 9 Feb '21 - 11:43 »
A simpler way to change the level is with the BASS_FX_VOLUME effect. For example, something like this:

Code: [Select]
int volfx = BASS.BASS_ChannelSetFX(streamMidi, BASS.BASS_FX_VOLUME, 0);
BASS.BASS_FX_VOLUME_PARAM param = new BASS.BASS_FX_VOLUME_PARAM();
param.fTarget = volume;
param.fTime = 0;
BASS.BASS_FXSetParamters(volfx, param);

Please see the BASS_FX_VOLUME_PARAM documentation for details.

Thanks!

Now some devices in Android 8.0 are having issues with WaveLock AudioMix. High CPU load can be the reason? In order to dismiss as much as possible the latency, next configuration is used:

Code: [Select]
BASS_SetConfig(
                BASS_CONFIG_DEV_BUFFER,
                1
        );
        if (!BASS.BASS_Init(-1, 44100, 0)) {
            return;
        }else{
        }

        BASS.BASS_Start();
        BASS_SetConfig(BASS_CONFIG_BUFFER,20);   
        BASS_SetConfig(BASS_CONFIG_UPDATEPERIOD,5);

int streamMidi = BASSMIDI.BASS_MIDI_StreamCreate(127,0 ,0);
        BASS.BASS_ChannelSetAttribute(streamMidi, BASSMIDI.BASS_ATTRIB_MIDI_SPEED, 101);
        BASS.BASS_ChannelSetAttribute(streamMidi, BASS_ATTRIB_BUFFER, 0);

Do you think that there is something wrong with that configuration?

Thanks

Ian @ un4seen

  • Administrator
  • Posts: 23563
Re: BASS for Android
« Reply #1823 on: 9 Feb '21 - 16:17 »
I guess you mean "wakelock" rather than "wavelock". Are you getting that even when your app is playing nothing, ie. when "streamMidi" is stopped? If so, have you enabled the BASS_CONFIG_DEV_NONSTOP option? That's disabled by default, which means BASS should automatically stop the output device when nothing is playing. Note you will need to stop the MIDI stream (not just play no notes in it) for that to apply.

Btw, when playback buffering is disabled (by setting BASS_ATTRIB_BUFFER to 0), neither the update period (BASS_CONFIG_UPDATEPERIOD) or buffer length (BASS_CONFIG_BUFFER) will affect latency. Only the device's period (BASS_CONFIG_DEV_PERIOD) and buffer length (BASS_CONFIG_DEV_BUFFER) will.

rrhh_fx

  • Posts: 21
Re: BASS for Android
« Reply #1824 on: 9 Feb '21 - 17:39 »
Sorry, you are right: "WakeLock" instead of "WaveLock". I am receiving that message in the Google Play console from external users, so I will take a look to the BASS_CONFIG_DEV_NONSTOP feature, and the app behaviour when it is not in foreground.

Regarding the buffers issue, that is clear now. Thanks for your quick reply.