Forums > MaxMSP

Spectrogram from Buffer

March 11, 2008 | 11:06 am

Is there a way to generate a spectrogram (using LCD in my case) by analysing the content of a buffer (it means creating the spectrogram in non realtime).

The idea would be to use the generated spectrogram in conjunction with the waveform (generated by the patch below) and have the spectrogram of the corresponding waveform.

I hope this is clear, and that it’s possible.

#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P message 302 400 50 9109513 3;
#P message 452 474 50 9109513 16;
#P flonum 302 482 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#N vpatcher 414 28 1130 714;
#P window setfont "Sans Serif" 9.;
#P message 85 186 54 9109513 penmode 5;
#P message 209 186 54 9109513 penmode 0;
#P window linecount 1;
#P newex 85 99 61 9109513 r redraw;
#P window linecount 0;
#P newex 85 626 50 9109513 s $0_LCD;
#P newex 405 107 55 9109513 unpack;
#P newex 405 87 55 9109513 r $0_size;
#P newex 405 131 29 9109513 t b i;
#P newex 450 223 27 9109513 / 2.;
#P newex 296 359 138 9109513 peek~ $0_un;
#P message 189 560 139 9109513 linesegment $1 $2 $3 $4 $5;
#P newex 296 391 89 9109513 * 25.;
#P newex 210 519 186 9109513 pack i i i i 69;
#P newex 313 48 33 9109513 * 44.1;
#P newex 147 217 42 9109513 Uzi $2;
#P newex 313 243 38 9109513 / 500.;
#P newex 296 327 27 9109513 * 0.;
#P newex 210 295 96 9109513 t i i;
#P newex 85 163 197 9109513 t b b b b;
#P message 271 186 28 9109513 clear;
#P newex 296 457 32 9109513 + 25.;
#P newex 313 28 76 9109513 r $1_zoomlength;
#B color 6;
#P newex 342 457 118 9109513 expr $f2 – $f1;
#N comlet color;
#P inlet 544 103 15 0;
#P newex 544 131 27 9109513 t b i;
#P newex 505 298 33 9109513 * 1.;
#N comlet vertical zoom;
#P inlet 482 103 15 0;
#P newex 482 131 56 9109513 t b b f;
#P newex 210 268 27 9109513 – 1;
#P fasten 1 0 10 0 487 159 90 159;
#P lcolor 15;
#P fasten 4 0 10 0 549 159 90 159;
#P lcolor 15;
#P connect 25 0 10 0;
#P connect 10 0 27 0;
#P fasten 9 0 24 0 276 213 90 213;
#P fasten 18 0 24 0 194 598 90 598;
#P connect 27 0 24 0;
#P fasten 26 0 24 0 214 211 90 211;
#P connect 10 1 14 0;
#P fasten 21 1 14 1 429 209 184 209;
#P connect 16 0 18 0;
#P connect 10 2 26 0;
#P connect 14 2 0 0;
#P connect 0 0 11 0;
#P connect 11 0 16 0;
#P lcolor 9;
#P connect 8 0 16 1;
#P fasten 10 3 9 0 276 181 276 181;
#P connect 11 1 12 0;
#P connect 12 0 19 0;
#P connect 19 0 17 0;
#P connect 17 0 8 0;
#P connect 11 0 16 2;
#P lcolor 9;
#P connect 7 0 15 0;
#P connect 15 0 13 0;
#P connect 21 0 13 0;
#P connect 13 0 12 1;
#P fasten 20 0 8 1 455 432 323 432;
#P lcolor 7;
#P fasten 21 1 13 1 429 223 346 223;
#P connect 17 0 6 0;
#P connect 6 0 16 3;
#P fasten 3 0 17 1 510 385 380 385;
#P fasten 4 1 16 4 566 495 391 495;
#P connect 22 0 23 0;
#P connect 23 0 21 0;
#P connect 23 1 20 0;
#P connect 20 0 6 1;
#P lcolor 7;
#P connect 2 0 1 0;
#P connect 1 1 3 0;
#P connect 20 0 3 0;
#P connect 1 2 3 1;
#P connect 5 0 4 0;
#P pop;
#P newobj 302 509 160 9109513 p draw;
#P message 172 379 28 9109513 2000;
#P flonum 172 397 76 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 172 413 76 9109513 s $1_zoomlength;
#B color 6;
#P message 63 447 41 9109513 replace;
#P newex 63 465 90 9109513 buffer~ $0_un 2000;
#P message 124 395 47 9109513 500 150;
#P newex 124 413 47 9109513 s $0_size;
#P newex 84 335 50 9109513 loadbang;
#P newex 63 415 60 9109513 s redraw;
#P toggle 63 376 15 0;
#P newex 63 395 60 9109513 metro 10;
#P newex 56 61 50 9109513 r $0_LCD;
#P user lcd 56 122 500 150 1 1 1 0 1;
#P comment 338 483 32 9109513 Zoom;
#P connect 6 0 4 0;
#P connect 6 0 8 0;
#P connect 6 0 13 0;
#P connect 6 0 17 0;
#P connect 6 0 16 0;
#P connect 17 0 15 0;
#P connect 16 0 14 1;
#P connect 15 0 14 0;
#P connect 13 0 12 0;
#P connect 12 0 11 0;
#P connect 10 0 9 0;
#P connect 4 0 3 0;
#P connect 3 0 5 0;
#P connect 8 0 7 0;
#P connect 2 0 1 0;
#P window clipboard copycount 18;


March 11, 2008 | 1:38 pm


March 11, 2008 | 2:31 pm

"Jitter Pvoc 2D" example is really nice but it isn’t what I try to get.

Here, we get the Spectrogram in realtime, corresponding to what is currently playing.

What I want to do is to get the Spectrogram from a buffer, like the Spectrogram in a lot of editing software.

1) You load a file in a buffer
2) You click on a button
3) You see the spectrogram of the buffer’s content (with LCD or whatever)

I don’t see any starting point to do that.


March 11, 2008 | 10:41 pm

By chance I was working on this recently, although not entirely in the manner you describe. I allow the system to take time to perform an analysis using (p)fft on live recorded material, and have an lcd draw the result as the proces goes on. So it takes realtime to do it.

By the way, as my screen, and therefor the lcd, is not wide enough to draw all frames, I select maximum values for each bin that occur over a number of frames. This method would work well for your waveform drawing method. Rather then drawing specific samples that happen to be at the index you’re at, selecting the maximum amplitude over a range (or it’s energy content) would result in a better looking waveform.

Maybe there’s something in Java that does all this in non-real time.

_
johan


March 11, 2008 | 10:55 pm

In fact, I would like to actualise the spectrogram every let’s say 50 milliseconds for example, to have a similar drawing to what we can get with the [waveform~] but concerning the frequency and not only the amplitude.

To be able to know if I make a loop on a melodic sound or a noisy one.

But thinking about it, it should be pretty hard on the CPU, I’ll continue to use the good old amplitude waveform.

But if one day, you come up with what you are talking about, which seems really cool, don’t hesitate to show…

Thanks again Johan.


Viewing 5 posts - 1 through 5 (of 5 total)