Lab 8

C · Local Linux terminal

The piano sounds right. Why does the screen show the wrong octave?

Your computer

Listen to the reference recording

Embedded Systems · Linux, C and threads. In the previous activity, one thread read keys while another produced sound. Add a third thread to draw a trace when the pianist presses or releases a key. The local screen and WAV recording work on a Linux computer with a C compiler, Linux userspace headers and Python 3.

Predict what fits on the screen

A 320-column screen displays 320 consecutive stereo frames sampled at 8,000 frames per second. How many milliseconds fit across the display? How many cycles of middle C (261.63 Hz) and of the C above it (523.25 Hz) should fit in that time? The two reference traces below came from the working program. Both panels cover the same amount of time.

Reference output showing middle C and the C one octave higher over the same 40 ms window.

Separate a display error from a tuning error

From the extracted worksheet directory, compile the starter. Open the viewer in a second terminal and follow the local address it prints. The viewer can wait for the first note while you run the score in the first terminal.

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

On Windows with the Python launcher, use py -3 wherever a command starts with python3.

python3 resources/play_score.py ./scope before.wav octave

Play the WAV. In the viewer, choose the first change (low C) and then the third change (high C). Count the cycles by counting upward crossings of the center line. You can also open the numbered SVG files inside before.wav.scope/ individually. Each filename gives the starting sample number. The viewer stops following live changes when you select a frame.

To measure the low C directly from the recording with no speakers, run:

python3 -c "import sys; sys.path.insert(0,'resources'); from inspect_audio import samples, positive_crossings; print(positive_crossings(samples('before.wav')[3360:5200]))"

Trace one column back to its PCM sample in sample_for_column in starter/scope.c. Repair the mapping. Recompile, run the octave score with the new filename after.wav, and point the viewer at that file. Keep the 8 kHz audio clock unchanged.

Trace Predicted cycles Starter display Repaired display
Low C
High C

Play three notes together

Run the repaired program with python3 resources/play_score.py ./scope chord.wav triad. Inspect the third captured change, when C, E and G sound together. Compare its shape with a single sine wave. The last capture begins just after the final key is released. Explain why it can still contain a decaying sound. Use fresh output filenames for new takes.

The audio thread hands the display thread a copy of the exact 320 samples being recorded. It then continues generating sound while the display draws. On a two-core system, the program places the audio thread on a separate allowed core from the input and video threads. Very close changes can share a snapshot. Explain why a slow display should be allowed to skip an old snapshot, and what would happen if the audio thread waited for each line to finish drawing.

Submit the completed table, the low-C frequency measured from the WAV, your code edit and one captured chord. Clearly identify the local display or instructor-provided video device you used.

FPGAcademy exercise · Exercise notice · LabsLand source license

Compare three recorded DE1-SoC oscilloscope traces