sanzrodrigo
YaBB Newbies
Offline
Posts: 17
Re: Minim: new audio library for processing
Reply #13 - Dec 14th , 2008, 6:26pm
Hello! i'm using the minim library, i started with the "RecordandPlayback" sketch and i'm trying to do a FFT analysis to the file that i'm recording in real time but i have this error.... Minim Error === === FFT.forward: The length of the passed sample buffer must be equal to timeSize(). Can someone help me? thanks, Rodrigo here is the patch: import ddf.minim.analysis.*; import ddf.minim.*; Minim minim; AudioInput in; AudioRecorder recorder; AudioPlayer player; FFT fft; void setup() { size(512, 200, P3D); textMode(SCREEN); minim = new Minim(this); // get a stereo line-in: sample buffer length of 2048 // default sample rate is 44100, default bit depth is 16 in = minim.getLineIn(Minim.STEREO, 2048); // create an AudioRecorder that will record from in to the filename specified, using buffered recording // buffered recording means that all captured audio will be written into a sample buffer // then, when save() is called, the contents of the buffer will actually be written to a file // the file will be located in the sketch's data folder. recorder = minim.createRecorder(in, "myrecording.wav", true); player = minim.loadFile("myrecording.wav",2048); textFont(createFont("Arial", 12)); fft = new FFT(player.bufferSize(), player.sampleRate()); fft.logAverages(44, 1); } void draw() { fft.forward(player.mix); float moyen = ((fft.getAvg(0) + fft.getAvg(1) + fft.getAvg(2) + fft.getAvg(3) + fft.getAvg(4) + fft.getAvg(5) + fft.getAvg(6) + fft.getAvg(7) + fft.getAvg(8)) / 9); println(moyen*10); // println(player.left.level()*1000); background(0); stroke(255); // draw the waveforms // the values returned by left.get() and right.get() will be between -1 and 1, // so we need to scale them up to see the waveform for(int i = 0; i < in.left.size()-1; i++) { line(i, 50 + in.left.get(i)*50, i+1, 50 + in.left.get(i+1)*50); line(i, 150 + in.right.get(i)*50, i+1, 150 + in.right.get(i+1)*50); } if ( recorder.isRecording() ) { text("Now recording...", 5, 15); } else { text("Not recording.", 5, 15); } } void keyReleased() { if ( key == 'r' ) { // to indicate that you want to start or stop capturing audio data, you must call // startRecording() and stopRecording() on the AudioFileOut object. You can start and stop // as many times as you like, the audio data will be appended to the end of the buffer // (in the case of buffered recording) or to the end of the file (in the case of streamed recording). if ( recorder.isRecording() ) { recorder.endRecord(); } else { recorder.beginRecord(); } } if ( key == 's' ) { // we've filled the file out buffer, // now write it to a file of the type we specified in setup // in the case of buffered recording, // this will appear to freeze the sketch for sometime, if the buffer is large // in the case of streamed recording, // it will not freeze as the data is already in the file and all that is being done // is closing the file. // save returns the recorded audio in an AudioRecording, // which we can then play with an AudioPlayer if ( player != null ) { player.close(); } player = recorder.save(); player.play(); } } void stop() { // always close Minim audio classes when you are done with them in.close(); if ( player != null ) { player.close(); } minim.stop(); super.stop(); }