C · Local Linux terminal
The piano reaches only one speaker
Online version: https://fpga.labsland.com/altera/embedded-systems/lab-08/part-06/
Your computer
Embedded Systems · Linux and C. A pianist records two overlapping notes and plays them back. The monitor file sounds right in both ears, yet the signal sent to the audio device is silent on one channel. Find the first place the two channels disagree.
Use a Linux terminal with a C compiler, Linux userspace headers and Python 3. The local exercise opens a private pseudo-terminal and captures the commands your piano writes. You can measure both channels even with a mono speaker or no headphones.
Follow one stereo frame
Each frame starts as a signed 32-bit sample. This piano sends the same music to both speakers. At startup it writes init once to clear the output FIFOs. For each frame it writes waitw to wait for room, followed by one left command and one right command. The device receives each command in its own write. At 8,000 stereo frames per second, predict how many waits and channel writes a four-second take needs.
| Measurement | Before repair | After repair |
|---|---|---|
| Frames captured | ||
| Left peak (16-bit PCM) | ||
| Right peak (16-bit PCM) | ||
| Number of note changes during replay |
Compare the two listening points
From the extracted folder, run:
cc -std=c11 -O2 -Wall -Wextra -Werror starter/stereo_piano.c -pthread -lm -o piano
python3 resources/capture_audio.py ./piano before resources/duet.txt
Open before/monitor.wav, then before/device.wav. Both files contain the performance and its replay. The monitor takes its samples from the synthesizer; the device file is reconstructed from the signed numbers your program sent to each channel. Compare the printed L and R peaks. The L != R line counts unequal pairs, and First negative L lets you check the sign on both sides. The first frame is silent by design, so the first two channel commands alone cannot reveal the fault. The example below shows a sounding interval from the starter's device output.
Repair the channel and check the timing
Read send_frame in starter/stereo_piano.c. For a negative sample, what exact value will reach each channel? Change the call responsible for the disagreement. Recompile and repeat the capture using a fresh folder named after. The peak and polarity should now match on both channels. Check the four saved and four played rows against the score. Their first column counts hundredths of a second since recording or replay began.
Open the waveform viewer with python3 resources/view_scope.py after/monitor.wav. Compare the first two note presses with the same two presses during replay. Which evidence checks the timing, and which proves the device actually received the right-channel samples?
For a final test, reduce only the right channel to half amplitude, keeping its sign. Predict the two peaks, then repeat with a third folder. Submit the table, your repair, and the measured peak ratio from the final test. Explain why checking the synthesizer's monitor alone would have missed the original fault.
FPGAcademy exercise · Exercise notice · LabsLand source license
