[PD] resizing samples, noob question

Frank Barknecht fbar at footils.org
Tue Feb 10 11:25:10 CET 2009

```Hallo,

> Hey guysI'm trying to create a patch  that play samples 'at speed'
> but which is then variable. I need an equation to turn the number of
> samples in a table into the length of the sound file in seconds.
> Using this I should be able to divide one by the number of seconds
> and use that figure to set the speed of a phasor~ object for correct
> speed playback, is that right? what's the equation?

You need to know the samplerate of your soundfile first - which may be
different from Pd's samplerate as reported by [samplerate~] !

Lets assume your file's samplerate is the CD-standard 44.1 kHz or 44100 Hz.
That means that 44100 samples are necessary to make up one second
(because 1 Hz = 1/s) and the duration of one sample is 1/44100
seconds.

So if you have a table of size X, then it has a duration of X *
1/44100 seconds or more general:

duration in seconds = number of samples / SR in Hz

If you use a phasor~ you need to get a frequency which is the inverse
of the duration:

freq(Hz) = 1/dur(s)= SR(Hz)/samples

At this frequency the soundfile would play at its natural speed.[1]

If you work with something like [vline~] to play your samples, you
have to take additional care of the fact, that these objects deal with
milliseconds, not seconds.

A duration expressed in milliseconds is 1000 times the number
describing the duration in seconds:

1 second = 1000 milliseconds
1.501 seconds = 1501 milliseconds

The duration of a table in milliseconds is thus:

dur(ms)    = 1000 * duration in seconds
= 1000 * (number of samples) / SR in Hz
= (number of samples) / SR(Hz)/1000
= (number of samples) / SR in kHz

The last transform uses the useful fact, that a frequency expressed in
Hz is 1000 times the frequency expressed in kHz:

44100 Hz = 44.1 kHz

Hint: If you work a lot with milliseconds it's often useful to think of
frequencies in kHz.

It's important to learn these relations for working with delays as
well. You may want to make some abstractions out of it.

[1] To transpose it, you can use the "Momentary Transposition Formulas
for Wavetables" from:
http://crca.ucsd.edu/~msp/techniques/latest/book-html/node28.html#sect2.momentaryformula

Ciao
--
Frank Barknecht            Do You RjDj.me?          _ ______footils.org__

```