2006-05-28 22:46:23 +02:00
|
|
|
/*
|
|
|
|
* Wine Driver for CoreAudio / AudioUnit
|
|
|
|
*
|
|
|
|
* Copyright 2005, 2006 Emmanuel Maillard
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-06-01 13:15:54 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2006-05-28 22:46:23 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2009-05-02 06:01:18 +02:00
|
|
|
#define ULONG CoreFoundation_ULONG
|
|
|
|
#define HRESULT CoreFoundation_HRESULT
|
2011-01-30 00:45:53 +01:00
|
|
|
#ifndef HAVE_AUDIOUNIT_AUDIOCOMPONENT_H
|
2009-05-02 06:01:18 +02:00
|
|
|
#include <CoreServices/CoreServices.h>
|
2011-01-30 00:45:53 +01:00
|
|
|
#endif
|
2006-05-28 22:46:23 +02:00
|
|
|
#include <AudioUnit/AudioUnit.h>
|
2007-04-25 00:55:33 +02:00
|
|
|
#include <AudioToolbox/AudioToolbox.h>
|
2009-05-02 06:01:18 +02:00
|
|
|
#undef ULONG
|
|
|
|
#undef HRESULT
|
2007-04-25 00:55:33 +02:00
|
|
|
|
2009-01-02 13:54:49 +01:00
|
|
|
#undef DPRINTF
|
2009-05-02 06:01:18 +02:00
|
|
|
#undef STDMETHODCALLTYPE
|
2009-10-11 21:11:19 +02:00
|
|
|
#include "coreaudio.h"
|
2008-12-20 16:02:41 +01:00
|
|
|
#include "wine/debug.h"
|
|
|
|
|
2011-01-30 00:45:53 +01:00
|
|
|
#ifndef HAVE_AUDIOUNIT_AUDIOCOMPONENT_H
|
|
|
|
/* Define new AudioComponent Manager functions for compatibility's sake */
|
|
|
|
typedef Component AudioComponent;
|
|
|
|
typedef ComponentDescription AudioComponentDescription;
|
|
|
|
typedef ComponentInstance AudioComponentInstance;
|
|
|
|
|
|
|
|
static inline AudioComponent AudioComponentFindNext(AudioComponent ac, AudioComponentDescription *desc)
|
|
|
|
{
|
|
|
|
return FindNextComponent(ac, desc);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline OSStatus AudioComponentInstanceNew(AudioComponent ac, AudioComponentInstance *aci)
|
|
|
|
{
|
|
|
|
return OpenAComponent(ac, aci);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline OSStatus AudioComponentInstanceDispose(AudioComponentInstance aci)
|
|
|
|
{
|
|
|
|
return CloseComponent(aci);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-01-30 00:45:54 +01:00
|
|
|
#ifndef HAVE_AUGRAPHADDNODE
|
|
|
|
static inline OSStatus AUGraphAddNode(AUGraph graph, const AudioComponentDescription *desc, AUNode *node)
|
|
|
|
{
|
|
|
|
return AUGraphNewNode(graph, desc, 0, NULL, node);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline OSStatus AUGraphNodeInfo(AUGraph graph, AUNode node, AudioComponentDescription *desc, AudioUnit *au)
|
|
|
|
{
|
|
|
|
return AUGraphGetNodeInfo(graph, node, desc, 0, NULL, au);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-12-20 16:02:41 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(wave);
|
2007-04-25 00:55:33 +02:00
|
|
|
WINE_DECLARE_DEBUG_CHANNEL(midi);
|
2006-05-28 22:46:23 +02:00
|
|
|
|
2009-10-11 21:11:37 +02:00
|
|
|
static const char *streamDescription(const AudioStreamBasicDescription* stream)
|
|
|
|
{
|
|
|
|
return wine_dbg_sprintf("\n mSampleRate : %f\n mFormatID : %s\n mFormatFlags : %lX\n mBytesPerPacket : %lu\n mFramesPerPacket : %lu\n mBytesPerFrame : %lu\n mChannelsPerFrame : %lu\n mBitsPerChannel : %lu\n",
|
|
|
|
stream->mSampleRate,
|
|
|
|
wine_dbgstr_fourcc(stream->mFormatID),
|
|
|
|
stream->mFormatFlags,
|
|
|
|
stream->mBytesPerPacket,
|
|
|
|
stream->mFramesPerPacket,
|
|
|
|
stream->mBytesPerFrame,
|
|
|
|
stream->mChannelsPerFrame,
|
|
|
|
stream->mBitsPerChannel);
|
|
|
|
}
|
|
|
|
|
2006-05-28 22:46:23 +02:00
|
|
|
extern OSStatus CoreAudio_woAudioUnitIOProc(void *inRefCon,
|
|
|
|
AudioUnitRenderActionFlags *ioActionFlags,
|
|
|
|
const AudioTimeStamp *inTimeStamp,
|
|
|
|
UInt32 inBusNumber,
|
|
|
|
UInt32 inNumberFrames,
|
|
|
|
AudioBufferList *ioData);
|
|
|
|
|
2006-12-28 18:05:24 +01:00
|
|
|
extern OSStatus CoreAudio_wiAudioUnitIOProc(void *inRefCon,
|
|
|
|
AudioUnitRenderActionFlags *ioActionFlags,
|
|
|
|
const AudioTimeStamp *inTimeStamp,
|
|
|
|
UInt32 inBusNumber,
|
|
|
|
UInt32 inNumberFrames,
|
|
|
|
AudioBufferList *ioData);
|
|
|
|
|
2006-05-28 22:46:23 +02:00
|
|
|
int AudioUnit_CreateDefaultAudioUnit(void *wwo, AudioUnit *au)
|
|
|
|
{
|
|
|
|
OSStatus err;
|
2011-01-30 00:45:53 +01:00
|
|
|
AudioComponent comp;
|
|
|
|
AudioComponentDescription desc;
|
2006-05-28 22:46:23 +02:00
|
|
|
AURenderCallbackStruct callbackStruct;
|
2009-10-11 21:11:37 +02:00
|
|
|
|
|
|
|
TRACE("\n");
|
2006-05-28 22:46:23 +02:00
|
|
|
|
|
|
|
desc.componentType = kAudioUnitType_Output;
|
|
|
|
desc.componentSubType = kAudioUnitSubType_DefaultOutput;
|
|
|
|
desc.componentManufacturer = kAudioUnitManufacturer_Apple;
|
|
|
|
desc.componentFlags = 0;
|
|
|
|
desc.componentFlagsMask = 0;
|
2006-05-31 14:52:58 +02:00
|
|
|
|
2011-01-30 00:45:53 +01:00
|
|
|
comp = AudioComponentFindNext(NULL, &desc);
|
2006-05-28 22:46:23 +02:00
|
|
|
if (comp == NULL)
|
|
|
|
return 0;
|
|
|
|
|
2011-01-30 00:45:53 +01:00
|
|
|
err = AudioComponentInstanceNew(comp, au);
|
2009-10-11 21:14:03 +02:00
|
|
|
if (err != noErr || *au == NULL)
|
2006-05-28 22:46:23 +02:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
callbackStruct.inputProc = CoreAudio_woAudioUnitIOProc;
|
|
|
|
callbackStruct.inputProcRefCon = wwo;
|
|
|
|
|
|
|
|
err = AudioUnitSetProperty( *au,
|
|
|
|
kAudioUnitProperty_SetRenderCallback,
|
|
|
|
kAudioUnitScope_Input,
|
|
|
|
0,
|
|
|
|
&callbackStruct,
|
|
|
|
sizeof(callbackStruct));
|
|
|
|
return (err == noErr);
|
|
|
|
}
|
|
|
|
|
|
|
|
int AudioUnit_CloseAudioUnit(AudioUnit au)
|
|
|
|
{
|
2011-01-30 00:45:53 +01:00
|
|
|
OSStatus err = AudioComponentInstanceDispose(au);
|
2006-05-28 22:46:23 +02:00
|
|
|
return (err == noErr);
|
|
|
|
}
|
|
|
|
|
2006-05-31 14:52:58 +02:00
|
|
|
int AudioUnit_InitializeWithStreamDescription(AudioUnit au, AudioStreamBasicDescription *stream)
|
2006-05-28 22:46:23 +02:00
|
|
|
{
|
|
|
|
OSStatus err = noErr;
|
|
|
|
|
2009-10-11 21:11:37 +02:00
|
|
|
TRACE("input format: %s\n", streamDescription(stream));
|
|
|
|
|
2006-05-28 22:46:23 +02:00
|
|
|
err = AudioUnitSetProperty(au, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input,
|
2006-05-31 14:52:58 +02:00
|
|
|
0, stream, sizeof(*stream));
|
|
|
|
|
2006-05-28 22:46:23 +02:00
|
|
|
if (err != noErr)
|
|
|
|
{
|
2009-10-11 21:11:19 +02:00
|
|
|
ERR("AudioUnitSetProperty return an error %s\n", wine_dbgstr_fourcc(err));
|
2006-05-28 22:46:23 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = AudioUnitInitialize(au);
|
|
|
|
if (err != noErr)
|
|
|
|
{
|
2009-10-11 21:11:19 +02:00
|
|
|
ERR("AudioUnitInitialize return an error %s\n", wine_dbgstr_fourcc(err));
|
2006-05-28 22:46:23 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int AudioUnit_SetVolume(AudioUnit au, float left, float right)
|
|
|
|
{
|
|
|
|
OSStatus err = noErr;
|
2009-10-16 02:19:20 +02:00
|
|
|
static int once;
|
|
|
|
|
|
|
|
if (!once++) FIXME("independent left/right volume not implemented (%f, %f)\n", left, right);
|
2006-05-28 22:46:23 +02:00
|
|
|
|
|
|
|
err = AudioUnitSetParameter(au, kHALOutputParam_Volume, kAudioUnitParameterFlag_Output, 0, left, 0);
|
|
|
|
|
|
|
|
if (err != noErr)
|
|
|
|
{
|
2009-10-11 21:11:19 +02:00
|
|
|
ERR("AudioUnitSetParameter return an error %s\n", wine_dbgstr_fourcc(err));
|
2006-05-28 22:46:23 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int AudioUnit_GetVolume(AudioUnit au, float *left, float *right)
|
|
|
|
{
|
|
|
|
OSStatus err = noErr;
|
2009-10-16 02:19:20 +02:00
|
|
|
static int once;
|
|
|
|
|
|
|
|
if (!once++) FIXME("independent left/right volume not implemented\n");
|
2006-05-28 22:46:23 +02:00
|
|
|
|
|
|
|
err = AudioUnitGetParameter(au, kHALOutputParam_Volume, kAudioUnitParameterFlag_Output, 0, left);
|
|
|
|
if (err != noErr)
|
|
|
|
{
|
2009-10-11 21:11:19 +02:00
|
|
|
ERR("AudioUnitGetParameter return an error %s\n", wine_dbgstr_fourcc(err));
|
2006-05-28 22:46:23 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
*right = *left;
|
|
|
|
return 1;
|
|
|
|
}
|
2006-12-28 18:05:24 +01:00
|
|
|
|
|
|
|
|
2006-12-28 18:07:24 +01:00
|
|
|
/* FIXME: implement sample rate conversion on input */
|
|
|
|
int AudioUnit_GetInputDeviceSampleRate(void)
|
|
|
|
{
|
|
|
|
AudioDeviceID defaultInputDevice;
|
|
|
|
UInt32 param;
|
2011-01-30 00:45:54 +01:00
|
|
|
AudioObjectPropertyAddress propertyAddress;
|
2006-12-28 18:07:24 +01:00
|
|
|
Float64 sampleRate;
|
|
|
|
OSStatus err;
|
|
|
|
|
|
|
|
param = sizeof(defaultInputDevice);
|
2011-01-30 00:45:54 +01:00
|
|
|
propertyAddress.mSelector = kAudioHardwarePropertyDefaultInputDevice;
|
|
|
|
propertyAddress.mScope = kAudioObjectPropertyScopeGlobal;
|
|
|
|
propertyAddress.mElement = kAudioObjectPropertyElementMaster;
|
|
|
|
err = AudioObjectGetPropertyData(kAudioObjectSystemObject, &propertyAddress, 0, NULL, ¶m, &defaultInputDevice);
|
2006-12-28 18:07:24 +01:00
|
|
|
if (err != noErr || defaultInputDevice == kAudioDeviceUnknown)
|
|
|
|
{
|
|
|
|
ERR("Couldn't get the default audio input device ID: %08lx\n", err);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
param = sizeof(sampleRate);
|
2011-01-30 00:45:54 +01:00
|
|
|
propertyAddress.mSelector = kAudioDevicePropertyNominalSampleRate;
|
|
|
|
propertyAddress.mScope = kAudioDevicePropertyScopeInput;
|
|
|
|
err = AudioObjectGetPropertyData(defaultInputDevice, &propertyAddress, 0, NULL, ¶m, &sampleRate);
|
2006-12-28 18:07:24 +01:00
|
|
|
if (err != noErr)
|
|
|
|
{
|
|
|
|
ERR("Couldn't get the device sample rate: %08lx\n", err);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return sampleRate;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-12-28 18:05:24 +01:00
|
|
|
int AudioUnit_CreateInputUnit(void* wwi, AudioUnit* out_au,
|
2006-12-28 18:06:23 +01:00
|
|
|
WORD nChannels, DWORD nSamplesPerSec, WORD wBitsPerSample,
|
|
|
|
UInt32* outFrameCount)
|
2006-12-28 18:05:24 +01:00
|
|
|
{
|
|
|
|
OSStatus err = noErr;
|
2011-01-30 00:45:53 +01:00
|
|
|
AudioComponentDescription description;
|
|
|
|
AudioComponent component;
|
2006-12-28 18:05:24 +01:00
|
|
|
AudioUnit au;
|
|
|
|
UInt32 param;
|
2011-01-30 00:45:54 +01:00
|
|
|
AudioObjectPropertyAddress propertyAddress;
|
2006-12-28 18:05:24 +01:00
|
|
|
AURenderCallbackStruct callback;
|
|
|
|
AudioDeviceID defaultInputDevice;
|
|
|
|
AudioStreamBasicDescription desiredFormat;
|
|
|
|
|
|
|
|
|
2006-12-28 18:06:23 +01:00
|
|
|
if (!outFrameCount)
|
|
|
|
{
|
|
|
|
ERR("Invalid parameter\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-12-28 18:05:24 +01:00
|
|
|
/* Open the AudioOutputUnit */
|
|
|
|
description.componentType = kAudioUnitType_Output;
|
|
|
|
description.componentSubType = kAudioUnitSubType_HALOutput;
|
|
|
|
description.componentManufacturer = kAudioUnitManufacturer_Apple;
|
|
|
|
description.componentFlags = 0;
|
|
|
|
description.componentFlagsMask = 0;
|
|
|
|
|
2011-01-30 00:45:53 +01:00
|
|
|
component = AudioComponentFindNext(NULL, &description);
|
2006-12-28 18:05:24 +01:00
|
|
|
if (!component)
|
|
|
|
{
|
2011-01-30 00:45:53 +01:00
|
|
|
ERR("AudioComponentFindNext(kAudioUnitSubType_HALOutput) failed\n");
|
2006-12-28 18:05:24 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-01-30 00:45:53 +01:00
|
|
|
err = AudioComponentInstanceNew(component, &au);
|
2006-12-28 18:05:24 +01:00
|
|
|
if (err != noErr || au == NULL)
|
|
|
|
{
|
2011-01-30 00:45:53 +01:00
|
|
|
ERR("AudioComponentInstanceNew failed: %08lx\n", err);
|
2006-12-28 18:05:24 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Configure the AudioOutputUnit */
|
|
|
|
/* The AUHAL has two buses (AKA elements). Bus 0 is output from the app
|
|
|
|
* to the device. Bus 1 is input from the device to the app. Each bus
|
|
|
|
* has two ends (AKA scopes). Data goes from the input scope to the
|
|
|
|
* output scope. The terminology is somewhat confusing because the terms
|
|
|
|
* "input" and "output" have two meanings. Here's a summary:
|
|
|
|
*
|
|
|
|
* Bus 0, input scope: refers to the source of data to be output as sound
|
|
|
|
* Bus 0, output scope: refers to the actual sound output device
|
|
|
|
* Bus 1, input scope: refers to the actual sound input device
|
|
|
|
* Bus 1, output scope: refers to the destination of data received by the input device
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Enable input on the AUHAL */
|
|
|
|
param = 1;
|
|
|
|
err = AudioUnitSetProperty(au, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Input, 1, ¶m, sizeof(param));
|
|
|
|
if (err != noErr)
|
|
|
|
{
|
|
|
|
ERR("Couldn't enable input on AUHAL: %08lx\n", err);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Disable Output on the AUHAL */
|
|
|
|
param = 0;
|
|
|
|
err = AudioUnitSetProperty(au, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Output, 0, ¶m, sizeof(param));
|
|
|
|
if (err != noErr)
|
|
|
|
{
|
|
|
|
ERR("Couldn't disable output on AUHAL: %08lx\n", err);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find the default input device */
|
|
|
|
param = sizeof(defaultInputDevice);
|
2011-01-30 00:45:54 +01:00
|
|
|
propertyAddress.mSelector = kAudioHardwarePropertyDefaultInputDevice;
|
|
|
|
propertyAddress.mScope = kAudioObjectPropertyScopeGlobal;
|
|
|
|
propertyAddress.mElement = kAudioObjectPropertyElementMaster;
|
|
|
|
err = AudioObjectGetPropertyData(kAudioObjectSystemObject, &propertyAddress, 0, NULL, ¶m, &defaultInputDevice);
|
2006-12-28 18:05:24 +01:00
|
|
|
if (err != noErr || defaultInputDevice == kAudioDeviceUnknown)
|
|
|
|
{
|
|
|
|
ERR("Couldn't get the default audio device ID: %08lx\n", err);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the current device to the default input device. */
|
|
|
|
err = AudioUnitSetProperty(au, kAudioOutputUnitProperty_CurrentDevice, kAudioUnitScope_Global, 0, &defaultInputDevice, sizeof(defaultInputDevice));
|
|
|
|
if (err != noErr)
|
|
|
|
{
|
|
|
|
ERR("Couldn't set current device of AUHAL to default input device: %08lx\n", err);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Setup render callback */
|
|
|
|
/* This will be called when the AUHAL has input data. However, it won't
|
|
|
|
* be passed the data itself. The callback will have to all AudioUnitRender. */
|
|
|
|
callback.inputProc = CoreAudio_wiAudioUnitIOProc;
|
|
|
|
callback.inputProcRefCon = wwi;
|
|
|
|
err = AudioUnitSetProperty(au, kAudioOutputUnitProperty_SetInputCallback, kAudioUnitScope_Global, 0, &callback, sizeof(callback));
|
|
|
|
if (err != noErr)
|
|
|
|
{
|
|
|
|
ERR("Couldn't set input callback of AUHAL: %08lx\n", err);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Setup the desired data format. */
|
2006-12-28 18:07:24 +01:00
|
|
|
/* FIXME: implement sample rate conversion on input. We shouldn't set
|
|
|
|
* the mSampleRate of this to the desired sample rate. We need to query
|
|
|
|
* the input device and use that. If they don't match, we need to set up
|
|
|
|
* an AUConverter to do the sample rate conversion on a separate thread. */
|
2006-12-28 18:05:24 +01:00
|
|
|
desiredFormat.mFormatID = kAudioFormatLinearPCM;
|
|
|
|
desiredFormat.mFormatFlags = kLinearPCMFormatFlagIsPacked;
|
|
|
|
if (wBitsPerSample != 8)
|
|
|
|
desiredFormat.mFormatFlags |= kLinearPCMFormatFlagIsSignedInteger;
|
|
|
|
desiredFormat.mSampleRate = nSamplesPerSec;
|
|
|
|
desiredFormat.mChannelsPerFrame = nChannels;
|
|
|
|
desiredFormat.mFramesPerPacket = 1;
|
|
|
|
desiredFormat.mBitsPerChannel = wBitsPerSample;
|
|
|
|
desiredFormat.mBytesPerFrame = desiredFormat.mBitsPerChannel * desiredFormat.mChannelsPerFrame / 8;
|
|
|
|
desiredFormat.mBytesPerPacket = desiredFormat.mBytesPerFrame * desiredFormat.mFramesPerPacket;
|
|
|
|
|
|
|
|
/* Set the AudioOutputUnit output data format */
|
|
|
|
err = AudioUnitSetProperty(au, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 1, &desiredFormat, sizeof(desiredFormat));
|
|
|
|
if (err != noErr)
|
|
|
|
{
|
|
|
|
ERR("Couldn't set desired input format of AUHAL: %08lx\n", err);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2006-12-28 18:06:23 +01:00
|
|
|
/* Get the number of frames in the IO buffer(s) */
|
|
|
|
param = sizeof(*outFrameCount);
|
|
|
|
err = AudioUnitGetProperty(au, kAudioDevicePropertyBufferFrameSize, kAudioUnitScope_Global, 0, outFrameCount, ¶m);
|
|
|
|
if (err != noErr)
|
|
|
|
{
|
|
|
|
ERR("Failed to get audio sample size: %08lx\n", err);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("Frame count: %lu\n", *outFrameCount);
|
|
|
|
|
|
|
|
/* Initialize the AU */
|
|
|
|
err = AudioUnitInitialize(au);
|
|
|
|
if (err != noErr)
|
|
|
|
{
|
|
|
|
ERR("Failed to initialize AU: %08lx\n", err);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2006-12-28 18:05:24 +01:00
|
|
|
*out_au = au;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
error:
|
|
|
|
if (au)
|
2011-01-30 00:45:53 +01:00
|
|
|
AudioComponentInstanceDispose(au);
|
2006-12-28 18:05:24 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-04-25 00:55:33 +02:00
|
|
|
/*
|
|
|
|
* MIDI Synth Unit
|
|
|
|
*/
|
|
|
|
int SynthUnit_CreateDefaultSynthUnit(AUGraph *graph, AudioUnit *synth)
|
|
|
|
{
|
|
|
|
OSStatus err;
|
2011-01-30 00:45:53 +01:00
|
|
|
AudioComponentDescription desc;
|
2007-04-25 00:55:33 +02:00
|
|
|
AUNode synthNode;
|
|
|
|
AUNode outNode;
|
|
|
|
|
|
|
|
err = NewAUGraph(graph);
|
|
|
|
if (err != noErr)
|
|
|
|
{
|
2009-10-11 21:11:19 +02:00
|
|
|
ERR_(midi)("NewAUGraph return %s\n", wine_dbgstr_fourcc(err));
|
2007-04-25 00:55:33 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
desc.componentManufacturer = kAudioUnitManufacturer_Apple;
|
|
|
|
desc.componentFlags = 0;
|
|
|
|
desc.componentFlagsMask = 0;
|
|
|
|
|
|
|
|
/* create synth node */
|
|
|
|
desc.componentType = kAudioUnitType_MusicDevice;
|
|
|
|
desc.componentSubType = kAudioUnitSubType_DLSSynth;
|
|
|
|
|
2011-01-30 00:45:54 +01:00
|
|
|
err = AUGraphAddNode(*graph, &desc, &synthNode);
|
2007-04-25 00:55:33 +02:00
|
|
|
if (err != noErr)
|
|
|
|
{
|
2011-01-30 00:45:54 +01:00
|
|
|
ERR_(midi)("AUGraphAddNode cannot create synthNode : %s\n", wine_dbgstr_fourcc(err));
|
2007-04-25 00:55:33 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* create out node */
|
|
|
|
desc.componentType = kAudioUnitType_Output;
|
|
|
|
desc.componentSubType = kAudioUnitSubType_DefaultOutput;
|
|
|
|
|
2011-01-30 00:45:54 +01:00
|
|
|
err = AUGraphAddNode(*graph, &desc, &outNode);
|
2007-04-25 00:55:33 +02:00
|
|
|
if (err != noErr)
|
|
|
|
{
|
2011-01-30 00:45:54 +01:00
|
|
|
ERR_(midi)("AUGraphAddNode cannot create outNode %s\n", wine_dbgstr_fourcc(err));
|
2007-04-25 00:55:33 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = AUGraphOpen(*graph);
|
|
|
|
if (err != noErr)
|
|
|
|
{
|
2009-10-11 21:11:19 +02:00
|
|
|
ERR_(midi)("AUGraphOpen return %s\n", wine_dbgstr_fourcc(err));
|
2007-04-25 00:55:33 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* connecting the nodes */
|
|
|
|
err = AUGraphConnectNodeInput(*graph, synthNode, 0, outNode, 0);
|
|
|
|
if (err != noErr)
|
|
|
|
{
|
2009-10-11 21:11:19 +02:00
|
|
|
ERR_(midi)("AUGraphConnectNodeInput cannot connect synthNode to outNode : %s\n", wine_dbgstr_fourcc(err));
|
2007-04-25 00:55:33 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the synth unit */
|
2011-01-30 00:45:54 +01:00
|
|
|
err = AUGraphNodeInfo(*graph, synthNode, 0, synth);
|
2007-04-25 00:55:33 +02:00
|
|
|
if (err != noErr)
|
|
|
|
{
|
2011-01-30 00:45:54 +01:00
|
|
|
ERR_(midi)("AUGraphNodeInfo return %s\n", wine_dbgstr_fourcc(err));
|
2007-04-25 00:55:33 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int SynthUnit_Initialize(AudioUnit synth, AUGraph graph)
|
|
|
|
{
|
|
|
|
OSStatus err = noErr;
|
|
|
|
|
|
|
|
err = AUGraphInitialize(graph);
|
|
|
|
if (err != noErr)
|
|
|
|
{
|
2009-10-11 21:11:19 +02:00
|
|
|
ERR_(midi)("AUGraphInitialize(%p) return %s\n", graph, wine_dbgstr_fourcc(err));
|
2007-04-25 00:55:33 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = AUGraphStart(graph);
|
|
|
|
if (err != noErr)
|
|
|
|
{
|
2009-10-11 21:11:19 +02:00
|
|
|
ERR_(midi)("AUGraphStart(%p) return %s\n", graph, wine_dbgstr_fourcc(err));
|
2007-04-25 00:55:33 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int SynthUnit_Close(AUGraph graph)
|
|
|
|
{
|
|
|
|
OSStatus err = noErr;
|
|
|
|
|
|
|
|
err = AUGraphStop(graph);
|
|
|
|
if (err != noErr)
|
|
|
|
{
|
2009-10-11 21:11:19 +02:00
|
|
|
ERR_(midi)("AUGraphStop(%p) return %s\n", graph, wine_dbgstr_fourcc(err));
|
2007-04-25 00:55:33 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = DisposeAUGraph(graph);
|
|
|
|
if (err != noErr)
|
|
|
|
{
|
2009-10-11 21:11:19 +02:00
|
|
|
ERR_(midi)("DisposeAUGraph(%p) return %s\n", graph, wine_dbgstr_fourcc(err));
|
2007-04-25 00:55:33 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|