问题
I work for an audio recorder app and would like to add gain control but I don't know how to do it. I have access to audio buffer but I don't know how to make the sound louder or slower. I see another apps that have a seekBar for selecting the decibels from a specific range.
aRecorder.read(buffer, 0, buffer.length);
fWriter.write(buffer); // Write buffer to file
Please tell me what should I do to implement gain control in my app.
Thanks.
回答1:
Changing the volume is simple, just multiply all the samples by some fraction. A change of +/- 3dB (decibels) corresponds to multiplication by 2 or 0.5 respectively (see http://en.wikipedia.org/wiki/Decibel). To prevent discontinuities in the output, make sure that you vary the multiplication factor smoothly from beginning to end.
See AudioSampleBuffer::applyGainRamp() @ http://www.rawmaterialsoftware.com/api/classAudioSampleBuffer.html
来源:https://stackoverflow.com/questions/10449963/android-how-to-add-gain-control-when-recording