Skip to content

Commit

Permalink
Merge pull request #73 from jj1bdx/latency-check
Browse files Browse the repository at this point in the history
Set PortAudio default latency time to 40ms
  • Loading branch information
jj1bdx committed Mar 8, 2024
2 parents 0b46bec + 1d31577 commit 8a22d1b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
12 changes: 12 additions & 0 deletions include/AudioOutput.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,18 @@ class SndfileOutput : public AudioOutput {

class PortAudioOutput : public AudioOutput {
public:
// Static variables.

// Minimum latency for audio output in seconds

// Values of m_outputparams.suggestedLatency from PortAudio:
// Mac mini 2023 with macOS 14.3.1: 0.014717
// Ubuntu 22.04.4 on x86_64: 0.034830
// Kenji's experiments show that
// 40ms (0.04) is sufficient for macOS, Ubuntu, and Raspberry Pi OS

static constexpr PaTime minimum_latency = 0.04;

//
// Construct PortAudio output stream.
//
Expand Down
7 changes: 7 additions & 0 deletions sfmbase/AudioOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,13 @@ PortAudioOutput::PortAudioOutput(const PaDeviceIndex device_index,
Pa_GetDeviceInfo(m_outputparams.device)->defaultHighOutputLatency;
m_outputparams.hostApiSpecificStreamInfo = NULL;

// Guarantee minimum latency.
if (m_outputparams.suggestedLatency < minimum_latency) {
m_outputparams.suggestedLatency = minimum_latency;
}

fprintf(stderr, "suggestedLatency = %f\n", m_outputparams.suggestedLatency);

m_paerror =
Pa_OpenStream(&m_stream,
NULL, // no input
Expand Down

0 comments on commit 8a22d1b

Please sign in to comment.