oledlg: Call the hook proc if present.
[wine] / dlls / winmm / winecoreaudio / audiounit.c
1 /*
2  * Wine Driver for CoreAudio / AudioUnit
3  *
4  * Copyright 2005, 2006 Emmanuel Maillard
5  *
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.
10  *
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.
15  *
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 #include "config.h"
22 #include "wine/debug.h"
23
24 WINE_DEFAULT_DEBUG_CHANNEL(wave);
25
26 #ifdef HAVE_AUDIOUNIT_AUDIOUNIT_H
27 #include <AudioUnit/AudioUnit.h>
28
29 extern OSStatus CoreAudio_woAudioUnitIOProc(void *inRefCon, 
30                                 AudioUnitRenderActionFlags *ioActionFlags, 
31                                 const AudioTimeStamp *inTimeStamp, 
32                                 UInt32 inBusNumber, 
33                                 UInt32 inNumberFrames, 
34                                 AudioBufferList *ioData);
35
36 int AudioUnit_CreateDefaultAudioUnit(void *wwo, AudioUnit *au)
37 {
38     OSStatus err;
39     Component comp;
40     ComponentDescription desc;
41     AURenderCallbackStruct callbackStruct;
42     
43     desc.componentType = kAudioUnitType_Output;
44     desc.componentSubType = kAudioUnitSubType_DefaultOutput;
45     desc.componentManufacturer = kAudioUnitManufacturer_Apple;
46     desc.componentFlags = 0;
47     desc.componentFlagsMask = 0;
48
49     comp = FindNextComponent(NULL, &desc);
50     if (comp == NULL)
51         return 0;
52     
53     err = OpenAComponent(comp, au);
54     if (comp == NULL)
55         return 0;
56         
57     callbackStruct.inputProc = CoreAudio_woAudioUnitIOProc;
58     callbackStruct.inputProcRefCon = wwo;
59
60     err = AudioUnitSetProperty( *au, 
61                                 kAudioUnitProperty_SetRenderCallback, 
62                                 kAudioUnitScope_Input,
63                                 0, 
64                                 &callbackStruct, 
65                                 sizeof(callbackStruct));
66     return (err == noErr);
67 }
68
69 int AudioUnit_CloseAudioUnit(AudioUnit au)
70 {
71     OSStatus err = CloseComponent(au);
72     return (err == noErr);
73 }
74
75 int AudioUnit_InitializeWithStreamDescription(AudioUnit au, AudioStreamBasicDescription *stream)
76 {
77     OSStatus err = noErr;
78         
79     err = AudioUnitSetProperty(au, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input,
80                                 0, stream, sizeof(*stream));
81
82     if (err != noErr)
83     {
84         ERR("AudioUnitSetProperty return an error %c%c%c%c\n", (char) (err >> 24), (char) (err >> 16), (char) (err >> 8), (char) err);
85         return 0;
86     }
87     
88     err = AudioUnitInitialize(au);
89     if (err != noErr)
90     {
91         ERR("AudioUnitInitialize return an error %c%c%c%c\n", (char) (err >> 24), (char) (err >> 16), (char) (err >> 8), (char) err);
92         return 0;
93     }
94     return 1;
95 }
96
97 int AudioUnit_SetVolume(AudioUnit au, float left, float right)
98 {
99     OSStatus err = noErr;
100    
101     err = AudioUnitSetParameter(au, kHALOutputParam_Volume, kAudioUnitParameterFlag_Output, 0, left, 0);
102                                 
103     if (err != noErr)
104     {
105         ERR("AudioUnitSetParameter return an error %c%c%c%c\n", (char) (err >> 24), (char) (err >> 16), (char) (err >> 8), (char) err);
106         return 0;
107     }
108     return 1;
109 }
110
111 int AudioUnit_GetVolume(AudioUnit au, float *left, float *right)
112 {
113     OSStatus err = noErr;
114     
115     err = AudioUnitGetParameter(au, kHALOutputParam_Volume, kAudioUnitParameterFlag_Output, 0, left);
116     if (err != noErr)
117     {
118         ERR("AudioUnitGetParameter return an error %c%c%c%c\n", (char) (err >> 24), (char) (err >> 16), (char) (err >> 8), (char) err);
119         return 0;
120     }
121     *right = *left;
122     return 1;
123 }
124 #endif