I have been scouring the internet for over a week now looking for a good way to manipulate audio files in the Android SDK. My goal is to apply special effects to the audio. May someone point me to a resource that can help me with this? I had to turn to StackOverflow because it is the only reliable place I know of for answers.
2 Answers
I'm assuming you mean that you want to digitally manipulate the audio files, i.e.at the byte level via some DSP technique?
If you want to manipulate in real-time (i.e. from the microhone) then take a look at android.media.AudioRecord.AudioRecord
. For example:
audioRecord = new AudioRecord(
MediaRecorder.AudioSource.MIC,
8000,
AudioFormat.CHANNEL_IN_STEREO,
AudioFormat.ENCODING_PCM_16BIT,
AudioTrack.getMinBufferSize(
8000,
AudioFormat.CHANNEL_IN_STEREO,
AudioFormat.ENCODING_PCM_16BIT)*20);
audioRecord.startRecording();
byte[] readBuffer = new byte[640];
int nbytes = audioRecord.read(readBuffer.getData(),0,readBuffer.length);
This will give you access to the raw audio data (in the example above Linear PCM 16 bit stereo).
If you want to read existing stored files (e.g. from the sdcard) and manipulate the audio, then take a look at java.io.FileInputStream
. Of course if the existing file is in a format other than Linear PCM (e.g. MP3) then you'll probably want to decode it to Linear PCM before applying any DSP-type manipulation. Cick here for an example of reading a file into a byte array. Click here for a link to an example of reading in an MP3 file and obtaining decoded raw PCM data.