#N canvas 433 61 664 621 12;
#X declare -stdpath ./;
#X obj 60 515 output~;
#X obj 407 431 samplerate~;
#X obj 407 455 / 2;
#X obj 394 508 tabwrite~ \$0-tab;
#X obj 60 481 tabread4~ \$0-tab;
#X obj 407 479 osc~;
#X obj 191 481 tabread4~ \$0-tab;
#X obj 191 515 output~;
#X obj 60 398 *~ 10000;
#X obj 60 451 +~;
#X floatatom 300 360 6 0 0 0 - - - 0;
#X msg 300 330 1;
#X obj 60 369 phasor~ 0.02;
#X msg 245 330 150001;
#X text 20 245 At left below an onset (1 or 150000 samples) is added to the index of a table lookup. If you select the onset of 150001 \, you should hear the truncation error. (The table contains a Nyquist signal and the "correct" output should be a 100 Hz. tone.) At right \, the onset is presented in the separate onset inlet. The worst-case truncation error drops by about 30 dB., f 89;
#X text 93 579 BAD;
#X text 225 579 GOOD;
#X text 124 330 ONSET INTO TABLE;
#X obj 514 19 declare -stdpath ./;
#X text 422 344 First \, generate the table:;
#X obj 394 344 bng 19 250 50 0 empty empty empty 17 7 0 10 #dfdfdf #000000 #000000;
#X obj 398 543 array define \$0-tab 200000;
#X text 18 19 USING ONSETS INTO TABREAD4~ TO IMPROVE ACCURACY IN SINGLE PRECISION, f 67;
#X text 20 55 None of this is needed if you have Pd compiled for double precision \, but in the case you have Pd compiled to work on 32-bit audio samples (a.k.a single precision) you do not have enough precision for use as indices into an array of more than about 32K samples. This is because the mantissa of a 32-bit floating point number has only 24 bits \, out of which you would be using 16 bits or more to address a sample more than 32K into the array \, so there would remain 8 or fewer bits to supply the fraction. In the most extreme situation possible \, the sample could contain a Nyquist frequency sinusoid and the output would then have only about 8 bits of accuracy!, f 89;
#X msg 418 382 \; pd dsp 1 \, fast-forward 4000;
#X text 20 178 You can use the "onset" inlet to [tabread4~] to get good accuracy reading longer arrays. The [tabread4~] object adds the index and the "main" (signal) inlet in double precision. So if \, for example \, the onset inlet could specify an integer exactly up to about 8 million (190 seconds at 44100 Hz) \, and the signal inlet could act as a displacement., f 89;
#X obj 300 383 sig~;
#X text 426 585 updated for Pd version 0.55;
#X connect 1 0 2 0;
#X connect 2 0 5 0;
#X connect 4 0 0 0;
#X connect 5 0 3 0;
#X connect 6 0 7 0;
#X connect 8 0 9 0;
#X connect 8 0 6 0;
#X connect 9 0 4 0;
#X connect 10 0 26 0;
#X connect 11 0 10 0;
#X connect 12 0 8 0;
#X connect 13 0 10 0;
#X connect 20 0 1 0;
#X connect 20 0 3 0;
#X connect 20 0 24 0;
#X connect 26 0 6 1;
#X connect 26 0 9 1;
