From 89a0052b2127a66abb42a56d8c10dfbec19b6bed Mon Sep 17 00:00:00 2001 From: spacy51 Date: Mon, 14 Jul 2008 17:59:15 +0000 Subject: [PATCH] ADDED stereo to surround upmixing (XAudio2) git-svn-id: https://svn.code.sf.net/p/vbam/code/trunk@588 a31d4220-a93d-0410-bf67-fe4944624d44 --- src/win32/XAudio2.cpp | 64 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/src/win32/XAudio2.cpp b/src/win32/XAudio2.cpp index 1435b1a6..a22cb59a 100644 --- a/src/win32/XAudio2.cpp +++ b/src/win32/XAudio2.cpp @@ -23,6 +23,7 @@ #define NBUFFERS 4 +#define STEREO_UPMIXING // MFC #include "stdafx.h" @@ -216,6 +217,69 @@ bool XAudio2_Output::init() return false; } + +#ifdef STEREO_UPMIXING + // set up stereo upmixing + XAUDIO2_DEVICE_DETAILS dd; + ZeroMemory( &dd, sizeof( dd ) ); + hr = xaud->GetDeviceDetails( 0, &dd ); + ASSERT( hr == S_OK ); + float *matrix = NULL; + matrix = (float*)malloc( sizeof( float ) * 2 * dd.OutputFormat.Format.nChannels ); + switch( dd.OutputFormat.Format.nChannels ) { + case 4: // 4.0 +//Speaker \ Left Source Right Source +/*Front L*/ matrix[0] = 1.0000f; matrix[1] = 0.0000f; +/*Front R*/ matrix[2] = 0.0000f; matrix[3] = 1.0000f; +/*Back L*/ matrix[4] = 1.0000f; matrix[5] = 0.0000f; +/*Back R*/ matrix[6] = 0.0000f; matrix[7] = 1.0000f; + break; + case 5: // 5.0 +//Speaker \ Left Source Right Source +/*Front L*/ matrix[0] = 1.0000f; matrix[1] = 0.0000f; +/*Front R*/ matrix[2] = 0.0000f; matrix[3] = 1.0000f; +/*Front C*/ matrix[4] = 0.7071f; matrix[5] = 0.7071f; +/*Side L*/ matrix[6] = 1.0000f; matrix[7] = 0.0000f; +/*Side R*/ matrix[8] = 0.0000f; matrix[9] = 1.0000f; + break; + case 6: // 5.1 +//Speaker \ Left Source Right Source +/*Front L*/ matrix[0] = 1.0000f; matrix[1] = 0.0000f; +/*Front R*/ matrix[2] = 0.0000f; matrix[3] = 1.0000f; +/*Front C*/ matrix[4] = 0.7071f; matrix[5] = 0.7071f; +/*LFE */ matrix[6] = 0.0000f; matrix[7] = 0.0000f; +/*Side L*/ matrix[8] = 1.0000f; matrix[9] = 0.0000f; +/*Side R*/ matrix[10] = 0.0000f; matrix[11] = 1.0000f; + break; + case 7: // 6.1 +//Speaker \ Left Source Right Source +/*Front L*/ matrix[0] = 1.0000f; matrix[1] = 0.0000f; +/*Front R*/ matrix[2] = 0.0000f; matrix[3] = 1.0000f; +/*Front C*/ matrix[4] = 0.7071f; matrix[5] = 0.7071f; +/*LFE */ matrix[6] = 0.0000f; matrix[7] = 0.0000f; +/*Side L*/ matrix[8] = 1.0000f; matrix[9] = 0.0000f; +/*Side R*/ matrix[10] = 0.0000f; matrix[11] = 1.0000f; +/*Back C*/ matrix[12] = 0.7071f; matrix[13] = 0.7071f; + break; + case 8: // 7.1 +//Speaker \ Left Source Right Source +/*Front L*/ matrix[0] = 1.0000f; matrix[1] = 0.0000f; +/*Front R*/ matrix[2] = 0.0000f; matrix[3] = 1.0000f; +/*Front C*/ matrix[4] = 0.7071f; matrix[5] = 0.7071f; +/*LFE */ matrix[6] = 0.0000f; matrix[7] = 0.0000f; +/*Back L*/ matrix[8] = 1.0000f; matrix[9] = 0.0000f; +/*Back R*/ matrix[10] = 0.0000f; matrix[11] = 1.0000f; +/*Side L*/ matrix[12] = 1.0000f; matrix[13] = 0.0000f; +/*Side R*/ matrix[14] = 0.0000f; matrix[15] = 1.0000f; + break; + } + hr = sVoice->SetOutputMatrix( NULL, 2, dd.OutputFormat.Format.nChannels, matrix ); + ASSERT( hr == S_OK ); + free( matrix ); + matrix = NULL; +#endif + + hr = sVoice->Start( 0 ); ASSERT( hr == S_OK ); playing = true;