ASIO fixes
This commit is contained in:
parent
94d6d451bc
commit
11e8dc7b3d
5 changed files with 53 additions and 24 deletions
|
@ -400,13 +400,6 @@ fflush(pFileDelay);
|
|||
const double dCurAddVal =
|
||||
( (double) TimeLastBlock.msecsTo ( CurTime ) - MIN_BLOCK_DURATION_MS );
|
||||
|
||||
/*
|
||||
// TEST
|
||||
static FILE* pFileTest = fopen("sti.dat", "w");
|
||||
fprintf(pFileTest, "%e\n", dCurAddVal);
|
||||
fflush(pFileTest);
|
||||
*/
|
||||
|
||||
RespTimeMoAvBuf.Add ( dCurAddVal * dCurAddVal ); // add squared value
|
||||
|
||||
// store old time value
|
||||
|
@ -416,6 +409,9 @@ fflush(pFileTest);
|
|||
// disable channel
|
||||
Channel.SetEnable ( false );
|
||||
|
||||
// disable sound interface
|
||||
Sound.Close();
|
||||
|
||||
// reset current signal level and LEDs
|
||||
SignalLevelMeterL.Reset();
|
||||
SignalLevelMeterR.Reset();
|
||||
|
|
|
@ -36,13 +36,21 @@ CClientSettingsDlg::CClientSettingsDlg ( CClient* pNCliP, QWidget* parent,
|
|||
|
||||
// init slider controls ---
|
||||
// sound buffer in
|
||||
#ifdef _WIN32
|
||||
SliderSndBufIn->setRange ( 1, AUD_SLIDER_LENGTH ); // for ASIO we only need one buffer
|
||||
#else
|
||||
SliderSndBufIn->setRange ( 2, AUD_SLIDER_LENGTH );
|
||||
#endif
|
||||
const int iCurNumInBuf = pClient->GetSndInterface()->GetInNumBuf();
|
||||
SliderSndBufIn->setValue ( iCurNumInBuf );
|
||||
TextSndBufIn->setText ( "In: " + QString().setNum ( iCurNumInBuf ) );
|
||||
|
||||
// sound buffer out
|
||||
#ifdef _WIN32
|
||||
SliderSndBufOut->setRange ( 1, AUD_SLIDER_LENGTH ); // for ASIO we only need one buffer
|
||||
#else
|
||||
SliderSndBufOut->setRange ( 2, AUD_SLIDER_LENGTH );
|
||||
#endif
|
||||
const int iCurNumOutBuf = pClient->GetSndInterface()->GetOutNumBuf();
|
||||
SliderSndBufOut->setValue ( iCurNumOutBuf );
|
||||
TextSndBufOut->setText ( "Out: " + QString().setNum ( iCurNumOutBuf ) );
|
||||
|
|
|
@ -412,7 +412,7 @@
|
|||
<item>
|
||||
<widget class="QGroupBox" name="GroupBoxSoundCardBuffers" >
|
||||
<property name="title" >
|
||||
<string>Sndcard Buffers</string>
|
||||
<string>Soundcard Buffers</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" >
|
||||
<property name="spacing" >
|
||||
|
|
|
@ -59,13 +59,17 @@ HANDLE m_ASIOEvent;
|
|||
// wave in
|
||||
int iInCurBlockToWrite;
|
||||
short* psSoundcardBuffer[MAX_SND_BUF_IN];
|
||||
bool bBufferOverrun;
|
||||
|
||||
// wave out
|
||||
int iOutCurBlockToWrite;
|
||||
short* psPlaybackBuffer[MAX_SND_BUF_OUT];
|
||||
bool bBufferUnderrun;
|
||||
|
||||
int iCurNumSndBufIn;
|
||||
int iCurNumSndBufOut;
|
||||
int iNewNumSndBufIn;
|
||||
int iNewNumSndBufOut;
|
||||
|
||||
// we must implement these functions here to get access to global variables
|
||||
int CSound::GetOutNumBuf() { return iCurNumSndBufOut; }
|
||||
|
@ -78,7 +82,7 @@ int CSound::GetInNumBuf() { return iCurNumSndBufIn; }
|
|||
bool CSound::Read ( CVector<short>& psData )
|
||||
{
|
||||
int i, j;
|
||||
bool bError = false;
|
||||
bool bError;
|
||||
|
||||
// check if device must be opened or reinitialized
|
||||
if ( bChangParamIn )
|
||||
|
@ -103,12 +107,16 @@ bool CSound::Read ( CVector<short>& psData )
|
|||
}
|
||||
}
|
||||
|
||||
// if the number of done buffers equals the total number of buffers, it is
|
||||
// very likely that a buffer got lost -> set error flag
|
||||
bError = ( iInCurBlockToWrite == iCurNumSndBufIn );
|
||||
|
||||
ASIOMutex.lock(); // get mutex lock
|
||||
{
|
||||
// check for buffer overrun in ASIO thread
|
||||
bError = bBufferOverrun;
|
||||
if ( bBufferOverrun )
|
||||
{
|
||||
// reset flag
|
||||
bBufferOverrun = false;
|
||||
}
|
||||
|
||||
// copy data from sound card in output buffer
|
||||
for ( i = 0; i < iBufferSizeStereo; i++ )
|
||||
{
|
||||
|
@ -146,7 +154,7 @@ void CSound::SetInNumBuf ( int iNewNum )
|
|||
// change only if parameter is different
|
||||
if ( iNewNum != iCurNumSndBufIn )
|
||||
{
|
||||
iCurNumSndBufIn = iNewNum;
|
||||
iNewNumSndBufIn = iNewNum;
|
||||
bChangParamIn = true;
|
||||
}
|
||||
}
|
||||
|
@ -157,8 +165,7 @@ void CSound::SetInNumBuf ( int iNewNum )
|
|||
\******************************************************************************/
|
||||
bool CSound::Write ( CVector<short>& psData )
|
||||
{
|
||||
// init return state
|
||||
bool bError = false;
|
||||
bool bError;
|
||||
|
||||
// check if device must be opened or reinitialized
|
||||
if ( bChangParamOut )
|
||||
|
@ -172,6 +179,14 @@ bool CSound::Write ( CVector<short>& psData )
|
|||
|
||||
ASIOMutex.lock(); // get mutex lock
|
||||
{
|
||||
// check for buffer underrun in ASIO thread
|
||||
bError = bBufferUnderrun;
|
||||
if ( bBufferUnderrun )
|
||||
{
|
||||
// reset flag
|
||||
bBufferUnderrun = false;
|
||||
}
|
||||
|
||||
// first check if buffer is available
|
||||
if ( iOutCurBlockToWrite < iCurNumSndBufOut )
|
||||
{
|
||||
|
@ -205,7 +220,7 @@ void CSound::SetOutNumBuf ( int iNewNum )
|
|||
// change only if parameter is different
|
||||
if ( iNewNum != iCurNumSndBufOut )
|
||||
{
|
||||
iCurNumSndBufOut = iNewNum;
|
||||
iNewNumSndBufOut = iNewNum;
|
||||
bChangParamOut = true;
|
||||
}
|
||||
}
|
||||
|
@ -334,9 +349,14 @@ if ( iASIOBufferSizeMono != iBufferSizeMono )
|
|||
}
|
||||
|
||||
|
||||
// our buffer management -----------------------------------------------
|
||||
// initialize write block pointer in
|
||||
// Our buffer management -----------------------------------------------
|
||||
// store new buffer number values
|
||||
iCurNumSndBufIn = iNewNumSndBufIn;
|
||||
iCurNumSndBufOut = iNewNumSndBufOut;
|
||||
|
||||
// initialize write block pointer in and overrun flag
|
||||
iInCurBlockToWrite = 0;
|
||||
bBufferOverrun = false;
|
||||
|
||||
// create memory for sound card buffer
|
||||
for ( i = 0; i < iCurNumSndBufIn; i++ )
|
||||
|
@ -349,8 +369,9 @@ if ( iASIOBufferSizeMono != iBufferSizeMono )
|
|||
psSoundcardBuffer[i] = new short[iBufferSizeStereo];
|
||||
}
|
||||
|
||||
// initialize write block pointer out
|
||||
// initialize write block pointer out and underrun flag
|
||||
iOutCurBlockToWrite = 0;
|
||||
bBufferUnderrun = false;
|
||||
|
||||
// create memory for playback buffer
|
||||
for ( j = 0; j < iCurNumSndBufOut; j++ )
|
||||
|
@ -403,7 +424,9 @@ CSound::CSound()
|
|||
int i;
|
||||
|
||||
// init number of sound buffers
|
||||
iNewNumSndBufIn = NUM_SOUND_BUFFERS_IN;
|
||||
iCurNumSndBufIn = NUM_SOUND_BUFFERS_IN;
|
||||
iNewNumSndBufOut = NUM_SOUND_BUFFERS_OUT;
|
||||
iCurNumSndBufOut = NUM_SOUND_BUFFERS_OUT;
|
||||
|
||||
// should be initialized because an error can occur during init
|
||||
|
@ -616,7 +639,8 @@ void CSound::bufferSwitch ( long index, ASIOBool processNow )
|
|||
}
|
||||
else
|
||||
{
|
||||
// TODO: buffer underrun, inform user somehow...?
|
||||
// set buffer underrun flag
|
||||
bBufferUnderrun = true;
|
||||
}
|
||||
|
||||
// capture
|
||||
|
@ -626,7 +650,8 @@ void CSound::bufferSwitch ( long index, ASIOBool processNow )
|
|||
}
|
||||
else
|
||||
{
|
||||
// TODO: buffer overrun, inform user somehow...?
|
||||
// set buffer overrun flag
|
||||
bBufferOverrun = true;
|
||||
}
|
||||
|
||||
// finally if the driver supports the ASIOOutputReady() optimization,
|
||||
|
|
|
@ -47,8 +47,8 @@
|
|||
#define MAX_SND_BUF_IN 100
|
||||
#define MAX_SND_BUF_OUT 100
|
||||
|
||||
#define NUM_SOUND_BUFFERS_IN 2
|
||||
#define NUM_SOUND_BUFFERS_OUT 2
|
||||
#define NUM_SOUND_BUFFERS_IN 1
|
||||
#define NUM_SOUND_BUFFERS_OUT 1
|
||||
|
||||
// maximum number of recognized sound cards installed in the system
|
||||
#define MAX_NUMBER_SOUND_CARDS 10
|
||||
|
|
Loading…
Reference in a new issue