winecoreaudio: Initial Audio Driver for Mac OS X.
[wine/gsoc_dplay.git] / dlls / winmm / winecoreaudio / audiounit.c
blobb9ac57cb780a97d9bfb24478e4d7441b05c5b9fb
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "config.h"
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",
33 stream.mSampleRate,
34 (char) (stream.mFormatID >> 24),
35 (char) (stream.mFormatID >> 16),
36 (char) (stream.mFormatID >> 8),
37 (char) stream.mFormatID,
38 stream.mFormatFlags,
39 stream.mBytesPerPacket,
40 stream.mFramesPerPacket,
41 stream.mBytesPerFrame,
42 stream.mChannelsPerFrame,
43 stream.mBitsPerChannel);
44 return streamStr;
47 extern OSStatus CoreAudio_woAudioUnitIOProc(void *inRefCon,
48 AudioUnitRenderActionFlags *ioActionFlags,
49 const AudioTimeStamp *inTimeStamp,
50 UInt32 inBusNumber,
51 UInt32 inNumberFrames,
52 AudioBufferList *ioData);
54 int AudioUnit_CreateDefaultAudioUnit(void *wwo, AudioUnit *au)
56 OSStatus err;
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);
67 if (comp == NULL)
68 return 0;
70 err = OpenAComponent(comp, au);
71 if (comp == NULL)
72 return 0;
74 callbackStruct.inputProc = CoreAudio_woAudioUnitIOProc;
75 callbackStruct.inputProcRefCon = wwo;
77 err = AudioUnitSetProperty( *au,
78 kAudioUnitProperty_SetRenderCallback,
79 kAudioUnitScope_Input,
80 0,
81 &callbackStruct,
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)
94 OSStatus err = noErr;
96 err = AudioUnitSetProperty(au, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input,
97 0, &stream, sizeof(AudioStreamBasicDescription));
99 if (err != noErr)
101 ERR("AudioUnitSetProperty return an error %c%c%c%c\n", (char) (err >> 24), (char) (err >> 16), (char) (err >> 8), (char) err);
102 return 0;
105 err = AudioUnitInitialize(au);
106 if (err != noErr)
108 ERR("AudioUnitInitialize return an error %c%c%c%c\n", (char) (err >> 24), (char) (err >> 16), (char) (err >> 8), (char) err);
109 return 0;
111 return 1;
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);
120 if (err != noErr)
122 ERR("AudioUnitSetParameter return an error %c%c%c%c\n", (char) (err >> 24), (char) (err >> 16), (char) (err >> 8), (char) err);
123 return 0;
125 return 1;
128 int AudioUnit_GetVolume(AudioUnit au, float *left, float *right)
130 OSStatus err = noErr;
132 err = AudioUnitGetParameter(au, kHALOutputParam_Volume, kAudioUnitParameterFlag_Output, 0, left);
133 if (err != noErr)
135 ERR("AudioUnitGetParameter return an error %c%c%c%c\n", (char) (err >> 24), (char) (err >> 16), (char) (err >> 8), (char) err);
136 return 0;
138 *right = *left;
139 return 1;
141 #endif