Spectralyzer

listens to an input and displays its spectrum in equal relative bandwidth steps.

This is useful for tuning multichannel speaker setups, e.g. with Latency and SpeakerAdjust.

// quick first example:

(

x = Spectralyzer.new(61); // make a spectralyzer,

x.makeWindow; // make a gui for it

x.listenTo({ PinkNoise.ar }); // listen to a sound

x.start; // start displaying

)

*new (nBands, minFreq, maxFreq, server)

nBands: number of equal relative width bands to analyse.

Default is 60 bands, which creates 1/6th octave bands for 20-20000 Hz.

minFreq: lowest band center freq, default 20Hz.

maxFreq: highest band center freq, default 20000Hz

server: the server to run on, default: Server.default.

x = Spectralyzer.new(20, 100, 8000); // ca. 3rd octaves, 100, 125, 160, 200

x.makeWindow;

x.freqs.round(0.1);

x = Spectralyzer.new(61, 20, 20000); // default ca 1/6 octaves

x.freqs.round(0.1);

x = Spectralyzer.new(31, 20, 20 * 1024); // precise 3rd octaves

x.freqs.round(0.1);

listenTo(src)

src: set the source to listen to. This can be anything a NodeProxy accepts as a source;

usually it will be an audio function or maybe an existing proxy.

multichannel sources will be converted to mono.

x.listenTo({ SinOsc.ar });

x.listenTo({ SoundIn.ar(0) });

x.listenTo({ SinOsc.ar([300, 500, 1200]) * 0.1 });

// set middle db value to display

x.midDb = -20;

x.midDb = -30;

// set range to display (midDb +- rangeDb)

x.rangeDb = 15;

x.rangeDb = 30;

x.rangeDb = 10; // higher resolution

// average over the last n measured amplitudes

x.avgN = 5;

x.avgN = 20;

x.avgN = 2;

x.avgN = 1;

x.avgN = 5;

// change time interval

x.dt = 0.03;

x.dt = 0.1;

x.dt = 0.3;

x.dt = 1;

x.dt = 0.1;

// usage example: adjust frequency response for a speaker.

// results could then be used e.g. in SpeakerAdjust.

p = ProxySpace.push;

~noyz = { PinkNoise.ar(1) ! 2 };

~noyz.play(vol: 0.5);

// listen to noise from microphone

x.listenTo({ SoundIn.ar(0) });

( // make two bands of parametric eq filter

~noyz.filter(5, { |in, f1=100,rq1=1,db1=0,f2=5000,rq2=1,db2=0|

MidEQ.ar(MidEQ.ar(in, f1, rq1, db1), f2, rq2, db2);

});

)

// eq for powerbook G4/1.25 speakers:

~noyz.set(\f1, 150, \rq1, 2, \db1, 6); // bass boost

~noyz.set(\f2, 7500, \rq2, 1, \db2, -4); // take out shrill highs

// take eq out completely

~noyz[5] = nil;