Spectrogram a spectral analysis view





SuperCollider allows for various modes of graphical representations of sound. The Spectrogram adds yet another mode (spectral view) to the Wave scope or the Frequency scope. 


See also:  SpectrogramWindow, FreqScope and Stethoscope



The Spectrogram comes in two modes, as a view that can be added to any Window, and a special window that functions like the FreqScope window. See example below for the spectrogram window.


Note that the server must be running before using the spectrogram:


s.boot;


Creation / Class Methods


*new (parent, bounds, bufSize, color, background, lowfreq, highfreq)

Initialising the view, either in a Window or not.

parent - a Window (optional).

bounds - a Rect where the spectrogram appears in the parent (optional).

bufSize - frames in FFT window. default: 1024. Use power-of-2 sizes, such as 512 or 2048.

color, background - the foreground and background Colors.

lowfreq, highfreq - you can specify the range of frequencies you want to visualise.

// the spectrogram in a window

w = Window.new("testing spectrogram", Rect(10,10, 600, 300)).front;

a = Spectrogram.new(w, Rect(10, 10, 580, 280));

a.start;

{Saw.ar(LFNoise1.kr(1).range(20,2250))}.play




Accessing Instance and Class Variables

rate_(arg1)

rate

Refresh rate. Default is 25 frames per second 

bufSize

frames in FFT window. see above.

intensity_(arg1)

intensity

Intensity is how strong the drawn color is.

Default value is 5.

Instance methods


start

starts analysis and drawing.

stop

stops analysis and drawing



inbus_ (inbus)

The audio bus of analysis.



color_ (argcolor)

The color that is drawn.

background_ (argcolor)

The background color.



setBufSize_ (buffersize)

Sets the buffer size of the fft window. See above.



a = Spectrogram.new( color: Color.red);

{LPF.ar(WhiteNoise.ar(1), LFNoise1.kr(1).range(20,12250))}.play;

a.start;

a.background_(Color.blue);

a.color_(Color.black);



Examples




// a simple view for quick inspections of sound

a = Spectrogram.new;

a.start;

{AudioIn.ar(1)}.play // feedback warning!


a.intensity = 15;

a.rate = 25;

a.color_(Color.red);

a.background_(Color.green(alpha:0.1));




// spectrogram in a window

(

w = Window.new("spectrogram".scramble, Rect(10,10, 600, 300)).front;

a = Spectrogram.new(w, Rect(10, 10, 560, 260));

a.start;

{Saw.ar(LFNoise1.kr(1).range(20,2250))}.play;

)




// spectrogram in a window with different colors

(

w = Window.new("spectrogram".scramble, Rect(10,10, 600, 300)).front;

a = Spectrogram.new(w, w.view.bounds.insetAll(30, 10, 42, 10), background:Color(0.2, 0.25, 0.2), color:Color.red);

a.start;

{Saw.ar(LFNoise1.kr(1).range(20,2250))}.play;

)




// an example showing where the low and high frequencies are scaled and large bufsize (FFT window)

(

w = Window.new("spectrogram".scramble, Rect(100,200, 600, 300)).front;

a = Spectrogram.new(w, Rect(10, 10, 550, 280), bufSize: 2048, lowfreq:1000, highfreq:10000);

a.start;

{SinOsc.ar(MouseY.kr(22050,1).poll(10, "frequency: "))}.play;

)


{Saw.ar(MouseX.kr(1, 1000))}.play;




// check also the spectrogram window

(

a = SpectrogramWindow.new;

{SinOsc.ar(MouseY.kr(22050, 1).poll(10, "frequency: "))}.play

)



// analogously to .scope and .freqscope, spectrogram is also added as a method to Function, thus:

{LFNoise1.ar(MouseX.kr(10, 4000)) * SinOsc.ar(MouseY.kr(15000, 1000, 1))}.spectrogram


{LPF.ar(WhiteNoise.ar(1), LFNoise1.kr(1).range(20,12250))}.spectrogram;


{Saw.ar(MouseX.kr(1, 1000))}.spectrogram;