Skip to content

Commit

Permalink
Optimize for most common case (min channels = 1).
Browse files Browse the repository at this point in the history
  • Loading branch information
tmiw committed Jan 24, 2024
1 parent 52f94b6 commit 67675eb
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/audio/PortAudioEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,35 +92,33 @@ std::vector<AudioDeviceSpecification> PortAudioEngine::getAudioDeviceList(AudioD
// on Windows.
PaStreamParameters streamParameters;
streamParameters.device = index;
streamParameters.channelCount =
direction == AUDIO_ENGINE_IN ? deviceInfo->maxInputChannels : deviceInfo->maxOutputChannels;
streamParameters.channelCount = 1;
streamParameters.sampleFormat = paInt16;
streamParameters.suggestedLatency = Pa_GetDeviceInfo(index)->defaultHighInputLatency;
streamParameters.hostApiSpecificStreamInfo = NULL;

while (streamParameters.channelCount >= 1)
int maxChannels = direction == AUDIO_ENGINE_IN ? deviceInfo->maxInputChannels : deviceInfo->maxOutputChannels;
while (streamParameters.channelCount < maxChannels)
{
PaError err = Pa_IsFormatSupported(
direction == AUDIO_ENGINE_IN ? &streamParameters : NULL,
direction == AUDIO_ENGINE_OUT ? &streamParameters : NULL,
deviceInfo->defaultSampleRate);

if (err == paFormatIsSupported)
{
streamParameters.channelCount--;
}
else
{
break;
}

streamParameters.channelCount++;
}

// Add information about this device to the result array.
AudioDeviceSpecification device;
device.deviceId = index;
device.name = wxString::FromUTF8(deviceInfo->name);
device.apiName = hostApiName;
device.minChannels = streamParameters.channelCount + 1;
device.minChannels = streamParameters.channelCount;
device.maxChannels =
direction == AUDIO_ENGINE_IN ? deviceInfo->maxInputChannels : deviceInfo->maxOutputChannels;
device.defaultSampleRate = deviceInfo->defaultSampleRate;
Expand Down

0 comments on commit 67675eb

Please sign in to comment.