Skip to content

Switch to PortAudio #76

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 4, 2025
Merged

Conversation

Cuda-Chen
Copy link
Collaborator

@Cuda-Chen Cuda-Chen commented Feb 23, 2025

Switch to PortAudio for cross-platform and cross backend compatibility.

Testing

Preparation

  1. Run make build-image to build Linux Kernel image and root filesystem.

Test Cases

play white noise

test procedures
  1. Execute speaker-test in emulator shell.
  2. Check the host speaker.
expected results
  1. A white noise should be played by host speaker in the first round while speaker-test is executing.
  2. The emulator should crash after the second round of playing white noise.

play sequence sound

test procedures
  1. Execute aplay /usr/share/sounds/alsa/Front_Center.wav in emulator.
  2. Check the host speaker.
  3. Execute aplay /usr/share/sounds/alsa/Front_Center.wav in emulator.
expected results
  1. A sound with "Front Center" speaking with stutter effect should be played in step 2.
  2. The emulator should crash after step 1.

Summary by Bito

This pull request integrates PortAudio to enhance cross-platform audio playback, replacing the previous CNFA submodule. It updates the Makefile for better build configurations, addresses issues like sound loss and system crashes, and improves PCM stream handling and compatibility, while also updating documentation.

Unit tests added: False

Estimated effort to review (1-5, lower is better): 2

@jserv
Copy link
Collaborator

jserv commented Feb 23, 2025

You should explain the motivation and benefit for the migration of PortAudio.

@Cuda-Chen Cuda-Chen force-pushed the switch-to-portaudio branch 4 times, most recently from 6d42303 to 6e00d27 Compare February 24, 2025 09:33
@jserv
Copy link
Collaborator

jserv commented Feb 24, 2025

Build failure:

  LD	semu
/usr/bin/ld: cannot find -lpulse: No such file or directory
collect2: error: ld returned 1 exit status

@sysprog21 sysprog21 deleted a comment from bito-code-review bot Feb 24, 2025
@sysprog21 sysprog21 deleted a comment from bito-code-review bot Feb 24, 2025
@sysprog21 sysprog21 deleted a comment from bito-code-review bot Feb 24, 2025
@sysprog21 sysprog21 deleted a comment from bito-code-review bot Feb 24, 2025
@sysprog21 sysprog21 deleted a comment from bito-code-review bot Feb 24, 2025
@sysprog21 sysprog21 deleted a comment from bito-code-review bot Feb 24, 2025
@Cuda-Chen
Copy link
Collaborator Author

Build failure:

  LD	semu
/usr/bin/ld: cannot find -lpulse: No such file or directory
collect2: error: ld returned 1 exit status

Thanks for the reminder!
I am still working on this issue.

@Cuda-Chen Cuda-Chen force-pushed the switch-to-portaudio branch from f26f174 to e331ed7 Compare March 1, 2025 08:47
@sysprog21 sysprog21 deleted a comment from bito-code-review bot Mar 1, 2025
@sysprog21 sysprog21 deleted a comment from bito-code-review bot Mar 1, 2025
@sysprog21 sysprog21 deleted a comment from bito-code-review bot Mar 1, 2025
@sysprog21 sysprog21 deleted a comment from bito-code-review bot Mar 1, 2025
@sysprog21 sysprog21 deleted a comment from bito-code-review bot Mar 1, 2025
@Cuda-Chen Cuda-Chen force-pushed the switch-to-portaudio branch from e331ed7 to e7184f0 Compare March 1, 2025 11:56
@jserv jserv changed the title [WIP] Switch to PortAudio Switch to PortAudio Mar 1, 2025
@Cuda-Chen Cuda-Chen force-pushed the switch-to-portaudio branch from e7184f0 to a73d91d Compare March 1, 2025 12:14
@Cuda-Chen Cuda-Chen marked this pull request as ready for review March 1, 2025 12:14
@jserv jserv marked this pull request as draft March 1, 2025 14:12
@sysprog21 sysprog21 deleted a comment from bito-code-review bot Mar 1, 2025
@Cuda-Chen Cuda-Chen force-pushed the switch-to-portaudio branch 2 times, most recently from c270822 to 856807d Compare March 4, 2025 11:43
@Cuda-Chen
Copy link
Collaborator Author

@Cuda-Chen, Why did you enable Enable hrtimer in ALSA configurations?

To make sure whether the hrtimer resolve the stuttering and sending invalid stream ID issues.

@Cuda-Chen
Copy link
Collaborator Author

Hi @jserv , I would like to summarize the current progress:

  1. For stuttering effect, the root case remains unknown. It seems that the sound driver just sends the sound with stuttering effect.
  2. For crash issue, it is confirmed that the sound driver sends the PCM frames with invalid stream ID. I need to come up with a solution (the current attempt needs more work). As a consequence, you may mark this PR into a draft PR.

@Cuda-Chen Cuda-Chen force-pushed the switch-to-portaudio branch 2 times, most recently from 5d0f852 to d6b9ac6 Compare May 15, 2025 07:29
@Cuda-Chen Cuda-Chen requested a review from jserv May 15, 2025 07:34
@Cuda-Chen Cuda-Chen force-pushed the switch-to-portaudio branch from d6b9ac6 to 7dd3664 Compare June 2, 2025 02:06
@Cuda-Chen Cuda-Chen requested a review from jserv June 2, 2025 06:54
Copy link
Collaborator

@jserv jserv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rebase the latest master branch.

@Cuda-Chen Cuda-Chen force-pushed the switch-to-portaudio branch from 7dd3664 to 99e44c7 Compare June 4, 2025 07:55
@Cuda-Chen Cuda-Chen requested a review from jserv June 4, 2025 08:09
@Cuda-Chen Cuda-Chen force-pushed the switch-to-portaudio branch from 99e44c7 to 1e978fd Compare June 4, 2025 10:02
@Cuda-Chen Cuda-Chen requested a review from jserv June 4, 2025 10:21
Switch to PortAudio for cross-platform and cross backend compatibility.

Linux v6.7 propose a solution to resolve sound stutter effect.
Therefore, upgrade the kernel version as well.

It is confirmed that there exists unknown issues in Linux Kernel
that user has to adjust the buffer size to more than four times of period size,
or the program cannot write PCM frames into guest ALSA stack.
@Cuda-Chen Cuda-Chen force-pushed the switch-to-portaudio branch from 1e978fd to d26f0dd Compare June 4, 2025 11:08
@Cuda-Chen Cuda-Chen requested a review from jserv June 4, 2025 12:29
@jserv jserv merged commit 82f39b9 into sysprog21:master Jun 4, 2025
3 checks passed
shengwen-tw added a commit to shengwen-tw/semu that referenced this pull request Jun 8, 2025
Fixes a compilation error introduced in sysprog21#76, where the `make all` target fails
during the build of the PortAudio library on GNU/Linux systems.

The failure was caused by a missing `-lsndio` linker flag. Adding this flag
resolves the issue and allows the build to complete successfully.
shengwen-tw added a commit to shengwen-tw/semu that referenced this pull request Jun 8, 2025
Fixes a compilation error introduced in sysprog21#76, where the `make all` target fails
during the build of the PortAudio library on GNU/Linux systems.

The failure was caused by a missing `-lsndio` linker flag. Adding this flag
resolves the issue and allows the build to complete successfully.
shengwen-tw added a commit to shengwen-tw/semu that referenced this pull request Jun 9, 2025
Fixes a compilation error introduced in sysprog21#76, where the `make all` target fails
during the build of the PortAudio library on GNU/Linux systems.

The failure was caused by PortAudio's configure script automatically enabling
the sndio backend when `libsndio-dev` headers are present, which leads to
linker errors due to missing `-lsndio`.

To avoid this, we now explicitly pass `--without-sndio` to PortAudio’s
configure script. This ensures that sndio support is disabled regardless of
system headers, eliminating the need for `-lsndio` and fixing the build.
ChinYikMing added a commit to ChinYikMing/semu that referenced this pull request Jun 9, 2025
Quote from portaudio/config.log:
...
configure:3194: checking whether the C compiler works
configure:3216: gcc  -I/opt/homebrew/opt/zlib/include portaudio/lib/.libs/libportaudio.a -framework CoreServices -framework CoreFoundation -framework AudioUnit -framewo    rk AudioToolbox -framework CoreAudio -lpthread -lm mini-gdbstub/build/libgdbstub.a conftest.c  >&5
clang: error: no such file or directory: 'portaudio/lib/.libs/libportaudio.a'
...
configure:3265: error: C compiler cannot create executables
...

The ./configure script fails on macOS because LDFLAGS includes static
libraries (libportaudio.a) that have not yet been built. This causes the
compiler check to fail with "C compiler cannot create executables".

This patch unsets LDFLAGS during the configure step to allow the test
program to compile and link successfully, enabling builds on macOS.

Related: sysprog21#76
ChinYikMing added a commit to ChinYikMing/semu that referenced this pull request Jun 10, 2025
Quote from portaudio/config.log:
...
configure:3194: checking whether the C compiler works
configure:3216: gcc  -I/opt/homebrew/opt/zlib/include portaudio/lib/.libs/libportaudio.a -framework CoreServices -framework CoreFoundation -framework AudioUnit -framewo    rk AudioToolbox -framework CoreAudio -lpthread -lm mini-gdbstub/build/libgdbstub.a conftest.c  >&5
clang: error: no such file or directory: 'portaudio/lib/.libs/libportaudio.a'
...
configure:3265: error: C compiler cannot create executables
...

The ./configure script fails on macOS because LDFLAGS includes static
libraries (libportaudio.a) that have not yet been built. This causes the
compiler check to fail with "C compiler cannot create executables".

This patch unsets LDFLAGS during the configure step to allow the test
program to compile and link successfully, enabling builds on macOS.

Related: sysprog21#76
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants