You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
miller-book/node28.html

587 lines
18 KiB

<!DOCTYPE html>
<!--Converted with LaTeX2HTML 2002-2-1 (1.71)
original version by: Nikos Drakos, CBLU, University of Leeds
* revised and updated by: Marcus Hennecke, Ross Moore, Herb Swan
* with significant contributions from:
Jens Lippmann, Marek Rouchal, Martin Wilck and others -->
<HTML>
<HEAD>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<TITLE>Sampling</TITLE>
<META NAME="description" CONTENT="Sampling">
<META NAME="keywords" CONTENT="book">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<META NAME="Generator" CONTENT="LaTeX2HTML v2002-2-1">
<META HTTP-EQUIV="Content-Style-Type" CONTENT="text/css">
<LINK REL="STYLESHEET" HREF="book.css">
<LINK REL="next" HREF="node29.html">
<LINK REL="previous" HREF="node27.html">
<LINK REL="up" HREF="node26.html">
<LINK REL="next" HREF="node29.html">
</HEAD>
<BODY >
<!--Navigation Panel-->
<A ID="tex2html960"
HREF="node29.html">
<IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next"
SRC="next.png"></A>
<A ID="tex2html954"
HREF="node26.html">
<IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up"
SRC="up.png"></A>
<A ID="tex2html948"
HREF="node27.html">
<IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous"
SRC="prev.png"></A>
<A ID="tex2html956"
HREF="node4.html">
<IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents"
SRC="contents.png"></A>
<A ID="tex2html958"
HREF="node201.html">
<IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index"
SRC="index.png"></A>
<BR>
<B> Next:</B> <A ID="tex2html961"
HREF="node29.html">Enveloping samplers</A>
<B> Up:</B> <A ID="tex2html955"
HREF="node26.html">Wavetables and samplers</A>
<B> Previous:</B> <A ID="tex2html949"
HREF="node27.html">The Wavetable Oscillator</A>
&nbsp; <B> <A ID="tex2html957"
HREF="node4.html">Contents</A></B>
&nbsp; <B> <A ID="tex2html959"
HREF="node201.html">Index</A></B>
<BR>
<BR>
<!--End of Navigation Panel-->
<H1><A ID="SECTION00620000000000000000"></A>
<A ID="sect2.sampling"></A>
<BR>
Sampling
</H1>
<P>
"Sampling"
<A ID="2203"></A>
is nothing more than recording a live signal into a wavetable, and then later
playing it out again. (In commercial samplers the entire wavetable is
usually called a "sample" but to avoid confusion we'll only use the word
"sample" here to mean a single number in an audio signal.)
<P>
At its simplest, a sampler is simply a wavetable oscillator, as was shown in
Figure <A HREF="node27.html#fig02.03">2.3</A>. However, in the earlier discussion we imagined playing
the oscillator back at a frequency high enough to be perceived as a pitch, at
least 30 Hertz or so. In the case of sampling, the frequency is usually lower
than 30 Hertz, and so the period, at least 1/30 second and perhaps much more, is
long enough that you can hear the individual cycles as separate events.
<P>
Going back to Figure <A HREF="node26.html#fig02.02">2.2</A>, suppose that instead of 40 points the
wavetable <IMG
WIDTH="31" HEIGHT="32" ALIGN="MIDDLE" BORDER="0"
SRC="img80.png"
ALT="$x[n]$"> is a one-second recording, at an original
sample rate of 44100, so that it has 44100 points; and let
<IMG
WIDTH="30" HEIGHT="32" ALIGN="MIDDLE" BORDER="0"
SRC="img2.png"
ALT="$y[n]$"> in part (b) of the figure have a period of 22050 samples. This
corresponds to a frequency of 2 Hertz. But what we hear is not a pitched sound
at 2 cycles per second (that's too slow to hear as a pitch) but rather, we
hear the original recording <IMG
WIDTH="31" HEIGHT="32" ALIGN="MIDDLE" BORDER="0"
SRC="img80.png"
ALT="$x[n]$"> played back repeatedly at double speed. We've
just reinvented the sampler.
<P>
In general, if we assume the sample rate <IMG
WIDTH="15" HEIGHT="14" ALIGN="BOTTOM" BORDER="0"
SRC="img36.png"
ALT="$R$"> of the recording is the same as
the output sample rate, if the wavetable has <IMG
WIDTH="18" HEIGHT="14" ALIGN="BOTTOM" BORDER="0"
SRC="img3.png"
ALT="$N$"> samples, and if we index
it with a sawtooth wave of period <IMG
WIDTH="20" HEIGHT="14" ALIGN="BOTTOM" BORDER="0"
SRC="img86.png"
ALT="$M$">,
the sample is sped up or slowed down by
a factor of <IMG
WIDTH="40" HEIGHT="32" ALIGN="MIDDLE" BORDER="0"
SRC="img191.png"
ALT="$N/M$">, equal to <IMG
WIDTH="47" HEIGHT="32" ALIGN="MIDDLE" BORDER="0"
SRC="img192.png"
ALT="$N f / R$"> if <IMG
WIDTH="13" HEIGHT="30" ALIGN="MIDDLE" BORDER="0"
SRC="img112.png"
ALT="$f$"> is the frequency in Hertz of the
sawtooth. If we denote the transposition factor by <IMG
WIDTH="9" HEIGHT="13" ALIGN="BOTTOM" BORDER="0"
SRC="img82.png"
ALT="$t$"> (so that, for instance,
<IMG
WIDTH="54" HEIGHT="32" ALIGN="MIDDLE" BORDER="0"
SRC="img193.png"
ALT="$t=3/2$"> means transposing upward a perfect fifth), and if we denote the
transposition in half-steps by <IMG
WIDTH="12" HEIGHT="14" ALIGN="BOTTOM" BORDER="0"
SRC="img194.png"
ALT="$h$">, then we get the
<A ID="2206"></A>Transposition Formulas for Looping Wavetables:
<A ID="sect2.transpositionformula"></A>
<BR><P></P>
<DIV ALIGN="CENTER">
<!-- MATH
\begin{displaymath}
t = {N / M} = {{N f} / R}
\end{displaymath}
-->
<IMG
WIDTH="130" HEIGHT="28" BORDER="0"
SRC="img195.png"
ALT="\begin{displaymath}
t = {N / M} = {{N f} / R}
\end{displaymath}">
</DIV>
<BR CLEAR="ALL">
<P></P>
<BR><P></P>
<DIV ALIGN="CENTER">
<!-- MATH
\begin{displaymath}
h = 12 \, {\log _ 2} \left ( {N \over M} \right ) =
12 \, {\log _ 2} \left ( {N f \over R} \right )
\end{displaymath}
-->
<IMG
WIDTH="241" HEIGHT="45" BORDER="0"
SRC="img196.png"
ALT="\begin{displaymath}
h = 12 \, {\log _ 2} \left ( {N \over M} \right ) =
12 \, {\log _ 2} \left ( {N f \over R} \right )
\end{displaymath}">
</DIV>
<BR CLEAR="ALL">
<P></P>
Frequently the desired transposition in half-steps (<IMG
WIDTH="12" HEIGHT="14" ALIGN="BOTTOM" BORDER="0"
SRC="img194.png"
ALT="$h$">) is known and the
formula must be solved for either <IMG
WIDTH="13" HEIGHT="30" ALIGN="MIDDLE" BORDER="0"
SRC="img112.png"
ALT="$f$"> or <IMG
WIDTH="18" HEIGHT="14" ALIGN="BOTTOM" BORDER="0"
SRC="img3.png"
ALT="$N$">:
<BR><P></P>
<DIV ALIGN="CENTER">
<!-- MATH
\begin{displaymath}
f = {{2^{h/12} R} \over N}
\end{displaymath}
-->
<IMG
WIDTH="79" HEIGHT="42" BORDER="0"
SRC="img197.png"
ALT="\begin{displaymath}
f = {{2^{h/12} R} \over N}
\end{displaymath}">
</DIV>
<BR CLEAR="ALL">
<P></P>
<BR><P></P>
<DIV ALIGN="CENTER">
<!-- MATH
\begin{displaymath}
N = {{2^{h/12} R} \over f}
\end{displaymath}
-->
<IMG
WIDTH="86" HEIGHT="45" BORDER="0"
SRC="img198.png"
ALT="\begin{displaymath}
N = {{2^{h/12} R} \over f}
\end{displaymath}">
</DIV>
<BR CLEAR="ALL">
<P></P>
<P>
So far we have used a sawtooth as the input wave <IMG
WIDTH="26" HEIGHT="32" ALIGN="MIDDLE" BORDER="0"
SRC="img199.png"
ALT="$y[t]$">, but, as suggested in
parts (d) and (e) of Figure <A HREF="node26.html#fig02.02">2.2</A>, we could use anything we like as an
input signal. In general, the transposition may be time dependent and
is controlled by the rate of change of the input signal.
<P>
The
transposition multiple <IMG
WIDTH="9" HEIGHT="13" ALIGN="BOTTOM" BORDER="0"
SRC="img82.png"
ALT="$t$"> and the transposition in half-steps <IMG
WIDTH="12" HEIGHT="14" ALIGN="BOTTOM" BORDER="0"
SRC="img194.png"
ALT="$h$"> are then
given by the
<A ID="2217"></A>Momentary Transposition Formulas for Wavetables:
<A ID="sect2.momentaryformula"></A>
<BR><P></P>
<DIV ALIGN="CENTER">
<!-- MATH
\begin{displaymath}
t[n] = \left | y[n] - y[n-1] \right |
\end{displaymath}
-->
<IMG
WIDTH="153" HEIGHT="28" BORDER="0"
SRC="img200.png"
ALT="\begin{displaymath}
t[n] = \left \vert y[n] - y[n-1] \right \vert
\end{displaymath}">
</DIV>
<BR CLEAR="ALL">
<P></P>
<BR><P></P>
<DIV ALIGN="CENTER">
<!-- MATH
\begin{displaymath}
h[n] = 12 {{\log_2} \left | y[n] - y[n-1] \right |}
\end{displaymath}
-->
<IMG
WIDTH="202" HEIGHT="28" BORDER="0"
SRC="img201.png"
ALT="\begin{displaymath}
h[n] = 12 {{\log_2} \left \vert y[n] - y[n-1] \right \vert}
\end{displaymath}">
</DIV>
<BR CLEAR="ALL">
<P></P>
(Here the enclosing bars "<IMG
WIDTH="7" HEIGHT="32" ALIGN="MIDDLE" BORDER="0"
SRC="img202.png"
ALT="$\vert$">" mean absolute value.)
For example, if
<IMG
WIDTH="61" HEIGHT="32" ALIGN="MIDDLE" BORDER="0"
SRC="img203.png"
ALT="$y[n] = n$">, then <IMG
WIDTH="78" HEIGHT="32" ALIGN="MIDDLE" BORDER="0"
SRC="img204.png"
ALT="$z[n] = x[n]$"> so we hear the wavetable at its original pitch,
and this is what the formula predicts since, in that case,
<BR><P></P>
<DIV ALIGN="CENTER">
<!-- MATH
\begin{displaymath}
y[n]-y[n-1] = 1
\end{displaymath}
-->
<IMG
WIDTH="129" HEIGHT="28" BORDER="0"
SRC="img205.png"
ALT="\begin{displaymath}
y[n]-y[n-1] = 1
\end{displaymath}">
</DIV>
<BR CLEAR="ALL">
<P></P>
On the other hand, if <IMG
WIDTH="69" HEIGHT="32" ALIGN="MIDDLE" BORDER="0"
SRC="img206.png"
ALT="$y[n] = 2n$">, then the wavetable is transposed up an
octave, consistent with
<BR><P></P>
<DIV ALIGN="CENTER">
<!-- MATH
\begin{displaymath}
y[n]-y[n-1] = 2
\end{displaymath}
-->
<IMG
WIDTH="129" HEIGHT="28" BORDER="0"
SRC="img207.png"
ALT="\begin{displaymath}
y[n]-y[n-1] = 2
\end{displaymath}">
</DIV>
<BR CLEAR="ALL">
<P></P>
If values of <IMG
WIDTH="30" HEIGHT="32" ALIGN="MIDDLE" BORDER="0"
SRC="img2.png"
ALT="$y[n]$"> are
decreasing with <IMG
WIDTH="13" HEIGHT="13" ALIGN="BOTTOM" BORDER="0"
SRC="img75.png"
ALT="$n$">, you hear the sample backward, but the transposition
formula still gives a positive multiplier. This all agrees with the
earlier Transposition Formula for Looping Wavetables; if a sawtooth ranges
from <IMG
WIDTH="11" HEIGHT="13" ALIGN="BOTTOM" BORDER="0"
SRC="img179.png"
ALT="$0$"> to <IMG
WIDTH="18" HEIGHT="14" ALIGN="BOTTOM" BORDER="0"
SRC="img3.png"
ALT="$N$">, <IMG
WIDTH="13" HEIGHT="30" ALIGN="MIDDLE" BORDER="0"
SRC="img112.png"
ALT="$f$"> times per second,
the difference of successive samples is just <IMG
WIDTH="47" HEIGHT="32" ALIGN="MIDDLE" BORDER="0"
SRC="img192.png"
ALT="$N f / R$">--except at the sample
at the beginning of each new cycle.
<P>
It's well known that transposing a recording also transposes its timbre--this
is the "chipmunk" effect. Not only are any periodicities (such as might
give rise to pitch) transposed, but so are the frequencies of
the overtones. Some timbres, notably those of vocal sounds, have characteristic
frequency ranges in which overtones are stronger than other nearby ones.
Such frequency ranges are also transposed, and this is is heard as
a timbre change. In language that will be made more precise in Section
<A HREF="node76.html#sect5-spectra">5.1</A>,
we say that the
<A ID="2221"></A><I>spectral envelope</I> is transposed along with the pitch or
pitches.
<P>
In both this and the preceding section, we have considered playing
wavetables periodically. In Section <A HREF="node27.html#sect2.oscillator">2.1</A> the playback
repeated quickly enough that the repetition gives rise to a pitch, say between
30 and 4000 times per second, roughly the range of a piano. In the current
section we assumed a wavetable one second long, and in this case
"reasonable" transposition factors (less than four octaves up) would give rise
to a rate of repetition below 30, usually much lower, and going down as low as
we wish.
<P>
The number 30 is significant for another reason: it is roughly the maximum
number of separate events the ear can discern per second; for instance, 30
vocal phonemes, or melodic notes, or attacks of a snare drum are about the most
we can hope to crowd into a second before our ability to distinguish them
breaks down.
<P>
A continuum exists between samplers and wavetable oscillators, in that the
patch of Figure <A HREF="node27.html#fig02.03">2.3</A> can either be regarded as a sampler (if the
frequency of repetition is less than about 20 Hertz) or as a wavetable oscillator
(if the frequency is greater than about 40 Hertz). It is possible to move
continuously between the two regimes.
Furthermore, it is not necessary to play an entire wavetable in a loop; with a bit
more arithmetic we can choose sub-segments of the wavetable, and these can change
in length and location continuously as the wavetable is played.
<P>
The practice of playing many small segments of a wavetable in rapid succession
is often called
<A ID="2225"></A><I>granular synthesis</I>.
For much more discussion of the possibilities, see [<A
HREF="node202.html#r-roads01">Roa01</A>].
<P>
Figure <A HREF="#fig02.05">2.5</A> shows how to build a very simple looping sampler. In the
figure, if the frequency is <IMG
WIDTH="13" HEIGHT="30" ALIGN="MIDDLE" BORDER="0"
SRC="img112.png"
ALT="$f$"> and the segment size in samples is <IMG
WIDTH="10" HEIGHT="13" ALIGN="BOTTOM" BORDER="0"
SRC="img208.png"
ALT="$s$">,
the output transposition factor is given by <IMG
WIDTH="67" HEIGHT="32" ALIGN="MIDDLE" BORDER="0"
SRC="img209.png"
ALT="$t = fs/R$">, where R is the sample
rate at which the wavetable was recorded (which need not equal the sample rate
the block diagram is working at.) In practice, this equation must usually
be solved for either <IMG
WIDTH="13" HEIGHT="30" ALIGN="MIDDLE" BORDER="0"
SRC="img112.png"
ALT="$f$"> or <IMG
WIDTH="10" HEIGHT="13" ALIGN="BOTTOM" BORDER="0"
SRC="img208.png"
ALT="$s$"> to attain a desired transposition.
<P>
In the figure, a sawtooth oscillator controls the location of wavetable lookup,
but the lower and upper values of the sawtooth aren't statically
specified as they were in Figure <A HREF="node27.html#fig02.03">2.3</A>; rather, the sawtooth
oscillator simply ranges from 0 to 1 in value and the range is adjusted
to select a desired segment of samples in the wavetable.
<P>
It might be desirable to specify the segment's location <IMG
WIDTH="8" HEIGHT="14" ALIGN="BOTTOM" BORDER="0"
SRC="img210.png"
ALT="$l$"> either as its
left-hand edge (its lower bound) or else as the segment's midpoint; in either
case we specify the length <IMG
WIDTH="10" HEIGHT="13" ALIGN="BOTTOM" BORDER="0"
SRC="img208.png"
ALT="$s$"> as a separate parameter. In the first
case, we start by
multiplying the sawtooth by <IMG
WIDTH="10" HEIGHT="13" ALIGN="BOTTOM" BORDER="0"
SRC="img208.png"
ALT="$s$">, so that it then ranges from <IMG
WIDTH="11" HEIGHT="13" ALIGN="BOTTOM" BORDER="0"
SRC="img179.png"
ALT="$0$"> to <IMG
WIDTH="10" HEIGHT="13" ALIGN="BOTTOM" BORDER="0"
SRC="img208.png"
ALT="$s$">; then
we add <IMG
WIDTH="8" HEIGHT="14" ALIGN="BOTTOM" BORDER="0"
SRC="img210.png"
ALT="$l$"> so that it now ranges from <IMG
WIDTH="8" HEIGHT="14" ALIGN="BOTTOM" BORDER="0"
SRC="img210.png"
ALT="$l$"> to <IMG
WIDTH="35" HEIGHT="30" ALIGN="MIDDLE" BORDER="0"
SRC="img211.png"
ALT="$l+s$">. In order to specify the
location as the segment's midpoint, we first subtract <IMG
WIDTH="27" HEIGHT="32" ALIGN="MIDDLE" BORDER="0"
SRC="img98.png"
ALT="$1/2$"> from the sawtooth
(so that it ranges from <IMG
WIDTH="39" HEIGHT="32" ALIGN="MIDDLE" BORDER="0"
SRC="img212.png"
ALT="$-1/2$"> to <IMG
WIDTH="27" HEIGHT="32" ALIGN="MIDDLE" BORDER="0"
SRC="img98.png"
ALT="$1/2$">), and then as before multiply by <IMG
WIDTH="10" HEIGHT="13" ALIGN="BOTTOM" BORDER="0"
SRC="img208.png"
ALT="$s$">
(so that it now ranges from <IMG
WIDTH="39" HEIGHT="32" ALIGN="MIDDLE" BORDER="0"
SRC="img213.png"
ALT="$-s/2$"> to <IMG
WIDTH="26" HEIGHT="32" ALIGN="MIDDLE" BORDER="0"
SRC="img214.png"
ALT="$s/2$">) and add <IMG
WIDTH="8" HEIGHT="14" ALIGN="BOTTOM" BORDER="0"
SRC="img210.png"
ALT="$l$"> to give a range from
<IMG
WIDTH="51" HEIGHT="32" ALIGN="MIDDLE" BORDER="0"
SRC="img215.png"
ALT="$l-s/2$"> to <IMG
WIDTH="51" HEIGHT="32" ALIGN="MIDDLE" BORDER="0"
SRC="img216.png"
ALT="$l+s/2$">.
<P>
<DIV ALIGN="CENTER"><A ID="fig02.05"></A><A ID="2232"></A>
<TABLE>
<CAPTION ALIGN="BOTTOM"><STRONG>Figure 2.5:</STRONG>
A simple looping sampler, as yet with no amplitude control.
There are inputs to control the frequency and the segment size and location.
The "-" operation is included if we wish the segment location to be specified
as the segment's midpoint; otherwise we specify the location of the left
end of the segment.</CAPTION>
<TR><TD><IMG
WIDTH="320" HEIGHT="398" BORDER="0"
SRC="img217.png"
ALT="\begin{figure}\psfig{file=figs/fig02.05.ps}\end{figure}"></TD></TR>
</TABLE>
</DIV>
<P>
In the looping sampler,
we will need to worry about maintaining continuity between the beginning and the
end of segments of the wavetable; we'll take this up in the next section.
<P>
A further detail is that, if the segment size and location are changing
with time (they might be digital audio signals themselves, for instance),
they will affect the transposition factor, and the pitch or timbre of the
output signal might waver up and down as a result. The simplest way to
avoid this problem is to synchronize changes in the values of <IMG
WIDTH="10" HEIGHT="13" ALIGN="BOTTOM" BORDER="0"
SRC="img208.png"
ALT="$s$"> and <IMG
WIDTH="8" HEIGHT="14" ALIGN="BOTTOM" BORDER="0"
SRC="img210.png"
ALT="$l$">
with the regular discontinuities of the sawtooth; since the signal jumps
discontinuously there, the transposition is not really defined there anyway,
and, if you are enveloping to hide the discontinuity, the effects of changes
in <IMG
WIDTH="10" HEIGHT="13" ALIGN="BOTTOM" BORDER="0"
SRC="img208.png"
ALT="$s$"> and <IMG
WIDTH="8" HEIGHT="14" ALIGN="BOTTOM" BORDER="0"
SRC="img210.png"
ALT="$l$"> are hidden as well.
<P>
<HR>
<!--Navigation Panel-->
<A ID="tex2html960"
HREF="node29.html">
<IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next"
SRC="next.png"></A>
<A ID="tex2html954"
HREF="node26.html">
<IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up"
SRC="up.png"></A>
<A ID="tex2html948"
HREF="node27.html">
<IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous"
SRC="prev.png"></A>
<A ID="tex2html956"
HREF="node4.html">
<IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents"
SRC="contents.png"></A>
<A ID="tex2html958"
HREF="node201.html">
<IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index"
SRC="index.png"></A>
<BR>
<B> Next:</B> <A ID="tex2html961"
HREF="node29.html">Enveloping samplers</A>
<B> Up:</B> <A ID="tex2html955"
HREF="node26.html">Wavetables and samplers</A>
<B> Previous:</B> <A ID="tex2html949"
HREF="node27.html">The Wavetable Oscillator</A>
&nbsp; <B> <A ID="tex2html957"
HREF="node4.html">Contents</A></B>
&nbsp; <B> <A ID="tex2html959"
HREF="node201.html">Index</A></B>
<!--End of Navigation Panel-->
<ADDRESS>
Miller Puckette
2006-12-30
</ADDRESS>
</BODY>
</HTML>