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();

	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.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s