#N canvas 556 77 545 468 12;
#X declare -stdpath ./;
#N canvas 394 108 652 570 fft-analysis 0;
#X obj 101 425 *~;
#X obj 62 425 *~;
#X obj 62 126 *~;
#X obj 62 96 inlet~;
#X obj 62 149 rfft~;
#X obj 62 488 *~;
#X obj 153 189 *~;
#X obj 62 454 rifft~;
#X obj 62 511 outlet~;
#X obj 119 189 *~;
#X obj 119 212 +~;
#X obj 319 116 block~ 1024 4;
#X obj 119 363 clip~;
#X obj 151 315 r squelch;
#X obj 97 124 tabreceive~ \$0-hann;
#X obj 151 338 expr 0.01*$f1*$f1;
#X obj 448 117 loadbang;
#X obj 119 393 *~ 0.00065;
#X obj 119 237 +~ 1e-20;
#X obj 119 274 q8_rsqrt~;
#X obj 100 482 tabreceive~ \$0-hann;
#X text 69 13 As in the previous patch \, this works by multiplying
each channel of the Fourier analysis by a real number computed from
the magnitude. If the magnitude is "m" \, the correction factor is
1/m \, but only to an upper limit controlled by the "squelch" parameter.
, f 68;
#X text 193 186 squared magnitude;
#X text 187 238 protect against divide-by-zero;
#X text 190 266 quick 8-bit-accurate reciprocal square root;
#X text 188 282 (done by table lookup - about 0.25% accurate);
#X text 200 393 normalize for 1024-point \, overlap-4 Hann;
#X text 117 149 outputs complex amplitudes;
#X text 166 363 limit the gain to squelch * squelch/100;
#X text 131 416 multiply gain by real and complex part of the amplitude
, f 29;
#X msg 448 140 \; window-size 1024 \; squelch 10 \; squelch-set set
10;
#X connect 0 0 7 1;
#X connect 1 0 7 0;
#X connect 2 0 4 0;
#X connect 3 0 2 0;
#X connect 4 0 9 0;
#X connect 4 0 9 1;
#X connect 4 0 1 0;
#X connect 4 1 6 0;
#X connect 4 1 6 1;
#X connect 4 1 0 0;
#X connect 5 0 8 0;
#X connect 6 0 10 1;
#X connect 7 0 5 0;
#X connect 9 0 10 0;
#X connect 10 0 18 0;
#X connect 12 0 17 0;
#X connect 13 0 15 0;
#X connect 14 0 2 1;
#X connect 15 0 12 2;
#X connect 16 0 30 0;
#X connect 17 0 0 1;
#X connect 17 0 1 1;
#X connect 18 0 19 0;
#X connect 19 0 12 0;
#X connect 20 0 5 1;
#X restore 105 293 pd fft-analysis;
#X floatatom 94 171 0 0 500 0 - squelch-set - 0;
#X obj 94 195 s squelch;
#N canvas 240 72 458 613 test-signal 0;
#X obj 134 457 line~;
#X obj 134 537 outlet~;
#X msg 134 432 0 \, \$1 \$2;
#X obj 187 353 /;
#X obj 271 322 * 0.001;
#X obj 134 510 hip~ 5;
#X obj 87 236 loadbang;
#X msg 87 331 1;
#X obj 87 353 metro 1000;
#X obj 225 292 t b b f;
#X obj 107 291 t b f;
#X obj 134 482 tabread4~ \$0-sample;
#X text 76 43 test signal: looped sample playback;
#X obj 129 153 hip~ 5;
#X obj 129 129 adc~ 1;
#X obj 191 147 s insamprate;
#X obj 119 82 inlet;
#X obj 191 123 samplerate~;
#X obj 106 267 r \$0-samplength;
#X obj 225 266 r \$0-insamprate;
#X obj 119 176 tabwrite~ \$0-sample;
#X obj 134 406 pack f f;
#X obj 87 378 float;
#X connect 0 0 11 0;
#X connect 2 0 0 0;
#X connect 3 0 8 1;
#X connect 3 0 21 1;
#X connect 4 0 3 1;
#X connect 5 0 1 0;
#X connect 6 0 7 0;
#X connect 7 0 8 0;
#X connect 8 0 22 0;
#X connect 9 0 7 0;
#X connect 9 1 3 0;
#X connect 9 2 4 0;
#X connect 10 0 7 0;
#X connect 10 1 3 0;
#X connect 10 1 22 1;
#X connect 11 0 5 0;
#X connect 13 0 20 0;
#X connect 14 0 13 0;
#X connect 16 0 17 0;
#X connect 16 0 20 0;
#X connect 17 0 15 0;
#X connect 18 0 10 0;
#X connect 19 0 9 0;
#X connect 21 0 2 0;
#X connect 22 0 21 0;
#X restore 105 262 pd test-signal;
#X obj 105 326 output~;
#N canvas 444 61 689 350 insample 0;
#N canvas 0 0 450 300 (subpatch) 0;
#X array \$0-sample 155944 float 0;
#X coords 0 1 155943 -1 400 150 1;
#X restore 262 48 graph;
#X obj 27 24 r read-sample;
#X obj 27 80 unpack s f;
#X obj 27 190 soundfiler;
#X text 364 250 read a sample;
#X obj 293 249 loadbang;
#X obj 27 106 t s b;
#X obj 80 111 symbol \$0-sample;
#X obj 27 141 pack s s;
#X msg 27 166 read -resize \$1 \$2;
#X obj 27 53 t a b;
#X msg 293 273 \; read-sample ../sound/bell.aiff;
#X obj 37 218 s \$0-samplength;
#X obj 124 80 s \$0-insamprate;
#X obj 27 253 /;
#X obj 27 287 * 1000;
#X obj 27 310 s \$0-samp-msec;
#X obj 65 253 r \$0-insamprate;
#X obj 124 54 f 44100;
#X connect 1 0 10 0;
#X connect 2 0 6 0;
#X connect 2 1 13 0;
#X connect 3 0 12 0;
#X connect 3 0 14 0;
#X connect 5 0 11 0;
#X connect 6 0 8 0;
#X connect 6 1 7 0;
#X connect 7 0 8 1;
#X connect 8 0 9 0;
#X connect 9 0 3 0;
#X connect 10 0 2 0;
#X connect 10 1 18 0;
#X connect 14 0 15 0;
#X connect 15 0 16 0;
#X connect 17 0 14 1;
#X connect 18 0 13 0;
#X restore 299 314 pd insample;
#X text 291 420 updated for Pd version 0.39;
#X text 53 49 Here we divide each complex channel in the Fourier analysis
by its own magnitude to "flatten" the spectrum. The "squelch" control
limits the amplitude boost the algorithm will apply. If infinite \,
you'll get a white spectrum. If less \, the louder parts of the spectrum
will be flattened but the quieter ones will only be boosted by the
squelch value.;
#X text 74 12 DYNAMIC RANGE COMPRESSION BY FOURIER ANALYSIS CHANNEL
;
#X floatatom 299 367 5 0 0 0 - \$0-samp-msec - 0;
#X obj 105 241 bng 15 250 50 0 empty empty empty 0 -6 0 8 #fcfcfc #000000
#000000;
#X text 352 366 sample length \, msec;
#X msg 293 189 ../sound/bell.aiff;
#X msg 299 212 ../sound/voice.wav;
#X msg 305 236 ../sound/voice2.wav;
#X text 128 172 <- squelch;
#X text 296 167 change input sound;
#X obj 293 265 s read-sample;
#N canvas 796 122 565 538 hann-window 0;
#N canvas 0 0 450 300 (subpatch) 0;
#X array \$0-hann 1024 float 0;
#X coords 0 1 1023 0 300 100 1;
#X restore 110 394 graph;
#X obj 327 184 osc~;
#X obj 327 209 *~ -0.5;
#X obj 327 233 +~ 0.5;
#X obj 310 276 tabwrite~ \$0-hann;
#X obj 86 113 r window-size;
#X obj 157 237 /;
#X obj 175 205 samplerate~;
#X obj 157 315 s window-sec;
#X obj 67 251 swap;
#X obj 67 275 /;
#X obj 67 299 s window-hz;
#X obj 168 265 * 1000;
#X obj 168 292 s window-msec;
#X obj 86 148 t f b f;
#X msg 175 155 resize \$1;
#X obj 175 179 s \$0-hann;
#X obj 279 122 r window-hz;
#X msg 352 154 0;
#X obj 279 150 t f b;
#X text 56 20 calculate Hann window table (variable window size) and
constants window-hz (fundamental frequency of analysis) \, window-sec
and window-msec (analysis window size in seconds and msec)., f 56
;
#X connect 1 0 2 0;
#X connect 2 0 3 0;
#X connect 3 0 4 0;
#X connect 5 0 14 0;
#X connect 6 0 8 0;
#X connect 6 0 12 0;
#X connect 7 0 6 1;
#X connect 7 0 9 1;
#X connect 9 0 10 0;
#X connect 9 1 10 1;
#X connect 10 0 11 0;
#X connect 12 0 13 0;
#X connect 14 0 6 0;
#X connect 14 0 9 0;
#X connect 14 1 7 0;
#X connect 14 2 15 0;
#X connect 15 0 16 0;
#X connect 17 0 19 0;
#X connect 18 0 1 1;
#X connect 19 0 1 0;
#X connect 19 1 4 0;
#X connect 19 1 18 0;
#X restore 299 336 pd hann-window;
#X text 124 238 <= record;
#X obj 61 408 declare -stdpath ./;
#X connect 0 0 4 0;
#X connect 0 0 4 1;
#X connect 1 0 2 0;
#X connect 3 0 0 0;
#X connect 10 0 3 0;
#X connect 12 0 17 0;
#X connect 13 0 17 0;
#X connect 14 0 17 0;
