Skip to content
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

Add WASAPI resampling so all sampling rates work #143

Merged
merged 17 commits into from
Jun 10, 2022
Merged

Conversation

nyanpasu64
Copy link
Collaborator

@nyanpasu64 nyanpasu64 commented Jun 1, 2022

Previously, after the WASAPI merge, using a sampling rate different from the system rate would fail to open a WASAPI stream.

This continues to run emulators or Blip_Buffer at the sampling rate in the program settings. Then it converts all audio from blip_buffer from int16 to float32, then (if the system speaker sampling rate doesn't match the tracker rate) uses libsamplerate medium to resample audio to the system sampling rate, and outputs to WASAPI as float32.

WAV export continues to use the sampling rate in the settings, and ignores the system speaker sampling rate.

This removes the 8-bit audio output option, for both system playback (useless), and WAV export (halves file size, but degrades quality more than FLAC or Opus compression).

  • Make settings dialog prettier (remove hole in dialog)
  • Change IDS_SOUND_BUFFER_ERROR message from "WASAPI error: Could not open audio stream (likely wrong sampling rate)!"

Behavior

I wrote a test build at nyanpasu64@debug-channels-rates, to see whether Windows and Wine would reject incorrect sampling rates or channel counts.

Windows rejects all alternative sampling rates, and 1 channel audio. (In theory there could be 1ch speakers like 1ch microphone?)

Wine allows all sampling rates and both 1/2 channel audio. It gives PulseAudio or PipeWire the task of resampling audio (pw-top shows Dn-FT at 44100 when the system rate is 48000). And PulseAudio is bad: https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/issues/310

speex-float-1 (the current default) indeed does introduce easily audible artifacts on specially prepared samples, but not on music that can be downloaded or bought in stores. The default has been changed from speex-float-3 to speex-float-1 because ARM-based and MIPS-based boards struggle even with speex-float-2 or speex-fixed-2.

😂

We should unconditionally resample to the system rate ourself, to protect Wine users from low-quality PulseAudio resampling. (done)

  • Test on Wine

Gumball2415 and others added 4 commits May 30, 2022 12:54
Once we add the resampler, we'll always generate audio at 16 bits and
use libsamplerate to convert to float32 (before optionally resampling).
nyanpasu64 and others added 5 commits June 2, 2022 10:41
Audio is generated at the sampling rate in the program settings. Wave
export outputs audio at the program sampling rate. Audio playback is
converted to float, resampled to the WASAPI sampling rate if it
differs, then sent to speakers.
This does not have a significant effect on behavior.
This prevents calling it too early before writing enough audio.
WAV export now always writes at 16-bit, and audio playback always
renders at 16-bit (due to Blip_Buffer), upmixes to float, then
resamples if necessary.
@nyanpasu64 nyanpasu64 marked this pull request as ready for review June 2, 2022 17:51
nyanpasu64 and others added 6 commits June 4, 2022 11:13
https://stackoverflow.com/q/11259128 indicates that project references
are the newer recommended system (and they add both build ordering, and
automatic linking without hard-coding the .lib name built by
libsamplerate, making the build setup cleaner).
Previously we tried to open a stream at the internal sampling rate, only
falling back to the system rate if it failed. This was pointless on
Windows, since opening a stream at a non-system rate always fails. On
Linux Wine, you *can* open a stream at any sampling rate, but this is a
bad idea since Wine delegates resampling to PulseAudio/PipeWire, and
PulseAudio uses a low-quality resampler by default
(https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/issues/310).
@nyanpasu64 nyanpasu64 marked this pull request as draft June 7, 2022 10:51
@nyanpasu64
Copy link
Collaborator Author

nyanpasu64 commented Jun 7, 2022

Issue: "WASAPI error: Could not open audio stream!" on 2012 MacBook Pro running Boot Camp Windows 7.

is this a fucking joke, it requires 4-channel audio output (and I don't even know the channel layout)

In any case, this issue is unrelated to this PR. See #145.

@nyanpasu64 nyanpasu64 marked this pull request as ready for review June 7, 2022 23:32
@nyanpasu64 nyanpasu64 merged commit 05ebb50 into master Jun 10, 2022
@nyanpasu64 nyanpasu64 deleted the add-resampler branch June 10, 2022 03:24
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