2.5 Summary#
Digital audio is usually synthesized and manipulated in memory as an array of floats (unquantized) in nominal range \([-1, 1]\), paired with a sample rate \(f_s\).
Synthesis is the inverse of recording: dream up a continuous function \(x(t)\) and evaluate it at sample times \(t_n = n / f_s\).
Loops are a ubiquitous primitive in computer music programming, because synthesis involves sampling functions at many points in time.
Vectorized computation replaces explicit Python loops with whole-array operations. It is equivalent but faster (precompiled inner loops) and more readable (one expression instead of many).
NumPy is the standard vectorization library. The core operations: array creation (
np.array,np.zeros), slicing, element-wise arithmetic, multi-dimensional arrays, and broadcasting.Stereo audio is a 2D array of shape
(num_samples, num_channels). To downmix to mono, takearray.mean(axis=1).Pyquist is a small wrapper around NumPy that bundles samples + sample rate into a single
pq.Audioobject, plus I/O / playback / plotting helpers.Adding two
pq.Audioobjects mixes them. Both array-style slicing (audio[a:b], in samples) and.segment(offset=, duration=)(in seconds) return a newpq.Audiowith the sample rate carried along.