Example #1
0
// irrKlang 3D sound engine example 03,
// demonstrating playing sounds directly from memory
int main(int argc, const char** argv)
{
	// start the sound engine with default parameters
	ISoundEngine* engine = createIrrKlangDevice();

	if (!engine)
		return 0; // error starting up the engine

	#ifdef __BIG_ENDIAN__
	printf("This example won't work on Power-PCs because the way we are "\
	       "storing the wave data in this example source file. Sorry.");
	return 0;
	#endif

	// To make irrKlang know about the memory we want to play, we register
	// the memory chunk as a sound source. We specify the name "testsound.wav", so
	// we can use the name later for playing back the sound. Note that you
	// could also specify a better fitting name like "ok.wav".
	// The method addSoundSource() also returns a pointer to the created sound source,
	// it can be used as parameter for play2D() later, if you don't want to
	// play sounds via string names.

	engine->addSoundSourceFromMemory(memorySoundData, memorySoundDataSize, "testsound.wav");

	// now play the sound until user presses escape

	printf("\nPlaying sound from memory.\n");
	printf("Press any key to play, ESCAPE to end program.\n");

	while(true) // endless loop until user exits
	{
		// play the sound we added to memory
		engine->play2D("testsound.wav");

		if (getch() == 27)
			break; // user pressed ESCAPE key, cancel
	}

	engine->drop(); // delete engine
	return 0;
}