I need to make a program in Processing that reverses a loaded .mp3 file, avoiding already implemented abstract functions (for example, a Minim
function that reverses a given sound, though I still haven't found such). I've tried many ways by now and it still doesn't play.
My last approach uses the Minim.loadFileIntoBuffer()
function to get a float[]
and then I reverse the buffer using Processing's reverse()
function. I then create an AudioSample
with the same float
array and the original file's format. I then proceed to play the sample using trigger()
.
Here's a snippet:
Minim minim;
AudioPlayer songPlayer;
MultiChannelBuffer song;
AudioSample reversedSong;
float[] reversedBuffer, mixBuffer;
void setup() {
size(512, 200);
minim = new Minim(this);
songPlayer = minim.loadFile("sound.mp3");
// loadFileIntoBuffer changes the MultiChannelBuffer's parameters to
// match the file's, so init values doesn't really matter
song = new MultiChannelBuffer(10, 3);
minim.loadFileIntoBuffer("sound.mp3", song);
mixBuffer = songPlayer.mix.toArray();
reversedBuffer = reverse(mixBuffer);
reversedSong = minim.createSample(reversedBuffer, songPlayer.getFormat());
reversedSong.trigger();
}
I've also tried some different solutions. Namely importing directly the file into a AudioSample
. The problem with most ways I've already used, I believe, is that I can only access an AudioBuffer
, i.e. a part of the whole sound. Thus, I cannot reverse it all.
Do you know any way of doing this?