Author Topic: BASS for Android  (Read 696437 times)

Serg

  • Posts: 7
Re: BASS for Android
« Reply #1775 on: 25 Oct '20 - 09:15 »
Tell me how to change the pitch of voice?

Ian @ un4seen

  • Administrator
  • Posts: 23311
Re: BASS for Android
« Reply #1776 on: 26 Oct '20 - 17:00 »
You can use the BASS_FX add-on's tempo processing to do that. For example, something like this:

Code: [Select]
decoder = BASS_StreamCreateFile(false, filename, 0, 0, BASS_STREAM_DECODE);
tempostream = BASS_Tempo_StreamCreate(decoder, BASS_FX_FREESOURCE);
BASS_ChannelSetAttribute(tempostream, BASS_ATTRIB_TEMPO_PITCH, pitchchange);
BASS_ChannelPlay(tempostream, false);

Please see the documentation for details on the mentioned functions and options.

Serg

  • Posts: 7
Re: BASS for Android
« Reply #1777 on: 1 Nov '20 - 13:14 »
Thanks for helping. please tell me how to remove background noise ?

Ian @ un4seen

  • Administrator
  • Posts: 23311
Re: BASS for Android
« Reply #1778 on: 3 Nov '20 - 15:03 »
BASS doesn't provide noise reduction options, so you would need to use a third-party library for that, eg. in a DSP function (via BASS_ChannelSetDSP). For example, here's one from xiph:

   https://github.com/xiph/rnnoise/

If the noise processing requires data blocks of a certain size (like that library does) then you can use the BASS_ATTRIB_GRANULE option (via BASS_ChannelSetAttribute) to tell BASS that.

gicci

  • Posts: 76
Re: BASS for Android
« Reply #1779 on: 15 Nov '20 - 02:44 »
Hi Ian,

I am struggling to support the new Android 11 "feature", that forces the access of files not recognized as media (like the soundfont files) through the SAF and not directly through file access.
I am evaluating different options, one is the usage of BASS_MIDI_FontInitUser providing a BASS_FILEPROCS. What is not clear to me is if and how this method supports SFZ which are split in multiple files, as there is the support of single file through that interface. Could you please clarify this aspect?

Thank you.

Ian @ un4seen

  • Administrator
  • Posts: 23311
Re: BASS for Android
« Reply #1780 on: 16 Nov '20 - 16:55 »
I guess you're thinking of SFZ files that use the #include directive? If BASSMIDI is unable to access the SFZ files itself then you would probably need to pre-process them, ie. load the main SFZ file to memory and insert the content of the #include files (in place of the #include lines) before feeding the entire thing to BASS_MIDI_FontInitUser. You will also need to add/modify "default_path" opcode(s) with the full path, so BASSMIDI knows where to find the sample files.

If your app doesn't actually need any Android 11 features, perhaps you can just have it target Android 10 (or lower) instead?

gicci

  • Posts: 76
Re: BASS for Android
« Reply #1781 on: 16 Nov '20 - 22:47 »
Quote
I guess you're thinking of SFZ files that use the #include directive? If BASSMIDI is unable to access the SFZ files itself then you would probably need to pre-process them, ie. load the main SFZ file to memory and insert the content of the #include files (in place of the #include lines) before feeding the entire thing to BASS_MIDI_FontInitUser. You will also need to add/modify "default_path" opcode(s) with the full path, so BASSMIDI knows where to find the sample files.

I am not expert of the SFZ file format, but I have seen that it references the samples through the "sample" opcode, I was not referring to the "#include" directive". The question was just how the sample files are loaded, if there is a way to control this when using the BASS_MIDI_FontInitUser interface. I see anyway that "#include" adds another level of complexity...
As the "default_path" opcode is supported, I could load the SFZ file in memory and inject the "default_path" opcode pointing to the base directory of the audio files. Those files can be accessed through the standard file interface.
It would be nice to have a way to control this through some parameter of BASS_FILEPROCS, with an OPEN directive, so that we could control the access to all the files needed by the SoundFont.

Quote
If your app doesn't actually need any Android 11 features, perhaps you can just have it target Android 10 (or lower) instead?

This is how it currently works, but this is not a viable long term solution: sooner or later Google with require to target at least that version to load the app on the store.

gicci

  • Posts: 76
Re: BASS for Android
« Reply #1782 on: 29 Nov '20 - 21:02 »
Hi Ian,

again about the SFZ support, I have some troubles passing the SFZ text file to BASS_MIDI_FontInit(ByteBuffer file, int flags) as it always return error. Am I doing something wrong or is this not supported?

Thank you.

Ian @ un4seen

  • Administrator
  • Posts: 23311
Re: BASS for Android
« Reply #1783 on: 30 Nov '20 - 13:51 »
Unfortunately, the BASS_MIDI_FontInit ByteBuffer option doesn't support SFZ (only SF2). That's because it's implemented by passing the BASS_MIDI_FONT_MEM flag to BASS_MIDI_FontInit, which doesn't have a parameter to tell the file size. SF2 files have a header that tells the size but SFZ files don't. So you currently need to use BASS_MIDI_FontInitUser instead to load an SFZ file from memory. I'm thinking of adding a new BASS_MIDI_FontInitMem or BASS_MIDI_FontInitEx function to make loading from memory simpler.

gicci

  • Posts: 76
Re: BASS for Android
« Reply #1784 on: 30 Nov '20 - 18:18 »
Ok, that will not be a problem, I already have BASS_MIDI_FontInitUser working for reading SF2, currently from documents opened using SAF.
If you extend the interface, as I already pointed out, it would be very useful to have at least way to specify the base directory for SFZ, so that the library will be able to correctly locate the media files. Even better there should be a way to open files using that interfaces, so that the access can be completely decoupled from the file system.

vu

  • Guest
Re: BASS for Android
« Reply #1785 on: 1 Dec '20 - 00:03 »
Hi, It seems like i can't load bass fx,  libbass_fx.so. Getting errorCode 41. Other addons like libbass_acc.so works.
Code: [Select]
val fxPlugin= BASS_PluginLoad("libbass_fx.so", 0)
//Vu

Ian @ un4seen

  • Administrator
  • Posts: 23311
Re: BASS for Android
« Reply #1786 on: 1 Dec '20 - 15:22 »
The BASS_PluginLoad function is only for loading add-ons that add support for file formats to BASS_StreamCreateFile/etc. Other add-ons like BASS_FX should just be used directly, ie. call the wanted functions in them.

emile_b

  • Posts: 16
Re: BASS for Android
« Reply #1787 on: 3 Dec '20 - 10:42 »
Sorry if this is already implemented or discussed.
Is it possible to have integer 'file descriptor' interface for opening files (BASS_StreamCreate)? The reason is to help with the new Android changes for Scoped Storage. I understand something has been added for the Java side (ParcelDescritors), but I actually open stuff in the native C code and convert files to fd's.

ZetDimanaMana

  • Posts: 4
Re: BASS for Android
« Reply #1788 on: 3 Dec '20 - 15:28 »
I have problem with recording and playback the audio after i speak and playback my voice, the voice is lopped and make a noise.

Ian @ un4seen

  • Administrator
  • Posts: 23311
Re: BASS for Android
« Reply #1789 on: 3 Dec '20 - 18:01 »
Sorry if this is already implemented or discussed.
Is it possible to have integer 'file descriptor' interface for opening files (BASS_StreamCreate)? The reason is to help with the new Android changes for Scoped Storage. I understand something has been added for the Java side (ParcelDescritors), but I actually open stuff in the native C code and convert files to fd's.

There isn't currently any way to pass a native file descriptor to BASS, but it should be possible to wrap it with BASS_StreamCreateUser. Something like this:

Code: [Select]
void CALLBACK MyFileCloseProc(void *user)
{
int fd = (int)user;
close(user); // close the file
}

QWORD CALLBACK MyFileLenProc(void *user)
{
int fd = (int)user;
struct stat s;
fstat(fd, &s);
return s.st_size; // return the file length
}

DWORD CALLBACK MyFileReadProc(void *buffer, DWORD length, void *user)
{
int fd = (int)user;
return read(fd, buffer, length); // read from file
}

BOOL CALLBACK MyFileSeekProc(QWORD offset, void *user)
{
int fd = (int)user;
return lseek(fd, offset, SEEK_SET) != -1; // seek to offset
}

...

BASS_FILEPROCS fileprocs = { MyFileCloseProc, MyFileLenProc, MyFileReadProc, MyFileSeekProc }; // callback table
stream = BASS_StreamCreateFileUser(STREAMFILE_NOBUFFER, 0, &fileprocs, (void*)fd); // create the stream

Please see the BASS_StreamCreateFileUser documentation for details.

I have problem with recording and playback the audio after i speak and playback my voice, the voice is lopped and make a noise.

That sounds like you have feedback, ie. the microphone is recapturing the sound from the speaker. Does the problem go away if you use headphones?

ZetDimanaMana

  • Posts: 4
Re: BASS for Android
« Reply #1790 on: 3 Dec '20 - 18:11 »
hmm yes if use headphone problem is fixed. but I want it when I don't use it there is no problem

emile_b

  • Posts: 16
Re: BASS for Android
« Reply #1791 on: 3 Dec '20 - 20:58 »

...
There isn't currently any way to pass a native file descriptor to BASS, but it should be possible to wrap it with BASS_StreamCreateUser. Something like this:


Ah yes good idea, that should work, thank you.

Ian @ un4seen

  • Administrator
  • Posts: 23311
Re: BASS for Android
« Reply #1792 on: 4 Dec '20 - 17:09 »
hmm yes if use headphone problem is fixed. but I want it when I don't use it there is no problem

You want AEC (Acoustic Echo Cancellation) for that. 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.

Ian @ un4seen

  • Administrator
  • Posts: 23311
Re: BASS for Android
« Reply #1793 on: 4 Dec '20 - 17:11 »
The Android versions of the BASSenc 2.4.15, BASSenc_FLAC 2.4.3, BASSenc_OGG 2.4.1, BASSenc_OPUS 2.4.2, BASSFLAC 2.4.4.5 releases are now up in the 1st post.

ZetDimanaMana

  • Posts: 4
Re: BASS for Android
« Reply #1794 on: 5 Dec '20 - 05:05 »
hmm yes if use headphone problem is fixed. but I want it when I don't use it there is no problem

You want AEC (Acoustic Echo Cancellation) for that. 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.

oh yeah but im want using jni without a java

ZetDimanaMana

  • Posts: 4
Re: BASS for Android
« Reply #1795 on: 8 Dec '20 - 11:41 »
How i use speex echo? please i tried all method still not work :(
« Last Edit: 8 Dec '20 - 16:56 by ZetDimanaMana »

Ian @ un4seen

  • Administrator
  • Posts: 23311
Re: BASS for Android
« Reply #1796 on: 8 Dec '20 - 18:04 »
I haven't used it myself, so I'm afraid I'm unable to help much with it, but there are some instructions in the Speex manual here:

   https://speex.org/docs/manual/speex-manual/node7.html#SECTION00740000000000000000

Google also found this with some useful info and code:

   https://stackoverflow.com/questions/12748277/speex-echo-cancellation-configuration

emile_b

  • Posts: 16
Re: BASS for Android
« Reply #1797 on: 8 Dec '20 - 20:18 »
I may be doing something wrong, but on my Android 11 Pixel 2 the audio plays for a fraction of a second then stop and shows this log. The next time I try to play a track BASS_ChannelPlay will return false and won't display the log. Need to reboot the phone to output the log again.

If I set BASS_CONFIG_ANDROID_AAUDIO = 0 it works fine, so this is not an issue But I thought it may be useful.



Code: [Select]
2020-12-08 19:46:05.911 12801-12801/com.emtronics.longplay D/Player: setPlayState PLAYING
2020-12-08 19:46:05.912 12801-12801/com.emtronics.longplay W/AudioManager: Use of stream types is deprecated for operations other than volume control
2020-12-08 19:46:05.912 12801-12801/com.emtronics.longplay W/AudioManager: See the documentation of requestAudioFocus() for what to use instead with android.media.AudioAttributes to qualify your playback use case
2020-12-08 19:46:05.918 12801-12801/com.emtronics.longplay D/AAudio: AAudioStream_requestStart(s#2) called --------------
2020-12-08 19:46:05.918 12801-12801/com.emtronics.longplay D/AAudioStream: setState(s#2) from 2 to 3
2020-12-08 19:46:05.938 12801-12801/com.emtronics.longplay D/ronics.longpla: PlayerBase::start() from IPlayer
2020-12-08 19:46:05.938 12801-12801/com.emtronics.longplay D/AAudio: AAudioStream_requestStart(s#2) returned 0 ---------
2020-12-08 19:46:05.938 12801-12801/com.emtronics.longplay D/Player: Playing file: track04.ogg
2020-12-08 19:46:05.939 12801-12886/com.emtronics.longplay D/AudioStreamInternalPlay_Client: callbackLoop() entering >>>>>>>>>>>>>>>
2020-12-08 19:46:05.939 12801-12886/com.emtronics.longplay D/AudioStreamInternal_Client: onEventFromServer - got AAUDIO_SERVICE_EVENT_STARTED
2020-12-08 19:46:05.939 12801-12886/com.emtronics.longplay D/AAudioStream: setState(s#2) from 3 to 4
2020-12-08 19:46:05.943 12801-12801/com.emtronics.longplay D/PlayerFragment: playerStateChanged
2020-12-08 19:46:05.944 12801-12801/com.emtronics.longplay D/ListFragment: playerStateChanged hidden, delaying notifyDataSetChanged
2020-12-08 19:46:06.158 12801-12886/com.emtronics.longplay D/AudioStreamInternal_Client: onEventFromServer - got AAUDIO_SERVICE_EVENT_STOPPED
2020-12-08 19:46:06.158 12801-12886/com.emtronics.longplay D/AAudioStream: setState(s#2) from 4 to 13
2020-12-08 19:46:06.158 12801-12886/com.emtronics.longplay W/AudioStreamInternal_Client: onEventFromServer - AAUDIO_SERVICE_EVENT_DISCONNECTED - FIFO cleared
2020-12-08 19:46:06.158 12801-12886/com.emtronics.longplay D/AudioStreamInternalPlay_Client: callbackLoop() exiting, result = -899, isActive() = 0 <<<<<<<<<<<<<<
2020-12-08 19:46:06.159 12801-12894/com.emtronics.longplay I/AAudio: AAudioStreamBuilder_openStream() called ----------------------------------------
2020-12-08 19:46:06.159 12801-12894/com.emtronics.longplay I/AudioStreamBuilder: rate   =      0, channels  = 0, format   = 0, sharing = SH, dir = OUTPUT
2020-12-08 19:46:06.159 12801-12894/com.emtronics.longplay I/AudioStreamBuilder: device =      0, sessionId = -1, perfMode = 12, callback: ON with frames = 0
2020-12-08 19:46:06.160 12801-12894/com.emtronics.longplay I/AudioStreamBuilder: usage  =      1, contentType = 0, inputPreset = 0, allowedCapturePolicy = 0
2020-12-08 19:46:06.160 12801-12894/com.emtronics.longplay I/AudioStreamBuilder: privacy sensitive = false
2020-12-08 19:46:06.160 12801-12894/com.emtronics.longplay D/ronics.longpla: PlayerBase::PlayerBase()
2020-12-08 19:46:06.161 12801-12894/com.emtronics.longplay D/AudioStreamInternal_Client: open() original HW burst = 96, minMicros = 2000 => SW burst = 96
2020-12-08 19:46:06.161 12801-12894/com.emtronics.longplay D/AAudioStream: setState(s#3) from 0 to 2
2020-12-08 19:46:06.162 12801-12894/com.emtronics.longplay I/AAudio: AAudioStreamBuilder_openStream() returns 0 = AAUDIO_OK for s#3 ----------------
2020-12-08 19:46:06.162 12801-12894/com.emtronics.longplay D/AAudio: AAudioStream_close(s#3) called ---------------
2020-12-08 19:46:06.162 12801-12894/com.emtronics.longplay D/AAudioStream: setState(s#3) from 2 to 11
2020-12-08 19:46:06.162 12801-12894/com.emtronics.longplay D/AAudioStream: setState(s#3) from 11 to 11
2020-12-08 19:46:06.162 12801-12894/com.emtronics.longplay E/AAudioStream: setState(3) tried to set to 11 but already CLOSING
2020-12-08 19:46:06.162 12801-12894/com.emtronics.longplay D/AAudioStream: setState(s#3) from 11 to 12
2020-12-08 19:46:06.162 12801-12894/com.emtronics.longplay D/AAudio: AAudioStream_close(s#3) returned 0 ---------
2020-12-08 19:46:06.162 12801-12894/com.emtronics.longplay I/AAudio: AAudioStreamBuilder_openStream() called ----------------------------------------
2020-12-08 19:46:06.162 12801-12894/com.emtronics.longplay I/AudioStreamBuilder: rate   =      0, channels  = 0, format   = 0, sharing = SH, dir = OUTPUT
2020-12-08 19:46:06.162 12801-12894/com.emtronics.longplay I/AudioStreamBuilder: device =      0, sessionId = -1, perfMode = 12, callback: ON with frames = 480
2020-12-08 19:46:06.162 12801-12894/com.emtronics.longplay I/AudioStreamBuilder: usage  =      1, contentType = 0, inputPreset = 0, allowedCapturePolicy = 0
2020-12-08 19:46:06.162 12801-12894/com.emtronics.longplay I/AudioStreamBuilder: privacy sensitive = false
2020-12-08 19:46:06.162 12801-12894/com.emtronics.longplay D/ronics.longpla: PlayerBase::PlayerBase()
2020-12-08 19:46:06.163 12801-12894/com.emtronics.longplay D/AudioStreamInternal_Client: open() original HW burst = 96, minMicros = 2000 => SW burst = 96
2020-12-08 19:46:06.163 12801-12894/com.emtronics.longplay D/AAudioStream: setState(s#4) from 0 to 2
2020-12-08 19:46:06.164 12801-12894/com.emtronics.longplay I/AAudio: AAudioStreamBuilder_openStream() returns 0 = AAUDIO_OK for s#4 ----------------
2020-12-08 19:46:06.164 12801-12894/com.emtronics.longplay D/AAudio: AAudioStream_requestStop(s#2) called
2020-12-08 19:46:06.164 12801-12894/com.emtronics.longplay D/IsochronousClockModel: stop(nanos = 4932326503641) max lateness = 22 micros
2020-12-08 19:46:06.164 12801-12894/com.emtronics.longplay D/AAudioStream: setState(s#2) from 13 to 9
2020-12-08 19:46:06.164 12801-12894/com.emtronics.longplay E/AAudioStream: setState(2) tried to set to 9 but already DISCONNECTED
2020-12-08 19:46:06.164 12801-12894/com.emtronics.longplay D/ronics.longpla: PlayerBase::stop() from IPlayer
2020-12-08 19:46:06.164 12801-12894/com.emtronics.longplay D/AAudio: AAudioStream_close(s#2) called ---------------
2020-12-08 19:46:06.164 12801-12894/com.emtronics.longplay E/AAudioStream: joinThread() - but has no thread
2020-12-08 19:46:06.164 12801-12894/com.emtronics.longplay D/AAudioStream: setState(s#2) from 13 to 11
2020-12-08 19:46:06.164 12801-12894/com.emtronics.longplay D/AAudioStream: setState(s#2) from 11 to 11
2020-12-08 19:46:06.164 12801-12894/com.emtronics.longplay E/AAudioStream: setState(2) tried to set to 11 but already CLOSING
2020-12-08 19:46:06.164 12801-12894/com.emtronics.longplay D/AAudioStream: setState(s#2) from 11 to 12
2020-12-08 19:46:06.164 12801-12894/com.emtronics.longplay D/AAudio: AAudioStream_close(s#2) returned 0 ---------
2020-12-08 19:46:06.164 12801-12894/com.emtronics.longplay D/AAudio: AAudioStream_requestStart(s#4) called --------------
2020-12-08 19:46:06.164 12801-12894/com.emtronics.longplay D/AAudioStream: setState(s#4) from 2 to 3
2020-12-08 19:46:06.176 12801-12894/com.emtronics.longplay D/AAudioStream: setState(s#4) from 3 to 2
2020-12-08 19:46:06.176 12801-12894/com.emtronics.longplay D/AAudio: AAudioStream_requestStart(s#4) returned -898 ---------



Ian @ un4seen

  • Administrator
  • Posts: 23311
Re: BASS for Android
« Reply #1798 on: 9 Dec '20 - 14:41 »
If you aren't already using it, please first give this latest build a try:

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

If the problem still happens with that then try setting BASS_CONFIG_DEV_NONSTOP to 1 via BASS_SetConfig before calling BASS_Init, and see if that helps. If it doesn't then also try setting BASS_CONFIG_ANDROID_AAUDIO to 2 (disables AAudio's low latency mode).

emile_b

  • Posts: 16
Re: BASS for Android
« Reply #1799 on: 22 Dec '20 - 16:28 »
If you aren't already using it, please first give this latest build a try:

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

If the problem still happens with that then try setting BASS_CONFIG_DEV_NONSTOP to 1 via BASS_SetConfig before calling BASS_Init, and see if that helps. If it doesn't then also try setting BASS_CONFIG_ANDROID_AAUDIO to 2 (disables AAudio's low latency mode).

Sorry for the delay. Very sorry but it actually just stared working OK (the released version). The only thing which happened was I had a minor OS update, not sure if that fixed it or a coincident. Thanks for the test builds, I'll try them if it happens again.