From cc6b8a85f8d65176b3a1fe79edcf8d7b648255a2 Mon Sep 17 00:00:00 2001 From: Volker Fischer Date: Sat, 20 Mar 2010 08:55:42 +0000 Subject: [PATCH] some more work on sound card channel mapping support for Windows --- src/clientsettingsdlgbase.ui | 152 ++++++++++++++++++++++++++++++++++- windows/sound.cpp | 64 ++++++++++++--- windows/sound.h | 20 ++++- 3 files changed, 222 insertions(+), 14 deletions(-) diff --git a/src/clientsettingsdlgbase.ui b/src/clientsettingsdlgbase.ui index 05d0277c..8749a99d 100755 --- a/src/clientsettingsdlgbase.ui +++ b/src/clientsettingsdlgbase.ui @@ -5,8 +5,8 @@ 0 0 - 562 - 310 + 535 + 382 @@ -205,6 +205,150 @@ + + + + + 0 + 0 + + + + QFrame::NoFrame + + + QFrame::Plain + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Input Channel Mapping + + + + + + + 3 + + + + + + + + 0 + 0 + + + + L + + + + + + + + 0 + 0 + + + + R + + + + + + + + + 3 + + + + + + + + + + + + + + + Output Channel Mapping + + + + + + + 3 + + + + + + + + 0 + 0 + + + + L + + + + + + + + 0 + 0 + + + + R + + + + + + + + + 3 + + + + + + + + + + + + + + @@ -212,8 +356,8 @@ - 71 - 16 + 153 + 0 diff --git a/windows/sound.cpp b/windows/sound.cpp index 421bde3b..5d2fa948 100755 --- a/windows/sound.cpp +++ b/windows/sound.cpp @@ -231,8 +231,6 @@ QString CSound::CheckDeviceCapabilities() } // check the number of available channels - long lNumInChan; - long lNumOutChan; ASIOGetChannels ( &lNumInChan, &lNumOutChan ); if ( ( lNumInChan < NUM_IN_OUT_CHANNELS ) || ( lNumOutChan < NUM_IN_OUT_CHANNELS ) ) @@ -298,10 +296,50 @@ QString CSound::CheckDeviceCapabilities() } } + // the device has changed, per definition we reset the channel + // mapping to the defaults (first two available channels) + ResetChannelMapping(); + // everything is ok, return empty string for "no error" case return ""; } +void CSound::SetLeftInputChannel ( const int iNewChan ) +{ + // apply parameter after input parameter check + if ( ( iNewChan >= 0 ) && ( iNewChan < lNumInChan ) ) + { + vSelectedInputChannels[0] = iNewChan; + } +} + +void CSound::SetRightInputChannel ( const int iNewChan ) +{ + // apply parameter after input parameter check + if ( ( iNewChan >= 0 ) && ( iNewChan < lNumInChan ) ) + { + vSelectedInputChannels[1] = iNewChan; + } +} + +void CSound::SetLeftOutputChannel ( const int iNewChan ) +{ + // apply parameter after input parameter check + if ( ( iNewChan >= 0 ) && ( iNewChan < lNumOutChan ) ) + { + vSelectedOutputChannels[0] = iNewChan; + } +} + +void CSound::SetRightOutputChannel ( const int iNewChan ) +{ + // apply parameter after input parameter check + if ( ( iNewChan >= 0 ) && ( iNewChan < lNumOutChan ) ) + { + vSelectedOutputChannels[1] = iNewChan; + } +} + int CSound::GetActualBufferSize ( const int iDesiredBufferSizeMono ) { int iActualBufferSizeMono; @@ -485,7 +523,9 @@ void CSound::Stop() CSound::CSound ( void (*fpNewCallback) ( CVector& psData, void* arg ), void* arg ) : CSoundBase ( true, fpNewCallback, arg ), vSelectedInputChannels ( NUM_IN_OUT_CHANNELS ), - vSelectedOutputChannels ( NUM_IN_OUT_CHANNELS ) + vSelectedOutputChannels ( NUM_IN_OUT_CHANNELS ), + lNumInChan ( 0 ), + lNumOutChan ( 0 ) { int i; @@ -517,12 +557,8 @@ CSound::CSound ( void (*fpNewCallback) ( CVector& psData, void* arg ), // init device index with illegal value to show that driver is not initialized lCurDev = -1; - // init selected channel numbers with defaults: use first available - // channels for input and output - vSelectedInputChannels[0] = 0; - vSelectedInputChannels[1] = 1; - vSelectedOutputChannels[0] = 0; - vSelectedOutputChannels[1] = 1; + // init channel mapping + ResetChannelMapping(); // set up the asioCallback structure asioCallbacks.bufferSwitch = &bufferSwitch; @@ -531,6 +567,16 @@ CSound::CSound ( void (*fpNewCallback) ( CVector& psData, void* arg ), asioCallbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfo; } +void CSound::ResetChannelMapping() +{ + // init selected channel numbers with defaults: use first available + // channels for input and output + vSelectedInputChannels[0] = 0; + vSelectedInputChannels[1] = 1; + vSelectedOutputChannels[0] = 0; + vSelectedOutputChannels[1] = 1; +} + CSound::~CSound() { // cleanup ASIO stuff diff --git a/windows/sound.h b/windows/sound.h index f20c6568..13c2b06f 100755 --- a/windows/sound.h +++ b/windows/sound.h @@ -63,22 +63,40 @@ public: virtual void OpenDriverSetup() { ASIOControlPanel(); } + // device selection int GetNumDev() { return lNumDevs; } QString GetDeviceName ( const int iDiD ) { return cDriverNames[iDiD]; } - QString SetDev ( const int iNewDev ); int GetDev() { return lCurDev; } + // channel selection + int GetNumInputChannels() { return static_cast ( lNumInChan ); } + QString GetInputChannelName ( const int iDiD ) { return channelInfosInput[iDiD].name; } + void SetLeftInputChannel ( const int iNewChan ); + void SetRightInputChannel ( const int iNewChan ); + int GetLeftInputChannel() { return vSelectedInputChannels[0]; } + int GetRightInputChannel() { return vSelectedInputChannels[1]; } + + int GetNumOutputChannels() { return static_cast ( lNumOutChan ); } + QString GetOutputChannelName ( const int iDiD ) { return channelInfosOutput[iDiD].name; } + void SetLeftOutputChannel ( const int iNewChan ); + void SetRightOutputChannel ( const int iNewChan ); + int GetLeftOutputChannel() { return vSelectedOutputChannels[0]; } + int GetRightOutputChannel() { return vSelectedOutputChannels[1]; } + protected: QVector LoadAndInitializeFirstValidDriver(); QString LoadAndInitializeDriver ( int iIdx ); int GetActualBufferSize ( const int iDesiredBufferSizeMono ); QString CheckDeviceCapabilities(); bool CheckSampleTypeSupported ( const ASIOSampleType SamType ); + void ResetChannelMapping(); int iASIOBufferSizeMono; int iASIOBufferSizeStereo; + long lNumInChan; + long lNumOutChan; CVector vSelectedInputChannels; CVector vSelectedOutputChannels;