7.2. Real Time Audio ProcessingΒΆ

The easiest way, and what we have done thusfar, is to have the complete signal \(x[n]\) in computer memory. Depending on the length this can be quite a lot of samples. In this section we look at one way to process audio streams ‘on the fly’.

Consider a standard stereo audio stream, sampled with a frequency of \(44.100\) Hz and discretizing both left and right channels in 16 bits per sample.

In audio processing we do not operate on each sample individually. Instead the audio stream is sequenced in buffers (chunks) of say 1024 samples. Most often the buffer size can be chosen by the programmer.

So the stream source outputs 1 buffer at a time and the sink takes that input and either writes it to disk, stores it in memory, makes a graphical visualization of the sound signal, or feeds it to a DAC to be played.

In this section we give two examples. In the first example we will display a sound signal read from a wav file (and feed it to the DAC). For the display we will be using Matplotlib.

In the second example we will process the sound signal using a low-pass filter and then pass it on to the portaudio default output port (most often your soundcard).

To do this in Python we will be using the Portaudio Portable Cross-platform Audio I/O library via the PyAudio Python package.