Skip to content

Commit

Permalink
Merge pull request #3277 from uklotzde/portaudio_hostapi
Browse files Browse the repository at this point in the history
lp1903462: PortAudio: Map host API index to type id
  • Loading branch information
daschuer authored Nov 10, 2020
2 parents 952ef2d + df8b94c commit 73ff6d5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
19 changes: 9 additions & 10 deletions src/soundio/sounddeviceportaudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,15 @@ const QRegularExpression kAlsaHwDeviceRegex("(.*) \\((plug)?(hw:(\\d)+(,(\\d)+))

} // anonymous namespace



SoundDevicePortAudio::SoundDevicePortAudio(UserSettingsPointer config,
SoundManager* sm,
const PaDeviceInfo* deviceInfo,
unsigned int devIndex,
QHash<PaHostApiIndex, PaHostApiTypeId> apiIndexToTypeId)
SoundManager* sm,
const PaDeviceInfo* deviceInfo,
PaHostApiTypeId deviceTypeId,
unsigned int devIndex)
: SoundDevice(config, sm),
m_pStream(NULL),
m_deviceInfo(deviceInfo),
m_deviceTypeId(deviceTypeId),
m_outputFifo(NULL),
m_inputFifo(NULL),
m_outputDrift(false),
Expand All @@ -97,7 +96,7 @@ SoundDevicePortAudio::SoundDevicePortAudio(UserSettingsPointer config,
// Setting parent class members:
m_hostAPI = Pa_GetHostApiInfo(deviceInfo->hostApi)->name;
m_dSampleRate = deviceInfo->defaultSampleRate;
if (apiIndexToTypeId.value(deviceInfo->hostApi) == paALSA) {
if (m_deviceTypeId == paALSA) {
// PortAudio gives the device name including the ALSA hw device. The
// ALSA hw device is an only somewhat reliable identifier; it may change
// when an audio interface is unplugged or Linux is restarted. Separating
Expand Down Expand Up @@ -196,7 +195,7 @@ SoundDeviceError SoundDevicePortAudio::open(bool isClkRefDevice, int syncBuffers
// in stereo and only take the first channel.
// TODO(rryan): Remove once PortAudio has a solution built in (and
// released).
if (m_deviceInfo->hostApi == paALSA) {
if (m_deviceTypeId == paALSA) {
// Only engage workaround if the device has enough input and output
// channels.
if (m_deviceInfo->maxInputChannels >= 2 &&
Expand All @@ -209,7 +208,6 @@ SoundDeviceError SoundDevicePortAudio::open(bool isClkRefDevice, int syncBuffers
}
}


// Sample rate
if (m_dSampleRate <= 0) {
m_dSampleRate = 44100.0;
Expand Down Expand Up @@ -323,7 +321,8 @@ SoundDeviceError SoundDevicePortAudio::open(bool isClkRefDevice, int syncBuffers


#ifdef __LINUX__
if (m_deviceInfo->hostApi == paALSA) {
if (m_deviceTypeId == paALSA) {
qInfo() << "Enabling ALSA real-time scheduling";
PaAlsa_EnableRealtimeScheduling(pStream, 1);
}
#endif
Expand Down
9 changes: 5 additions & 4 deletions src/soundio/sounddeviceportaudio.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@


#include <portaudio.h>
#include <QHash>
#include <QString>

#include "soundio/sounddevice.h"
Expand All @@ -15,8 +14,10 @@ class ControlProxy;
class SoundDevicePortAudio : public SoundDevice {
public:
SoundDevicePortAudio(UserSettingsPointer config,
SoundManager* sm, const PaDeviceInfo* deviceInfo,
unsigned int devIndex, QHash<PaHostApiIndex, PaHostApiTypeId> apiIndexToTypeId);
SoundManager* sm,
const PaDeviceInfo* deviceInfo,
PaHostApiTypeId deviceTypeId,
unsigned int devIndex);
~SoundDevicePortAudio() override;

SoundDeviceError open(bool isClkRefDevice, int syncBuffers) override;
Expand Down Expand Up @@ -57,6 +58,7 @@ class SoundDevicePortAudio : public SoundDevice {
// Struct containing information about this device. Don't free() it, it
// belongs to PortAudio.
const PaDeviceInfo* m_deviceInfo;
const PaHostApiTypeId m_deviceTypeId;
// Description of the output stream going to the soundcard.
PaStreamParameters m_outputParams;
// Description of the input stream coming from the soundcard.
Expand All @@ -78,4 +80,3 @@ class SoundDevicePortAudio : public SoundDevice {
PerformanceTimer m_clkRefTimer;
PaTime m_lastCallbackEntrytoDacSecs;
};

3 changes: 2 additions & 1 deletion src/soundio/soundmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,9 @@ void SoundManager::queryDevicesPortaudio() {
PaTime defaultHighOutputLatency
double defaultSampleRate
*/
const auto deviceTypeId = paApiIndexToTypeId.value(deviceInfo->hostApi);
auto currentDevice = SoundDevicePointer(new SoundDevicePortAudio(
m_pConfig, this, deviceInfo, i, paApiIndexToTypeId));
m_pConfig, this, deviceInfo, deviceTypeId, i));
m_devices.push_back(currentDevice);
if (!strcmp(Pa_GetHostApiInfo(deviceInfo->hostApi)->name,
MIXXX_PORTAUDIO_JACK_STRING)) {
Expand Down

0 comments on commit 73ff6d5

Please sign in to comment.