some more CoreAudio work
This commit is contained in:
parent
4e9e5c36f0
commit
758e72ffd5
3 changed files with 55 additions and 45 deletions
|
@ -160,7 +160,7 @@ int CSound::Init ( const int iNewPrefMonoBufferSize )
|
||||||
// get actual buffer size
|
// get actual buffer size
|
||||||
iJACKBufferSizeMono = jack_get_buffer_size ( pJackClient );
|
iJACKBufferSizeMono = jack_get_buffer_size ( pJackClient );
|
||||||
|
|
||||||
// init base clasee
|
// init base class
|
||||||
CSoundBase::Init ( iJACKBufferSizeMono );
|
CSoundBase::Init ( iJACKBufferSizeMono );
|
||||||
|
|
||||||
// set internal buffer size value and calculate stereo buffer size
|
// set internal buffer size value and calculate stereo buffer size
|
||||||
|
|
|
@ -61,33 +61,6 @@ void CSound::OpenCoreAudio()
|
||||||
{
|
{
|
||||||
throw CGenErr ( tr ( "CoreAudio audio unit set property failed" ) );
|
throw CGenErr ( tr ( "CoreAudio audio unit set property failed" ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
// set up stream format
|
|
||||||
AudioStreamBasicDescription streamFormat;
|
|
||||||
streamFormat.mSampleRate = SYSTEM_SAMPLE_RATE;
|
|
||||||
streamFormat.mFormatID = kAudioFormatLinearPCM;
|
|
||||||
streamFormat.mFormatFlags = kAudioFormatFlagIsSignedInteger;
|
|
||||||
streamFormat.mFramesPerPacket = 1;
|
|
||||||
streamFormat.mChannelsPerFrame = 1;
|
|
||||||
streamFormat.mBitsPerChannel = 16;
|
|
||||||
streamFormat.mBytesPerPacket = 2;
|
|
||||||
streamFormat.mBytesPerFrame = 2;
|
|
||||||
|
|
||||||
if ( AudioUnitSetProperty ( gOutputUnit,
|
|
||||||
kAudioUnitProperty_StreamFormat,
|
|
||||||
kAudioUnitScope_Input,
|
|
||||||
0,
|
|
||||||
&streamFormat,
|
|
||||||
sizeof(streamFormat) ) )
|
|
||||||
{
|
|
||||||
throw CGenErr ( tr ( "CoreAudio stream format set property failed" ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
// initialize unit
|
|
||||||
if ( AudioUnitInitialize ( gOutputUnit ) )
|
|
||||||
{
|
|
||||||
throw CGenErr ( tr ( "Initialization of CoreAudio failed" ) );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSound::CloseCoreAudio()
|
void CSound::CloseCoreAudio()
|
||||||
|
@ -117,31 +90,49 @@ void CSound::Stop()
|
||||||
|
|
||||||
int CSound::Init ( const int iNewPrefMonoBufferSize )
|
int CSound::Init ( const int iNewPrefMonoBufferSize )
|
||||||
{
|
{
|
||||||
|
// store buffer size
|
||||||
|
iCoreAudioBufferSizeMono = iNewPrefMonoBufferSize;
|
||||||
|
|
||||||
/*
|
// first uninitialize unit
|
||||||
// try setting buffer size
|
AudioUnitUninitialize ( gOutputUnit );
|
||||||
// TODO seems not to work! -> no audio after this operation!
|
|
||||||
//jack_set_buffer_size ( pJackClient, iNewPrefMonoBufferSize );
|
|
||||||
|
|
||||||
// get actual buffer size
|
// set up stream format
|
||||||
iJACKBufferSizeMono = jack_get_buffer_size ( pJackClient );
|
AudioStreamBasicDescription streamFormat;
|
||||||
|
streamFormat.mSampleRate = SYSTEM_SAMPLE_RATE;
|
||||||
|
streamFormat.mFormatID = kAudioFormatLinearPCM;
|
||||||
|
streamFormat.mFormatFlags = kAudioFormatFlagIsSignedInteger;
|
||||||
|
streamFormat.mFramesPerPacket = iCoreAudioBufferSizeMono;
|
||||||
|
streamFormat.mBytesPerFrame = streamFormat.mChannelsPerFrame * 2; // short type
|
||||||
|
streamFormat.mBytesPerPacket = streamFormat.mBytesPerFrame * streamFormat.mFramesPerPacket;
|
||||||
|
streamFormat.mChannelsPerFrame = 2; // stereo
|
||||||
|
streamFormat.mBitsPerChannel = 16;
|
||||||
|
|
||||||
// init base clasee
|
if ( AudioUnitSetProperty ( gOutputUnit,
|
||||||
CSoundBase::Init ( iJACKBufferSizeMono );
|
kAudioUnitProperty_StreamFormat,
|
||||||
|
kAudioUnitScope_Input,
|
||||||
|
0,
|
||||||
|
&streamFormat,
|
||||||
|
sizeof(streamFormat) ) )
|
||||||
|
{
|
||||||
|
throw CGenErr ( tr ( "CoreAudio stream format set property failed" ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
// (re-)initialize unit
|
||||||
|
if ( AudioUnitInitialize ( gOutputUnit ) )
|
||||||
|
{
|
||||||
|
throw CGenErr ( tr ( "Initialization of CoreAudio failed" ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
// init base class
|
||||||
|
CSoundBase::Init ( iCoreAudioBufferSizeMono );
|
||||||
|
|
||||||
// set internal buffer size value and calculate stereo buffer size
|
// set internal buffer size value and calculate stereo buffer size
|
||||||
iJACKBufferSizeStero = 2 * iJACKBufferSizeMono;
|
iCoreAudioBufferSizeStero = 2 * iCoreAudioBufferSizeMono;
|
||||||
|
|
||||||
// create memory for intermediate audio buffer
|
// create memory for intermediate audio buffer
|
||||||
vecsTmpAudioSndCrdStereo.Init ( iJACKBufferSizeStero );
|
vecsTmpAudioSndCrdStereo.Init ( iCoreAudioBufferSizeStero );
|
||||||
|
|
||||||
return iJACKBufferSizeMono;
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
// TEST
|
|
||||||
return 256;
|
|
||||||
|
|
||||||
|
return iNewPrefMonoBufferSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
OSStatus CSound::process ( void* inRefCon,
|
OSStatus CSound::process ( void* inRefCon,
|
||||||
|
@ -153,6 +144,17 @@ OSStatus CSound::process ( void* inRefCon,
|
||||||
{
|
{
|
||||||
CSound* pSound = reinterpret_cast<CSound*> ( inRefCon );
|
CSound* pSound = reinterpret_cast<CSound*> ( inRefCon );
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
for ( UInt32 channel = 1; channel < ioData->mNumberBuffers; channel++)
|
||||||
|
{
|
||||||
|
memcpy ( ioData->mBuffers[channel].mData,
|
||||||
|
ioData->mBuffers[0].mData,
|
||||||
|
ioData->mBuffers[0].mDataByteSize );
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
// get input data pointer
|
// get input data pointer
|
||||||
jack_default_audio_sample_t* in_left =
|
jack_default_audio_sample_t* in_left =
|
||||||
|
@ -169,10 +171,12 @@ OSStatus CSound::process ( void* inRefCon,
|
||||||
pSound->vecsTmpAudioSndCrdStereo[2 * i] = (short) ( in_left[i] * _MAXSHORT );
|
pSound->vecsTmpAudioSndCrdStereo[2 * i] = (short) ( in_left[i] * _MAXSHORT );
|
||||||
pSound->vecsTmpAudioSndCrdStereo[2 * i + 1] = (short) ( in_right[i] * _MAXSHORT );
|
pSound->vecsTmpAudioSndCrdStereo[2 * i + 1] = (short) ( in_right[i] * _MAXSHORT );
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
// call processing callback function
|
// call processing callback function
|
||||||
pSound->ProcessCallback ( pSound->vecsTmpAudioSndCrdStereo );
|
pSound->ProcessCallback ( pSound->vecsTmpAudioSndCrdStereo );
|
||||||
|
|
||||||
|
/*
|
||||||
// get output data pointer
|
// get output data pointer
|
||||||
jack_default_audio_sample_t* out_left =
|
jack_default_audio_sample_t* out_left =
|
||||||
(jack_default_audio_sample_t*) jack_port_get_buffer (
|
(jack_default_audio_sample_t*) jack_port_get_buffer (
|
||||||
|
|
|
@ -50,6 +50,12 @@ public:
|
||||||
QString SetDev ( const int ) { return ""; } // dummy
|
QString SetDev ( const int ) { return ""; } // dummy
|
||||||
int GetDev() { return 0; }
|
int GetDev() { return 0; }
|
||||||
|
|
||||||
|
// these variables should be protected but cannot since we want
|
||||||
|
// to access them from the callback function
|
||||||
|
CVector<short> vecsTmpAudioSndCrdStereo;
|
||||||
|
int iCoreAudioBufferSizeMono;
|
||||||
|
int iCoreAudioBufferSizeStero;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void OpenCoreAudio();
|
void OpenCoreAudio();
|
||||||
void CloseCoreAudio();
|
void CloseCoreAudio();
|
||||||
|
|
Loading…
Reference in a new issue