[PD] tabread4~ sample size (pd file attached)

Frank Barknecht fbar at footils.org
Thu Aug 17 18:21:40 CEST 2006


Hallo,
Enrique Erne hat gesagt: // Enrique Erne wrote:

> try something like this:
> 
> [soundfiler]
> |
> [/ 44100]
> |
> [pow -1]
> |
> [phasor~]

Another possibility is to use [vline~] instead of [phasor~] as in
C05.sampler.oneshot.pd and then restart the sample-player, when the
sample has finished. 

I "borrowed" this algorithm for my clone of the [play-samp~]
abstraction of RTC-lib (attached), which is a sample player, that can
both play a sample just once as well as loop it. 

C05.sampler.oneshot.pd should be quite clear, the only thing that may
be a bit hard to understand at first is the funny looking message: ";
phase 1, 4.41e+08 1e+07;" But actually it has an easy explanation: 
4.41e+08 is the sample [vline~] should approach in 1e+07 msec. This
will make vline~ go at the same speed as it would go if it would need
to reach sample number 44100 in 1 second, that is if it was playing at
"CD-audio-speed". The speed is:

4.41e+08 smps / 1e+07msec 
= 44100 smps / 1000 msec 
= 44100 smps / 1 sec 
= 44.1 kHz 
= CD

Miller just decided to let it go to some really huge sample number
during a very long time (1e+07msec) so that no calculations about the
length of the sample are needed in oneshot-mode.

Of course if you want to loop, you *need to* do these calculations to
restart the loop when the sample has played completly. This is easy to
achieve by just converting the size of the array in samples to the
duration it would have, if it was played with the sample's samplerate.

Again assuming this is 44.1kHz, you get the duration in msecs by
dividing the number of samples by 44.1.

Attached play-samp~.pd uses Zexy's [arraysize] to get the length of
the sample to play, but you could also just use soundfiler's output
instead. The sample is first played as "oneshot" sample, but
additionally a [delay] object is set up to play the sample again (and
again) after the duration calculated like above. (Additionally
transposition is implemented by just scaling the vline~-input
accordingly.)

Ciao
-- 
 Frank Barknecht                 _ ______footils.org_ __goto10.org__
-------------- next part --------------
#N canvas 192 80 584 531 10;
#X obj 463 47 inlet;
#X obj 169 74 unpack f s f;
#X obj 169 48 inlet;
#X obj 208 420 outlet~;
#X obj 208 315 tabread4~;
#X obj 208 174 list prepend set;
#X obj 208 200 list trim;
#X text 223 49 IN: transposition tablename gain;
#X obj 119 284 vline~;
#N canvas 238 24 737 582 trigger-sample 1;
#X text 90 155 Wait for the;
#X text 88 169 cutoff to finish;
#X text 71 446 set the upper line~ to start;
#X text 70 465 at the first sample and go;
#X text 69 486 forever (until the next trigger);
#X obj 212 211 t b b;
#X obj 298 499 s \$0-phase;
#X obj 212 315 s \$0-cutoff;
#X obj 212 53 inlet;
#X obj 242 136 s \$0-cutoff;
#X text 87 118 cut the sound off;
#X obj 212 266 f;
#X obj 389 57 inlet;
#X obj 212 77 t b b;
#X text 394 37 gain;
#X obj 315 57 inlet;
#X text 314 35 transpos;
#X obj 298 454 * 1e+07;
#X obj 299 435 f 1;
#X msg 298 478 1 \, 4.41e+08 \$1;
#X obj 463 466 r \$0-arraysize;
#X obj 345 303 moses 0;
#X obj 406 534 s \$0-phase;
#X obj 406 467 * 1e+07;
#X obj 407 448 f 1;
#X obj 406 490 pack 0 0;
#X msg 406 513 \$2 \, -4.41e+08 \$1;
#X obj 423 426 abs;
#X obj 315 78 t a a;
#X obj 299 307 < 0;
#X obj 299 331 select 0 1;
#X obj 299 285 f;
#X obj 345 273 pow -1;
#X msg 242 107 0 2;
#X obj 212 164 delay 2;
#X connect 5 0 11 0;
#X connect 5 1 31 0;
#X connect 8 0 13 0;
#X connect 11 0 7 0;
#X connect 12 0 11 1;
#X connect 13 0 34 0;
#X connect 13 1 33 0;
#X connect 15 0 28 0;
#X connect 17 0 19 0;
#X connect 18 0 17 0;
#X connect 19 0 6 0;
#X connect 20 0 25 1;
#X connect 21 0 27 0;
#X connect 21 1 18 1;
#X connect 23 0 25 0;
#X connect 24 0 23 0;
#X connect 25 0 26 0;
#X connect 26 0 22 0;
#X connect 27 0 24 1;
#X connect 28 0 31 1;
#X connect 28 1 32 0;
#X connect 29 0 30 0;
#X connect 30 0 18 0;
#X connect 30 1 24 0;
#X connect 31 0 29 0;
#X connect 32 0 21 0;
#X connect 33 0 9 0;
#X connect 34 0 5 0;
#X restore 53 192 pd trigger-sample;
#X obj 224 348 r \$0-cutoff;
#X obj 208 390 *~;
#X obj 224 368 vline~;
#X obj 119 250 r \$0-phase;
#X obj 238 269 arraysize;
#X obj 208 229 t a b a;
#X obj 238 291 s \$0-arraysize;
#X obj 463 71 s \$0-loop;
#X obj 133 110 t a b a;
#N canvas 0 0 433 475 loops 0;
#X obj 89 174 spigot 0;
#X obj 207 246 r \$0-arraysize;
#X obj 89 324 delay;
#X obj 132 323 t b;
#X obj 140 150 r \$0-loop;
#X obj 89 64 inlet;
#X obj 89 352 outlet;
#X obj 155 173 select 0;
#X msg 155 195 stop;
#X floatatom 188 318 8 0 0 0 - - -;
#X obj 207 268 / 44.1;
#X obj 159 290 *;
#X obj 89 113 pow -1;
#X obj 89 89 abs;
#X obj 89 138 t b a;
#X connect 0 0 2 0;
#X connect 1 0 10 0;
#X connect 2 0 3 0;
#X connect 2 0 6 0;
#X connect 3 0 0 0;
#X connect 4 0 0 1;
#X connect 4 0 7 0;
#X connect 5 0 13 0;
#X connect 7 0 8 0;
#X connect 8 0 2 0;
#X connect 10 0 11 1;
#X connect 11 0 2 1;
#X connect 11 0 9 0;
#X connect 12 0 14 0;
#X connect 13 0 12 0;
#X connect 14 0 0 0;
#X connect 14 1 11 0;
#X restore 26 145 pd loops;
#X connect 0 0 17 0;
#X connect 1 0 18 0;
#X connect 1 1 5 0;
#X connect 1 2 9 2;
#X connect 2 0 1 0;
#X connect 4 0 11 0;
#X connect 5 0 6 0;
#X connect 6 0 15 0;
#X connect 8 0 4 0;
#X connect 10 0 12 0;
#X connect 11 0 3 0;
#X connect 12 0 11 1;
#X connect 13 0 8 0;
#X connect 14 0 16 0;
#X connect 15 0 4 0;
#X connect 15 1 14 0;
#X connect 15 2 14 0;
#X connect 18 0 19 0;
#X connect 18 1 9 0;
#X connect 18 2 9 1;
#X connect 19 0 9 0;
-------------- next part --------------
#N canvas 424 240 594 423 10;
#X text 205 201 reversed \, attenuated;
#X obj 125 226 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0
1;
#X text 212 178 transposed \, attenuated;
#X msg 365 23 MSP-RTC;
#X text 24 325 1999 by Karlheinz Essl;
#X text 24 56 Plays one sample. The object requires a list sent to
its input with the following elements: transposition factor (float
between -N and N) - buffer name - gain factor (float between 0 an 1).
If 1 is sent to the right input \, the sample would loop until a 0
is sent.;
#X text 24 29 play-samp~;
#X text 154 156 original pitch \, original gain;
#X text 148 229 loop on/off;
#X text 25 127 NB: a negative transposition factor plays back the sample
backwards;
#X obj 48 226 play-samp~;
#X obj 266 283 openpanel;
#X obj 265 358 table play-samp;
#X msg 266 304 read -resize \$1 play-samp;
#X obj 266 330 soundfiler;
#X msg 48 159 1 play-samp 1;
#X msg 63 181 2.5 play-samp 0.25;
#X obj 266 256 bng 20 250 50 0 empty empty open-sample 0 -6 0 8 -262144
-1 -1;
#X obj 48 257 ezdac~;
#X msg 83 202 -1 play-samp 0.8;
#X connect 1 0 10 1;
#X connect 10 0 18 0;
#X connect 10 0 18 1;
#X connect 11 0 13 0;
#X connect 13 0 14 0;
#X connect 15 0 10 0;
#X connect 16 0 10 0;
#X connect 17 0 11 0;
#X connect 19 0 10 0;


More information about the Pd-list mailing list