- Well, after two days of not being able to work on this due to Comps prep and trouble with a significant fraction of my vehicles, maybe I can get something working today.
- Added everything from How to: Integrate X3DAudio with XAudio2, and definitely got a result – when the emitter position moved off of center, the sound cut out. Now you might think that’s a bad thing, but my guess is that I have some variable that either being set with zero or junk, which is messing up the sound matrix calculations.
- Using the XAudio2Sound3D project as a source of code to mine, I pulled over the (much more extensive) emitter setup and now have things working, although not as clearly as I’d like. Next is to clean up and package the code into the SampleSound-derived classes.
- And by the way, this might be a good hard hat to try the rig on: http://www.amazon.com/ERB-19224-Americana-Full-Ratchet/dp/B001LYB7JW
- Cleared a lot of nonessential (i.e. listening cone)code out of the emitter
- Realized that I could probably use voice->SetOutputMatrix() to set the channels directly. I added a method that cleans out the dspSettings.matrixCoefficients and then sets a single value in the matrix. Whadaya know – it worked 🙂
- Need to do some packaging of the code, but I now have enough to do tests for the situational awareness system and to get rid of the MIDI boards for the vibrotactile controller.
Category Archives: Sound
Now that XAudio2 is clear, time to be confused with X3DAudio
- Finished rolling up the SampleSounds(s) into BasicAudio.
- Starting on 3D audio, using How to: Integrate X3DAudio with XAudio2
- Adding the 3D calls to the main() in ConsoleSound2, just after the BasicAudio class has been initialized.
- Had to add x3daudio.lib to the project and <x3daudio.h> to the #includes.
- This looks to be the meat of the calculation. It looks like X3DCalculate() works on the relative position of an Emitter and the Listener and uses that to populate a DSP. Once that’s done, then the Audio2 source is manipulated appropriately.
-
X3DAudioCalculate( g_audioState.x3DInstance, &g_audioState.listener, &g_audioState.emitter, dwCalcFlags, &g_audioState.dspSettings ); IXAudio2SourceVoice* voice = g_audioState.pSourceVoice; if( voice ) { // Apply X3DAudio generated DSP settings to XAudio2 voice->SetFrequencyRatio( g_audioState.dspSettings.DopplerFactor ); voice->SetOutputMatrix( g_audioState.pMasteringVoice, INPUTCHANNELS, g_audioState.nChannels, g_audioState.matrixCoefficients ); voice->SetOutputMatrix(g_audioState.pSubmixVoice, 1, 1, &g_audioState.dspSettings.ReverbLevel); XAUDIO2_FILTER_PARAMETERS FilterParametersDirect = { LowPassFilter, 2.0f * sinf(X3DAUDIO_PI/6.0f * g_audioState.dspSettings.LPFDirectCoefficient), 1.0f }; // see XAudio2CutoffFrequencyToRadians() in XAudio2.h for more information on the formula used here voice->SetOutputFilterParameters(g_audioState.pMasteringVoice, &FilterParametersDirect); XAUDIO2_FILTER_PARAMETERS FilterParametersReverb = { LowPassFilter, 2.0f * sinf(X3DAUDIO_PI/6.0f * g_audioState.dspSettings.LPFReverbCoefficient), 1.0f }; // see XAudio2CutoffFrequencyToRadians() in XAudio2.h for more information on the formula used here voice->SetOutputFilterParameters(g_audioState.pSubmixVoice, &FilterParametersReverb); }
Boring progress. But hey! Progress :-)
Today’s work. Just solid satisfying programming, though I am playing fast and loose with pointers because of headaches getting const to behave properly.
- Working on getting multi buffer support. Done! Also got repeating sound working.
- Going to put a basic Audio class together to manage SampleSounds.
- Done. BasicAudio (awesome name, huh?) is pretty wrapped up. Once all this is clean and commented, I’ll post the files.
- Start on 3D/multichannel tomorrow?
Approaching understanding
Today was a good day of slow progress! Here’s the play by play.
- Building a copy of XAudio2BasicSound, cleverly calling it ConsoleSound2.
- Since it depends on SDKwavefile, I had to pull SAFE_DELETE, SAFE_DELETE_ARRAY, and SAFE_RELEASE from dxut.h. It also requires dxerr.h. but that’s in the regular directx include directory.
- Extremely empty code right now, but it compiles and links. On a side note, the compiler should accept the environment variable $(DXSDK_DIR), but it doesn’t. And adding macros is an enormous pain, as near as I can tell.
- The code is ported over and works. It’s all stuck in a main() right now. I need to clean up and build an Audio class. Actually, looking at the way the code is set up, a WavSampleSound class might be better. It probably could extend from a SampleSound class, but I’ll break that out later…
- Class is mostly done and running!
-

- The only bug that I have is that I can run the sound only once. I still need to figure out how to reload the buffer.
3D sound compiled and running, if not understood all that well…
Today’s twists and turns:
- More Audio3d.
- Starting to add in the 3dAudio based on this and this and this.
- Got an audio link error and chased that down, discovering a few things along the way.
- There is directX help for C++ in (“C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Documentation\DirectX9\directx_sdk.chm”). I don’t know it it’s any good, but I’m going to look though it next. Note that this is DX9, not 11. I’m *hoping* that this is all up to date…
- Pointed Configuration Properties->Linker->General->Additional Library Directories at (C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Lib\x86), and added the following files to Configuration Properties->Linker->Input->additional dependencies”
- d3d11.lib
d3dx11.lib
winmm.lib
xinput.lib
X3DAudio.lib - This is a change from the libraries that the demo book points at, which were dxd9 libs. Recompiled and ran the code with no problems. I did attempt to clean up the xact3dInstance pointer in ~Audio3d(), but delete[] threw an exception
- d3d11.lib
- Reading through the DX documentation, which, though it is in the DX9 folder, contains information about DX11. Whatever.
- The documentation is kind of what you’d expect, but it let me find the tutorials and demos, which are quite nice. On my machine, the demos that I’m interested in are located here: (C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Samples\C++\XAudio2). It contains 4 projects:
- XAudio2BasicSound
- XAudioBasicStream
- XAudio2CustomAPO
- XAudio2Sound3D
- Each project has source and MSVC2008 and MSVC2010 project files. I’ve just opened up the XAudio2Sound3D MSVC2010 project, and it compiled and ran just fine:

- This is almost exactly what I intend to build for the test environment, so that’s pretty cool. And using the buttons or the keyboard, I can drive the sound emitter around my head. Woohoo!
- Next goal is to build up a copy of XAudio2BasicSound and then add the 3D components (without the graphics) from XAudio2Sound3D.
One of those days when work interfered with school
Only a couple of hours worked today – someone decided that today would be a good day to discuss server security, and I had a nice lunch consulting (kibitzing?) with Greg, an old buddy of mine about his new company/product.
- Work on Audio3d class
- It appears that you *have* to include <xact3.h> before <xact3d3.h>. It seems to be tied up with <x3daudio.h>, which is declared before <xact3.h> in <xact3d3.h>. If I reverse the order of those calls, no error messages. otherwise I get the following (included for the next poor soul who pastes this error in Google):
-
1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winnt.h(6361): error C2146: syntax error : missing ';' before identifier 'ContextRecord' 1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winnt.h(6361): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winnt.h(6361): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winnt.h(12983): error C2065: 'PCONTEXT' : undeclared identifier 1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winnt.h(12984): error C2146: syntax error : missing ')' before identifier 'ContextRecord' 1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winnt.h(12984): warning C4229: anachronism used : modifiers on data are ignored 1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winnt.h(12984): error C2182: 'RtlCaptureContext' : illegal use of type 'void' 1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winnt.h(12984): error C2491: 'RtlCaptureContext' : definition of dllimport data not allowed 1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winnt.h(12984): error C2059: syntax error : ')' 1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winnt.h(13372): error C2143: syntax error : missing ';' before '__stdcall' 1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winnt.h(13372): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winnt.h(13376): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winnt.h(14982): error C3861: '__readfsdword': identifier not found 1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winbase.h(1048): error C2146: syntax error : missing ';' before identifier 'LPCONTEXT' 1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winbase.h(1048): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winbase.h(1048): error C2378: 'PCONTEXT' : redefinition; symbol cannot be overloaded with a typedef 1> c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winnt.h(13372) : see declaration of 'PCONTEXT' 1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winbase.h(1048): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winbase.h(3610): error C2061: syntax error : identifier 'PCONTEXT' 1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winbase.h(4449): error C2061: syntax error : identifier 'LPCONTEXT' 1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winbase.h(4457): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winbase.h(4457): error C2143: syntax error : missing ',' before '*' 1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winbase.h(15112): error C2143: syntax error : missing ';' before '__stdcall' 1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winbase.h(15112): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winbase.h(15116): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
-
- This truly is one of the reasons the Microsoft drives me so crazy…
3D sound and the search for a header file.
Today, I was going to extend the audio app to do some simple 3D sound. Nope. Aside from a lot of distractions that really only allowed me to get a couple of hours work done, the C++ documentation for this capability is getting harder and harder to find. And for some reason, Microsoft does not seem to believe in producing samples of code that actually do something. Instead, there are lots of nested pages, each pointing to a tidbit of information. Sigh. Anyway, here’s today’s struggles.
- I thought this tutorial would be the best way to get positional information, but it appears to be stale. The New Way seems to be this.
- Close, but it’s actually part of the Windows API now?
- Nope that’s C#. Still looking. Since I have xact3.h working, trying to stay in this space…
- 3D XACT using C++
- Which references How To: Integrate X3DAudio with XACT
- Still looking for what headers to include. Got it. It’s <xact3d3.h>. Don’t confuse this with <xact3.h>
- Ok, at least for now (and yet again!) I think I know what’s going on and what I should do next. For tomorrow, I start writing a 3D version of Audio.h/Audio.cpp and then try calling that from the ConsoleSoundApp.
A much better day…
Today’s stuff.
- Imported the sound example code from P2DG chapter 7 into MSVC and successfully compiled.
- And runs! With sound!
-

- Next we try to put the audio class into a console app (main as opposed to winmain) and see if that can be made to work.
- That went pretty smoothly. I had to add the DirectX “include” directories, add stdafx.h to the audio.cpp file and cast some char* to LPWSTR. The next step is to fill out the main() so that the audio is initialized and then run a loop to send different audio commands. A good task for Monday.
Beating on OpenAL, then giving up. Microsoft wins.
Progress for today
- Copied the OpenAL SDK out of the ProgramFiles(x86) directory where the installer put it and put it in my menagerie of API test code
- Converted the MSVC 2005 project to 2010
- Tried to compile, but the target names didn’t match. Adjusted the output name in the Properties->Configuration Properties->Linker->General->Output File field from PlayMultiChannelWin32.exe to PlayMultiChannel.exe.
- Compiled and ran in debug mode, but got the same problem where the audio is going to the 3 front speakers.
- Since all else has failed, I’m going to RTFM. In OpenAL 1.1 SDK/docs is a collection of documents. Going to start with the OpenAL Programmer’s Guide.
- It’s more of an API listing. Though I did discover there is a thing known as the OpenAL Utility Linrary (ALUT), which might be useful. Here are some good notes:
- So this is really weird. I’m looking through the code to see how the channels are activated, and there doesn’t seem to be anything explicit. But I do find where the wav files are stored. Listening to these samples in windows media player, the correct Dolby channels are selected for 5.1 and 7.1. It seems as though OpenAl is flattening the information to the front three channels. Wile poking around on the OpenAL website, I came across the following regarding Vista:
- With Microsoft’s decision to remove the audio hardware layer in Windows Vista, legacy DirectSound 3D games will no longer use hardware 3D algorithms for audio spatialization. Instead they will have to rely upon the new Microsoft software mixer that is built into Windows Vista. This new software mixer will give the users basic audio support for their old Direct Sound games but since it has no hardware layer, all EAX® effects will be lost, and no individual per-voice processing can be performed using dedicated hardware processing.
- I think I’m getting “basic” audio support. This explains why the codebase has not been touched since 2008 or so. Looks like a dead end.
- Moving along, it’s time to try DirectX. The samples I can find online don’t really thrill me, but looking at books on Amazon, I found Programming 2D Games (P2DG), which has a nice section on sound. It’s now sitting in my Kindle Library. Let’s see how that goes.
- Downloading the DirectX SDK. All 572 MB of it. Last updated in 2010. Why is this making me nervous?
- Ran the DirectX installer, which blew up, but seems to have installed all the components, and the demos run. The demo games do generate Dolby 7.1 as well, so that’s progress…
- Following the steps in Chapter 7 (Sound) in P2DG. XACT opend up just fine. Importing wav files from the OpenAL media directory. Interestingly, some .wav files choked as “unrecognizable” Don’t know why…

- Got the sounds imported and playing in XACT and the Audio Console. And considering how much stuff didn’t work today, That’s enough progress to leave on a high note.
A bit of a new direction
Somewhere in the middle of finals, I realized I had this nice FLTK/OpenGL application I’d written in C++:
It currently calculates and outputs audio commands to an Arduino that in turn talks to MIDI boards for each channel. But if I can use the main CPU’s internal audio capability, then I can have a deeper level of capability, and it works for enough of my current projects that it’s probably worth building some generic capability.
So that means I need a C++ library and API that can be built using the MSVC 2010 IDE. Possible options are:
- OpenAL (http://connect.creativelabs.com/openal/default.aspx)
- Downloaded and installed the OpenAl11CoreSDK from here. It installed to C:\Program Files (x86)\OpenAL 1.1 SDK
- Started to run through some of the executable demos, and found PlayMultiChannelWin64.exe. It works in my Plantronics headphones, but I need to bring in an extension cord tomorrow to hook up to the helmet.
- The Windows Core Audio APIs (http://msdn.microsoft.com/en-us/library/windows/desktop/dd370802(v=vs.85).aspx)
- XAudio2 – a low-level audio API that provides signal processing and mixing foundation for developing high performance audio engines for games. (http://msdn.microsoft.com/en-us/library/windows/desktop/hh405049(v=vs.85).aspx)
- Allegro – Allegro 4 and Allegro 5 are cross-platform, open source, game programming libraries, primarily for C and C++ developers (http://alleg.sourceforge.net/)
- Simple and Fast Multimedia Library (http://www.sfml-dev.org/) – May be built on OpenAl.
- PortAudio – a free, cross-platform, open-source, audio I/O library. It lets you write simple audio programs in ‘C’ or C++ that will compile and run on many platforms including Windows, Macintosh OS X, and Unix. (http://www.portaudio.com/)
- Libao – (http://www.xiph.org/ao/)
- Jack – (http://jackaudio.org/)
