-odac --messagelevel=134 sr = 44100 ksmps = 64 nchnls = 4 0dbfs = 1 A4 = 442 chn_k "peak", 1 ; Channel to get peak information from graph gi_fftSizes[] fillarray 2048, 4096, 8192, 16384 gk_fftSize init 4096 gk_peakFreq init 0 gk_peakGain init 0 gi_refreshRates[] fillarray 10,12,15,18,20,24,30 gk_refreshRate init 20 instr PlayPeak ; play the detected peak frequency kamp = ampdb(gk_peakGain) apeak oscili kamp, sc_lag(gk_peakFreq, 0.1) apeak *= linsegr:a(0, 0.1, 1, 0.1, 0) outch 1, apeak endin instr Spectrum k0 invalue "ch1" k1 invalue "ch2" k2 invalue "ch3" k3 invalue "ch4" kfftSizeIndex invalue "fftsize" kplayPeak invalue "playpeak" kfilterlow invalue "filterlow" kinGain invalue "ingain" gk_peakGain invalue "peakgain" krefreshRateIdx invalue "refreshrateidx" ; We need to use chnget to receive the peak information kpeak chnget "peak" khasPeak = kpeak > 0 ? 1:0 gk_peakFreq samphold kpeak, khasPeak if kplayPeak == 1 && changed(khasPeak) == 1 then if khasPeak == 1 then schedulek("PlayPeak", 0, -1) else turnoff2("PlayPeak", 0, 1) endif endif kfftSize = gi_fftSizes[kfftSizeIndex] krefreshRate = gi_refreshRates[krefreshRateIdx] if kfftSize != gk_fftSize || krefreshRate != gk_refreshRate then gk_fftSize = kfftSize gk_refreshRate = krefreshRate reinit dispReset endif a0 inch 1 a1 inch 2 a2 init 0 a3 init 0 a0 *= k0 a1 *= k1 if nchnls > 2 then a2 inch 3 a2 *= k2 if nchnls > 3 then a3 inch 4 a3 *= k3 endif endif amix = sum(a0, a1, a2, a3) amix *= ampdb(kinGain) ; filter low frequencies from spectrum if kfilterlow == 1 then aspectrum pareq amix, 30, 0, 0.05, 1 else aspectrum = amix endif denorm aspectrum dispReset: iperiod = 1/i(gk_refreshRate) print iperiod dispfft aspectrum, iperiod, i(gk_fftSize) endin instr PostInit ; this needs to run at a point where the fft curve already ; exists, which, depending on gk_fftSize, is, at the latest, ; 16384 / sr (16384 / 44100 = 0.37...) outvalue "spectrum", "@find fft aspectrum" outvalue "spectrum", "@getPeak peak" turnoff endin schedule "Spectrum", 0, -1 schedule "PostInit", 16384/sr + 0.01, -1 0 0 1010 576 true 22 22 22 spectrum 10 9 1000 500 {ae3dee92-fc91-44c4-9b0f-b8656a7eb4f3} true 0 -3 Spectrum - Press mouse to show/play peak 0 2.00000000 1.00000000 1.00000000 1.00000000 lin lin false true false false false true true ch1 10 520 30 30 {5aae7b7e-875a-492f-89cb-dbb779039dbe} true 0 -3 Enable Channel 1 true ch2 40 520 30 30 {00c02e40-ab30-4c76-8737-0f1c375df75a} true 0 -3 Enable Channel 2 false ch3 70 520 30 30 {cb2805f4-c9ec-4a28-ba5c-459a2e3cec59} true 0 -3 Enable Channel 3 false ch4 100 520 30 30 {2192eed2-7818-45d5-8593-200cb766966c} true 0 -3 Enable Channel 4 false fftsize 150 520 80 30 {e3a55dea-950a-4c43-a7ef-50f107379f17} true 0 -3 FFT size 2048 0 4096 1 8192 2 16384 3 2 false 30 550 80 25 {342a2cbb-91b5-413b-9de1-aa82f1d74a0d} true 0 -3 center top Arial 13 3 239 240 241 255 255 255 false 1 0 145 550 80 25 {09805d02-0ae6-4f4c-9c39-6b7e61fb1356} true 0 -3 center top Arial 13 3 241 241 241 255 255 255 false 1 0 playpeak 459 519 30 30 {f8803c6a-6fba-459f-a113-0e33c0ff19d1} true 0 0 Play the peak frequency when the mouse is pressed true 435 550 80 25 {67e8666d-183c-491d-b465-61d7a1a218d5} true 0 -3 center top Arial 13 3 239 240 241 255 255 255 false 1 0 ingain 585 515 56 54 {ce2ca6ad-fa91-4b89-a2eb-7c092f529f22} true 1 7 Input Gain (dB) -24.00000000 24.00000000 0.00000000 lin continuous 0.01000000 false 245 124 0 #f57c00 0 #000000 true true true 505 530 80 25 {8e80da70-b7b1-4f2d-935c-3e78f2730099} true 0 -3 right top Arial 13 3 239 240 241 255 255 255 false 1 0 peakgain 720 515 56 54 {5951dec6-0e29-4eed-a7c9-3438955fabc4} true 0 0 Input Gain (dB) -80.00000000 0.00000000 -23.70400000 lin continuous 0.01000000 false 245 124 0 #f57c00 0 #512900 true true true 640 530 80 25 {b1e91595-3134-4b62-943e-17e7f17b2058} true 0 -3 right top Arial 13 3 239 240 241 255 255 255 false 1 0 340 550 100 26 {d9b44e66-bfec-4a49-ba48-e52e29d1e889} true 0 -3 center top Arial 13 3 239 240 241 255 255 255 false 1 0 filterlow 375 520 30 30 {761ac268-c49b-4473-a0df-c045ea9fdaa4} true 0 0 Filter low frequencies true refreshrateidx 250 520 80 30 {6aab35af-5577-4c32-a245-d69c50b0dfcd} true 0 0 Refresh Rate 10 0 12 1 15 2 18 3 20 4 24 5 30 6 4 false 250 550 84 25 {432a9bd1-1587-40a7-a618-e256a453b4e4} true 0 -3 center top Arial 13 3 241 241 241 255 255 255 false 1 0 794 519 196 45 {13da7982-27d8-46ae-a425-3aecf9e1c34c} true 0 -3 left center Liberation Sans 13 3 239 239 239 48 53 58 false 3 0