dpvoice: Turn GetCompressionTypes into a semi-stub.
[wine.git] / dlls / winecoreaudio.drv / audiounit.c
blobb49d214193d205f09be316b243b362d4fecba7cb
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
33 #undef DPRINTF
34 #undef STDMETHODCALLTYPE
35 #include "coreaudio.h"
36 #include "wine/debug.h"
38 #ifndef HAVE_AUDIOUNIT_AUDIOCOMPONENT_H
39 /* Define new AudioComponent Manager types for compatibility's sake */
40 typedef ComponentDescription AudioComponentDescription;
41 #endif
43 #ifndef HAVE_AUGRAPHADDNODE
44 static inline OSStatus AUGraphAddNode(AUGraph graph, const AudioComponentDescription *desc, AUNode *node)
46 return AUGraphNewNode(graph, desc, 0, NULL, node);
49 static inline OSStatus AUGraphNodeInfo(AUGraph graph, AUNode node, AudioComponentDescription *desc, AudioUnit *au)
51 return AUGraphGetNodeInfo(graph, node, desc, 0, NULL, au);
53 #endif
55 WINE_DEFAULT_DEBUG_CHANNEL(wave);
56 WINE_DECLARE_DEBUG_CHANNEL(midi);
58 int AudioUnit_SetVolume(AudioUnit au, float left, float right)
60 OSStatus err = noErr;
61 static int once;
63 if (!once++) FIXME("independent left/right volume not implemented (%f, %f)\n", left, right);
65 err = AudioUnitSetParameter(au, kHALOutputParam_Volume, kAudioUnitParameterFlag_Output, 0, left, 0);
67 if (err != noErr)
69 ERR("AudioUnitSetParameter return an error %s\n", wine_dbgstr_fourcc(err));
70 return 0;
72 return 1;
75 int AudioUnit_GetVolume(AudioUnit au, float *left, float *right)
77 OSStatus err = noErr;
78 static int once;
80 if (!once++) FIXME("independent left/right volume not implemented\n");
82 err = AudioUnitGetParameter(au, kHALOutputParam_Volume, kAudioUnitParameterFlag_Output, 0, left);
83 if (err != noErr)
85 ERR("AudioUnitGetParameter return an error %s\n", wine_dbgstr_fourcc(err));
86 return 0;
88 *right = *left;
89 return 1;
94 * MIDI Synth Unit
96 int SynthUnit_CreateDefaultSynthUnit(AUGraph *graph, AudioUnit *synth)
98 OSStatus err;
99 AudioComponentDescription desc;
100 AUNode synthNode;
101 AUNode outNode;
103 err = NewAUGraph(graph);
104 if (err != noErr)
106 ERR_(midi)("NewAUGraph return %s\n", wine_dbgstr_fourcc(err));
107 return 0;
110 desc.componentManufacturer = kAudioUnitManufacturer_Apple;
111 desc.componentFlags = 0;
112 desc.componentFlagsMask = 0;
114 /* create synth node */
115 desc.componentType = kAudioUnitType_MusicDevice;
116 desc.componentSubType = kAudioUnitSubType_DLSSynth;
118 err = AUGraphAddNode(*graph, &desc, &synthNode);
119 if (err != noErr)
121 ERR_(midi)("AUGraphAddNode cannot create synthNode : %s\n", wine_dbgstr_fourcc(err));
122 return 0;
125 /* create out node */
126 desc.componentType = kAudioUnitType_Output;
127 desc.componentSubType = kAudioUnitSubType_DefaultOutput;
129 err = AUGraphAddNode(*graph, &desc, &outNode);
130 if (err != noErr)
132 ERR_(midi)("AUGraphAddNode cannot create outNode %s\n", wine_dbgstr_fourcc(err));
133 return 0;
136 err = AUGraphOpen(*graph);
137 if (err != noErr)
139 ERR_(midi)("AUGraphOpen return %s\n", wine_dbgstr_fourcc(err));
140 return 0;
143 /* connecting the nodes */
144 err = AUGraphConnectNodeInput(*graph, synthNode, 0, outNode, 0);
145 if (err != noErr)
147 ERR_(midi)("AUGraphConnectNodeInput cannot connect synthNode to outNode : %s\n", wine_dbgstr_fourcc(err));
148 return 0;
151 /* Get the synth unit */
152 err = AUGraphNodeInfo(*graph, synthNode, 0, synth);
153 if (err != noErr)
155 ERR_(midi)("AUGraphNodeInfo return %s\n", wine_dbgstr_fourcc(err));
156 return 0;
159 return 1;
162 int SynthUnit_Initialize(AudioUnit synth, AUGraph graph)
164 OSStatus err = noErr;
166 err = AUGraphInitialize(graph);
167 if (err != noErr)
169 ERR_(midi)("AUGraphInitialize(%p) return %s\n", graph, wine_dbgstr_fourcc(err));
170 return 0;
173 err = AUGraphStart(graph);
174 if (err != noErr)
176 ERR_(midi)("AUGraphStart(%p) return %s\n", graph, wine_dbgstr_fourcc(err));
177 return 0;
180 return 1;
183 int SynthUnit_Close(AUGraph graph)
185 OSStatus err = noErr;
187 err = AUGraphStop(graph);
188 if (err != noErr)
190 ERR_(midi)("AUGraphStop(%p) return %s\n", graph, wine_dbgstr_fourcc(err));
191 return 0;
194 err = DisposeAUGraph(graph);
195 if (err != noErr)
197 ERR_(midi)("DisposeAUGraph(%p) return %s\n", graph, wine_dbgstr_fourcc(err));
198 return 0;
201 return 1;