Lab 8

C · Local Linux terminal

Why does the scale start an octave too low?

Your computer

Listen to the reference recording

Embedded Systems · Audio · C on Linux. Make a stereo recording of thirteen notes, from middle C to the next C. You need a C compiler and Python 3. You can measure every note without speakers. This activity writes a WAV file on your computer.

Predict the recording

The audio clock advances by 8,000 stereo frames each second. Each note lasts 300 ms. Predict the number of frames per note, the total duration, and how many periods of a 440 Hz tone fit in one note. The two channels should contain the same signal.

From the extracted worksheet directory run:

cc -std=c11 -O2 -Wall -Wextra -Werror starter/scale.c -lm -o scale
./scale before.wav
python3 resources/inspect_audio.py scale before.wav

Open the file in an audio player or inspect the printed frequencies. The first note should be about 261.63 Hz, the tenth 440 Hz and the last 523.25 Hz. Record those three measured frequencies before changing anything. Does doubling the playback speed also give the requested duration?

Repair the oscillator

Follow one sample from oscillator through phase_at to stereo_frame. What should happen to the phase each time the sample index increases by one? Change the oscillator so that its frequency in radians per sample agrees with the 8 kHz clock. Build again, write after.wav and repeat the same measurements. Keep the 300 ms duration and the header sample rate unchanged.

Measurement Prediction Initial recording After repair
Total duration
First C, Hz
A, Hz
Last C, Hz

For a further experiment, change the note length to 150 ms. Predict the new recording length. Listen or examine the duration in the file properties. The supplied meter groups samples into 300 ms windows, so restore the original duration before using it again to grade individual pitches.

On a DE1-SoC Computer, the same sample can be written to each channel's output FIFO when both have room. The board clock consumes each stereo pair. Which component plays that timing role when someone opens your WAV file? Submit the three frequency pairs, your source edit and your explanation.

FPGAcademy audio exercise · Exercise notice · LabsLand source license

Compare three recorded DE1-SoC oscilloscope traces