Monthly Archives: June 2013

Starting to polish

  • I’m going to add the ability to create and store a named sound within BasicAudio. Sounds really don’t need to be created outside of the instance.
  • Lunch meeting with Shawn about R&D. Good meeting with good chili to boot.
  • Got the createSound method working and cleaned up the Console app some more
int _tmain(int argc, _TCHAR* argv[])
{
	BasicAudio *ba = new BasicAudio();
	ba->init();

	wprintf( L"\nReady to play mono WAV PCM file(s)...\n" );

	WavSampleSound *singleSound = (WavSampleSound *)ba->createSound(L"music", L"Wavs\\MusicMono.wav", 0);
	WavSampleSound *continuousSound = (WavSampleSound *)ba->createSound(L"heli", L"Wavs\\heli.wav", XAUDIO2_LOOP_INFINITE);

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

	// printf("hit return to exit");
	// getchar();

	return 0;
}

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

Ye gods, we might actually have something to use here…

  • Well, after two days of not being able to work on this due to Comps prep and trouble with a significant fraction of my vehicles, maybe I can get something working today.
  • Added everything from How to: Integrate X3DAudio with XAudio2, and definitely got a result – when the emitter position moved off of center, the sound cut out. Now you might think that’s a bad thing, but my guess is that I have some variable that either being set with zero or junk, which is messing up the sound matrix calculations.
  • Using the XAudio2Sound3D project as a source of code to mine, I pulled over the (much more extensive) emitter setup and now have things working, although not as clearly as I’d like. Next is to clean up and package the code into the SampleSound-derived classes.
  • And by the way, this might be a good hard hat to try the rig on: http://www.amazon.com/ERB-19224-Americana-Full-Ratchet/dp/B001LYB7JW
  • Cleared a lot of nonessential (i.e. listening cone)code out of the emitter
  • Realized that I could probably use voice->SetOutputMatrix() to set the channels directly. I added a method that cleans out the dspSettings.matrixCoefficients and then sets a single value in the matrix. Whadaya know – it worked 🙂
  • Need to do some packaging of the code, but I now have enough to do tests for the situational awareness system and to get rid of the MIDI boards for the vibrotactile controller.