Monthly Archives: May 2013

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.

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

When does surround not equal surround?

Apparently when you’re using OpenAL.

There is a multichannel test binary that you can run. (C:\Program Files (x86)\OpenAL 1.1 SDK\samples\bin\win64\PlayMultiChannelWin64.exe). It should run

front left, center, front right, rear right, rear left, and subwoofer.

Instead, it’s running

front left, front right, and center.

I’ve verified that all eight speakers are working in the test app that comes with the drivers. I’ve also verified that the sound is correctly sent using the Control Panel Sound->configure tool. So I’m not sure if it’s OpenAl or something else. Ah well. That’s for tomorrow.

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: