Mercurial > sdl-ios-xcode
diff src/cdrom/macosx/AudioFilePlayer.cpp @ 935:f8d5ddc7aef1
Audio improvements from Max Horn, including a new CoreAudio driver for MacOSX
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sat, 21 Aug 2004 02:06:30 +0000 |
parents | da0a2ad35bf4 |
children |
line wrap: on
line diff
--- a/src/cdrom/macosx/AudioFilePlayer.cpp Fri Aug 20 22:35:23 2004 +0000 +++ b/src/cdrom/macosx/AudioFilePlayer.cpp Sat Aug 21 02:06:30 2004 +0000 @@ -67,30 +67,29 @@ OSStatus AudioFileManager::Render (AudioBuffer &ioData) { - OSStatus result = AudioConverterFillBuffer(mParentConverter, - AudioFileManager::ACInputProc, - this, - &ioData.mDataByteSize, - ioData.mData); - if (result) { - SDL_SetError ("AudioConverterFillBuffer:%ld\n", result); - mParent.DoNotification (result); - } else { - mByteCounter += ioData.mDataByteSize / 2; - AfterRender(); - } + OSStatus result = noErr; + + if (mBufferOffset >= mBufferSize) { + result = GetFileData(&mTmpBuffer, &mBufferSize); + if (result) { + SDL_SetError ("AudioConverterFillBuffer:%ld\n", result); + mParent.DoNotification (result); + return result; + } + + mBufferOffset = 0; + } + + if (ioData.mDataByteSize > mBufferSize - mBufferOffset) + ioData.mDataByteSize = mBufferSize - mBufferOffset; + ioData.mData = (char *)mTmpBuffer + mBufferOffset; + mBufferOffset += ioData.mDataByteSize; + + mByteCounter += ioData.mDataByteSize; + AfterRender(); return result; } -OSStatus AudioFileManager::ACInputProc (AudioConverterRef inAudioConverter, - UInt32* outDataSize, - void** outData, - void* inUserData) -{ - AudioFileManager* THIS = (AudioFileManager*)inUserData; - return THIS->GetFileData(outData, outDataSize); -} - AudioFileManager::~AudioFileManager () { if (mFileBuffer) { @@ -102,7 +101,6 @@ AudioFilePlayer::AudioFilePlayer (const FSRef *inFileRef) : mConnected (false), mAudioFileManager (0), - mConverter (0), mNotifier (0), mStartFrame (0) { @@ -124,39 +122,14 @@ bytesPerSecond); } -// you can put a rate scalar here to play the file faster or slower -// by multiplying the same rate by the desired factor -// eg fileSampleRate * 2 -> twice as fast -// before you create the AudioConverter -void AudioFilePlayer::SetDestination (AudioUnit &inDestUnit, - int inBusNumber) +void AudioFilePlayer::SetDestination (AudioUnit &inDestUnit) { if (mConnected) throw static_cast<OSStatus>(-1); //can't set dest if already engaged mPlayUnit = inDestUnit; - mBusNumber = inBusNumber; OSStatus result = noErr; - if (mConverter) { - result = AudioConverterDispose (mConverter); - THROW_RESULT("AudioConverterDispose") - } - - AudioStreamBasicDescription destDesc; - UInt32 size = sizeof (destDesc); - result = AudioUnitGetProperty (inDestUnit, - kAudioUnitProperty_StreamFormat, - kAudioUnitScope_Input, - inBusNumber, - &destDesc, - &size); - THROW_RESULT("AudioUnitGetProperty") - -#if DEBUG - printf("Destination format:\n"); - PrintStreamDesc (&destDesc); -#endif //we can "down" cast a component instance to a component ComponentDescription desc; @@ -171,19 +144,14 @@ THROW_RESULT("BAD COMPONENT") } - - result = AudioConverterNew (&mFileDescription, &destDesc, &mConverter); - THROW_RESULT("AudioConverterNew") - -#if 0 - // this uses the better quality SRC - UInt32 srcID = kAudioUnitSRCAlgorithm_Polyphase; - result = AudioConverterSetProperty(mConverter, - kAudioConverterSampleRateConverterAlgorithm, - sizeof(srcID), - &srcID); - THROW_RESULT("AudioConverterSetProperty") -#endif + /* Set the input format of the audio unit. */ + result = AudioUnitSetProperty (inDestUnit, + kAudioUnitProperty_StreamFormat, + kAudioUnitScope_Input, + 0, + &mFileDescription, + sizeof (mFileDescription)); + THROW_RESULT("AudioUnitSetProperty") } void AudioFilePlayer::SetStartFrame (int frame) @@ -220,22 +188,18 @@ FSClose (mForkRefNum); mForkRefNum = 0; } - - if (mConverter) { - AudioConverterDispose (mConverter); - mConverter = 0; - } } void AudioFilePlayer::Connect() { #if DEBUG - printf ("Connect:%x,%ld, engaged=%d\n", (int)mPlayUnit, mBusNumber, (mConnected ? 1 : 0)); + printf ("Connect:%x, engaged=%d\n", (int)mPlayUnit, (mConnected ? 1 : 0)); #endif if (!mConnected) { - mAudioFileManager->Connect(mConverter); - + mAudioFileManager->DoConnect(); + + // set the render callback for the file data to be supplied to the sound converter AU mInputCallback.inputProc = AudioFileManager::FileInputProc; mInputCallback.inputProcRefCon = mAudioFileManager; @@ -243,7 +207,7 @@ OSStatus result = AudioUnitSetProperty (mPlayUnit, kAudioUnitProperty_SetInputCallback, kAudioUnitScope_Input, - mBusNumber, + 0, &mInputCallback, sizeof(mInputCallback)); THROW_RESULT("AudioUnitSetProperty") @@ -272,7 +236,7 @@ void AudioFilePlayer::Disconnect () { #if DEBUG - printf ("Disconnect:%x,%ld, engaged=%d\n", (int)mPlayUnit, mBusNumber, (mConnected ? 1 : 0)); + printf ("Disconnect:%x,%ld, engaged=%d\n", (int)mPlayUnit, 0, (mConnected ? 1 : 0)); #endif if (mConnected) { @@ -283,7 +247,7 @@ OSStatus result = AudioUnitSetProperty (mPlayUnit, kAudioUnitProperty_SetInputCallback, kAudioUnitScope_Input, - mBusNumber, + 0, &mInputCallback, sizeof(mInputCallback)); if (result)