There are days things just work

  • Making nice clean classes for audio
  • Emitter goes into the SampledSound base class – done. Almost easy, though I had to go and relearn how C++ constructors work. Gawd, it’s been a while…
  • Everything else goes into BasicAudio – done. Had some problems with frequency until I realized that I hadn’t zeroed out the listener velocity.
  • And actually, I need to be able to set velocity for doppler effects. Need to add methods like the position methods tomorrow.
  • So the classes are built, and my main() test loop is down to this:
int _tmain(int argc, _TCHAR* argv[])
{
	BasicAudio *ba = new BasicAudio();
	ba->init();
	IXAudio2* pXAudio2 = ba->getXaudioPtr();
	wprintf( L"\nReady to play mono WAV PCM file(s)...\n" );

	WavSampleSound *continuousSound = new WavSampleSound();
	WavSampleSound *singleSound = new WavSampleSound();

	continuousSound->initPCM(pXAudio2, L"Wavs\\heli.wav", XAUDIO2_LOOP_INFINITE );
	singleSound->initPCM(pXAudio2, L"Wavs\\MusicMono.wav", 0 );

	ba->addSampleSound(continuousSound);
	ba->addSampleSound(singleSound);

	int keyIn;
	printf("Type 'x' to quit\nC start continuous\nc stop continuous\nS start single\n");
	bool doit = true;

	int channelIndex = -1;
	while(doit){
		if(kbhit()){
			keyIn = getch();
			channelIndex = -1;

			printf("key = %c\n", keyIn);
			switch(keyIn){
				case 'x' : doit = false;

				break;
				case 'C' : continuousSound->start(); // play sound
				break;
				case 'c' : continuousSound->stop(); // cease sound
				break;
				case 'S' : singleSound->start(); // play sound
				break;
				case 'w' :
				continuousSound->setEmitterZ(continuousSound->getEmitterZ() + (FLOAT32)0.5);
				break;
				case 's' :
				continuousSound->setEmitterZ(continuousSound->getEmitterZ() - (FLOAT32)0.5);
				break;
				case 'a' :
				continuousSound->setEmitterX(continuousSound->getEmitterX() - (FLOAT32)0.5);
				break;
				case 'd' :
				continuousSound->setEmitterX(continuousSound->getEmitterX() + (FLOAT32)0.5);
				break;
				case 'p':
				ba->printMatrixCoefficients();
				break;
				case '0' : channelIndex = 0; break;
				case '1' : channelIndex = 1; break;
				case '2' : channelIndex = 2; break;
				case '3' : channelIndex = 3; break;
				case '4' : channelIndex = 4; break;
				case '5' : channelIndex = 5; break;
				case '6' : channelIndex = 6; break;
				case '7' : channelIndex = 7; break;
			}
			if(channelIndex == -1){
				IXAudio2SourceVoice* voice = continuousSound->getSourceVoice();
				ba->play3DVoice(continuousSound->getEmitter(), voice);
			}else{
				printf("channel = %d\n", channelIndex);
				IXAudio2SourceVoice* voice = continuousSound->getSourceVoice();
				ba->playOnChannelVoice(voice, channelIndex);
			}
		}
		ba->run(); // perform periodic sound engine tasks
		Sleep(100);
	}

	wprintf( L"\nFinished playing\n" );

	// All XAudio2 interfaces are released when the engine is destroyed, but being tidy

	ba->destroy();

	return 0;
}
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