diff --git a/linux/sound.cpp b/linux/sound.cpp index c76f4214..f35efd66 100755 --- a/linux/sound.cpp +++ b/linux/sound.cpp @@ -160,7 +160,7 @@ int CSound::Init ( const int iNewPrefMonoBufferSize ) // get actual buffer size iJACKBufferSizeMono = jack_get_buffer_size ( pJackClient ); - // init base clasee + // init base class CSoundBase::Init ( iJACKBufferSizeMono ); // set internal buffer size value and calculate stereo buffer size diff --git a/mac/sound.cpp b/mac/sound.cpp index bc7047ca..a67b2612 100755 --- a/mac/sound.cpp +++ b/mac/sound.cpp @@ -61,33 +61,6 @@ void CSound::OpenCoreAudio() { 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() @@ -117,31 +90,49 @@ void CSound::Stop() int CSound::Init ( const int iNewPrefMonoBufferSize ) { + // store buffer size + iCoreAudioBufferSizeMono = iNewPrefMonoBufferSize; -/* -// try setting buffer size -// TODO seems not to work! -> no audio after this operation! -//jack_set_buffer_size ( pJackClient, iNewPrefMonoBufferSize ); + // first uninitialize unit + AudioUnitUninitialize ( gOutputUnit ); - // get actual buffer size - iJACKBufferSizeMono = jack_get_buffer_size ( pJackClient ); + // set up stream format + 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 - CSoundBase::Init ( iJACKBufferSizeMono ); + if ( AudioUnitSetProperty ( gOutputUnit, + 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 - iJACKBufferSizeStero = 2 * iJACKBufferSizeMono; + iCoreAudioBufferSizeStero = 2 * iCoreAudioBufferSizeMono; // create memory for intermediate audio buffer - vecsTmpAudioSndCrdStereo.Init ( iJACKBufferSizeStero ); - - return iJACKBufferSizeMono; -*/ - - -// TEST -return 256; + vecsTmpAudioSndCrdStereo.Init ( iCoreAudioBufferSizeStero ); + return iNewPrefMonoBufferSize; } OSStatus CSound::process ( void* inRefCon, @@ -153,6 +144,17 @@ OSStatus CSound::process ( void* inRefCon, { CSound* pSound = reinterpret_cast ( 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 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 + 1] = (short) ( in_right[i] * _MAXSHORT ); } +*/ // call processing callback function pSound->ProcessCallback ( pSound->vecsTmpAudioSndCrdStereo ); +/* // get output data pointer jack_default_audio_sample_t* out_left = (jack_default_audio_sample_t*) jack_port_get_buffer ( diff --git a/mac/sound.h b/mac/sound.h index 0b2e01fc..0f1bf4ee 100755 --- a/mac/sound.h +++ b/mac/sound.h @@ -50,6 +50,12 @@ public: QString SetDev ( const int ) { return ""; } // dummy int GetDev() { return 0; } + // these variables should be protected but cannot since we want + // to access them from the callback function + CVector vecsTmpAudioSndCrdStereo; + int iCoreAudioBufferSizeMono; + int iCoreAudioBufferSizeStero; + protected: void OpenCoreAudio(); void CloseCoreAudio();