Reversing a sound with Processing and Minim -
i need make program in processing reverses loaded .mp3 file, avoiding implemented abstract functions (for example, minim function reverses given sound, though still haven't found such). i've tried many ways , still doesn't play.
my last approach uses minim.loadfileintobuffer() function float[] , reverse buffer using processing's reverse() function. create audiosample same float array , original file's format. proceed play sample using trigger().
here's 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 multichannelbuffer's parameters // match file's, init values doesn't 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 tried different solutions. namely importing directly file audiosample. problem ways i've used, believe, can access audiobuffer, i.e. part of whole sound. thus, cannot reverse all.
do know way of doing this?
ok managed it, simpler process.
i original sample's channels , directly manipulate them. first, construct new floatarray same size channels. then, put values in original using same procedure.
it's far being beautiful implementation , it's more time-complex be. trick, since limited using no implemented high level functions.
void revert() { /* sample audiosample, created in setup() */ float[] leftchannel = sample.getchannel(audiosample.left); float[] rightchannel = sample.getchannel(audiosample.right); float[] leftreversed = new float[leftchannel.length]; float[] rightreversed = new float[rightchannel.length]; int size = leftchannel.length-1; /*inverts array*/ for(int i=0; i<=size; i++){ leftreversed[i] = leftchannel[size-i]; rightreversed[i] = rightchannel[size-i]; } /*copies original array*/ for(int i=0; i<size; i++){ leftchannel[i] = leftreversed[i]; rightchannel[i] = rightreversed[i]; } }
Comments
Post a Comment