C · Local Linux terminal
The notes are right. Where did the rests go?
Online version: https://fpga.labsland.com/altera/embedded-systems/lab-08/part-05/
Your computer
Embedded Systems · Linux and C. Record a two-note performance, then listen to its replay. The notes overlap, the first finger lifts while the second note continues, and both hands are off the keys before the recording ends. Can a player reproduce that phrasing with just a list of pitches and start times?
You need a Linux computer with a C compiler, Linux userspace headers and Python 3. In the local exercise, two timed button events stand in for the board pushbuttons. A WAV file contains your performance followed by its replay. The waveform viewer works without speakers.
Predict the timeline
Open resources/duet.txt. The first KEY1 asks the empty recorder to play. KEY0 then starts a take at 0.30 s and stops it at 1.65 s. The second KEY1 starts replay at 2.00 s. Q plays middle C and E plays the E above it. A stopwatch tick lasts 0.01 s.
| Change | Tick within the take | Predicted time in the replay |
|---|---|---|
| C pressed at 0.50 s | ||
| E pressed at 0.75 s | ||
| C released at 1.00 s | ||
| E released at 1.25 s |
On the board, LEDR0 marks recording, LEDR1 marks playback and both are dark when idle. At the start of each pass the six HEX digits show 00:30:00 and count down in minutes, seconds and hundredths. Predict their reading when E is released.
Hear what the recorder saved
From the extracted folder, run:
cc -std=c11 -O2 -Wall -Wextra -Werror starter/recorder.c -pthread -lm -o recorder
python3 resources/play_take.py ./recorder before.wav resources/duet.txt
python3 resources/view_scope.py before.wav
Open the local address printed by the viewer. Play before.wav in your audio player. Compare the silence after both fingers lift in the first pass with the same interval in the replay. In the viewer, step through the first four changes and the replay changes. Which note disappears first in each pass? Stop the viewer with Ctrl+C when finished.
The upper trace (1) shows the original performance. The lower trace (2) shows the starter’s replay, aligned to the same start time. Each vertical slice gives the peak amplitude of a short section of the WAV. Where should the last silent interval begin?
Read the terminal rows: saved and played give the tick, Linux key code and state (1 down, 0 up). The two codes in this performance are 16 for Q and 18 for E. Did the replay scheduler miss a saved event, or did the recorder discard it before playback?
Repair and stress the recording
Change save_transition in starter/recorder.c. Preserve the two meaningful transitions of a piano key. Recompile, then repeat the command using a fresh name, after.wav. Compare the four saved times with the four played times; Linux scheduling may shift a reading by a few hundredths. Use the WAV and the viewer to verify the rest before the return to idle.
Make a copy of the score. Insert a repeated Q event (state 2) at 0.60 s and extend the E note by 0.15 s. Predict which rows and sounds should change, then run your score. Hand in the table, one before/after playback observation and the rows from your edited performance that support it.
FPGAcademy exercise · Exercise notice · LabsLand source license
