Search
lxdream.org :: lxdream :: r701:1ff36bb68c79
lxdream 0.9.1
released Jun 29
Download Now
changeset701:1ff36bb68c79
parent700:4650d0c7f6f9
child702:d39fc81e9630
authornkeynes
dateSun Jun 22 07:43:02 2008 +0000 (11 years ago)
Change to use AudioDevice, following pattern used by esd. Sounds _much_ better now.
src/drivers/audio_osx.c
1.1 --- a/src/drivers/audio_osx.c Sun Jun 22 06:49:00 2008 +0000
1.2 +++ b/src/drivers/audio_osx.c Sun Jun 22 07:43:02 2008 +0000
1.3 @@ -17,21 +17,26 @@
1.4 */
1.5 #include <stdio.h>
1.6 #include <unistd.h>
1.7 -#include <AudioToolbox/AudioToolbox.h>
1.8 -#include <AudioUnit/AudioUnitProperties.h>
1.9 +#include <CoreAudio/CoreAudio.h>
1.10 #include "aica/audio.h"
1.11 #include "lxdream.h"
1.12
1.13 -static AudioUnit output_au;
1.14 +#define BUFFER_SIZE (sizeof(float)*2*2205)
1.15 +
1.16 +static AudioDeviceID output_device;
1.17 static volatile audio_buffer_t output_buffer = NULL;
1.18 -static int sample_size;
1.19 +static uint32_t buffer_size;
1.20
1.21 -OSStatus audio_osx_callback( void *inRefCon, AudioUnitRenderActionFlags *ioActionFlags,
1.22 - const AudioTimeStamp *inTimeStamp, UInt32 inBusNumber,
1.23 - UInt32 inNumberFrames, AudioBufferList *ioData )
1.24 +OSStatus audio_osx_callback( AudioDeviceID inDevice,
1.25 + const AudioTimeStamp *inNow,
1.26 + const AudioBufferList *inInputData,
1.27 + const AudioTimeStamp *inInputTime,
1.28 + AudioBufferList *outOutputData,
1.29 + const AudioTimeStamp *inOutputTime,
1.30 + void *inClientData)
1.31 {
1.32 - char *output = ioData->mBuffers[0].mData;
1.33 - int data_requested = inNumberFrames * sample_size;
1.34 + char *output = outOutputData->mBuffers[0].mData;
1.35 + int data_requested = buffer_size;
1.36
1.37 while( output_buffer != NULL && data_requested > 0 ) {
1.38 int copysize = output_buffer->length - output_buffer->posn;
1.39 @@ -54,62 +59,36 @@
1.40
1.41 static gboolean audio_osx_shutdown()
1.42 {
1.43 - AudioUnitUninitialize( output_au );
1.44 - CloseComponent( output_au );
1.45 + AudioDeviceStop( output_device, audio_osx_callback );
1.46 + AudioDeviceRemoveIOProc( output_device, audio_osx_callback );
1.47 return TRUE;
1.48 }
1.49
1.50 static gboolean audio_osx_init()
1.51 {
1.52 - AURenderCallbackStruct callbackData;
1.53 + UInt32 size = sizeof(output_device);
1.54 AudioStreamBasicDescription outputDesc;
1.55 UInt32 outputDescSize = sizeof(outputDesc);
1.56 - ComponentDescription cd;
1.57 - Component c;
1.58 -
1.59 - cd.componentType = kAudioUnitType_Output;
1.60 - cd.componentSubType = kAudioUnitSubType_DefaultOutput;
1.61 - cd.componentManufacturer = kAudioUnitManufacturer_Apple;
1.62 - cd.componentFlags = 0;
1.63 - cd.componentFlagsMask = 0;
1.64 -
1.65 - c = FindNextComponent( NULL, &cd );
1.66 - if( c == NULL ) {
1.67 +
1.68 + if( AudioHardwareGetProperty(kAudioHardwarePropertyDefaultOutputDevice,
1.69 + &size, &output_device) != noErr ||
1.70 + output_device == kAudioDeviceUnknown ) {
1.71 + return FALSE;
1.72 + }
1.73 +
1.74 + if( AudioDeviceGetProperty( output_device, 1, 0, kAudioDevicePropertyStreamFormat,
1.75 + &outputDescSize, &outputDesc ) != noErr ) {
1.76 return FALSE;
1.77 }
1.78
1.79 - if( OpenAComponent( c, &output_au ) != noErr ) {
1.80 - return FALSE;
1.81 - }
1.82 -
1.83 - if( AudioUnitGetProperty( output_au, kAudioUnitProperty_StreamFormat,
1.84 - kAudioUnitScope_Global, 0, &outputDesc, &outputDescSize ) != noErr ) {
1.85 - CloseComponent( output_au );
1.86 + buffer_size = BUFFER_SIZE;
1.87 +
1.88 + if( AudioDeviceSetProperty( output_device, 0, 0, 0, kAudioDevicePropertyBufferSize,
1.89 + sizeof(buffer_size), &buffer_size ) != noErr ) {
1.90 return FALSE;
1.91 }
1.92
1.93 - outputDesc.mSampleRate = DEFAULT_SAMPLE_RATE;
1.94 - sample_size = outputDesc.mBytesPerFrame;
1.95 -
1.96 - if( AudioUnitSetProperty( output_au, kAudioUnitProperty_StreamFormat,
1.97 - kAudioUnitScope_Global, 0, &outputDesc, sizeof(outputDesc) ) != noErr ) {
1.98 - CloseComponent( output_au );
1.99 - return FALSE;
1.100 - }
1.101 -
1.102 - if( AudioUnitInitialize( output_au ) != noErr ) {
1.103 - CloseComponent( output_au );
1.104 - return FALSE;
1.105 - }
1.106 -
1.107 - callbackData.inputProc = audio_osx_callback;
1.108 - callbackData.inputProcRefCon = NULL;
1.109 - if( AudioUnitSetProperty( output_au, kAudioUnitProperty_SetRenderCallback,
1.110 - kAudioUnitScope_Global, 0, &callbackData, sizeof(callbackData)) != noErr ) {
1.111 - audio_osx_shutdown();
1.112 - return FALSE;
1.113 - }
1.114 -
1.115 + AudioDeviceAddIOProc( output_device, audio_osx_callback, NULL );
1.116 return TRUE;
1.117 }
1.118 static gboolean audio_osx_process_buffer( audio_buffer_t buffer )
1.119 @@ -117,22 +96,26 @@
1.120 if( output_buffer == NULL ) {
1.121 output_buffer = buffer;
1.122 output_buffer->posn = 0;
1.123 - AudioOutputUnitStart(output_au);
1.124 + AudioDeviceStart(output_device, audio_osx_callback);
1.125 return FALSE;
1.126 }
1.127 }
1.128
1.129 void audio_osx_start()
1.130 {
1.131 + if( output_buffer != NULL ) {
1.132 + AudioDeviceStart(output_device, audio_osx_callback);
1.133 + }
1.134 }
1.135
1.136 void audio_osx_stop()
1.137 {
1.138 + AudioDeviceStop( output_device, audio_osx_callback );
1.139 }
1.140
1.141
1.142 struct audio_driver audio_osx_driver = {
1.143 - "osx",
1.144 + "osx",
1.145 N_("OS X CoreAudio system driver"),
1.146 DEFAULT_SAMPLE_RATE,
1.147 AUDIO_FMT_FLOATST,
.