some fixes

This commit is contained in:
Volker Fischer 2008-07-12 23:33:27 +00:00
parent 2cf4e4f285
commit d0e6f9985a
3 changed files with 295 additions and 131 deletions

View file

@ -210,11 +210,6 @@ void CClient::run()
PostWinMessage ( MS_SOUND_IN, MUL_COL_LED_GREEN ); PostWinMessage ( MS_SOUND_IN, MUL_COL_LED_GREEN );
} }
// TEST
//Sleep(300);
//wait(3000);
// copy data from one stereo buffer in two separate buffers // copy data from one stereo buffer in two separate buffers
iInCnt = 0; iInCnt = 0;
for ( i = 0; i < iSndCrdBlockSizeSam; i++ ) for ( i = 0; i < iSndCrdBlockSizeSam; i++ )

View file

@ -19,24 +19,42 @@
<bool>true</bool> <bool>true</bool>
</property> </property>
<layout class="QHBoxLayout" > <layout class="QHBoxLayout" >
<property name="margin" >
<number>9</number>
</property>
<property name="spacing" > <property name="spacing" >
<number>6</number> <number>6</number>
</property> </property>
<property name="leftMargin" >
<number>9</number>
</property>
<property name="topMargin" >
<number>9</number>
</property>
<property name="rightMargin" >
<number>9</number>
</property>
<property name="bottomMargin" >
<number>9</number>
</property>
<item> <item>
<widget class="QGroupBox" name="GroupBoxJitterBuffer" > <widget class="QGroupBox" name="GroupBoxJitterBuffer" >
<property name="title" > <property name="title" >
<string>Jitter Buffer</string> <string>Jitter Buffer</string>
</property> </property>
<layout class="QVBoxLayout" > <layout class="QVBoxLayout" >
<property name="margin" >
<number>9</number>
</property>
<property name="spacing" > <property name="spacing" >
<number>6</number> <number>6</number>
</property> </property>
<property name="leftMargin" >
<number>9</number>
</property>
<property name="topMargin" >
<number>9</number>
</property>
<property name="rightMargin" >
<number>9</number>
</property>
<property name="bottomMargin" >
<number>9</number>
</property>
<item> <item>
<widget class="QLabel" name="TextNetBuf" > <widget class="QLabel" name="TextNetBuf" >
<property name="minimumSize" > <property name="minimumSize" >
@ -58,12 +76,21 @@
</item> </item>
<item> <item>
<layout class="QHBoxLayout" > <layout class="QHBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" > <property name="spacing" >
<number>6</number> <number>6</number>
</property> </property>
<property name="leftMargin" >
<number>0</number>
</property>
<property name="topMargin" >
<number>0</number>
</property>
<property name="rightMargin" >
<number>0</number>
</property>
<property name="bottomMargin" >
<number>0</number>
</property>
<item> <item>
<spacer> <spacer>
<property name="orientation" > <property name="orientation" >
@ -120,18 +147,25 @@
</item> </item>
<item> <item>
<layout class="QHBoxLayout" > <layout class="QHBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" > <property name="spacing" >
<number>6</number> <number>6</number>
</property> </property>
<property name="leftMargin" >
<number>0</number>
</property>
<property name="topMargin" >
<number>0</number>
</property>
<property name="rightMargin" >
<number>0</number>
</property>
<property name="bottomMargin" >
<number>0</number>
</property>
<item> <item>
<widget class="CMultiColorLED" native="1" name="CLEDNetwPut" > <widget class="CMultiColorLED" native="1" name="CLEDNetwPut" >
<property name="sizePolicy" > <property name="sizePolicy" >
<sizepolicy> <sizepolicy vsizetype="Fixed" hsizetype="Fixed" >
<hsizetype>0</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
@ -153,9 +187,7 @@
<item> <item>
<widget class="CMultiColorLED" native="1" name="CLEDNetwGet" > <widget class="CMultiColorLED" native="1" name="CLEDNetwGet" >
<property name="sizePolicy" > <property name="sizePolicy" >
<sizepolicy> <sizepolicy vsizetype="Fixed" hsizetype="Fixed" >
<hsizetype>0</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
@ -185,12 +217,21 @@
<string>Block Size</string> <string>Block Size</string>
</property> </property>
<layout class="QVBoxLayout" > <layout class="QVBoxLayout" >
<property name="margin" >
<number>9</number>
</property>
<property name="spacing" > <property name="spacing" >
<number>6</number> <number>6</number>
</property> </property>
<property name="leftMargin" >
<number>9</number>
</property>
<property name="topMargin" >
<number>9</number>
</property>
<property name="rightMargin" >
<number>9</number>
</property>
<property name="bottomMargin" >
<number>9</number>
</property>
<item> <item>
<widget class="QLabel" name="TextNetBufSiFactIn" > <widget class="QLabel" name="TextNetBufSiFactIn" >
<property name="minimumSize" > <property name="minimumSize" >
@ -212,12 +253,21 @@
</item> </item>
<item> <item>
<layout class="QHBoxLayout" > <layout class="QHBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" > <property name="spacing" >
<number>6</number> <number>6</number>
</property> </property>
<property name="leftMargin" >
<number>0</number>
</property>
<property name="topMargin" >
<number>0</number>
</property>
<property name="rightMargin" >
<number>0</number>
</property>
<property name="bottomMargin" >
<number>0</number>
</property>
<item> <item>
<spacer> <spacer>
<property name="orientation" > <property name="orientation" >
@ -274,12 +324,21 @@
</item> </item>
<item> <item>
<layout class="QHBoxLayout" > <layout class="QHBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" > <property name="spacing" >
<number>6</number> <number>6</number>
</property> </property>
<property name="leftMargin" >
<number>0</number>
</property>
<property name="topMargin" >
<number>0</number>
</property>
<property name="rightMargin" >
<number>0</number>
</property>
<property name="bottomMargin" >
<number>0</number>
</property>
<item> <item>
<spacer> <spacer>
<property name="orientation" > <property name="orientation" >
@ -356,34 +415,59 @@
<string>Sndcard Buffers</string> <string>Sndcard Buffers</string>
</property> </property>
<layout class="QVBoxLayout" > <layout class="QVBoxLayout" >
<property name="margin" >
<number>9</number>
</property>
<property name="spacing" > <property name="spacing" >
<number>6</number> <number>6</number>
</property> </property>
<property name="leftMargin" >
<number>9</number>
</property>
<property name="topMargin" >
<number>9</number>
</property>
<property name="rightMargin" >
<number>9</number>
</property>
<property name="bottomMargin" >
<number>9</number>
</property>
<item> <item>
<layout class="QHBoxLayout" > <layout class="QHBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" > <property name="spacing" >
<number>6</number> <number>6</number>
</property> </property>
<property name="leftMargin" >
<number>0</number>
</property>
<property name="topMargin" >
<number>0</number>
</property>
<property name="rightMargin" >
<number>0</number>
</property>
<property name="bottomMargin" >
<number>0</number>
</property>
<item> <item>
<layout class="QVBoxLayout" > <layout class="QVBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" > <property name="spacing" >
<number>6</number> <number>6</number>
</property> </property>
<property name="leftMargin" >
<number>0</number>
</property>
<property name="topMargin" >
<number>0</number>
</property>
<property name="rightMargin" >
<number>0</number>
</property>
<property name="bottomMargin" >
<number>0</number>
</property>
<item> <item>
<widget class="QLabel" name="TextSndBufOut" > <widget class="QLabel" name="TextSndBufOut" >
<property name="sizePolicy" > <property name="sizePolicy" >
<sizepolicy> <sizepolicy vsizetype="Minimum" hsizetype="MinimumExpanding" >
<hsizetype>3</hsizetype>
<vsizetype>1</vsizetype>
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
@ -407,12 +491,21 @@
</item> </item>
<item> <item>
<layout class="QHBoxLayout" > <layout class="QHBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" > <property name="spacing" >
<number>6</number> <number>6</number>
</property> </property>
<property name="leftMargin" >
<number>0</number>
</property>
<property name="topMargin" >
<number>0</number>
</property>
<property name="rightMargin" >
<number>0</number>
</property>
<property name="bottomMargin" >
<number>0</number>
</property>
<item> <item>
<spacer> <spacer>
<property name="orientation" > <property name="orientation" >
@ -458,18 +551,25 @@
</item> </item>
<item> <item>
<layout class="QVBoxLayout" > <layout class="QVBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" > <property name="spacing" >
<number>6</number> <number>6</number>
</property> </property>
<property name="leftMargin" >
<number>0</number>
</property>
<property name="topMargin" >
<number>0</number>
</property>
<property name="rightMargin" >
<number>0</number>
</property>
<property name="bottomMargin" >
<number>0</number>
</property>
<item> <item>
<widget class="QLabel" name="TextSndBufIn" > <widget class="QLabel" name="TextSndBufIn" >
<property name="sizePolicy" > <property name="sizePolicy" >
<sizepolicy> <sizepolicy vsizetype="Minimum" hsizetype="MinimumExpanding" >
<hsizetype>3</hsizetype>
<vsizetype>1</vsizetype>
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
@ -493,12 +593,21 @@
</item> </item>
<item> <item>
<layout class="QHBoxLayout" > <layout class="QHBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" > <property name="spacing" >
<number>6</number> <number>6</number>
</property> </property>
<property name="leftMargin" >
<number>0</number>
</property>
<property name="topMargin" >
<number>0</number>
</property>
<property name="rightMargin" >
<number>0</number>
</property>
<property name="bottomMargin" >
<number>0</number>
</property>
<item> <item>
<spacer> <spacer>
<property name="orientation" > <property name="orientation" >
@ -547,7 +656,7 @@
<item> <item>
<widget class="QLabel" name="TextLabel1" > <widget class="QLabel" name="TextLabel1" >
<property name="text" > <property name="text" >
<string>In / Out:</string> <string>Out / In:</string>
</property> </property>
<property name="alignment" > <property name="alignment" >
<set>Qt::AlignCenter</set> <set>Qt::AlignCenter</set>
@ -559,18 +668,25 @@
</item> </item>
<item> <item>
<layout class="QHBoxLayout" > <layout class="QHBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" > <property name="spacing" >
<number>6</number> <number>6</number>
</property> </property>
<property name="leftMargin" >
<number>0</number>
</property>
<property name="topMargin" >
<number>0</number>
</property>
<property name="rightMargin" >
<number>0</number>
</property>
<property name="bottomMargin" >
<number>0</number>
</property>
<item> <item>
<widget class="CMultiColorLED" native="1" name="CLEDSoundIn" > <widget class="CMultiColorLED" native="1" name="CLEDSoundOut" >
<property name="sizePolicy" > <property name="sizePolicy" >
<sizepolicy> <sizepolicy vsizetype="Fixed" hsizetype="Fixed" >
<hsizetype>0</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
@ -590,11 +706,9 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="CMultiColorLED" native="1" name="CLEDSoundOut" > <widget class="CMultiColorLED" native="1" name="CLEDSoundIn" >
<property name="sizePolicy" > <property name="sizePolicy" >
<sizepolicy> <sizepolicy vsizetype="Fixed" hsizetype="Fixed" >
<hsizetype>0</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
@ -624,20 +738,38 @@
<string>Debug</string> <string>Debug</string>
</property> </property>
<layout class="QVBoxLayout" > <layout class="QVBoxLayout" >
<property name="margin" >
<number>9</number>
</property>
<property name="spacing" > <property name="spacing" >
<number>6</number> <number>6</number>
</property> </property>
<property name="leftMargin" >
<number>9</number>
</property>
<property name="topMargin" >
<number>9</number>
</property>
<property name="rightMargin" >
<number>9</number>
</property>
<property name="bottomMargin" >
<number>9</number>
</property>
<item> <item>
<layout class="QHBoxLayout" > <layout class="QHBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" > <property name="spacing" >
<number>6</number> <number>6</number>
</property> </property>
<property name="leftMargin" >
<number>0</number>
</property>
<property name="topMargin" >
<number>0</number>
</property>
<property name="rightMargin" >
<number>0</number>
</property>
<property name="bottomMargin" >
<number>0</number>
</property>
<item> <item>
<widget class="QLabel" name="TextLabelStdDevTimerLabel" > <widget class="QLabel" name="TextLabelStdDevTimerLabel" >
<property name="text" > <property name="text" >
@ -662,12 +794,21 @@
</item> </item>
<item> <item>
<layout class="QHBoxLayout" > <layout class="QHBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" > <property name="spacing" >
<number>6</number> <number>6</number>
</property> </property>
<property name="leftMargin" >
<number>0</number>
</property>
<property name="topMargin" >
<number>0</number>
</property>
<property name="rightMargin" >
<number>0</number>
</property>
<property name="bottomMargin" >
<number>0</number>
</property>
<item> <item>
<widget class="QLabel" name="TextLabel1_2" > <widget class="QLabel" name="TextLabel1_2" >
<property name="text" > <property name="text" >
@ -681,9 +822,7 @@
<item> <item>
<widget class="CMultiColorLED" native="1" name="CLEDProtocolStatus" > <widget class="CMultiColorLED" native="1" name="CLEDProtocolStatus" >
<property name="sizePolicy" > <property name="sizePolicy" >
<sizepolicy> <sizepolicy vsizetype="Fixed" hsizetype="Fixed" >
<hsizetype>0</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>

View file

@ -49,7 +49,8 @@ ASIOBufferInfo bufferInfos[2 * NUM_IN_OUT_CHANNELS]; // for input and output b
ASIOChannelInfo channelInfos[2 * NUM_IN_OUT_CHANNELS]; ASIOChannelInfo channelInfos[2 * NUM_IN_OUT_CHANNELS];
bool bASIOPostOutput; bool bASIOPostOutput;
ASIOCallbacks asioCallbacks; ASIOCallbacks asioCallbacks;
int iBufferSize; int iBufferSizeMono;
int iBufferSizeStereo;
// event // event
HANDLE m_ASIOEvent; HANDLE m_ASIOEvent;
@ -81,8 +82,8 @@ bool CSound::Read ( CVector<short>& psData )
// check if device must be opened or reinitialized // check if device must be opened or reinitialized
if ( bChangParamIn ) if ( bChangParamIn )
{ {
// Reinit sound interface // Reinit sound interface (init recording requires stereo buffer size)
InitRecordingAndPlayback ( iBufferSize ); InitRecordingAndPlayback ( iBufferSizeStereo );
// Reset flag // Reset flag
bChangParamIn = false; bChangParamIn = false;
@ -108,7 +109,7 @@ bool CSound::Read ( CVector<short>& psData )
ASIOMutex.lock(); // get mutex lock ASIOMutex.lock(); // get mutex lock
{ {
// copy data from sound card in output buffer // copy data from sound card in output buffer
for ( i = 0; i < iBufferSize; i++ ) for ( i = 0; i < iBufferSizeStereo; i++ )
{ {
psData[i] = psSoundcardBuffer[0][i]; psData[i] = psSoundcardBuffer[0][i];
} }
@ -116,7 +117,7 @@ bool CSound::Read ( CVector<short>& psData )
// move all other data in buffer // move all other data in buffer
for ( j = 0; j < iInCurBlockToWrite - 1; j++ ) for ( j = 0; j < iInCurBlockToWrite - 1; j++ )
{ {
for ( i = 0; i < iBufferSize; i++ ) for ( i = 0; i < iBufferSizeStereo; i++ )
{ {
psSoundcardBuffer[j][i] = psSoundcardBuffer[j + 1][i]; psSoundcardBuffer[j][i] = psSoundcardBuffer[j + 1][i];
} }
@ -161,8 +162,8 @@ bool CSound::Write ( CVector<short>& psData )
// check if device must be opened or reinitialized // check if device must be opened or reinitialized
if ( bChangParamOut ) if ( bChangParamOut )
{ {
// reinit sound interface // reinit sound interface (init recording requires stereo buffer size)
InitRecordingAndPlayback ( iBufferSize ); InitRecordingAndPlayback ( iBufferSizeStereo );
// reset flag // reset flag
bChangParamOut = false; bChangParamOut = false;
@ -174,7 +175,7 @@ bool CSound::Write ( CVector<short>& psData )
if ( iOutCurBlockToWrite < iCurNumSndBufOut ) if ( iOutCurBlockToWrite < iCurNumSndBufOut )
{ {
// copy stereo data from input in soundcard buffer // copy stereo data from input in soundcard buffer
for ( int i = 0; i < iBufferSize; i++ ) for ( int i = 0; i < iBufferSizeStereo; i++ )
{ {
psPlaybackBuffer[iOutCurBlockToWrite][i] = psData[i]; psPlaybackBuffer[iOutCurBlockToWrite][i] = psData[i];
} }
@ -222,17 +223,20 @@ void CSound::InitRecordingAndPlayback ( int iNewBufferSize )
ASIOMutex.lock(); // get mutex lock ASIOMutex.lock(); // get mutex lock
{ {
// we need mono buffer size but get stereo buffer size
const int iNewBufferSizeMono = iNewBufferSize / 2;
// calculate "nearest" buffer size and set internal parameter accordingly // calculate "nearest" buffer size and set internal parameter accordingly
// first check minimum and maximum values // first check minimum and maximum values
if ( iNewBufferSize < HWBufferInfo.lMinSize ) if ( iNewBufferSizeMono < HWBufferInfo.lMinSize )
{ {
iBufferSize = HWBufferInfo.lMinSize; iBufferSizeMono = HWBufferInfo.lMinSize;
} }
else else
{ {
if ( iNewBufferSize > HWBufferInfo.lMaxSize ) if ( iNewBufferSizeMono > HWBufferInfo.lMaxSize )
{ {
iBufferSize = HWBufferInfo.lMaxSize; iBufferSizeMono = HWBufferInfo.lMaxSize;
} }
else else
{ {
@ -244,17 +248,17 @@ void CSound::InitRecordingAndPlayback ( int iNewBufferSize )
// test loop // test loop
while ( ( iTrialBufSize <= HWBufferInfo.lMaxSize ) && ( !bSizeFound ) ) while ( ( iTrialBufSize <= HWBufferInfo.lMaxSize ) && ( !bSizeFound ) )
{ {
if ( iTrialBufSize > iNewBufferSize ) if ( iTrialBufSize > iNewBufferSizeMono )
{ {
// test which buffer size fits better: the old one or the // test which buffer size fits better: the old one or the
// current one // current one
if ( ( iTrialBufSize - iNewBufferSize ) < ( iNewBufferSize - iLastTrialBufSize ) ) if ( ( iTrialBufSize - iNewBufferSizeMono ) < ( iNewBufferSizeMono - iLastTrialBufSize ) )
{ {
iBufferSize = iTrialBufSize; iBufferSizeMono = iTrialBufSize;
} }
else else
{ {
iBufferSize = iLastTrialBufSize; iBufferSizeMono = iLastTrialBufSize;
} }
// exit while loop // exit while loop
@ -278,9 +282,19 @@ void CSound::InitRecordingAndPlayback ( int iNewBufferSize )
} }
} }
// create and activate ASIO buffers // calculate stereo buffer size
iBufferSizeStereo = 2 * iBufferSizeMono;
// TEST test if requested buffer size is supported by the audio hardware, if not, fire error
if ( iNewBufferSize != iBufferSizeStereo )
{
throw CGenErr ( "Required sound card buffer size not allowed by the audio hardware." );
}
// create and activate ASIO buffers (buffer size in samples)
ASIOCreateBuffers ( bufferInfos, 2 * NUM_IN_OUT_CHANNELS, ASIOCreateBuffers ( bufferInfos, 2 * NUM_IN_OUT_CHANNELS,
iBufferSize * BYTES_PER_SAMPLE, &asioCallbacks ); iBufferSizeMono, &asioCallbacks );
// now set all the buffer details // now set all the buffer details
for ( i = 0; i < 2 * NUM_IN_OUT_CHANNELS; i++ ) for ( i = 0; i < 2 * NUM_IN_OUT_CHANNELS; i++ )
@ -309,7 +323,7 @@ void CSound::InitRecordingAndPlayback ( int iNewBufferSize )
delete[] psSoundcardBuffer[i]; delete[] psSoundcardBuffer[i];
} }
psSoundcardBuffer[i] = new short[iBufferSize]; psSoundcardBuffer[i] = new short[iBufferSizeStereo];
} }
// initialize write block pointer out // initialize write block pointer out
@ -323,10 +337,10 @@ void CSound::InitRecordingAndPlayback ( int iNewBufferSize )
delete[] psPlaybackBuffer[j]; delete[] psPlaybackBuffer[j];
} }
psPlaybackBuffer[j] = new short[iBufferSize]; psPlaybackBuffer[j] = new short[iBufferSizeStereo];
// clear new buffer // clear new buffer
for ( i = 0; i < iBufferSize; i++ ) for ( i = 0; i < iBufferSizeStereo; i++ )
{ {
psPlaybackBuffer[j][i] = 0; psPlaybackBuffer[j][i] = 0;
} }
@ -352,6 +366,10 @@ void CSound::Close()
// wait for the thread to terminate // wait for the thread to terminate
Sleep ( 500 ); Sleep ( 500 );
// stop audio and dispose ASIO buffers
ASIOStop();
ASIODisposeBuffers();
// set flag to open devices the next time it is initialized // set flag to open devices the next time it is initialized
bChangParamIn = true; bChangParamIn = true;
bChangParamOut = true; bChangParamOut = true;
@ -540,55 +558,67 @@ void CSound::bufferSwitch ( long index, ASIOBool processNow )
{ {
if ( bufferInfos[i].isInput == false ) if ( bufferInfos[i].isInput == false )
{ {
// PLAYBACK -------------------------------------------------------- // PLAYBACK ----------------------------------------------------
if ( iOutCurBlockToWrite > 0 ) if ( iOutCurBlockToWrite > 0 )
{ {
// copy data from sound card in output buffer // copy data from sound card in output buffer
for ( iCurSample = 0; iCurSample < iBufferSize; iCurSample++ ) for ( iCurSample = 0; iCurSample < iBufferSizeMono; iCurSample++ )
{ {
((short*) bufferInfos[i].buffers[index])[iCurSample] = // copy interleaved stereo data in mono sound card buffer
psSoundcardBuffer[0][iCurSample]; ((short*) bufferInfos[i].buffers[index])[iCurSample] =
psSoundcardBuffer[0][2 * iCurSample + bufferInfos[i].channelNum];
} }
// move all other data in buffer
for ( int j = 0; j < iOutCurBlockToWrite - 1; j++ )
{
for ( iCurSample = 0; iCurSample < iBufferSize; iCurSample++ )
{
psPlaybackBuffer[j][iCurSample] =
psPlaybackBuffer[j + 1][iCurSample];
}
}
// adjust "current block to write" pointer
iOutCurBlockToWrite--;
}
else
{
// TODO: buffer underrun, inform user somehow...?
} }
} }
else else
{ {
// CAPTURE --------------------------------------------------------- // CAPTURE -----------------------------------------------------
// first check if buffer is available // first check if buffer is available
if ( iInCurBlockToWrite < iCurNumSndBufIn ) if ( iInCurBlockToWrite < iCurNumSndBufIn )
{ {
// copy new captured block in thread transfer buffer // copy new captured block in thread transfer buffer
for ( iCurSample = 0; iCurSample < iBufferSize; iCurSample++ ) for ( iCurSample = 0; iCurSample < iBufferSizeMono; iCurSample++ )
{ {
psSoundcardBuffer[iInCurBlockToWrite][iCurSample] = // copy mono data interleaved in stereo buffer
psSoundcardBuffer[iInCurBlockToWrite][2 * iCurSample + bufferInfos[i].channelNum] =
((short*) bufferInfos[i].buffers[index])[iCurSample]; ((short*) bufferInfos[i].buffers[index])[iCurSample];
} }
iInCurBlockToWrite++;
}
else
{
// TODO: buffer overrun, inform user somehow...?
} }
} }
} }
// Manage thread interface buffers for input and output ----------------
// capture
if ( iInCurBlockToWrite < iCurNumSndBufIn )
{
iInCurBlockToWrite++;
}
else
{
// TODO: buffer overrun, inform user somehow...?
}
// playback
if ( iOutCurBlockToWrite > 0 )
{
// move all other data in playback buffer
for ( int j = 0; j < iOutCurBlockToWrite - 1; j++ )
{
for ( iCurSample = 0; iCurSample < iBufferSizeStereo; iCurSample++ )
{
psPlaybackBuffer[j][iCurSample] =
psPlaybackBuffer[j + 1][iCurSample];
}
}
// adjust "current block to write" pointer
iOutCurBlockToWrite--;
}
else
{
// TODO: buffer underrun, inform user somehow...?
}
} }
ASIOMutex.unlock(); ASIOMutex.unlock();