Tag Archives: msvc

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
    • 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
  • 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: XAudio2demo
  • 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.

A working console app!

Good progress today

Looks like everything is working in the proof of concept! Here’s the code:

#include "stdafx.h"
#include <Windows.h>
#include <conio.h>
#include "audio.h"

int _tmain(int argc, _TCHAR* argv[])
	int keyIn;
	HRESULT hr;                 // standard return type
	LPTSTR buf;
	LPTSTR targetDir = "C:\\Programming 2D Games in DirectX 11\\Chapter 7 - Sound\\ConsoleSound\\ConsoleSound\\ConsoleSound";
	Audio *audio = new Audio();

	buf = (LPTSTR)calloc(256, sizeof(char));
	GetCurrentDirectory(256, buf);
	printf("Current dir: '%s'\n", buf);
	if (*WAVE_BANK != '' && *SOUND_BANK != '')  // if sound files defined
		if( FAILED( hr = audio->initialize() ) )
				printf("Failed to initialize sound system because media file not found.\n");
				printf("hit return to exit\n");
				return -1;
				printf("Failed to initialize sound system.\n");
				printf("hit return to exit\n");
				return -1;

	printf("Type 'x' to quit, 1, 2, or 3 for sounds.\n");
	bool doit = true;
			keyIn = getch();

			printf("key = %c\n", keyIn);
			case 'x' : doit = false; 
			case '1' : audio->playCue(BEEP1);                  // play sound
			case '2' : audio->playCue(BEEP2);                  // play sound
			case '3' : audio->playCue(BEEP3);                  // play sound
		audio->run();                       // perform periodic sound engine tasks

	printf("hit return to exit");
	return 0;

Tomorrow, we’ll try to add positional sound.

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!
  •  withSound
  • 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.