29 #include "../../idlib/precompiled.h"
30 #include "../../sound/snd_local.h"
32 #include <Carbon/Carbon.h>
33 #include <CoreAudio/CoreAudio.h>
45 bool Lock(
void **pDSLockedBuffer,
ulong *dwDSLockedBufferSize ) {
return false; }
46 bool Unlock(
void *pDSLockedBuffer,
dword dwDSLockedBufferSize ) {
return false; }
53 bool Flush(
void ) {
return false; }
70 AudioDevicePropertyID inPropertyID,
75 const AudioTimeStamp* inNow,
76 const AudioBufferList* inInputData,
77 const AudioTimeStamp* inInputTime,
78 AudioBufferList* outOutputData,
79 const AudioTimeStamp* inOutputTime,
126 if ( status != kAudioHardwareNoError ) {
130 if ( status != kAudioHardwareNoError ) {
136 AudioHardwareUnload();
148 common->
Printf(
"------------------------------------------------\n" );
159 AudioDevicePropertyID inPropertyID,
160 void* inClientData) {
162 return kAudioHardwareNoError;
171 const AudioTimeStamp* inNow,
172 const AudioBufferList* inInputData,
173 const AudioTimeStamp* inInputTime,
174 AudioBufferList* outOutputData,
175 const AudioTimeStamp* inOutputTime,
176 void* inClientData ) {
180 soundSystem->
AsyncMix( (
int)inOutputTime->mSampleTime, (
float*)outOutputData->mBuffers[ 0 ].mData );
186 return kAudioHardwareNoError;
195 static char buf[
sizeof( OSStatus ) + 1 ];
196 strncpy( buf, (
const char *)&status,
sizeof( OSStatus ) );
197 buf[
sizeof( OSStatus ) ] =
'\0';
211 AudioDeviceID *deviceList;
214 status = AudioHardwareGetPropertyInfo( kAudioHardwarePropertyDevices, &size,
NULL );
215 if ( status != kAudioHardwareNoError ) {
221 deviceCount = size /
sizeof( AudioDeviceID );
222 if ( !deviceCount ) {
228 deviceList = (AudioDeviceID*)malloc( size );
229 status = AudioHardwareGetProperty( kAudioHardwarePropertyDevices, &size, deviceList );
230 if ( status != kAudioHardwareNoError ) {
238 for( i = 0; i < deviceCount; i++ ) {
240 status = AudioDeviceGetProperty( deviceList[ i ], 0,
false, kAudioDevicePropertyDeviceName, &size, buf );
241 if ( status != kAudioHardwareNoError ) {
247 common->
Printf(
" %d: ID %d, %s - ", i, deviceList[ i ], buf );
249 status = AudioDeviceGetProperty( deviceList[ i ], 0,
false, kAudioDevicePropertyDeviceManufacturer, &size, buf );
250 if ( status != kAudioHardwareNoError ) {
251 common->
Warning(
"AudioDeviceGetProperty kAudioDevicePropertyDeviceManufacturer %d failed. status: %s", i,
ExtractStatus( status ) );
264 status = AudioHardwareGetProperty( kAudioHardwarePropertyDefaultOutputDevice, &size, &
selectedDevice );
265 if ( status != kAudioHardwareNoError ) {
266 common->
Warning(
"AudioHardwareGetProperty kAudioHardwarePropertyDefaultOutputDevice failed. status: %s",
ExtractStatus( status ) );
289 size =
sizeof( sampleRate );
290 status = AudioDeviceGetProperty(
selectedDevice, 0,
false, kAudioDevicePropertyNominalSampleRate, &size, &sampleRate );
291 if ( status != kAudioHardwareNoError ) {
296 common->
Printf(
"current nominal rate: %g\n", sampleRate );
304 status = AudioDeviceSetProperty(
selectedDevice,
NULL, 0,
false, kAudioDevicePropertyNominalSampleRate, size, &sampleRate );
305 if ( status != kAudioHardwareNoError ) {
313 size =
sizeof( UInt32 );
314 status = AudioDeviceGetProperty(
selectedDevice, 0,
false, kAudioDevicePropertyBufferFrameSize, &size, &frameSize );
315 if ( status != kAudioHardwareNoError ) {
320 common->
Printf(
"current frame size: %d\n", frameSize );
323 AudioValueRange frameSizeRange;
324 size =
sizeof( AudioValueRange );
325 status = AudioDeviceGetProperty(
selectedDevice, 0,
false, kAudioDevicePropertyBufferFrameSizeRange, &size, &frameSizeRange );
326 if ( status != kAudioHardwareNoError ) {
331 common->
Printf(
"frame size allowed range: %g %g\n", frameSizeRange.mMinimum, frameSizeRange.mMaximum );
341 common->
Printf(
"setting frame size to: %d\n", frameSize );
342 size =
sizeof( frameSize );
343 status = AudioDeviceSetProperty(
selectedDevice,
NULL, 0,
false, kAudioDevicePropertyBufferFrameSize, size, &frameSize );
344 if ( status != kAudioHardwareNoError ) {
355 UInt32 channels[ 2 ];
356 size = 2 *
sizeof( UInt32 );
357 status = AudioDeviceGetProperty(
selectedDevice, 0,
false, kAudioDevicePropertyPreferredChannelsForStereo, &size, &channels );
358 if ( status != kAudioHardwareNoError ) {
363 common->
Printf(
"using stereo channel IDs %d %d\n", channels[ 0 ], channels[ 1 ] );
366 if ( status != kAudioHardwareNoError ) {
374 if ( status != kAudioHardwareNoError ) {
400 AudioValueRange *rangeArray;
402 status = AudioDeviceGetPropertyInfo(
selectedDevice, 0,
false, kAudioDevicePropertyAvailableNominalSampleRates, &size,
NULL );
403 if ( status != kAudioHardwareNoError ) {
407 rangeCount = size /
sizeof( AudioValueRange );
408 rangeArray = (AudioValueRange *)malloc( size );
412 status = AudioDeviceGetProperty(
selectedDevice, 0,
false, kAudioDevicePropertyAvailableNominalSampleRates, &size, rangeArray );
413 if ( status != kAudioHardwareNoError ) {
419 for( i = 0; i < rangeCount; i++ ) {
420 common->
Printf(
" %d: min %g max %g\n", i, rangeArray[ i ].mMinimum, rangeArray[ i ].mMaximum );
442 long gestaltOSVersion;
443 err = Gestalt(gestaltSystemVersion, &gestaltOSVersion);
444 if ( err || gestaltOSVersion < 0x1040 ) {
idCVarSystem * cvarSystem
const char * ExtractStatus(OSStatus status)
static idCVar s_numberOfSpeakers
const int MIXBUFFER_SAMPLES
AudioDeviceID selectedDevice
short * GetMixBuffer(void)
int GetMixBufferSize(void)
static OSStatus DeviceIOProc(AudioDeviceID inDevice, const AudioTimeStamp *inNow, const AudioBufferList *inInputData, const AudioTimeStamp *inInputTime, AudioBufferList *outOutputData, const AudioTimeStamp *inOutputTime, void *inClientData)
bool Unlock(void *pDSLockedBuffer, dword dwDSLockedBufferSize)
bool Sys_LoadOpenAL(void)
void SetInteger(const int value)
virtual void SetCVarBool(const char *name, const bool value, int flags=0)=0
int GetInteger(void) const
int GetNumberOfSpeakers(void)
static OSStatus DeviceListener(AudioDeviceID inDevice, UInt32 inChannel, Boolean isInput, AudioDevicePropertyID inPropertyID, void *inClientData)
idCVar s_device("s_device","-1", CVAR_SYSTEM|CVAR_ARCHIVE|CVAR_INTEGER,"Sound device to use. -1 for default device")
virtual void VPCALL Mul(float *dst, const float constant, const float *src, const int count)=0
virtual void Printf(const char *fmt,...) id_attribute((format(printf
bool GetCurrentPosition(ulong *pdwCurrentWriteCursor)
static WindowRef ValidModeCallbackProc inCallback OSStatus err
idSoundSystem * soundSystem
bool Lock(void **pDSLockedBuffer, ulong *dwDSLockedBufferSize)
void GetAvailableNominalSampleRates(void)
static idAudioHardware * Alloc()
virtual void virtual void Warning(const char *fmt,...) id_attribute((format(printf
void Sys_LeaveCriticalSection(int index)
virtual int AsyncMix(int soundTime, float *mixBuffer)=0
void Sys_EnterCriticalSection(int index)
virtual ~idAudioHardware()
idSIMDProcessor * SIMDProcessor