Good progress today
- Ran the example app with the audio server off. All still runs fine.
- Working on getting the sound to run in a basic console app.
- I was having problems with strings, specifically LPTSTR. It turns out that LPSTR changes based on compiler settings. Here’s how you make an LPTSTR char*:
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(); SetCurrentDirectory(targetDir); 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() ) ) { if( hr == HRESULT_FROM_WIN32( ERROR_FILE_NOT_FOUND ) ){ printf("Failed to initialize sound system because media file not found.\n"); printf("hit return to exit\n"); getchar(); return -1; } else{ printf("Failed to initialize sound system.\n"); printf("hit return to exit\n"); getchar(); return -1; } } } printf("Type 'x' to quit, 1, 2, or 3 for sounds.\n"); bool doit = true; while(doit){ if(kbhit()){ keyIn = getch(); printf("key = %c\n", keyIn); switch(keyIn){ case 'x' : doit = false; break; case '1' : audio->playCue(BEEP1); // play sound break; case '2' : audio->playCue(BEEP2); // play sound break; case '3' : audio->playCue(BEEP3); // play sound break; } } audio->run(); // perform periodic sound engine tasks Sleep(100); } SAFE_DELETE(audio); printf("hit return to exit"); getchar(); return 0; }
Tomorrow, we’ll try to add positional sound.
- Haven’t had time to verify that this is correct code for my particular DirectX setup, but it looks close: http://www.rastertek.com/dx11tut31.html. It looks like a lot of good stuff on the site if you walk in through the front door.