150 likes | 370 Vues
GAM532 DPS932 – Week 10. 3 D Audio. 3D Sound and The Scene. Mono Sound Effects. Stereo Music. Mono vs Stereo. Left - Right 100% 100% Ch 1 Ch 1. Mono Sound File. One Channel. Left - Right 100% 100% Ch 1 Ch 2. Stereo Sound File. Two Channels.
E N D
GAM532DPS932 – Week 10 3D Audio
3D Sound and The Scene Mono Sound Effects Stereo Music
Mono vs Stereo Left - Right100% 100% Ch 1Ch 1 Mono Sound File One Channel Left - Right100% 100% Ch 1Ch 2 Stereo Sound File Two Channels
3D Sound and The Scene Mono Sound Effects Stereo Music
Deriving Spatial Info From Matrix Up Direction [ 23, 32, -17 ] Forward Direction Orientation Position [ 0, 1, 0, 0 ] * AbsTransform = Up Direction Forward Direction = [ 0, 0, -1, 0 ] * AbsTransform Position Vector = [ 0, 0, 0, 1 ] * AbsTransform
Initializing 3D Audio #include <X3DAudio.h> #pragma comment (lib, "X3DAudio.lib") //After XAudio2 is initialized… XAUDIO2_DEVICE_DETAILS vd; engine->GetDeviceDetails(0, &vd); //initialize the 3D audio system X3DAudioInitialize(vd.OutputFormat.dwChannelMask, X3DAUDIO_SPEED_OF_SOUND, x3h); X3DAUDIO_DSP_SETTINGS set; //used later set.SrcChannelCount = 1; set.DstChannelCount = vd.OutputFormat.Format.nChannels; set.pMatrixCoefficients = new float[set.DstChannelCount]; //No additional initialization must be done with OpenAL
Emitter Spatial Information Directionality Distance, Direction, & Velocity Up Direction Attenuation Doppler Effect Forward Direction Position Vector
Initializing a 3D Emitter X3DAUDIO_EMITTER emt; ZeroMemory(&emit, sizeof(emit)); emt.ChannelCount = 1; //sets # output channels emt.CurveDistanceScaler = 14; emit.DopplerScaler= 1; emit.InnerRadius= 2; emit.ChannelRadius= 1; //Note: This simply prepares the struct, the //listener info isn’t updated yet //No additional code required for OpenAL
Updating Emitter //Sets the spatial information of the emitter emt.OrientFront = frontVec;//3 float array emt.OrientTop = upVec; emt.Position = posVec; //Note: This simply prepares the struct, the //emitter info isn’t updated yet //Sets the spatial information of the emitter alSourcefv(src, AL_POSITION, posVec);//3 float array alSourcefv(src, AL_ORIENTATION, forwardVec); //3 float //Unlike DX, this sets the emitter information //immediately
Listener Spatial Information Left - Right70% 70% Left - Right80%20% Left - Right20% 80% Up Direction Right Channel Left Channel Forward Direction Position Vector Listener facing screen
Updating Listener X3DAUDIO_LISTENER lst; //Sets the spatial information of the listener lst.OrientFront = frontVec;//3 float array lst.OrientTop = upVec; Lst.Position = posVec; //Note: This simply prepares the struct, the //listener info isn’t updated yet //Sets the spatial information of the listener alListenerfv(AL_POSITION, posVec);//3 float array //6 float array, first 3 up vector, last 3 forward vector alListenerfv(AL_ORIENTATION, ori); //Unlike DX, this sets the listeners information //immediately
Applying 3D Audio in XAudio2 X3DAudioCalculate(x3h, &lst, //The listener struct &emt, //The emitter struct X3DAUDIO_CALCULATE_MATRIX, //instruct the calculation of the sound matrix &set); //DPS struct to be used below engine->SetOutputMatrix(master, //The master voice 1, //number of source channels vd.OutputFormat.Format.nChannels, //number of output channels set.pMatrixCoefficients); //Sound matrix
Updating Emitter Velocity //Sets the spatial information of the emitter emt.Velocity = velocity; //when updating the emitter X3DAudioCalculate(x3h, &lst, &emt, X3DAUDIO_CALCULATE_MATRIX | X3DAUDIO_CALCULATE_DOPPLER, &set); //Sets the spatial information of the emitter alSourcefv(src, AL_VELOCITY, velocity);//3 float array
To Do • Continue work on your enhancement • Work on OpenGL labs