diff options
| author | Jules Blok <jules.blok@gmail.com> | 2015-06-10 00:00:12 +0200 |
|---|---|---|
| committer | Jules Blok <jules.blok@gmail.com> | 2015-06-10 00:00:12 +0200 |
| commit | 7dfced21a2e5aac7195e0e1ad76468e30306766b (patch) | |
| tree | bd671b639d3d911460b767caabad8fc8a759a6bf /Source/Core/AudioCommon/CoreAudioSoundStream.cpp | |
| parent | c25be031fc1031d795157d8344b87b7841145197 (diff) | |
| parent | 7b0a65e295c784f9d573f2ef52d4e2a7b9bb2889 (diff) | |
Merge branch 'master' into stable
Diffstat (limited to 'Source/Core/AudioCommon/CoreAudioSoundStream.cpp')
| -rw-r--r-- | Source/Core/AudioCommon/CoreAudioSoundStream.cpp | 133 |
1 files changed, 133 insertions, 0 deletions
diff --git a/Source/Core/AudioCommon/CoreAudioSoundStream.cpp b/Source/Core/AudioCommon/CoreAudioSoundStream.cpp new file mode 100644 index 0000000000..3c1d6039af --- /dev/null +++ b/Source/Core/AudioCommon/CoreAudioSoundStream.cpp @@ -0,0 +1,133 @@ +// Copyright 2009 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#include <CoreServices/CoreServices.h> + +#include "AudioCommon/CoreAudioSoundStream.h" + +OSStatus CoreAudioSound::callback(void *inRefCon, + AudioUnitRenderActionFlags *ioActionFlags, + const AudioTimeStamp *inTimeStamp, UInt32 inBusNumber, + UInt32 inNumberFrames, AudioBufferList *ioData) +{ + for (UInt32 i = 0; i < ioData->mNumberBuffers; i++) + ((CoreAudioSound *)inRefCon)->m_mixer-> + Mix((short *)ioData->mBuffers[i].mData, + ioData->mBuffers[i].mDataByteSize / 4); + + return noErr; +} + +bool CoreAudioSound::Start() +{ + OSStatus err; + AURenderCallbackStruct callback_struct; + AudioStreamBasicDescription format; + AudioComponentDescription desc; + AudioComponent component; + + desc.componentType = kAudioUnitType_Output; + desc.componentSubType = kAudioUnitSubType_DefaultOutput; + desc.componentFlags = 0; + desc.componentFlagsMask = 0; + desc.componentManufacturer = kAudioUnitManufacturer_Apple; + component = AudioComponentFindNext(nullptr, &desc); + if (component == nullptr) + { + ERROR_LOG(AUDIO, "error finding audio component"); + return false; + } + + err = AudioComponentInstanceNew(component, &audioUnit); + if (err != noErr) + { + ERROR_LOG(AUDIO, "error opening audio component"); + return false; + } + + FillOutASBDForLPCM(format, m_mixer->GetSampleRate(), + 2, 16, 16, false, false, false); + err = AudioUnitSetProperty(audioUnit, + kAudioUnitProperty_StreamFormat, + kAudioUnitScope_Input, 0, &format, + sizeof(AudioStreamBasicDescription)); + if (err != noErr) + { + ERROR_LOG(AUDIO, "error setting audio format"); + return false; + } + + callback_struct.inputProc = callback; + callback_struct.inputProcRefCon = this; + err = AudioUnitSetProperty(audioUnit, + kAudioUnitProperty_SetRenderCallback, + kAudioUnitScope_Input, 0, &callback_struct, + sizeof callback_struct); + if (err != noErr) + { + ERROR_LOG(AUDIO, "error setting audio callback"); + return false; + } + + err = AudioUnitSetParameter(audioUnit, + kHALOutputParam_Volume, + kAudioUnitParameterFlag_Output, 0, + m_volume / 100., 0); + if (err != noErr) + ERROR_LOG(AUDIO, "error setting volume"); + + err = AudioUnitInitialize(audioUnit); + if (err != noErr) + { + ERROR_LOG(AUDIO, "error initializing audiounit"); + return false; + } + + err = AudioOutputUnitStart(audioUnit); + if (err != noErr) + { + ERROR_LOG(AUDIO, "error starting audiounit"); + return false; + } + + return true; +} + +void CoreAudioSound::SetVolume(int volume) +{ + OSStatus err; + m_volume = volume; + + err = AudioUnitSetParameter(audioUnit, + kHALOutputParam_Volume, + kAudioUnitParameterFlag_Output, 0, + volume / 100., 0); + if (err != noErr) + ERROR_LOG(AUDIO, "error setting volume"); +} + +void CoreAudioSound::SoundLoop() +{ +} + +void CoreAudioSound::Stop() +{ + OSStatus err; + + err = AudioOutputUnitStop(audioUnit); + if (err != noErr) + ERROR_LOG(AUDIO, "error stopping audiounit"); + + err = AudioUnitUninitialize(audioUnit); + if (err != noErr) + ERROR_LOG(AUDIO, "error uninitializing audiounit"); + + err = AudioComponentInstanceDispose(audioUnit); + if (err != noErr) + ERROR_LOG(AUDIO, "error closing audio component"); +} + +void CoreAudioSound::Update() +{ +} |
