Simple 3D mixer confusion
Simple 3D mixer confusion
- Subject: Simple 3D mixer confusion
- From: John Stiles <email@hidden>
- Date: Wed, 5 May 2004 11:19:21 -0700
I am trying to use the 3D mixer to make positional sounds work on real
5.1 hardware. At my disposal, I have a Sonica Theater USB box with
outputs for five speakers and a subwoofer.
I have existing code which can play a WAV positioned in 3D space using
the 3D mixer unit. This is serving me quite well. Far-away sounds are
quieter than nearby sounds, and there is a bit of stereo positioning
(not a ton, but enough).
I hooked up the Sonica Theater USB box and installed the latest drivers
from the m-audio web site. The M-Audio setup application shows lots of
surround sound options and multi-speaker configuration; however, Audio
MIDI Setup shows it as a simple "2ch 16-bit" output device. (Even my
SoundSticks have more options--they can go 1ch or 24-bit!) I am not
100% sure but I get the feeling that the Sonica's real purpose is to
SIMULATE surround from a 2-channel input signal, which is pretty lame.
I hope I'm wrong :)
I also got some code from an Apple Game Kitchen that is supposed to
allow my mixer unit to send 5.1 sound to the output unit. (I didn't
attend the kitchen personally; this was brought back by a coworker.)
Apparently the snippet of code at the bottom of this message was able
to get 5.1 going on whatever hardware setup they were running at Apple.
Unsurprisingly, on the Sonica it fails. A bit more surprisingly, it is
also failing testing on the machines in our testing lab, which claim
that our output unit's input format is not a writable property. I don't
understand this, since it's writable on my machine.
So my questions are--what am I doing wrong? Should the Sonica be
showing up as something more than a 2-channel device? Is this Apple
Game Kitchen code useful? Do bugs need to get filed? :)
// CODE SNIPPET!
err = AudioUnitGetProperty( m_outputUnit,
kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 0, &format,
&dataSize );
ASSERTN( err == noErr, err );
format.mChannelsPerFrame = (m_speakerMode == SPEAKERMODE_SURROUND)? 5:
2;
format.mBytesPerPacket = sizeof(float);
format.mBytesPerFrame = sizeof(float);
format.mFormatFlags |= kAudioFormatFlagIsNonInterleaved;
err = AudioUnitSetProperty( m_outputUnit,
kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &format,
sizeof(format) );
if( err != noErr )
{
if( m_speakerMode == SPEAKERMODE_SURROUND )
{
// THIS HAPPENS ON MY SONICA THEATER USB BOX
printf( "FAILED! Surround sound is not supported on this hardware.\n"
);
m_speakerMode = SPEAKERMODE_STEREO;
return err;
}
// THIS HAPPENS TO THE TESTERS, BUT NO PROBLEMS FOR ME AND MY
SOUNDSTICKS OR INTERNAL OUT
printf( "FAILED! Unable to set the speaker mode (output unit: stream
input format). (%d)\n", err );
m_speakerMode = SPEAKERMODE_STEREO;
return err;
}
err = AudioUnitSetProperty( m_mixerUnit,
kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 0, &format,
sizeof(format) );
if( err != noErr )
{
// THIS HASN'T HAPPENED TO ANYONE YET, JUST BEING PARANOID
printf( "Unable to set the speaker mode (mixer unit: stream output
format). (%d)\n", err );
m_speakerMode = SPEAKERMODE_STEREO;
return err;
}
AudioChannelLayout layout = {};
layout.mChannelLayoutTag = (m_speakerMode == SPEAKERMODE_SURROUND)?
kAudioChannelLayoutTag_AudioUnit_5_0: kAudioChannelLayoutTag_Stereo; //
is 5_0 correct? or do I want 5_1??
err = AudioUnitSetProperty( m_outputUnit,
kAudioUnitProperty_AudioChannelLayout, kAudioUnitScope_Input, 0,
&layout, sizeof(layout) );
ASSERTN( err == noErr, err );
err = AudioUnitSetProperty( m_mixerUnit,
kAudioUnitProperty_AudioChannelLayout, kAudioUnitScope_Output, 0,
&layout, sizeof(layout) );
ASSERTN( err == noErr, err );
UInt32 spatialization = kSpatializationAlgorithm_EqualPowerPanning;
switch( m_speakerMode )
{
case SPEAKERMODE_HEADPHONES: spatialization =
kSpatializationAlgorithm_HRTF; break;
case SPEAKERMODE_SURROUND: spatialization =
kSpatializationAlgorithm_SoundField; break;
}
for( int channel=0; channel<64; channel++ )
{
err = AudioUnitSetProperty( m_mixerUnit,
kAudioUnitProperty_SpatializationAlgorithm,
kAudioUnitScope_Input,
channel,
&spatialization,
sizeof(spatialization) );
ASSERTN( err == noErr, err );
}
_______________________________________________
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.