Emagic EMI 2|6 Sample Code
Emagic EMI 2|6 Sample Code
- Subject: Emagic EMI 2|6 Sample Code
- From: Christof Faller <email@hidden>
- Date: Mon, 11 Feb 2002 17:10:54 -0500
This e-mail contains sample code for properly initializing
the EMI 2|6 for use as a device and with AudioUnits. The
proviced source works specifically with the EMI 2|6 and
does not poll the audio device properly for initializing
other devices.
The sample code correctly initializes the audio device,
but then uses an AudioUnit to access the device (such
that the MacOS X does the re-sampling, in this case
32kHz to 44.1kHz).
As mentioned in an earlier post, the EMI 2|6 can be used with
MacOS X as follows:
It is enough to just have Classic with the EMI driver installed running
while you plug the USB device in, and it will initialize correctly.
===> let me know if anyone is interested in sample code for a
corresponding AU callback function.
Chris
========================================================
Here is sample code for initializing the EMI 2|6 for stereo usage
(below is similar code for 6 channel usage)
========================================================
Before running this code make sure the EMI 2|6 is selected as your
default output device in the MacOS X control panel.
#define BUFSIZE_FRAMES 1024
AudioStreamBasicDescription austream;
AudioDeviceID audiodeviceid;
OSStatus err = noErr;
UInt32 count, devicebuffersize;
// get audio device associated with AudioUnit
count = sizeof(austream);
err = AudioUnitGetProperty(
audiounitinstance,
kAudioOutputUnitProperty_CurrentDevice,
kAudioUnitScope_Global,
0, &audiodeviceid, &count);
if (err != noErr) {
fprintf(stderr, "Could not get audio device id!\n");
exit(0);
}
// set properties of audio device
austream.mSampleRate = 44100;
austream.mFormatID = kAudioFormatLinearPCM;
austream.mFormatFlags = kLinearPCMFormatFlagIsFloat |
kLinearPCMFormatFlagIsBigEndian |
kLinearPCMFormatFlagIsPacked;
austream.mBytesPerPacket = 8;
austream.mFramesPerPacket = 1;
austream.mBytesPerFrame = 8;
austream.mChannelsPerFrame = 2;
austream.mBitsPerChannel = 32;
count = sizeof(austream);
err = AudioDeviceSetProperty(audiodeviceid,
NULL, 0, 0, kAudioDevicePropertyStreamFormat,
count, &austream);
if (err != noErr) {
fprintf(stderr, "Could not set number of channels for audio
device!\n");
exit(0);
}
count = sizeof(devicebuffersize);
devicebuffersize = BUFSIZE_FRAMES;
err = AudioDeviceSetProperty(audiodeviceid,
NULL, 0, 0, kAudioDevicePropertyBufferFrameSize,
count, &devicebuffersize);
if (err != noErr) {
fprintf(stderr, "Could not set audio device buffer size!\n");
exit(0);
}
// set audio stream format for AudioUnit
austream.mSampleRate = 32000;
austream.mFormatID = kAudioFormatLinearPCM;
austream.mFormatFlags = kLinearPCMFormatFlagIsFloat |
kLinearPCMFormatFlagIsBigEndian |
kLinearPCMFormatFlagIsPacked;
austream.mBytesPerPacket = 8;
austream.mFramesPerPacket = 1;
austream.mBytesPerFrame = 8;
austream.mChannelsPerFrame = 2;
austream.mBitsPerChannel = 32;
count = sizeof(AudioStreamBasicDescription);
err = AudioUnitSetProperty(
audiounitinstance,
kAudioUnitProperty_StreamFormat,
kAudioUnitScope_Input,
0, (void *) &austream, count);
if (err != noErr) {
fprintf(stderr, "Could not setup audio unit stream format
for surround!!\n");
exit(0);
}
========================================================
Here is sample code for initializing the EMI 2|6 for 6 channel usage
========================================================
#define BUFSIZE_FRAMES 2048
My experience is that for seamless 6 channel playback a buffer
at lease as big as specified (2048) is necessary.
AudioStreamBasicDescription austream;
AudioDeviceID audiodeviceid;
OSStatus err = noErr;
UInt32 count, devicebuffersize;
// get audio device associated with AudioUnit
count = sizeof(austream);
err = AudioUnitGetProperty(
audiounitinstance,
kAudioOutputUnitProperty_CurrentDevice,
kAudioUnitScope_Global,
0, &audiodeviceid, &count);
if (err != noErr) {
fprintf(stderr, "Could not get audio device id!\n");
exit(0);
}
// set properties of audio device
austream.mSampleRate = 44100;
austream.mFormatID = kAudioFormatLinearPCM;
austream.mFormatFlags = kLinearPCMFormatFlagIsFloat |
kLinearPCMFormatFlagIsBigEndian |
kLinearPCMFormatFlagIsPacked;
austream.mBytesPerPacket = 24;
austream.mFramesPerPacket = 1;
austream.mBytesPerFrame = 24;
austream.mChannelsPerFrame = 6;
austream.mBitsPerChannel = 32;
count = sizeof(austream);
err = AudioDeviceSetProperty(audiodeviceid,
NULL, 0, 0, kAudioDevicePropertyStreamFormat,
count, &austream);
if (err != noErr) {
fprintf(stderr, "Could not set number of channels for audio
device!\n");
exit(0);
}
count = sizeof(devicebuffersize);
devicebuffersize = BUFSIZE_FRAMES;
err = AudioDeviceSetProperty(audiodeviceid,
NULL, 0, 0, kAudioDevicePropertyBufferFrameSize,
count, &devicebuffersize);
if (err != noErr) {
fprintf(stderr, "Could not set audio device buffer size!\n");
exit(0);
}
// set audio stream format for AudioUnit
austream.mSampleRate = 32000;
austream.mFormatID = kAudioFormatLinearPCM;
austream.mFormatFlags = kLinearPCMFormatFlagIsFloat |
kLinearPCMFormatFlagIsBigEndian |
kLinearPCMFormatFlagIsPacked;
austream.mBytesPerPacket = 24;
austream.mFramesPerPacket = 1;
austream.mBytesPerFrame = 24;
austream.mChannelsPerFrame = 6;
austream.mBitsPerChannel = 32;
count = sizeof(AudioStreamBasicDescription);
err = AudioUnitSetProperty(
audiounitinstance,
kAudioUnitProperty_StreamFormat,
kAudioUnitScope_Input,
0, (void *) &austream, count);
if (err != noErr) {
fprintf(stderr, "Could not setup audio unit stream format
for surround!!\n");
exit(0);
}
========================================================
_______________________________________________
coreaudio-api mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/coreaudio-api
Do not post admin requests to the list. They will be ignored.