Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Playing audio backwards

Hi I'd like to play audio backwards in Android. How do I accomplish it? Any pointers will be appreciated. Thanks.

like image 735
Ragunath Jawahar Avatar asked Feb 02 '11 20:02

Ragunath Jawahar


1 Answers

there probably isn't a functionality in the apis for this.

however, it's quite easy to play pcm audio data backwards.

a demonstration using c++ style pseudo-code:

/* assuming 1 channel (mono), 16 bit LPCM */
const int16_t* const audioFileBuffer = audioFile.audioBuffer();

/* forward */
for (int idx = 0, sampleCount = audioFile.sampleCount(); idx < sampleCount; ++idx) {
    outputBuffer[idx] = audioFileBuffer[idx];
}

/* reverse */
for (int idx = 0, sampleCount = audioFile.sampleCount(), read = audioFile.sampleCount() - 1; idx < sampleCount; ++idx, --read) {
    outputBuffer[idx] = audioFileBuffer[read];
}
like image 108
justin Avatar answered Sep 17 '22 23:09

justin