From 2b99e65d24bfcb7b565b989772bdd7d286147126 Mon Sep 17 00:00:00 2001 From: briaguya <70942617+briaguya-ai@users.noreply.github.com> Date: Tue, 5 Jul 2022 19:30:30 -0400 Subject: [PATCH] update pulseaudio for 44.1khz audio (#587) * use pulseaudio defaults * spaces/tabs * pulseaudio values tuned for n64 audio at 44.1khz * update tlength * remove one hardcoded samplerate Co-authored-by: briaguya --- .../libultraship/PulseAudioPlayer.cpp | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/libultraship/libultraship/PulseAudioPlayer.cpp b/libultraship/libultraship/PulseAudioPlayer.cpp index 8c930a449..21603c2b9 100644 --- a/libultraship/libultraship/PulseAudioPlayer.cpp +++ b/libultraship/libultraship/PulseAudioPlayer.cpp @@ -77,11 +77,24 @@ namespace Ship ss.rate = this->GetSampleRate(); ss.channels = 2; + #define SAMPLES_HIGH 752 + #define SAMPLES_LOW 720 + pa_buffer_attr attr; - attr.maxlength = (1600 + 544 + 528 + 1600) * 4; - attr.tlength = (528*2 + 544) * 4; - attr.prebuf = 1500 * 4; - attr.minreq = 161 * 4; + // set the max length to the desired buffered level, plus + // 3x the high sample rate, which is what the n64 audio engine + // can output at one time, x2 to avoid overflow in case of the + // n64 audio engine running faster than pulseaudio, all multiplied + // by 4 because each sample is 4 bytes + attr.maxlength = (GetDesiredBuffered() + 3 * SAMPLES_HIGH * 2) * 4; + + // slightly more than one double audio update + attr.prebuf = SAMPLES_HIGH * 3 * 1.5 * 4; + + attr.minreq = 222 * 4; + attr.tlength = (GetSampleRate() / 20) * 4; + + // initialize to a value that is deemed sensible by the server attr.fragsize = (uint32_t)-1; m_Stream = pa_stream_new(m_Context, "zelda", &ss, NULL);