Skip to content

Commit a2348ec

Browse files
committed
Implement VirtIO sound device capture
Implement VirtIO sound device capture, with adding notice that the capture usually doesn't work for the reason of 'semu' emulation part.
1 parent 10cdcbc commit a2348ec

File tree

4 files changed

+444
-93
lines changed

4 files changed

+444
-93
lines changed

.ci/test-sound.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
# Source common functions and settings
6+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
7+
export SCRIPT_DIR
8+
source "${SCRIPT_DIR}/common.sh"
9+
10+
SAMPLE_SOUND="/usr/share/sounds/alsa/Front_Center.wav"
11+
12+
TEST_SOUND() {
13+
ASSERT expect <<DONE
14+
set timeout ${TIMEOUT}
15+
spawn make check
16+
expect "buildroot login:" { send "root\\n" } timeout { exit 1 }
17+
expect "# " { send "uname -a\\n" } timeout { exit 2 }
18+
19+
expect "riscv32 GNU/Linux" { send "aplay ${SAMPLE_SOUND} --fatal-errors > /dev/null\\n"} timeout { exit 3 }
20+
expect "# " { send "aplay -C -d 3 --fatal-errors -f S16_LE > /dev/null"} timeout { exit 4 }
21+
expect "# " { } timeout { exit 5 }
22+
DONE
23+
}
24+
25+
# Clean up any existing semu processes before starting tests
26+
cleanup
27+
28+
# Test sound device
29+
TEST_SOUND
30+
echo "✓ sound test passed"
31+
32+
exit 0

.github/workflows/main.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ jobs:
6969
run: sudo .ci/test-netdev.sh
7070
shell: bash
7171
timeout-minutes: 10
72+
- name: sound test
73+
run: .ci/test-sound.sh
74+
shell: bash
75+
timeout-minutes: 5
7276

7377
semu-macOS:
7478
runs-on: macos-latest
@@ -118,6 +122,10 @@ jobs:
118122
shell: bash
119123
timeout-minutes: 20
120124
if: ${{ success() }}
125+
- name: sound test
126+
run: .ci/test-sound.sh
127+
shell: bash
128+
timeout-minutes: 20
121129

122130
coding_style:
123131
runs-on: ubuntu-24.04

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ A minimalist RISC-V system emulator capable of running Linux the kernel and corr
1212
- Three types of I/O support using VirtIO standard:
1313
- virtio-blk acquires disk image from the host.
1414
- virtio-net is mapped as TAP interface.
15-
- virtio-snd uses [PortAudio](https://github.com/PortAudio/portaudio) for sound playback on the host with one limitations:
16-
- As some unknown issues in guest Linux OS (confirmed in v6.7 and v6.12), you need
17-
to adjust the buffer size to more than four times of period size, or
18-
the program cannot write the PCM frames into guest OS ALSA stack.
15+
- virtio-snd uses [PortAudio](https://github.com/PortAudio/portaudio) for sound playback and capture on the host with one limitations:
16+
- As a confirmed issue that `semu` cannot send/receive PCM frames in time, causing
17+
the ALSA stack stuck in XRUN state until `semu` being rebooted.
18+
- For playback, you can try to adjust the buffer size to more than four times of period size.
1919
- For instance, the following buffer/period size settings on `aplay` has been tested
2020
with broken and stutter effects yet complete with no any errors: `aplay --buffer-size=32768 --period-size=4096 /usr/share/sounds/alsa/Front_Center.wav`.
21+
- For capture, ALSA usually stucks in XRUN state, so you may try more times and pray for your own luck.
2122

2223
## Prerequisites
2324

0 commit comments

Comments
 (0)