2 * Wine Driver for CoreAudio / AudioUnit
4 * Copyright 2005, 2006 Emmanuel Maillard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "wine/debug.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(wave
);
26 #ifdef HAVE_AUDIOUNIT_AUDIOUNIT_H
27 #include <AudioUnit/AudioUnit.h>
29 static char streamStr
[512] = {0};
30 static char *streamDescription(AudioStreamBasicDescription stream
)
32 sprintf(streamStr
, "\n mSampleRate : %f\n mFormatID : %c%c%c%c\n mFormatFlags : %lX\n mBytesPerPacket : %u\n mFramesPerPacket : %u\n mBytesPerFrame : %u\n mChannelsPerFrame : %u\n mBitsPerChannel : %u\n",
34 (char) (stream
.mFormatID
>> 24),
35 (char) (stream
.mFormatID
>> 16),
36 (char) (stream
.mFormatID
>> 8),
37 (char) stream
.mFormatID
,
39 stream
.mBytesPerPacket
,
40 stream
.mFramesPerPacket
,
41 stream
.mBytesPerFrame
,
42 stream
.mChannelsPerFrame
,
43 stream
.mBitsPerChannel
);
47 extern OSStatus
CoreAudio_woAudioUnitIOProc(void *inRefCon
,
48 AudioUnitRenderActionFlags
*ioActionFlags
,
49 const AudioTimeStamp
*inTimeStamp
,
51 UInt32 inNumberFrames
,
52 AudioBufferList
*ioData
);
54 int AudioUnit_CreateDefaultAudioUnit(void *wwo
, AudioUnit
*au
)
57 ComponentDescription desc
;
58 AURenderCallbackStruct callbackStruct
;
60 desc
.componentType
= kAudioUnitType_Output
;
61 desc
.componentSubType
= kAudioUnitSubType_DefaultOutput
;
62 desc
.componentManufacturer
= kAudioUnitManufacturer_Apple
;
63 desc
.componentFlags
= 0;
64 desc
.componentFlagsMask
= 0;
66 Component comp
= FindNextComponent(NULL
, &desc
);
70 err
= OpenAComponent(comp
, au
);
74 callbackStruct
.inputProc
= CoreAudio_woAudioUnitIOProc
;
75 callbackStruct
.inputProcRefCon
= wwo
;
77 err
= AudioUnitSetProperty( *au
,
78 kAudioUnitProperty_SetRenderCallback
,
79 kAudioUnitScope_Input
,
82 sizeof(callbackStruct
));
83 return (err
== noErr
);
86 int AudioUnit_CloseAudioUnit(AudioUnit au
)
88 OSStatus err
= CloseComponent(au
);
89 return (err
== noErr
);
92 int AudioUnit_InitializeWithStreamDescription(AudioUnit au
, AudioStreamBasicDescription stream
)
96 err
= AudioUnitSetProperty(au
, kAudioUnitProperty_StreamFormat
, kAudioUnitScope_Input
,
97 0, &stream
, sizeof(AudioStreamBasicDescription
));
101 ERR("AudioUnitSetProperty return an error %c%c%c%c\n", (char) (err
>> 24), (char) (err
>> 16), (char) (err
>> 8), (char) err
);
105 err
= AudioUnitInitialize(au
);
108 ERR("AudioUnitInitialize return an error %c%c%c%c\n", (char) (err
>> 24), (char) (err
>> 16), (char) (err
>> 8), (char) err
);
114 int AudioUnit_SetVolume(AudioUnit au
, float left
, float right
)
116 OSStatus err
= noErr
;
118 err
= AudioUnitSetParameter(au
, kHALOutputParam_Volume
, kAudioUnitParameterFlag_Output
, 0, left
, 0);
122 ERR("AudioUnitSetParameter return an error %c%c%c%c\n", (char) (err
>> 24), (char) (err
>> 16), (char) (err
>> 8), (char) err
);
128 int AudioUnit_GetVolume(AudioUnit au
, float *left
, float *right
)
130 OSStatus err
= noErr
;
132 err
= AudioUnitGetParameter(au
, kHALOutputParam_Volume
, kAudioUnitParameterFlag_Output
, 0, left
);
135 ERR("AudioUnitGetParameter return an error %c%c%c%c\n", (char) (err
>> 24), (char) (err
>> 16), (char) (err
>> 8), (char) err
);