Files
@ r9464:ce84e83c962a
Branch filter:
Location: cpp/openttd-patchpack/source/src/sound/cocoa_s.cpp
r9464:ce84e83c962a
4.5 KiB
text/x-c
(svn r13384) -Update: WebTranslator2 update to 2008-06-05 08:15:43
brazilian_portuguese - 9 fixed, 6 changed by tucalipe (15)
catalan - 9 fixed by arnaullv (9)
croatian - 13 fixed by knovak (13)
czech - 33 fixed by Hadez (33)
danish - 47 fixed by ThomasA (47)
dutch - 9 fixed by habell (9)
estonian - 42 fixed, 5 changed by kristjans (47)
finnish - 5 fixed, 1 changed by kerba (6)
french - 9 fixed, 2 changed by glx (8), belugas (3)
icelandic - 75 fixed by scrooge (75)
italian - 9 fixed, 12 changed by lorenzodv (21)
korean - 76 fixed, 15 changed by leejaeuk5 (91)
portuguese - 7 fixed by izhirahider (7)
romanian - 97 fixed, 302 changed by CrystyB (399)
russian - 12 fixed by Smoky555 (12)
spanish - 12 fixed by eusebio (12)
swedish - 13 fixed by ChrillDeVille (6), daishan (7)
turkish - 39 fixed, 1 changed by jnmbk (40)
ukrainian - 10 fixed by mad (10)
brazilian_portuguese - 9 fixed, 6 changed by tucalipe (15)
catalan - 9 fixed by arnaullv (9)
croatian - 13 fixed by knovak (13)
czech - 33 fixed by Hadez (33)
danish - 47 fixed by ThomasA (47)
dutch - 9 fixed by habell (9)
estonian - 42 fixed, 5 changed by kristjans (47)
finnish - 5 fixed, 1 changed by kerba (6)
french - 9 fixed, 2 changed by glx (8), belugas (3)
icelandic - 75 fixed by scrooge (75)
italian - 9 fixed, 12 changed by lorenzodv (21)
korean - 76 fixed, 15 changed by leejaeuk5 (91)
portuguese - 7 fixed by izhirahider (7)
romanian - 97 fixed, 302 changed by CrystyB (399)
russian - 12 fixed by Smoky555 (12)
spanish - 12 fixed by eusebio (12)
swedish - 13 fixed by ChrillDeVille (6), daishan (7)
turkish - 39 fixed, 1 changed by jnmbk (40)
ukrainian - 10 fixed by mad (10)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | /* $Id$ */
/** @file cocoa_s.cpp Sound driver for cocoa. */
/*****************************************************************************
* Cocoa sound driver *
* Known things left to do: *
* - Might need to do endian checking for it to work on both ppc and x86 *
*****************************************************************************/
#ifdef WITH_COCOA
#define MAC_OS_X_VERSION_MIN_REQUIRED MAC_OS_X_VERSION_10_3
#include <AvailabilityMacros.h>
#include <AudioUnit/AudioUnit.h>
/* Name conflict */
#define Rect OTTDRect
#define Point OTTDPoint
#define WindowClass OTTDWindowClass
#include "../stdafx.h"
#include "../debug.h"
#include "../driver.h"
#include "../mixer.h"
#include "../core/endian_func.hpp"
#include "cocoa_s.h"
#undef WindowClass
#undef Point
#undef Rect
static FSoundDriver_Cocoa iFSoundDriver_Cocoa;
static AudioUnit _outputAudioUnit;
/* The CoreAudio callback */
static OSStatus audioCallback(void *inRefCon, AudioUnitRenderActionFlags *inActionFlags, const AudioTimeStamp *inTimeStamp, UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList * ioData)
{
MxMixSamples(ioData->mBuffers[0].mData, ioData->mBuffers[0].mDataByteSize / 4);
return noErr;
}
const char *SoundDriver_Cocoa::Start(const char * const *parm)
{
Component comp;
ComponentDescription desc;
struct AURenderCallbackStruct callback;
AudioStreamBasicDescription requestedDesc;
/* Setup a AudioStreamBasicDescription with the requested format */
requestedDesc.mFormatID = kAudioFormatLinearPCM;
requestedDesc.mFormatFlags = kLinearPCMFormatFlagIsPacked;
requestedDesc.mChannelsPerFrame = 2;
requestedDesc.mSampleRate = GetDriverParamInt(parm, "hz", 11025);
requestedDesc.mBitsPerChannel = 16;
requestedDesc.mFormatFlags |= kLinearPCMFormatFlagIsSignedInteger;
#ifdef TTD_BIG_ENDIAN
requestedDesc.mFormatFlags |= kLinearPCMFormatFlagIsBigEndian;
#endif
requestedDesc.mFramesPerPacket = 1;
requestedDesc.mBytesPerFrame = requestedDesc.mBitsPerChannel * requestedDesc.mChannelsPerFrame / 8;
requestedDesc.mBytesPerPacket = requestedDesc.mBytesPerFrame * requestedDesc.mFramesPerPacket;
/* Locate the default output audio unit */
desc.componentType = kAudioUnitType_Output;
desc.componentSubType = kAudioUnitSubType_HALOutput;
desc.componentManufacturer = kAudioUnitManufacturer_Apple;
desc.componentFlags = 0;
desc.componentFlagsMask = 0;
comp = FindNextComponent (NULL, &desc);
if (comp == NULL) {
return "cocoa_s: Failed to start CoreAudio: FindNextComponent returned NULL";
}
/* Open & initialize the default output audio unit */
if (OpenAComponent(comp, &_outputAudioUnit) != noErr) {
return "cocoa_s: Failed to start CoreAudio: OpenAComponent";
}
if (AudioUnitInitialize(_outputAudioUnit) != noErr) {
return "cocoa_s: Failed to start CoreAudio: AudioUnitInitialize";
}
/* Set the input format of the audio unit. */
if (AudioUnitSetProperty(_outputAudioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &requestedDesc, sizeof(requestedDesc)) != noErr) {
return "cocoa_s: Failed to start CoreAudio: AudioUnitSetProperty (kAudioUnitProperty_StreamFormat)";
}
/* Set the audio callback */
callback.inputProc = audioCallback;
callback.inputProcRefCon = NULL;
if (AudioUnitSetProperty(_outputAudioUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input, 0, &callback, sizeof(callback)) != noErr) {
return "cocoa_s: Failed to start CoreAudio: AudioUnitSetProperty (kAudioUnitProperty_SetRenderCallback)";
}
/* Finally, start processing of the audio unit */
if (AudioOutputUnitStart(_outputAudioUnit) != noErr) {
return "cocoa_s: Failed to start CoreAudio: AudioOutputUnitStart";
}
/* We're running! */
return NULL;
}
void SoundDriver_Cocoa::Stop()
{
struct AURenderCallbackStruct callback;
/* stop processing the audio unit */
if (AudioOutputUnitStop(_outputAudioUnit) != noErr) {
DEBUG(driver, 0, "cocoa_s: Core_CloseAudio: AudioOutputUnitStop failed");
return;
}
/* Remove the input callback */
callback.inputProc = 0;
callback.inputProcRefCon = 0;
if (AudioUnitSetProperty(_outputAudioUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input, 0, &callback, sizeof(callback)) != noErr) {
DEBUG(driver, 0, "cocoa_s: Core_CloseAudio: AudioUnitSetProperty (kAudioUnitProperty_SetRenderCallback) failed");
return;
}
if (CloseComponent(_outputAudioUnit) != noErr) {
DEBUG(driver, 0, "cocoa_s: Core_CloseAudio: CloseComponent failed");
return;
}
}
#endif /* WITH_COCOA */
|