Hi I'd like to play audio backwards in Android. How do I accomplish it? Any pointers will be appreciated. Thanks.
Asked
Active
Viewed 5,295 times
8
-
Have you tried passing a negative sample-rate to AudioTrack.setPlaybackRate? :) – kusma Feb 02 '11 at 21:20
-
@kusma, haven't tried it yet. Will update you on this. – Ragunath Jawahar Feb 03 '11 at 14:43
-
What about using C code and then trying to compile it with Android? C/C++ code would give you access to the audio file as an array. – Sriram Feb 04 '11 at 06:37
2 Answers
5
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];
}

justin
- 104,054
- 14
- 179
- 226
0
I'm not sure if there is a native way to do it (I am still new to the Android development scene myself) but if it came down to it, you could always try decoding the file yourself in reverse rather than relying on the existing API.

codewario
- 19,553
- 20
- 90
- 159