bcrypt: Make format_gnutls_signature() static.
[wine.git] / dlls / winecoreaudio.drv / audiounit.c
blob5f20b3dcb252fb90952cb9d662e886d5f374a030
1 /*
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "config.h"
23 #define ULONG CoreFoundation_ULONG
24 #define HRESULT CoreFoundation_HRESULT
25 #ifndef HAVE_AUDIOUNIT_AUDIOCOMPONENT_H
26 #include <CoreServices/CoreServices.h>
27 #endif
28 #include <AudioUnit/AudioUnit.h>
29 #include <AudioToolbox/AudioToolbox.h>
30 #undef ULONG
31 #undef HRESULT
32 #undef STDMETHODCALLTYPE
33 #include "coreaudio.h"
34 #include "wine/debug.h"
36 #ifndef HAVE_AUDIOUNIT_AUDIOCOMPONENT_H
37 /* Define new AudioComponent Manager types for compatibility's sake */
38 typedef ComponentDescription AudioComponentDescription;
39 #endif
41 #ifndef HAVE_AUGRAPHADDNODE
42 static inline OSStatus AUGraphAddNode(AUGraph graph, const AudioComponentDescription *desc, AUNode *node)
44 return AUGraphNewNode(graph, desc, 0, NULL, node);
47 static inline OSStatus AUGraphNodeInfo(AUGraph graph, AUNode node, AudioComponentDescription *desc, AudioUnit *au)
49 return AUGraphGetNodeInfo(graph, node, desc, 0, NULL, au);
51 #endif
53 WINE_DEFAULT_DEBUG_CHANNEL(wave);
54 WINE_DECLARE_DEBUG_CHANNEL(midi);
56 int AudioUnit_SetVolume(AudioUnit au, float left, float right)
58 OSStatus err = noErr;
59 static int once;
61 if (!once++) FIXME("independent left/right volume not implemented (%f, %f)\n", left, right);
63 err = AudioUnitSetParameter(au, kHALOutputParam_Volume, kAudioUnitParameterFlag_Output, 0, left, 0);
65 if (err != noErr)
67 ERR("AudioUnitSetParameter return an error %s\n", wine_dbgstr_fourcc(err));
68 return 0;
70 return 1;
73 int AudioUnit_GetVolume(AudioUnit au, float *left, float *right)
75 OSStatus err = noErr;
76 static int once;
78 if (!once++) FIXME("independent left/right volume not implemented\n");
80 err = AudioUnitGetParameter(au, kHALOutputParam_Volume, kAudioUnitParameterFlag_Output, 0, left);
81 if (err != noErr)
83 ERR("AudioUnitGetParameter return an error %s\n", wine_dbgstr_fourcc(err));
84 return 0;
86 *right = *left;
87 return 1;
92 * MIDI Synth Unit
94 int SynthUnit_CreateDefaultSynthUnit(AUGraph *graph, AudioUnit *synth)
96 OSStatus err;
97 AudioComponentDescription desc;
98 AUNode synthNode;
99 AUNode outNode;
101 err = NewAUGraph(graph);
102 if (err != noErr)
104 ERR_(midi)("NewAUGraph return %s\n", wine_dbgstr_fourcc(err));
105 return 0;
108 desc.componentManufacturer = kAudioUnitManufacturer_Apple;
109 desc.componentFlags = 0;
110 desc.componentFlagsMask = 0;
112 /* create synth node */
113 desc.componentType = kAudioUnitType_MusicDevice;
114 desc.componentSubType = kAudioUnitSubType_DLSSynth;
116 err = AUGraphAddNode(*graph, &desc, &synthNode);
117 if (err != noErr)
119 ERR_(midi)("AUGraphAddNode cannot create synthNode : %s\n", wine_dbgstr_fourcc(err));
120 return 0;
123 /* create out node */
124 desc.componentType = kAudioUnitType_Output;
125 desc.componentSubType = kAudioUnitSubType_DefaultOutput;
127 err = AUGraphAddNode(*graph, &desc, &outNode);
128 if (err != noErr)
130 ERR_(midi)("AUGraphAddNode cannot create outNode %s\n", wine_dbgstr_fourcc(err));
131 return 0;
134 err = AUGraphOpen(*graph);
135 if (err != noErr)
137 ERR_(midi)("AUGraphOpen return %s\n", wine_dbgstr_fourcc(err));
138 return 0;
141 /* connecting the nodes */
142 err = AUGraphConnectNodeInput(*graph, synthNode, 0, outNode, 0);
143 if (err != noErr)
145 ERR_(midi)("AUGraphConnectNodeInput cannot connect synthNode to outNode : %s\n", wine_dbgstr_fourcc(err));
146 return 0;
149 /* Get the synth unit */
150 err = AUGraphNodeInfo(*graph, synthNode, 0, synth);
151 if (err != noErr)
153 ERR_(midi)("AUGraphNodeInfo return %s\n", wine_dbgstr_fourcc(err));
154 return 0;
157 return 1;
160 int SynthUnit_Initialize(AudioUnit synth, AUGraph graph)
162 OSStatus err = noErr;
164 err = AUGraphInitialize(graph);
165 if (err != noErr)
167 ERR_(midi)("AUGraphInitialize(%p) return %s\n", graph, wine_dbgstr_fourcc(err));
168 return 0;
171 err = AUGraphStart(graph);
172 if (err != noErr)
174 ERR_(midi)("AUGraphStart(%p) return %s\n", graph, wine_dbgstr_fourcc(err));
175 return 0;
178 return 1;
181 int SynthUnit_Close(AUGraph graph)
183 OSStatus err = noErr;
185 err = AUGraphStop(graph);
186 if (err != noErr)
188 ERR_(midi)("AUGraphStop(%p) return %s\n", graph, wine_dbgstr_fourcc(err));
189 return 0;
192 err = DisposeAUGraph(graph);
193 if (err != noErr)
195 ERR_(midi)("DisposeAUGraph(%p) return %s\n", graph, wine_dbgstr_fourcc(err));
196 return 0;
199 return 1;