I want to amplify the audioData that is recorded by microphone using Oboe Library. I created AudioEngine.cpp like this: https://github.com/google/oboe/blob/master/samples/LiveEffect/src/main/cpp/LiveEffectEngine.cpp Here's is the class that has audioData:
DataCallbackResult
AudioEngine::onAudioReady(AudioStream *oboeStream, void *audioData, int32_t numFrames) {
/* some code */
// add your audio processing here
return DataCallbackResult::Continue;
}
In the LiveEffect sample both the recording and playback streams are AudioFormat::I16
i.e. 16 bit integers. On this line you're casting to float
:
auto *outputData = static_cast<float *>(audioData);
This is going to cause the distortion you hear so instead just cast to int16_t
and multiply by a constant amplitude.
Make sure to check that the scaled up sample value isn't above INT16_MAX
otherwise you'll get wraparound and distortion.