should always look the same
I agree with you, it should, but it doesn't.
Check the code bellow.
It generates a 2D list with the values: first dimension is the buffer size and the second one is the time (there is a variable there to quick cut out and just get the start of the file for testing)
It will print to the terminal the values in blocks (of the buffer size).
Just copy/paste the terminal output to an TXT file (to keep it for comparaison) and run again the sketch.
Maybe, the last number is the same, so looks right.
Sometimes, even a few before the last are also the same, so it should be right...
But if you copy one string on numbers, go to your TXT file, and make a search for it, it won't be there.... so is not actually exactly the same every time.
- import ddf.minim.analysis.*;
- import ddf.minim.*;
- FFT fftLin;
- Minim minim;
- AudioPlayer groove;
- ArrayList<ArrayList> waveMap = new ArrayList<ArrayList>();
- int lines = 1000; // How long you want to get values from the file
- void setup() {
- noLoop();
- minim = new Minim(this);
- groove = minim.loadFile("test_sound.mp3");
- groove.mute();
- groove.play();
- // GET VALUES
- while (lines>0) {
- ArrayList<Float> waveVal = new ArrayList<Float>();
- for (int i = 0; i < groove.bufferSize(); i++) {
- waveVal.add(groove.mix.get(i));
- }
- waveMap.add(waveVal);
- lines--;
- }
- // PRINT VALUES
- for (int i=0; i<waveMap.size(); i++) {
- for (int j=0; j<groove.bufferSize(); j++) {
- print(waveMap.get(i).get(j) + " ");
- }
- println();
- println();
- }
- exit();
- }
For me the issue is in the 'playing' part.
Also the downside of this approach, is that to get the analysis of a one hour long sound file, you need to wait one hour... which is nonsense considering it's digital.
Thinking in an analog way, is like you are physically playing it and then digital recording it to your computer (so you get the values), instead of just reading it since it is actually digitalized from the beginning.
Think of DV cassetes, when you need to actually play the video in order to import it (because you are recording the stream) vs the drag and copy of and video file.
I will look deeper into Minim documentation, should be a way to just get everything at once instead of while it's playing.