开发者

Playing audio backwards

Hi I'd like to play开发者_开发技巧 audio backwards in Android. How do I accomplish it? Any pointers will be appreciated. Thanks.


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];
}


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜