Android Superpowered SDK Record and play simultaneously

My goal is to play a local file when recording a microphone with a low latency microphone. I came to the Superpowered library because from the documentation it provides a low latency function. I created a player using SuperpoweredAdvancedAudioPlayer and SuperpoweredAndroidAudioIO and it works great.

SuperpoweredAndroidAudioIO has a constructor with parameters boolean enableInput, boolean enableOutput . I am currently using enableInput == false and enableOutput == true. When I believe these parameters - no effect.

I wonder if it is possible to simultaneously record a file and play another file?

There is also a SuperpoweredRecorder class in the library, but it is not talking about writing directly to disk. And you need to use the createWAV, fwrite, closeWAV methods. I tried to implement the recorder separately, but the quality is not very good (it is two to three times faster than real recording + the sound accelerates). Here is the simplest piece of code for the record I used:

void SuperpoweredFileRecorder::start(const char *destinationPath) { file = createWAV(destinationPath, sampleRate, 2); audioIO = new SuperpoweredAndroidAudioIO(sampleRate, bufferSize, true, false, audioProcessing, NULL, bufferSize); // Start audio input/output. } void SuperpoweredFileRecorder::stop() { closeWAV(file); audioIO->stop(); } static bool audioProcessing(void *clientdata, short int *audioInputOutput, int numberOfSamples, int samplerate) { fwrite(audioInputOutput, sizeof(short int), numberOfSamples, file); return false; } 

I probably can't use Superpowered for this purpose and should just record with OpenSL ES directly.

Thanks in advance!

+5
source share
3 answers

After experimenting, I found a solution.

  • SuperpoweredRecorder works great for recording tracks;
  • I created SuperpoweredAndroidAudioIO to separate sources - one for playback and one for the recorder. After some manipulation of the synchronization, it works well (I minimized the delay to a very low level, so that fits my needs).

I am posting a piece of code with an idea that I implemented:

https://bitbucket.org/snippets/kasurd/Mynnp/nativesuperpoweredrecorder-with

Hope this helps someone!

+5
source

You can do this with a single instance of SuperpoweredAndroidAudioIO with the enableInput parameter and enableOutput set to true.

The sound processing callback (audioProcessing () in your case) receives the audio (microphone) in the audioInputOutput parameter. Just transfer this to your SuperpoweredRecorder and it will write it to disk.

After that, do SuperpoweredAdvancedAudioPlayer processing and convert the result to audioInputOutput. This will go to the audio output.

So this looks like a pseudo code:

 audioProcessing(audioInputOutput) { recorder->process(audioInputOutput) player->process(some_buffer) float_to_short_int(some_buffer, audioInputOutput) } 

Never do fwrite in a sound processing callback, as it should complete in a very short time, and disk operations may be too slow.

+4
source

For me, this works when I double the number of OfSamples

 fwrite(audioInputOutput, sizeof(short int), numberOfSamples * 2, file); 

This will result in clear stereo sound.

0
source

Source: https://habr.com/ru/post/1236431/


All Articles