Author Topic: BASS for Android  (Read 390164 times)

Ian @ un4seen

  • Administrator
  • Posts: 20393
Re: BASS for Android
« Reply #450 on: 18 Nov '13 - 16:19 »
Please check the error code via BASS_ErrorGetCode, like this...

Code: [Select]
BASS.BASS_ChannelSetPosition(chan, BASS.BASS_ChannelSeconds2Bytes(chan, to), BASS.BASS_POS_BYTE);
int errorcode=BASS.BASS_ErrorGetCode();

You can then see the BASS_ErrorGetCode and BASS_ChannelSetPosition documentation for what problem the error code indicates.

norbert

  • Posts: 119
Re: BASS_MIDI_StreamGetEvents problem
« Reply #451 on: 19 Nov '13 - 17:59 »
The call to BASS_MIDI_StreamGetEvents results in an error:

11-19 18:52:08.725: ERROR/dalvikvm(14178): Failed adding to JNI local ref table (has 1024 entries)
11-19 18:52:08.735: ERROR/dalvikvm(14178): VM aborting



First I'm getting the number of events by
Code: [Select]
 int cnt = BASSMIDI.BASS_MIDI_StreamGetEvents(handle, trackIndex, eventType, null);


cnt = 1530

Then to get the actual events:

Code: [Select]
 BASSMIDI.BASS_MIDI_EVENT[] bassEvents = new BASSMIDI.BASS_MIDI_EVENT[cnt];

           int res = BASSMIDI.BASS_MIDI_StreamGetEvents(handle, trackIndex, eventType, bassEvents);

The last call results in the above messages. The app crashes (no chance to catch any exception). I'm using the lastest lib versions.

Any idea what goes wrong here?
 
    
« Last Edit: 19 Nov '13 - 18:03 by norbert »

Ian @ un4seen

  • Administrator
  • Posts: 20393
Re: BASS for Android
« Reply #452 on: 20 Nov '13 - 16:51 »
An updated BASSMIDI version that should fix the problem is now up in the 1st post. Let me know if the problem still occurs with that.

norbert

  • Posts: 119
Re: BASS for Android BASS_MIDI_StreamGetEvents
« Reply #453 on: 20 Nov '13 - 18:47 »
Thanks, now BASS_MIDI_StreamGetEvents is working fine!

MistaGreen

  • Guest
Re: BASS for Android
« Reply #454 on: 26 Nov '13 - 22:03 »
Is it possible to play MOD music (XM, IT, S3M, MOD, MTM, UMX) on Android using BASS library? If yes then could you show me the way how to do it.

Thanks!

Ian @ un4seen

  • Administrator
  • Posts: 20393
Re: BASS for Android
« Reply #455 on: 28 Nov '13 - 16:21 »
Yes, it is possible to play MOD formats with BASS. The main function of interest for that is BASS_MusicLoad. The minimum bare-bones code could look something like this...

Code: [Select]
BASS.BASS_Init(-1, 44100, 0); // initialize default output
music=BASS.BASS_MusicLoad(filename, 0, 0, BASS.BASS_SAMPLE_LOOP|BASS.BASS_MUSIC_RAMP, 1); // load a MOD file
BASS.BASS_ChannelPlay(music, false); // start playing it

Please see the documentation for details.

norbert

  • Posts: 119
Re: BASS for Android: Number of midi tracks
« Reply #456 on: 1 Dec '13 - 16:26 »
To get the number of tracks in a midi file the following code works in 99% of all cases:

Code: [Select]
       int tracks = 0;
        Float dummy = new Float(0);

        while (BASS.BASS_ChannelGetAttribute(channel, BASSMIDI.BASS_ATTRIB_MIDI_TRACK_VOL +tracks,dummy))
        {
            tracks++;
        }

But with some midi files this code only reports one track, although when I open the midi file in a notation program it shows 5 tracks, each with another instrument / channel.

So could it be that BASSMIDI.BASS_ATTRIB_MIDI_TRACK_VOL is not reliable enough to detect the number of tracks ?
What could be another way to detect it ?(I could also upload the affected midi file).

[Update: Uploaded midi file]
« Last Edit: 3 Dec '13 - 18:01 by norbert »

Ian @ un4seen

  • Administrator
  • Posts: 20393
Re: BASS for Android
« Reply #457 on: 2 Dec '13 - 16:41 »
That sounds strange. Please do upload the affected MIDI file to have a look at here...

   ftp.un4seen.com/incoming/

norbert

  • Posts: 119
Re: BASS for Android
« Reply #458 on: 4 Dec '13 - 19:14 »
I've uploaded the midi file - not sure whether successful  -it disappeared immediatly from the incoming folder

Ian @ un4seen

  • Administrator
  • Posts: 20393
Re: BASS for Android
« Reply #459 on: 5 Dec '13 - 15:33 »
Your file was received fine, thanks. It is a "type 0" MIDI file, which means it only has 1 track ("type 1" files can have multiple tracks). The notation program that you're using is probably separating the MIDI channels used in the track.

norbert

  • Posts: 119
Re: BASS for Android
« Reply #460 on: 5 Dec '13 - 18:30 »
ok, thanks! I have another question:

when starting my bass app (which uses a soundfont) again (only the first time via the dev. studio, the second time via a tap on the icon!), the playback sounds  "damaged", the frequencies are somehow messed up. I am preloading the samples of the soundfont (BASS_MIDI_StreamLoadSamples), which takes a few seconds the first time, and when starting the app again, the sample preloading only lasts a few milliseconds.
=> So the samples are not really unloaded ? 

Currently I'm calling in onDestroy()

Code: [Select]
        BASSMIDI.BASS_MIDI_FontFree(chan);
        BASS.BASS_Free();
        BASS.BASS_PluginFree(0);

I have also tried BASSMIDI.BASS_MIDI_FontUnload(chan,-1,-1) - doesn't help.
Similar (non bass related) soundcard problems occur with audio applications on windows when the computer wakes up from standby...

So what could help here ? somehow "reset" the audio device ? Or another way to force the unloading of the samples (but maybe this is not the origin of the problem)
Or somehow tell android that the app must not be kept "alive" / cached ?

Ian @ un4seen

  • Administrator
  • Posts: 20393
Re: BASS for Android
« Reply #461 on: 6 Dec '13 - 18:16 »
I haven't looked into Android's file caching but if it's like normal Linux, the faster sample loading the 2nd time round is probably because Android still has the soundfont cached in memory after the 1st time.

Regarding the messed-up sound, to help narrow-down what the cause is, please see if you can reproduce it with the MIDITEST example included in the Android BASS package. If that is affected too, you could then try playing different file formats with one of the other examples to check whether the problem is only affecting MIDI playback.

norbert

  • Posts: 119
Re: BASS for Android
« Reply #462 on: 7 Dec '13 - 08:52 »
You can reproduce it with the MIDITEST example, if you use a wavepacked soundfont  (I' using ChoriumRevA).  If it is not wavepacked, everything is fine when starting it the 2nd time (fast loading AND flawless sound).

learning

  • Guest
Re: BASS for Android
« Reply #463 on: 8 Dec '13 - 02:41 »
Tried to stream HTTPS (TLS) URL via the sample netradio android app. It fails with error code 2. Running latest Android 4.4.  Used the link https://uk.un4seen.com/test.mp3 as provided in http://www.un4seen.com/forum/?topic=14998.0.

Next, I tried it with an internal system with valid CA signed certificate. nginx webserver reported the following log:
"client sent plain HTTP request to HTTPS port while reading client request headers"

Is there any special configuration to make netradio android app work over HTTPS?

Thanks


Ian @ un4seen

  • Administrator
  • Posts: 20393
Re: BASS for Android
« Reply #464 on: 9 Dec '13 - 17:43 »
You can reproduce it with the MIDITEST example, if you use a wavepacked soundfont  (I' using ChoriumRevA).  If it is not wavepacked, everything is fine when starting it the 2nd time (fast loading AND flawless sound).

I don't seem to be able to reproduce the problem here; should it be very noticeable or is it subtle? If it's affecting a particular MIDI file, please upload that file to try here...

   ftp.un4seen.com/incoming/

Is there any special configuration to make netradio android app work over HTTPS?

Unfortunately, HTTPS isn't currently supported by BASS on Android. That will hopefully be added in future, but if you would like to have HTTPS now, you could use a 3rd-party (or your own) HTTP library with HTTPS support to handle the download and feed that into a custom file stream created via BASS_StreamCreateFileUser (with system=STREAMFILE_BUFFER).

norbert

  • Posts: 119
Re: BASS for Android
« Reply #465 on: 9 Dec '13 - 18:25 »

I don't seem to be able to reproduce the problem here; should it be very noticeable or is it subtle? If it's affecting a particular MIDI file, please upload that file to try it here
No it is not subtle.
The sound is heavy affected, you can just guess some of the instruments...
Also this happens with every Midi file and also on three different devices+
Nexus 7. , Galaxy Note1 and Galaxy S5370, with three different OS versions.
I would guess it could have sth to do with the libbasswv.so?

Maybe I should upload the packed soundfont ..? but it is just the original ChoriumRevA packed with -xbh256 or so.

I have just tried it with a different soundfont - same result.
If you want you can try (size is just 880 kb):
 https://db.tt/UL5Wv4Mg


 
« Last Edit: 10 Dec '13 - 15:04 by norbert »

Ian @ un4seen

  • Administrator
  • Posts: 20393
Re: BASS for Android
« Reply #466 on: 10 Dec '13 - 17:42 »
Ah, I see what you mean now (I was previously relaunching from Eclipse). The explanation for the problem when launching on the device is that Android doesn't terminate apps when they're closed (they stay loaded in the background), so it is actually the same app instance that's running when you relaunch it. That means the soundfont is still loaded from the 1st time, but the Wavpack decoder isn't due to the BASS_Free and BASS_PluginFree calls in onDestroy, so the packed samples can't be loaded and you end up with noise (whatever happens to be in memory). To avoid that, the soundfont should also be freed in onDestroy. I've put an updated MIDITEST example that does that up in the package in the 1st post.

Ian @ un4seen

  • Administrator
  • Posts: 20393
Re: BASS for Android
« Reply #467 on: 13 Dec '13 - 17:52 »
The latest version (2.4.1.3) of the BASSOPUS add-on is now up in the first post.

Vladislav

  • Guest
Re: BASS for Android
« Reply #468 on: 20 Dec '13 - 03:40 »
Hi . I'm trying to save track after buffering ,but code below save less then ~1/4 file before closing stream .
Code: [Select]
private final BASS.DOWNLOADPROC StatusProc=new BASS.DOWNLOADPROC(){
        @Override
        public void DOWNLOADPROC(ByteBuffer buffer, int length, Object user){
            if ((Integer)user!=req){
                return; // make sure this is still the current request
            }
            if (buffer==null || length != 0) {
                try {
                    if (buffer!=null) { // got data, write to file...
                        if (fc==null){
                            File file = new File(filePath);
                            if(!file.exists())
                                file.createNewFile();
                            fc=new FileOutputStream(file).getChannel();
                        }
                        bufferedBytes += length;
                        fc.write(buffer);
                    } else if (fc!=null) {
                        fc.close();
                        }
                    }

                } catch (IOException e) {}

            }
        }
    };

And how i start stream :
Code: [Select]
        int r;
        synchronized(lock){
            r=++req;
        }
        int c = BASS.BASS_StreamCreateURL(url, 0, BASS.BASS_SAMPLE_LOOP|BASS.BASS_STREAM_PRESCAN, StatusProc, r);
        synchronized(lock){
            if (r!=req) {
                if (c!=0) {
                    BASS.BASS_StreamFree(c);
                }
                throw new IOException("prepare exception");
            }
            chan=c;
        }

        if(chan == 0) {
            throw new IOException("prepare exception");
        }


Vladislav

  • Guest
Re: BASS for Android
« Reply #469 on: 20 Dec '13 - 15:35 »
Adition ot the question ,Now file completly saved , but amoun of bytes from function DOWNLOADPROC  less than ~1/4 . My goal is save file after  buffering and show secondary progress(buffer progress).

norbert

  • Posts: 119
Re: BASS for Android:
« Reply #470 on: 21 Dec '13 - 10:39 »
I've got two BASSMIDI questions/problems:

1. cracking noise

Sometimes, when there are many notes in a MIDI file played at the same time, you can hear a cracking noise.

As I could not recognize any stuttering, I would not think it is the result of to much cpu usage, but rather too high volume levels (?)

I can vaguely remember there was a flag to be passed to the channel or similar for limiting the volume level to avoid such noise ?

2. No BASS_MIDI_StreamGetMarks ?
Is there a technical reason why only BASS_MIDI_StreamGetMark is included in the BASSMIDI.java, but not BASS_MIDI_StreamGetMarks  ?
 

« Last Edit: 21 Dec '13 - 16:02 by norbert »

Ian @ un4seen

  • Administrator
  • Posts: 20393
Re: BASS for Android
« Reply #471 on: 22 Dec '13 - 17:35 »
Adition ot the question ,Now file completly saved , but amoun of bytes from function DOWNLOADPROC  less than ~1/4 . My goal is save file after  buffering and show secondary progress(buffer progress).

Please confirm how you are determining that only 1/4 of the data is saved, eg. are you playing back the saved file? If not, please try that. You could also try logging the amount of data received by your DOWNLOADPROC function, and then compare that with the size of the saved file.

I've got two BASSMIDI questions/problems:

1. cracking noise

Sometimes, when there are many notes in a MIDI file played at the same time, you can hear a cracking noise.

As I could not recognize any stuttering, I would not think it is the result of to much cpu usage, but rather too high volume levels (?)

I can vaguely remember there was a flag to be passed to the channel or similar for limiting the volume level to avoid such noise ?

You could try lowering the volume level via BASS_MIDI_FontSetVolume, eg. set it below 1.0. Let me know if you still get the crackling noise even then.

2. No BASS_MIDI_StreamGetMarks ?
Is there a technical reason why only BASS_MIDI_StreamGetMark is included in the BASSMIDI.java, but not BASS_MIDI_StreamGetMarks  ?

No technical reason, just forgetfulness :) ... An updated BASSMIDI.java file is up in the package now.

Vladislav

  • Guest
Re: BASS for Android
« Reply #472 on: 22 Dec '13 - 21:43 »
Please confirm how you are determining that only 1/4 of the data is saved, eg. are you playing back the saved file? If not, please try that. You could also try logging the amount of data received by your DOWNLOADPROC function, and then compare that with the size of the saved file.

How i determine buffered length and show it:
Code: [Select]
long bufferedBytes = 0;
private final BASS.DOWNLOADPROC StatusProc=new BASS.DOWNLOADPROC()
    {
        @Override
        public void DOWNLOADPROC(ByteBuffer buffer, int length, Object user)
        {
            if ((Integer)user!=req){
                return;
            }
                try {
                    if (buffer!=null) { /
                        if (fc==null){
                            fc=new FileOutputStream(file).getChannel();
                        }
                        bufferedBytes += length;  //this how i determine bufferedBytes;
                        fc.write(buffer);
                    } else if (fc!=null) {
                        fc.close();
                         Log.i("TAG","bufferedBytes is " + bufferedBytes + " all bytes is " +                              BASS.BASS_ChannelGetLength(chan,BASS.BASS_POS_BYTE));//When i show bytes
                        }
                    }
                } catch (IOException e) {}
        }
    };

norbert

  • Posts: 119
Thanks, I've tried the BASS_MIDI_StreamGetMarks function with this midi file https://www.dropbox.com/s/u9ldcgmfl8uyiw5/brahms_jungeLieder.mid.

Unfortunately, the app crashes immediately without exception message when calling the function with BASS_MIDI_MARK_LYRIC (With BASS_MIDI_MARK_TEXT it's fine).

Code: [Select]

 BASSMIDI.BASS_MIDI_MARK[] marksText = GetMidiMarksAllTracks(chan, BASSMIDI.BASS_MIDI_MARK_TEXT); // ok
 BASSMIDI.BASS_MIDI_MARK[] marksLyr = GetMidiMarksAllTracks(chan, BASSMIDI.BASS_MIDI_MARK_LYRIC);  // will crash

  ... ...

  static BASSMIDI.BASS_MIDI_MARK[] GetMidiMarksAllTracks(int chan, int type){


        int cnt=BASSMIDI.BASS_MIDI_StreamGetMarks(chan, -1,type ,null); // get number of markers

        if(cnt==0) return new BASSMIDI.BASS_MIDI_MARK[0];

        BASSMIDI.BASS_MIDI_MARK[] marks= new BASSMIDI.BASS_MIDI_MARK[cnt];

        BASSMIDI.BASS_MIDI_StreamGetMarks(chan,-1,type,marks); // crash here when with BASS_MIDI_MARK_LYRIC

       return marks;
    }


_Tobias

  • Posts: 10
Re: BASS for Android
« Reply #474 on: 26 Dec '13 - 15:47 »
Do you think porting the Opus codec to Android would be easy? I'm not in the need of it but it sure would be nice since it's freely licensed (http://www.opus-codec.org/license/). Also, it's supposed to be better than AAC and MP3 (http://www.opus-codec.org/comparison/)