示例#1
0
文件: main.cpp 项目: neilogd/soloud
// Entry point
int main(int argc, char *argv[])
{
    // Define a couple of variables
    SoLoud::Soloud soloud;  // SoLoud engine core
    SoLoud::Speech speech;  // A sound source (speech, in this case)

    // Configure sound source
    speech.setText("1 2 3   1 2 3   Hello world. Welcome to So-Loud.");

    // initialize SoLoud.
    soloud.init();

    // Play the sound source (we could do this several times if we wanted)
    soloud.play(speech);

    // Wait until sounds have finished
    while (soloud.getActiveVoiceCount() > 0)
    {
        // Still going, sleep for a bit
        SoLoud::Thread::sleep(100);
    }

    // Clean up SoLoud
    soloud.deinit();

    // All done.
    return 0;
}
示例#2
0
文件: main.cpp 项目: Itaros/soloud
int main(int argc, char *argv[])
{
	SoLoud::Soloud soloud;

	int i;
	for (i = 0; i < SoLoud::Soloud::BACKEND_MAX; i++)
	{
		printf("-----\n"
			"Backend %d:%s\n",
			i, i==0?"(auto)":"");
		int res = soloud.init(0, i);
		if (res == SoLoud::SO_NO_ERROR)
		{
			printf(
				"ID:       %d\n"
				"String:   \"%s\"\n"
				"Rate:     %d\n"
				"Buffer:   %d\n"
				"Channels: %d%s (default)\n",
				soloud.getBackendId(),
				soloud.getBackendString() == 0 ? "(null)" : soloud.getBackendString(),
				soloud.getBackendSamplerate(),
				soloud.getBackendBufferSize(),
				soloud.getBackendChannels(),
				(soloud.getBackendChannels() == 6 ? " (5.1 surround)" : soloud.getBackendChannels() == 4 ? " (quad)" : soloud.getBackendChannels() == 2 ? " (stereo)" : soloud.getBackendChannels() == 1 ? " (mono)" : ""));
			soloud.deinit();
			int j;
			for (j = 1; j < 7; j++)
			{
				int res = soloud.init(0, i, 0, 0, j);
				if (res == SoLoud::SO_NO_ERROR && soloud.getBackendChannels() == j)
				{
					printf("Channels: %d%s\n", soloud.getBackendChannels(), (soloud.getBackendChannels() == 6 ? " (5.1 surround)" : soloud.getBackendChannels() == 4 ? " (quad)" : soloud.getBackendChannels() == 2 ? " (stereo)" : soloud.getBackendChannels() == 1 ? " (mono)" : ""));
					soloud.deinit();
				}
			}
		}
		else
		{
			printf("Failed: %s\n", soloud.getErrorString(res));
		}
	}
	return 0;
}
示例#3
0
文件: main.cpp 项目: Fincodr/soloud
// Entry point
int main(int argc, char *argv[])
{
	gMusic1.load("audio/plonk_wet.ogg");
	gMusic2.load("audio/plonk_dry.ogg");

	gMusic1.setLooping(1);
	gMusic2.setLooping(1);

	// Initialize SDL's subsystems - in this case, only video.
	if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) 
	{
		fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError());
		exit(1);
	}

	gSoloud.init(SoLoud::Soloud::CLIP_ROUNDOFF | SoLoud::Soloud::ENABLE_VISUALIZATION);

	// Register SDL_Quit to be called at exit; makes sure things are
	// cleaned up when we quit.
	atexit(SDL_Quit);	

	// Attempt to create a 640x480 window with 32bit pixels.
	screen = SDL_SetVideoMode(400, 256, 32, SDL_SWSURFACE);
	font = SDL_LoadBMP("graphics/font.bmp");

	// If we fail, return error.
	if ( screen == NULL ) 
	{
		fprintf(stderr, "Unable to set 640x480 video: %s\n", SDL_GetError());
		exit(1);
	}

	gMusichandle1 = gSoloud.play(gMusic1,0,0,1);
	gMusichandle2 = gSoloud.play(gMusic2,1,0,1);

	SoLoud::handle grouphandle = gSoloud.createVoiceGroup();
	gSoloud.addVoiceToGroup(grouphandle, gMusichandle1);
	gSoloud.addVoiceToGroup(grouphandle, gMusichandle2);
	
	gSoloud.setProtectVoice(grouphandle, 1); // protect all voices in group 
	gSoloud.setPause(grouphandle, 0);        // unpause all voices in group 
	
	gSoloud.destroyVoiceGroup(grouphandle); // remove group, leaves voices alone

	int cycle = 0;

	// Main loop: loop forever.
	while (1)
	{
		cycle++;
		// Render stuff
		render();
		// Poll for events, and handle the ones we care about.
		SDL_Event event;
		while (SDL_PollEvent(&event)) 
		{
			switch (event.type) 
			{
			case SDL_KEYDOWN:
				switch (event.key.keysym.sym)
				{
				case SDLK_1: 
					gSfx.loadPreset(SoLoud::Sfxr::EXPLOSION, cycle);
					gSoloud.play(gSfx, 1, ((rand()%512)-256)/256.0f);
					break;
				case SDLK_2: 
					gSfx.loadPreset(SoLoud::Sfxr::BLIP, cycle);
					gSoloud.play(gSfx, 1, ((rand()%512)-256)/256.0f);
					break;
				case SDLK_3: 
					gSfx.loadPreset(SoLoud::Sfxr::COIN, cycle);
					gSoloud.play(gSfx, 1, ((rand()%512)-256)/256.0f);
					break;
				case SDLK_4: 
					gSfx.loadPreset(SoLoud::Sfxr::HURT, cycle);
					gSoloud.play(gSfx, 1, ((rand()%512)-256)/256.0f);
					break;
				case SDLK_5: 
					gSfx.loadPreset(SoLoud::Sfxr::JUMP, cycle);
					gSoloud.play(gSfx, 1, ((rand()%512)-256)/256.0f);
					break;
				case SDLK_6: 
					gSfx.loadPreset(SoLoud::Sfxr::LASER, cycle);
					gSoloud.play(gSfx, 1, ((rand()%512)-256)/256.0f);
					break;
				case SDLK_7:
					gSoloud.fadeVolume(gMusichandle1, 1, 2);
					gSoloud.fadeVolume(gMusichandle2, 0, 2);
					break;
				case SDLK_8:
					gSoloud.fadeVolume(gMusichandle2, 1, 2);
					gSoloud.fadeVolume(gMusichandle1, 0, 2);
					break;
				case SDLK_9:
					gSoloud.fadeRelativePlaySpeed(gMusichandle1, 0.2f, 5);
					gSoloud.fadeRelativePlaySpeed(gMusichandle2, 0.2f, 5);
					break;
				case SDLK_0:
					gSoloud.fadeRelativePlaySpeed(gMusichandle1, 1, 5);
					gSoloud.fadeRelativePlaySpeed(gMusichandle2, 1, 5);
					break;
				}
				break;
			case SDL_KEYUP:
				// If escape is pressed, return (and thus, quit)
				if (event.key.keysym.sym == SDLK_ESCAPE)
				{
					gSoloud.deinit();
					return 0;
				}
				break;
			case SDL_QUIT:
				gSoloud.deinit();

				return(0);
			}
		}
	}
	return 0;
}