I am in the very ealy stages of developing this app but looking into it I have already reached a problem. I need to be able to play an audio file backwards (you know like to reveal hidden messages ;)). I have no experience working with audio on android and have no idea if this is even possible.
I found a question on here which solves the problem in java (Click Here For Question)
But this makes use of the javax.sound library which android does not support. Will I need this library to solve this problem or is there another way to reverse an audio file?
Reverse tape effects are special effects created by recording sound onto magnetic tape and then physically reversing the tape so that when the tape is played back, the sounds recorded on it are heard in reverse. Backmasking is a type of reverse tape effect.
A typical WAV file consists of a 44-byte header followed by the actual sample values. The size of a "frame" is dependent upon the WAV file's properties: a file that is stereo and 16-bits-per-sample will have a 4-byte frame size (two bytes for the left sample and two bytes for the right sample).
So in code, you would create a second WAV file by creating a byte array the same overall size as the original. You copy the 44-byte header from the original into the copy, and then iterate through the original frames starting at the last and working forward to the first. You copy each frame into the inverse location in the copy array (i.e. last original frame is copied into the copy array immediately after the header; second-to-last frame is copied after the first frame etc.). Then just play the reversed file.
So you don't need the javax.sound library to do this - you just need to be able to copy and manipulate bytes. FYI, not all WAV files are "canonical" like this (canonical means 44-byte header plus sample values, and nothing else). The WAV format is actually a RIFF format, which means in theory you need to do more complex extraction of the sample values. In practice (especially if you're creating the WAV files yourself) you can usually get away with a much simpler approach as I've described here.
NOTE: if your sounds are MP3 files, then reversing is a more complicated task, since the sample data are not stored as samples in an MP3 file. If you're using MP3s, one way to reverse them is to convert them to WAV and then reverse the WAV file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With