#N canvas 465 57 552 579 12;
#X declare -stdpath ./;
#N canvas 394 108 595 625 fft-analysis 0;
#X obj 101 465 *~;
#X obj 62 465 *~;
#X obj 62 126 *~;
#X obj 62 96 inlet~;
#X obj 62 149 rfft~;
#X obj 62 528 *~;
#X obj 153 189 *~;
#X obj 62 494 rifft~;
#X obj 62 561 outlet~;
#X obj 119 189 *~;
#X obj 119 212 +~;
#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 119 237 +~ 1e-20;
#X obj 100 522 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 117 149 outputs complex amplitudes;
#X text 166 363 limit the gain to squelch * squelch/100;
#X text 131 456 multiply gain by real and complex part of the amplitude, f 29;
#X obj 119 274 rsqrt~;
#X text 169 274 reciprocal square root;
#X obj 360 113 r window-size;
#X msg 360 139 set \$1 4;
#X obj 360 165 block~;
#X obj 167 424 expr 2/(3*$f1);
#X obj 167 395 r window-size;
#X text 282 424 normalize;
#X obj 119 423 *~ 0;
#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 15 0;
#X connect 11 0 31 0;
#X connect 12 0 14 0;
#X connect 13 0 2 1;
#X connect 14 0 11 2;
#X connect 15 0 23 0;
#X connect 16 0 5 1;
#X connect 23 0 11 0;
#X connect 25 0 26 0;
#X connect 26 0 27 0;
#X connect 28 0 31 1;
#X connect 29 0 28 0;
#X connect 31 0 0 1;
#X connect 31 0 1 1;
#X restore 89 300 pd fft-analysis;
#X floatatom 136 202 5 1 200 0 squelch squelch-set squelch 16;
#N canvas 406 293 383 306 test-signal 0;
#X obj 105 229 outlet~;
#X text 63 27 test signal: looped sample playback;
#X obj 105 139 *~;
#X obj 105 105 phasor~;
#X obj 105 186 tabread4~ \$0-sample;
#X obj 105 76 r \$0-hz;
#X obj 139 140 r \$0-size;
#X connect 2 0 4 0;
#X connect 3 0 2 0;
#X connect 4 0 0 0;
#X connect 5 0 3 0;
#X connect 6 0 2 1;
#X restore 89 259 pd test-signal;
#X obj 89 343 output~;
#X text 58 68 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., f 61;
#N canvas 580 123 518 506 hann-window 0;
#N canvas 0 0 450 300 (subpatch) 0;
#X array \$0-hann 1024 float 0;
#X coords 0 1 1023 0 227 152 1;
#X restore 240 262 graph;
#X obj 112 366 osc~;
#X obj 112 391 *~ -0.5;
#X obj 112 415 +~ 0.5;
#X obj 95 458 tabwrite~ \$0-hann;
#X obj 64 236 swap;
#X obj 64 260 /;
#X msg 140 150 resize \$1;
#X obj 140 174 s \$0-hann;
#X msg 137 336 0;
#X obj 64 332 t f b;
#X obj 75 114 s window-size;
#X floatatom 64 294 8 0 0 0 - - - 0;
#X text 130 294 window hz;
#X text 246 123 Calculate Hann window table (variable window size) by getting the period of the window and Hz. Also get the analysis window size in seconds and msec., f 33;
#X obj 89 206 samplerate~;
#X obj 64 160 t f b f;
#X obj 64 60 inlet;
#X connect 1 0 2 0;
#X connect 2 0 3 0;
#X connect 3 0 4 0;
#X connect 5 0 6 0;
#X connect 5 1 6 1;
#X connect 6 0 12 0;
#X connect 7 0 8 0;
#X connect 9 0 1 1;
#X connect 10 0 1 0;
#X connect 10 1 4 0;
#X connect 10 1 9 0;
#X connect 12 0 10 0;
#X connect 15 0 5 1;
#X connect 16 0 5 0;
#X connect 16 1 15 0;
#X connect 16 2 7 0;
#X connect 17 0 11 0;
#X connect 17 0 16 0;
#X restore 289 523 pd hann-window;
#X obj 44 22 cnv 5 5 25 empty empty Dynamic\ Range\ Compression\ by\ Fourier\ Analysis 15 13 0 16 #dfdfdf #202020 0;
#N canvas 621 135 735 607 insample 0;
#N canvas 0 0 450 300 (subpatch) 0;
#X array \$0-sample 155944 float 2;
#X coords 0 1 155944 -1 279 142 1 0 0;
#X restore 375 268 graph;
#X obj 121 246 soundfiler;
#X msg 188 276 \$1;
#X obj 163 307 swap;
#X obj 163 335 /;
#X floatatom 163 395 10 0 0 0 - - - 0;
#X obj 175 160 symbol \$0-sample;
#X obj 42 124 openpanel;
#X msg 121 215 read -resize \$1 \$2;
#X obj 121 188 pack s s;
#X obj 121 160 t a b;
#X floatatom 121 446 9 0 0 0 - - - 0;
#X floatatom 248 384 6 0 0 0 - - - 0;
#X text 219 271 sample rate, f 6;
#X obj 54 19 inlet;
#X obj 121 502 s \$0-size;
#X obj 163 421 s \$0-hz;
#X obj 54 63 route bang;
#X obj 42 97 bng 19 250 50 0 empty empty empty 0 -10 0 12 #dfdfdf #000000 #000000;
#X obj 352 107 adc~ 1;
#X obj 407 19 inlet;
#X obj 556 78 samplerate~;
#X obj 407 170 tabwrite~ \$0-sample;
#X obj 569 167 s \$0-sample;
#X msg 569 140 resize \$1;
#X obj 556 111 * 2;
#X text 588 112 2 seconds;
#X obj 556 199 s \$0-size;
#X text 169 57 Subpatch to initialize patch \, load file into array and record., f 22;
#X obj 203 547 outlet;
#X obj 248 411 / 1000;
#X obj 203 487 /;
#X obj 224 517 r \$0-ms;
#X obj 493 113 s \$0-hz;
#X msg 493 88 0.5;
#X msg 448 114 2000;
#X obj 448 139 s \$0-ms;
#X obj 450 527 declare -stdpath ./;
#X obj 454 442 loadbang;
#X msg 454 468 \; squelch-set 10;
#X connect 1 0 3 0;
#X connect 1 0 11 0;
#X connect 1 1 2 0;
#X connect 2 0 3 1;
#X connect 2 0 12 0;
#X connect 3 0 4 0;
#X connect 3 1 4 1;
#X connect 4 0 5 0;
#X connect 5 0 16 0;
#X connect 6 0 9 1;
#X connect 7 0 10 0;
#X connect 8 0 1 0;
#X connect 9 0 8 0;
#X connect 10 0 9 0;
#X connect 10 1 6 0;
#X connect 11 0 15 0;
#X connect 11 0 31 0;
#X connect 12 0 30 0;
#X connect 14 0 17 0;
#X connect 17 0 18 0;
#X connect 17 1 10 0;
#X connect 18 0 7 0;
#X connect 19 0 22 0;
#X connect 20 0 21 0;
#X connect 20 0 22 0;
#X connect 20 0 35 0;
#X connect 20 0 34 0;
#X connect 21 0 25 0;
#X connect 24 0 23 0;
#X connect 25 0 24 0;
#X connect 25 0 27 0;
#X connect 30 0 31 1;
#X connect 31 0 29 0;
#X connect 32 0 29 0;
#X connect 34 0 33 0;
#X connect 35 0 36 0;
#X connect 38 0 39 0;
#X restore 287 348 pd insample;
#X obj 309 296 bng 19 250 50 0 empty empty empty 0 -10 0 12 #dfdfdf #000000 #000000;
#X msg 283 217 ../sound/bell.aiff;
#X msg 292 240 ../sound/voice.wav;
#X msg 299 264 ../sound/voice2.wav;
#X text 348 192 read input sound;
#X text 336 296 choose a file;
#X obj 283 190 loadbang;
#X obj 361 322 bng 19 250 50 0 empty empty empty 0 -10 0 12 #dfdfdf #000000 #000000;
#X text 387 317 record 2 sec, f 6;
#X floatatom 287 377 8 0 0 0 - - - 0;
#X text 352 377 length in ms;
#X obj 289 435 loadbang;
#X msg 289 463 1024;
#X floatatom 289 490 5 0 0 0 - - - 0;
#X text 332 463 default window size;
#X text 332 490 change window size;
#X text 93 438 In this example we can also change the window size. The subpatch to the right calculates a hann window according to the window size in samples., f 22;
#X connect 0 0 3 0;
#X connect 2 0 0 0;
#X connect 7 0 17 0;
#X connect 8 0 7 0;
#X connect 9 0 7 0;
#X connect 10 0 7 0;
#X connect 11 0 7 0;
#X connect 14 0 9 0;
#X connect 15 0 7 1;
#X connect 19 0 20 0;
#X connect 20 0 21 0;
#X connect 21 0 5 0;
