[PD] sampling animation example

Orm Finnendahl finnendahl at folkwang-hochschule.de
Thu May 16 22:53:22 CEST 2002


Hi all,

I attached an animation of the basics of sampling and synthesizing
made for my csound class here in Berlin using pd and its graphic
capabilities. It had quite some effect on my students (they normally
use Max/MSP) and definetely changed their attitude towards pd ;-)

It only covers the most basic principles of sampling and synthesizing
in the digital realm but IMO explains things much clearer and easier
to understand than lengthy written explanations. It might look strange
as I'm using a 6x10 console font and didn't check it against the
standard pd font.

This also could be considered my first contribution to Krzysztof's pd
doc project (although it doesn't document pd itself and might be off
topic due to its more general nature).

--
Orm
-------------- next part --------------
#N struct curve-template float x1 float y1 float x2 float y2 float
width float color;
#N canvas 1 0 986 537 10;
#N canvas 492 2 450 300 curve-template 0;
#X obj 61 201 template float x1 float y1 float x2 float y2 float width
float color;
#X obj 99 163 drawpolygon color width x1 y1 x2 y2;
#X restore 72 260 pd curve-template;
#N canvas 0 0 450 300 curve-data 0;
#X coords 0 1 100 -1 200 140 1;
#X restore 71 10 pd curve-data;
#N canvas 0 0 450 300 graph1 0;
#X array f-table 100 float 1;
#A 0 0 0.0627906 0.125333 0.187381 0.24869 0.309017 0.368125 0.42578
0.481754 0.535827 0.587786 0.637424 0.684547 0.728969 0.770514 0.809017
0.844328 0.876307 0.904827 0.929777 0.951057 0.968583 0.982287 0.992115
0.998027 1 0.998027 0.992115 0.982287 0.968583 0.951056 0.929776 0.904827
0.876306 0.844327 0.809016 0.770512 0.728967 0.684546 0.637423 0.587784
0.535825 0.481752 0.425777 0.368123 0.309015 0.248688 0.187379 0.125331
0.0627883 -2.23319e-06 -0.0627928 -0.125335 -0.187383 -0.248692 -0.309019
-0.368127 -0.425781 -0.481756 -0.535829 -0.587787 -0.637426 -0.684549
-0.728971 -0.770515 -0.809019 -0.84433 -0.876308 -0.904828 -0.929778
-0.951057 -0.968584 -0.982288 -0.992115 -0.998027 -1 -0.998026 -0.992114
-0.982287 -0.968582 -0.951055 -0.929775 -0.904826 -0.876305 -0.844326
-0.809015 -0.770511 -0.728966 -0.684544 -0.637421 -0.587782 -0.535823
-0.48175 -0.425775 -0.368121 -0.309013 -0.248686 -0.187377 -0.125329
-0.0627861;
#X coords 0 1 99 -1 200 140 1;
#X restore 71 10 graph;
#N canvas 537 281 450 300 f-table 0;
#X obj 142 201 tabwrite f-table;
#X obj 169 113 sin;
#X floatatom 167 139 5 0 0;
#X floatatom 168 31 0 0 0;
#X obj 168 91 * 6.28319;
#X obj 168 61 / 100;
#X obj 265 110 t f f f;
#X obj 265 84 f;
#X obj 332 85 + 1;
#X obj 333 109 sel 100;
#X msg 265 60 0;
#X obj 264 12 inlet;
#X connect 1 0 2 0;
#X connect 2 0 0 0;
#X connect 3 0 5 0;
#X connect 4 0 1 0;
#X connect 5 0 4 0;
#X connect 6 0 8 0;
#X connect 6 1 3 0;
#X connect 6 2 0 1;
#X connect 7 0 6 0;
#X connect 8 0 9 0;
#X connect 9 1 7 0;
#X connect 10 0 7 0;
#X connect 11 0 10 0;
#X restore 73 238 pd f-table;
#X msg 73 217 bang;
#N canvas 0 0 450 300 capture-data 0;
#X coords 0 1 100 -1 200 140 1;
#X restore 71 10 pd capture-data;
#N canvas 0 0 450 300 output-data 0;
#X scalar curve-template 0 0.218688 0 0.248688 2 0 \;;
#X coords 0 1 400 -1 800 140 1;
#X restore 72 376 pd output-data;
#N canvas 0 0 299 284 works 0;
#N canvas 490 67 450 300 traverse-f-table 0;
#X msg 299 175 bang;
#X msg 89 51 bang;
#X obj 34 240 append curve-template x1 y1 x2 y2 width color;
#X obj 299 216 pointer;
#X msg 299 195 traverse pd-curve-data \, bang;
#X msg 299 138 \; pd-curve-data clear;
#X obj 89 74 t b b b;
#X msg 52 126 \$1 \$2 \$3 \$4 10 411;
#X obj 89 29 metro 100;
#X obj 88 6 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 1;
#N canvas 498 260 450 475 access-f-table 0;
#X floatatom 353 87 0 0 0;
#X obj 185 160 t f f f;
#X obj 185 134 f;
#X obj 138 137 + 1;
#X msg 305 67 0;
#X obj 138 161 % 100;
#X obj 276 34 inlet;
#X obj 185 75 inlet;
#X obj 105 264 pack 0 0 0 0;
#X msg 185 98 bang;
#X obj 104 285 outlet;
#X obj 211 194 + 0;
#X msg 255 190 0.07;
#X obj 320 130 tabread f-table;
#X obj 355 192 <;
#X obj 355 213 sel 1;
#X obj 354 246 outlet;
#X obj 397 248 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1
-1;
#X obj 353 107 t f f;
#X obj 227 226 + 0.07;
#X obj 248 248 - 0.07;
#X connect 0 0 18 0;
#X connect 1 0 3 0;
#X connect 1 1 8 0;
#X connect 1 2 0 0;
#X connect 1 2 11 0;
#X connect 2 0 1 0;
#X connect 3 0 5 0;
#X connect 4 0 2 0;
#X connect 5 0 2 1;
#X connect 6 0 4 0;
#X connect 7 0 9 0;
#X connect 8 0 10 0;
#X connect 9 0 2 0;
#X connect 11 0 8 2;
#X connect 12 0 19 1;
#X connect 12 0 20 1;
#X connect 13 0 19 0;
#X connect 13 0 20 0;
#X connect 14 0 15 0;
#X connect 15 0 16 0;
#X connect 15 0 17 0;
#X connect 18 0 14 1;
#X connect 18 0 13 0;
#X connect 18 1 14 0;
#X connect 19 0 8 1;
#X connect 20 0 8 3;
#X restore 52 104 pd access-f-table;
#X obj 52 5 inlet;
#X obj 138 6 inlet;
#X obj 83 165 outlet;
#X obj 154 164 outlet;
#X connect 0 0 4 0;
#X connect 1 0 6 0;
#X connect 3 0 2 6;
#X connect 4 0 3 0;
#X connect 6 0 10 0;
#X connect 6 1 0 0;
#X connect 6 2 5 0;
#X connect 7 0 2 0;
#X connect 7 0 13 0;
#X connect 8 0 1 0;
#X connect 9 0 8 0;
#X connect 10 0 7 0;
#X connect 10 1 14 0;
#X connect 11 0 9 0;
#X connect 12 0 8 1;
#X restore -23 244 pd traverse-f-table;
#X obj 97 21 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 1
;
#X obj 16 21 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 1
;
#X obj 116 21 bng 48 250 50 0 empty empty empty 0 -6 0 8 -262144 -24198
-1;
#X obj 16 41 vsl 15 128 0.1 0.4 0 0 empty empty empty 0 -8 0 8 -262144
-1 -1 0 1;
#X floatatom 16 177 5 0 0;
#X obj 97 41 vsl 15 128 1 13.7 0 0 empty empty empty 0 -8 0 8 -262144
-1 -1 0 1;
#X floatatom 97 176 5 0 0;
#N canvas 490 67 489 323 capture-f-table 0;
#X msg 299 175 bang;
#X msg 210 61 bang;
#X obj 34 240 append curve-template x1 y1 x2 y2 width color;
#X obj 299 216 pointer;
#X obj 210 84 t b b b;
#X obj 88 6 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 1;
#X obj 52 5 inlet;
#X obj 138 6 inlet;
#X obj 55 105 lister;
#X obj 89 29 metro 1000;
#X obj 10 6 inlet;
#X obj 203 11 inlet;
#X msg 299 195 traverse pd-capture-data \, bang;
#X msg 299 138 \; pd-capture-data clear;
#X obj 93 50 outlet;
#X msg 33 71 \$1 \$2 \$3 \$4 \$5 90;
#X obj 252 14 loadbang;
#X obj 33 266 append curve-template2 x1 y1 x2 y2 width color;
#X obj 129 181 gate 2 1;
#X obj 335 16 inlet;
#X msg 30 127 \$2;
#X obj 30 187 s output-val;
#X obj 71 147 r amplitude;
#X obj 30 167 * 1;
#X obj 30 147 - 0.07;
#X connect 0 0 12 0;
#X connect 1 0 4 0;
#X connect 3 0 2 6;
#X connect 3 0 17 6;
#X connect 4 1 0 0;
#X connect 4 2 13 0;
#X connect 5 0 9 0;
#X connect 6 0 5 0;
#X connect 7 0 9 1;
#X connect 8 0 18 0;
#X connect 8 0 20 0;
#X connect 9 0 8 0;
#X connect 9 0 14 0;
#X connect 10 0 15 0;
#X connect 11 0 1 0;
#X connect 12 0 3 0;
#X connect 15 0 8 1;
#X connect 16 0 1 0;
#X connect 18 0 2 0;
#X connect 18 1 17 0;
#X connect 19 0 18 1;
#X connect 20 0 24 0;
#X connect 22 0 23 1;
#X connect 23 0 21 0;
#X connect 24 0 23 0;
#X restore 83 345 pd capture-f-table;
#N canvas 500 14 450 300 capture-f-table-to-output 0;
#X msg 299 175 bang;
#X msg 233 93 bang;
#X obj 34 240 append curve-template x1 y1 x2 y2 width color;
#X obj 299 216 pointer;
#X obj 233 116 t b b b;
#X obj 316 65 lister;
#X obj 10 6 inlet;
#X obj 160 9 inlet;
#X msg 299 138 \; pd-output-data clear;
#X msg 299 195 traverse pd-output-data \, bang;
#N canvas 498 260 450 475 access-f-table 0;
#X floatatom 353 87 0 0 0;
#X obj 185 160 t f f f;
#X obj 185 134 f;
#X obj 138 137 + 1;
#X msg 305 67 0;
#X obj 276 34 inlet;
#X obj 185 75 inlet;
#X msg 185 98 bang;
#X obj 203 197 outlet;
#X obj 355 192 <;
#X obj 355 213 sel 1;
#X obj 354 246 outlet;
#X obj 397 248 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1
-1;
#X obj 353 107 t f f;
#X obj 138 161 % 400;
#X connect 0 0 13 0;
#X connect 1 0 3 0;
#X connect 1 1 8 0;
#X connect 1 2 0 0;
#X connect 2 0 1 0;
#X connect 3 0 14 0;
#X connect 4 0 2 0;
#X connect 4 0 0 0;
#X connect 5 0 4 0;
#X connect 6 0 7 0;
#X connect 7 0 2 0;
#X connect 9 0 10 0;
#X connect 10 0 11 0;
#X connect 10 0 12 0;
#X connect 13 0 9 1;
#X connect 13 1 9 0;
#X connect 14 0 2 1;
#X restore 135 70 pd access-f-table;
#X obj 135 34 t b b;
#X msg 315 24 \$2 \$4;
#X obj 34 191 pack 0 0 0 0;
#X msg 34 214 \$1 \$2 \$3 \$4 2 0;
#X msg 317 86 \$2;
#X obj 118 151 + 0.04;
#X obj 163 151 + 0.07;
#X obj 389 10 inlet;
#X obj 232 32 loadbang;
#X obj 332 110 * 1;
#X obj 346 87 r amplitude;
#X connect 0 0 9 0;
#X connect 1 0 4 0;
#X connect 3 0 2 6;
#X connect 4 1 0 0;
#X connect 4 2 8 0;
#X connect 5 0 15 0;
#X connect 6 0 12 0;
#X connect 7 0 11 0;
#X connect 9 0 3 0;
#X connect 10 0 13 2;
#X connect 10 0 13 0;
#X connect 10 1 1 0;
#X connect 11 0 10 0;
#X connect 11 1 5 0;
#X connect 12 0 5 1;
#X connect 13 0 14 0;
#X connect 14 0 2 0;
#X connect 15 0 20 0;
#X connect 16 0 13 1;
#X connect 17 0 13 3;
#X connect 18 0 10 1;
#X connect 19 0 10 1;
#X connect 19 0 0 0;
#X connect 20 0 17 0;
#X connect 20 0 16 0;
#X connect 21 0 20 1;
#X restore 95 410 pd capture-f-table-to-output;
#X obj 176 385 spigot;
#X obj 116 102 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0
1;
#X obj 116 120 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1
-1;
#X obj 34 21 sel 1;
#X obj 97 200 expr 1000/$f1;
#X obj 116 93 + 1;
#X obj 116 72 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 1
;
#X obj 210 19 loadbang;
#X msg 207 43 0.1;
#X msg 238 44 1;
#X obj 257 467 s amplitude;
#X obj 251 40 vsl 15 128 0 1 0 0 empty empty empty 0 -8 0 8 -262144
-1 -1 12700 1;
#X obj 16 405 s in-freq;
#X floatatom 251 175 5 0 0;
#X obj 21 201 expr 10/$f1;
#X obj 16 217 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 1
;
#X obj 32 306 sel 1;
#X msg 48 347 1;
#X msg 51 328 bang;
#X msg 24 328 19.9203;
#X msg 44 276 0.251;
#X msg 86 277 5;
#X obj 43 152 * 1;
#X connect 0 0 8 0;
#X connect 0 0 9 0;
#X connect 0 1 8 3;
#X connect 1 0 8 1;
#X connect 2 0 0 0;
#X connect 2 0 13 0;
#X connect 4 0 32 0;
#X connect 5 0 22 0;
#X connect 5 0 24 0;
#X connect 6 0 7 0;
#X connect 7 0 14 0;
#X connect 8 0 3 0;
#X connect 8 0 10 0;
#X connect 10 0 9 1;
#X connect 11 0 10 1;
#X connect 12 0 9 2;
#X connect 13 1 1 0;
#X connect 14 0 8 2;
#X connect 15 0 8 4;
#X connect 16 0 15 0;
#X connect 17 0 18 0;
#X connect 17 0 19 0;
#X connect 18 0 4 0;
#X connect 19 0 6 0;
#X connect 19 0 21 0;
#X connect 21 0 20 0;
#X connect 21 0 23 0;
#X connect 24 0 0 1;
#X connect 25 0 26 0;
#X connect 26 0 29 0;
#X connect 26 0 30 0;
#X connect 26 0 31 0;
#X connect 26 1 28 0;
#X connect 27 0 32 1;
#X connect 28 0 27 0;
#X connect 29 0 32 1;
#X connect 30 0 4 0;
#X connect 31 0 6 0;
#X connect 32 0 5 0;
#X coords 0 140 200 0 400 300 1;
#X restore 329 10 pd works;
#N canvas 0 0 450 300 curve-template2 0;
#X obj 61 201 template float x1 float y1 float x2 float y2 float width
float color;
#X obj 99 163 drawpolygon color width x1 y1 x2 y2;
#X obj 99 137 drawpolygon 0 2 x1 -1.1 x1 y2;
#X restore 72 283 pd curve-template2;
#X text 72 358 output table;
#X text 71 157 red - input signal;
#X text 70 169 green - sampled values from input signal;
#X text 503 81 show x - increments;
#X text 348 13 input signal;
#X text 455 13 sampler;
#X text 349 212 freq;
#X text 503 113 capture to output table;
#X text 503 132 clear output table;
#N canvas 336 420 263 300 csound-show 0;
#X obj 198 50 r in-freq;
#X obj 47 49 r output-val;
#X obj 127 50 r amplitude;
#X floatatom 2 102 5 0 0;
#X floatatom 160 103 5 0 0;
#X floatatom 116 103 5 0 0;
#X connect 0 0 4 0;
#X connect 1 0 3 0;
#X connect 2 0 5 0;
#X coords 0 0 1 1 300 60 1;
#X restore 329 313 pd csound-show;
#X text 660 209 amplitude;
#X text 456 213 samplerate;
#X text 392 350 oscil;
#X text 459 350 xamp \,;
#X text 509 350 xcps \,;
#X text 331 350 aout;
#X text 330 311 csound orc-statement;
#X text 563 350 f-table-no;
#X text 392 332 oscil;
#X text 562 332 1;
#X text 350 258 scale input freq;
#X text 350 270 slider to show aliasing;
#X text 752 357 Orm Finnendahl 2002;
#N canvas 533 2 450 573 help1 0;
#X text 10 22 This patch exemplifies two basic principles of digital
;
#X text 10 34 signal processing: sampling audio and synthesizing wave
;
#X text 10 46 forms. It was written for a csound class in Berlin 2002.
;
#X text 10 58 below is a description of sampling. click on "pd help2"
;
#X text 10 70 for help on synthesizing wave forms.;
#X text 10 94 1. sampling audio;
#X text 10 118 click the toggle below "input signal" to show an animated
;
#X text 10 130 simulation of a sine wave oscillation of some signal
;
#X text 10 142 (represented by the red square) \, say \, received at
the inlet;
#X text 10 154 of a digital-to-analog converter. In order to sample
the;
#X text 10 166 signal \, the value of the input signal is measured
at;
#X text 10 178 regular time intervals \, called the "sampling rate"
(or sr).;
#X text 10 190 click on the toggle below "sampler" to show this in
;
#X text 10 202 animation. If the frequency of the input signals change
\,;
#X text 10 214 (left slider) \, the number of samples per period gets
lower \,;
#X text 10 226 if the sr isn't changed (which is the normal case in
;
#X text 10 238 digital audio). To see \, how the sampled values get
stored;
#X text 10 250 (in a soundfile for example) \, move the slider of the
;
#X text 10 262 sampler all the way up and click on the "capture to
output;
#X text 10 274 table" toggle. Watch how the frequency of the wave stored
;
#X text 10 286 in the output table changes if you move the left (input
;
#X text 10 298 signal) slider.;
#X text 10 334 aliasing;
#X text 10 358 click on the toggle below the input signal slider to
set;
#X text 10 370 the frequencies of the input signal and the sample rate
to;
#X text 10 382 the same value (5 Hz). Watch how the sample stays on
the;
#X text 10 394 same value all the time and the captured signal becomes
a;
#X text 10 406 horizontal line (if the green square is barely visible
\,;
#X text 10 418 stop the sampler and try to start it in a moment when
the;
#X text 10 430 red square is near the left edge of the f-table window).
;
#X text 10 442 If you increase the frequency of the input signal \,
the;
#X text 10 454 green square starts moving to the right \, if you decrease
it;
#X text 10 466 beyond 5 Hz \, it starts moving to the left. Notice
that the;
#X text 10 478 frequency of the sampled signal is equal for input;
#X text 10 490 frequencies symmetrical to 5 Hz (e.g. 5.141 Hz and 4.859
;
#X text 10 502 Hz). Since the green square seems to move in the opposite
;
#X text 10 514 directions \, the sampled signals below 5 Hz are 180
degree;
#X text 10 526 phase shifted versions of the signals above 5 Hz.;
#X restore 72 308 pd help1;
#N canvas 0 0 450 300 help2 0;
#X text 16 24 now go back to the previous example once again: turn
off;
#X text 16 36 the "scale input freq" toggle \, turn off "capture to
output;
#X text 16 48 table" and move the sliders for the input frequency and
;
#X text 16 60 sample rate all the way down (to 0.1 and 10 Hz;
#X text 16 72 respectively).;
#X text 16 96 2. synthesizing wave forms;
#X text 16 120 if we are going to synthesize wave forms \, we simulate
the;
#X text 16 132 previous example within the computer. If you turn on
the;
#X text 16 144 input signal \, the sampler and the "show x-increments"
;
#X text 16 156 toggle \, you can see the regular horizontal spacing
of lines;
#X text 16 168 during the sampling process. If you increase the input
;
#X text 16 180 frquency \, watch how the spacing also increases. This
gives;
#X text 16 192 a method to generate output signals of different;
#X text 16 204 frequencies using a constant sampling rate: read cyclically
;
#X text 16 216 through a stored function table of one period of the
;
#X text 16 228 waveform you want to generate. The x-increment gives
a;
#X text 16 240 measure of the obtained frequency. You can generate
any;
#X text 16 252 periodic waveform that way. To check that out \, draw
in the;
#X text 16 264 f-table window (start by clicking on any point in the
curve;
#X text 16 276 and drag the mouse).;
#X text 16 300 The window "csound orc-statement";
#X text 16 312 shows the moving values of the variables during the
;
#X text 16 324 generation of output. In addition you can change the
;
#X text 16 336 amplitude with the right slider.;
#X restore 72 329 pd help2;
#X text 131 308 click here for instructions;
#X text 111 216 restore f-table to sine-wave;
#X connect 4 0 3 0;


More information about the Pd-list mailing list