some more ASIO stuff
This commit is contained in:
parent
ceacfd9a13
commit
2d368f6ace
2 changed files with 67 additions and 12 deletions
|
@ -327,12 +327,62 @@ void CSound::InitRecordingAndPlayback ( int iNewBufferSize )
|
||||||
// first, stop audio
|
// first, stop audio
|
||||||
ASIOStop();
|
ASIOStop();
|
||||||
|
|
||||||
// set internal parameters
|
// calculate "nearest" buffer size and set internal parameter accordingly
|
||||||
iBufferSize = iNewBufferSize;
|
// first check minimum and maximum values
|
||||||
|
if ( iNewBufferSize < HWBufferInfo.lMinSize )
|
||||||
|
{
|
||||||
|
iBufferSize = HWBufferInfo.lMinSize;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if ( iNewBufferSize > HWBufferInfo.lMaxSize )
|
||||||
|
{
|
||||||
|
iBufferSize = HWBufferInfo.lMaxSize;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// initialization
|
||||||
|
int iTrialBufSize = HWBufferInfo.lMinSize;
|
||||||
|
int iLastTrialBufSize = HWBufferInfo.lMinSize;
|
||||||
|
bool bSizeFound = false;
|
||||||
|
|
||||||
|
// test loop
|
||||||
|
while ( ( iTrialBufSize <= HWBufferInfo.lMaxSize ) && ( !bSizeFound ) )
|
||||||
|
{
|
||||||
|
if ( iTrialBufSize > iNewBufferSize )
|
||||||
|
{
|
||||||
|
// test which buffer size fits better: the old one or the
|
||||||
|
// current one
|
||||||
|
if ( ( iTrialBufSize - iNewBufferSize ) < ( iNewBufferSize - iLastTrialBufSize ) )
|
||||||
|
{
|
||||||
|
iBufferSize = iTrialBufSize;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
iBufferSize = iLastTrialBufSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
// exit while loop
|
||||||
|
bSizeFound = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// store old trial buffer size
|
||||||
|
iLastTrialBufSize = iTrialBufSize;
|
||||||
|
|
||||||
|
// increment trial buffer size (check for special case first)
|
||||||
|
if ( HWBufferInfo.lGranularity == -1 )
|
||||||
|
{
|
||||||
|
// special case: buffer sizes are a power of 2
|
||||||
|
iTrialBufSize *= 2;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
iTrialBufSize += HWBufferInfo.lGranularity;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TODO this should be done in the setinoutbuf functions
|
|
||||||
// create and activate buffers
|
// create and activate buffers
|
||||||
ASIOCreateBuffers(bufferInfos, 2 * NUM_IN_OUT_CHANNELS,
|
ASIOCreateBuffers(bufferInfos, 2 * NUM_IN_OUT_CHANNELS,
|
||||||
iBufferSize * BYTES_PER_SAMPLE, &asioCallbacks);
|
iBufferSize * BYTES_PER_SAMPLE, &asioCallbacks);
|
||||||
|
@ -527,15 +577,11 @@ pstrDevices[0] = driverInfo.name;
|
||||||
throw CGenErr ( "The audio device does not support required number of channels." );
|
throw CGenErr ( "The audio device does not support required number of channels." );
|
||||||
}
|
}
|
||||||
|
|
||||||
// check the usable buffer sizes
|
// query the usable buffer sizes
|
||||||
long lMinSize;
|
ASIOGetBufferSize ( &HWBufferInfo.lMinSize,
|
||||||
long lMaxSize;
|
&HWBufferInfo.lMaxSize,
|
||||||
long lPreferredSize;
|
&HWBufferInfo.lPreferredSize,
|
||||||
long lGranularity;
|
&HWBufferInfo.lGranularity );
|
||||||
ASIOGetBufferSize ( &lMinSize, &lMaxSize, &lPreferredSize, &lGranularity );
|
|
||||||
|
|
||||||
// TODO make use of the information...
|
|
||||||
|
|
||||||
|
|
||||||
// set the sample rate and check if sample rate is supported
|
// set the sample rate and check if sample rate is supported
|
||||||
ASIOSetSampleRate ( SND_CRD_SAMPLE_RATE );
|
ASIOSetSampleRate ( SND_CRD_SAMPLE_RATE );
|
||||||
|
|
|
@ -104,6 +104,15 @@ protected:
|
||||||
bool bASIOPostOutput;
|
bool bASIOPostOutput;
|
||||||
ASIOCallbacks asioCallbacks;
|
ASIOCallbacks asioCallbacks;
|
||||||
|
|
||||||
|
// audio hardware buffer info
|
||||||
|
struct sHWBufferInfo
|
||||||
|
{
|
||||||
|
long lMinSize;
|
||||||
|
long lMaxSize;
|
||||||
|
long lPreferredSize;
|
||||||
|
long lGranularity;
|
||||||
|
} HWBufferInfo;
|
||||||
|
|
||||||
// callbacks
|
// callbacks
|
||||||
static void bufferSwitch ( long index, ASIOBool processNow );
|
static void bufferSwitch ( long index, ASIOBool processNow );
|
||||||
static ASIOTime* bufferSwitchTimeInfo ( ASIOTime *timeInfo, long index, ASIOBool processNow );
|
static ASIOTime* bufferSwitchTimeInfo ( ASIOTime *timeInfo, long index, ASIOBool processNow );
|
||||||
|
|
Loading…
Reference in a new issue