示例#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
void Sound_Inspect(Asset& asset, bool deselected) {
	static int handle;
	static SoLoud::Bus bus;

	if (deselected) {
		soloud.stopAll();
		return;
	}

	bus.setVisualizationEnable(true);
	SoLoud::AudioSource *src = (SoLoud::AudioSource*) asset.resource;
	
	ImGui::Text("Channels: %i", src->mChannels);
	ImGui::Text("Sample Rate: %0.f", src->mBaseSamplerate);
	
	int voice = soloud.getVoiceFromHandle(handle);
	if (ImGui::Button(voice == -1 ? "Play" : "Stop")) {
		if (voice != -1) {
			bus.stop();
		} else {
			soloud.stopAll();
			soloud.play(bus);
			handle = bus.play(*src);
		}
	}

	float *fft = bus.calcFFT();
	ImGui::PlotHistogram("##FFT", fft, 256 / 2, 0, nullptr, 0, 20, ImVec2(0, 160), 8);
}
示例#3
0
	void soloud_sdl1_audiomixer(void *userdata, Uint8 *stream, int len)
	{
		short *buf = (short*)stream;
		SoLoud::Soloud *soloud = (SoLoud::Soloud *)userdata;
		int samples = len / (gActiveAudioSpec.channels * sizeof(short));
		soloud->mixSigned16(buf, samples);
	}
示例#4
0
	void soloud_sdl_audiomixer(void *userdata, Uint8 *stream, int len)
	{
		int samples = len / 4;
		short *buf = (short*)stream;
		SoLoud::Soloud *soloud = (SoLoud::Soloud *)userdata;
		float *mixdata = (float*)(soloud->mBackendData);
		soloud->mix(mixdata, samples);

		int i;
		for (i = 0; i < samples*2; i++)
		{
			buf[i] = (short)(mixdata[i] * 0x7fff);
		}
	}
示例#5
0
	static int portaudio_callback( 
				const void *input,
				void *output,
				unsigned long frameCount,
				const PaStreamCallbackTimeInfo* timeInfo,
				PaStreamCallbackFlags statusFlags,
				void *userData ) 
	{
		SoLoud::Soloud *soloud = (SoLoud::Soloud *)userData;
		float *mixdata = (float*)(soloud->mBackendData);
		soloud->mix((float*)output, frameCount);

		return 0;
	}
示例#6
0
	void soloud_sdlstatic_audiomixer(void *userdata, Uint8 *stream, int len)
	{
		short *buf = (short*)stream;
		SoLoud::Soloud *soloud = (SoLoud::Soloud *)userdata;
		if (gActiveAudioSpec.format == AUDIO_F32)
		{
			int samples = len / (gActiveAudioSpec.channels * sizeof(float));
			soloud->mix((float *)buf, samples);
		}
		else // assume s16 if not float
		{
			int samples = len / (gActiveAudioSpec.channels * sizeof(short));
			soloud->mixSigned16(buf, samples);
		}
	}
示例#7
0
	int DemoEntry(int argc, char *argv[])
	{
		gSoloud.init(SoLoud::Soloud::CLIP_ROUNDOFF | SoLoud::Soloud::ENABLE_VISUALIZATION);
		gSoloud.setGlobalVolume(0.75);
		gSoloud.setPostClipScaler(0.75);

		gSpeechbusHandle = gSoloud.play(gSpeechbus);
		gSfxbusHandle = gSoloud.play(gSfxbus);
		gMusicbusHandle = gSoloud.play(gMusicbus);

		gSpeech[0].setText("There is flaky pastry in my volkswagon.");
		gSpeech[1].setText("The fragmentation of empiricism is hardly influential in its interdependence.");
		gSpeech[2].setText("Sorry, my albatros is not inflatable.");
		gSpeech[3].setText("The clairvoyance of omnipotence is in fact quite closed-minded in its ecology.");
		gSpeech[4].setText("Cheese is quite nice.");
		gSpeech[5].setText("Pineapple Scones with Squash and Pastrami Sandwich");
		gSpeech[6].setText("The smart trader nowadays will be sure not to prorate OTC special-purpose entities.");
		gSpeech[7].setText("The penguins are in the toilets.");
		gSpeech[8].setText("Don't look, but there is a mountain lion stalking your children");
		gSpeech[9].setText("The train has already gone, would you like to hire a bicycle?");

		gSfxloop.load("audio/war_loop.ogg");
		gSfxloop.setLooping(1);
		gMusicloop.load("audio/algebra_loop.ogg");
		gMusicloop.setLooping(1);

		gSfxbus.play(gSfxloop);
		gMusicbus.play(gMusicloop);
		return 0;
	}
示例#8
0
文件: main.cpp 项目: neilogd/soloud
int DemoEntry(int argc, char *argv[])
{
    gMusic.load("audio/Jakim - Aboriginal Derivatives.mon");
    gMusic.setParams(10);

    gEcho.setParams(0.2f, 0.5f, 0.05f);
    gBiquad.setParams(SoLoud::BiquadResonantFilter::LOWPASS, 44100, 4000, 2);

    gMusic.setLooping(1);
    gMusic.setFilter(0, &gBiquad);
    gMusic.setFilter(1, &gLofi);
    gMusic.setFilter(2, &gEcho);
    gMusic.setFilter(3, &gDCRemoval);

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

    gMusichandle = gSoloud.play(gMusic);
    waveform = SoLoud::Monotone::SAW;
    gMusic.setParams(hwchannels, waveform);

    return 0;
}
示例#9
0
文件: main.cpp 项目: Itaros/soloud
int DemoEntry(int argc, char *argv[])
{
	gSoloud.init(SoLoud::Soloud::CLIP_ROUNDOFF | SoLoud::Soloud::ENABLE_VISUALIZATION);
	gSoloud.setGlobalVolume(4);
	gSoloud.setMaxActiveVoiceCount(16);
	int i;
	for (i = 0; i < VOICES; i++)
	{
		gSfx[i].loadPreset(SoLoud::Sfxr::COIN, i);
		gSfx[i].setLooping(1);
		gSfx[i].setInaudibleBehavior(false, false); // make sure we don't kill inaudible sounds
		gSfx[i].set3dMinMaxDistance(1, 100);
		gSfx[i].set3dAttenuation(SoLoud::AudioSource::LINEAR_DISTANCE, 1);
	}
	int j;
	for (i = 0; i < VOICEGRID; i++)
	{
		for (j = 0; j < VOICEGRID; j++)
		{
			gSndHandle[i * VOICEGRID + j] = gSoloud.play3d(gSfx[i * VOICEGRID + j], i * 15 + 20.0f, 0, j * 15 + 20.0f);
		}
	}
	return 0;
}
示例#10
0
unsigned int Snd_Play(AssetHandle assetHandle, float volume, float pan, bool loop) {
	Asset* asset = Asset_Get(ASSET_ANY, assetHandle);

	if (asset->type != ASSET_SOUND && asset->type != ASSET_SPEECH && asset->type != ASSET_MOD) {
		Con_Error(ERR_GAME, "asset not valid");
		return 0;
	}

	if (asset->resource == nullptr) {
		Con_Error(ERR_GAME, "asset resource not valid");
		return 0;
	}

	SoLoud::AudioSource *src = (SoLoud::AudioSource*) asset->resource;
	src->setLooping(loop);
	return soloud.play(*src, volume, pan);
}
示例#11
0
文件: main.cpp 项目: Itaros/soloud
void DemoMainloop()
{
	int i, j;
	DemoUpdateStart();

	float tick = DemoTick() / 1000.0f;

	gSoloud.set3dListenerParameters(
		(float)gMouseX, 0, (float)gMouseY,
		0, 0, 0, 
		0, 1, 0);

	gSoloud.update3dAudio();

	for (i = 0; i < VOICEGRID; i++)
	{
		for (j = 0; j < VOICEGRID; j++)
		{
			float v = gSoloud.getOverallVolume(gSndHandle[i * VOICEGRID + j]);
			DemoTriangle(
				i * 15 + 20.0f, j * 15 + 20.0f,
				i * 15 + 20.0f - 5, j * 15 + 20.0f + 5,
				i * 15 + 20.0f + 5, j * 15 + 20.0f + 5,
				0xff000000 | (int)(v * 0xff) * 0x010101);
			DemoTriangle(
				i * 15 + 20.0f, j * 15 + 20.0f + 10,
				i * 15 + 20.0f - 5, j * 15 + 20.0f + 5,
				i * 15 + 20.0f + 5, j * 15 + 20.0f + 5,
				0xff000000 | (int)(v * 0xff) * 0x010101);
		}
	}

	float *buf = gSoloud.getWave();
	float *fft = gSoloud.calcFFT();

	ONCE(ImGui::SetNextWindowPos(ImVec2(500, 20)));
	ImGui::Begin("Output");
	ImGui::PlotLines("##Wave", buf, 256, 0, "Wave", -1, 1, ImVec2(264, 80));
	ImGui::PlotHistogram("##FFT", fft, 256 / 2, 0, "FFT", 0, 10, ImVec2(264, 80), 8);
	ImGui::Text("Active voices    : %d", gSoloud.getActiveVoiceCount());
	ImGui::Text("Total voices     : %d", gSoloud.getVoiceCount());
	ImGui::Text("Maximum voices   : %d", VOICE_COUNT);
	ImGui::End();

	DemoUpdateEnd();
}
示例#12
0
void Snd_Stop(unsigned int handle) {
	soloud.stop(handle);
}
示例#13
0
	void DemoMainloop()
	{
		DemoUpdateStart();

		if (speechtick < DemoTick())
		{
			int h = gSpeechbus.play(gSpeech[speechcount % 10], (rand() % 200) / 50.0f + 2, (rand() % 20) / 10.0f - 1);
			speechcount++;
			gSoloud.setRelativePlaySpeed(h, (rand() % 100) / 200.0f + 0.75f);
			gSoloud.fadePan(h, (rand() % 20) / 10.0f - 1, 2);
			speechtick = DemoTick() + 4000;
		}

		float *buf = gSoloud.getWave();
		float *fft = gSoloud.calcFFT();

		ONCE(ImGui::SetNextWindowPos(ImVec2(500, 20)));
		ImGui::Begin("Output");
		ImGui::PlotLines("##Wave", buf, 256, 0, "Wave", -1, 1, ImVec2(264, 80));
		ImGui::PlotHistogram("##FFT", fft, 256 / 2, 0, "FFT", 0, 10, ImVec2(264, 80), 8);
		ImGui::Text("Speech bus volume : %d%%", (int)floor(gSoloud.getVolume(gSpeechbusHandle) * 100));
		ImGui::Text("Music bus volume  : %d%%", (int)floor(gSoloud.getVolume(gMusicbusHandle) * 100));
		ImGui::Text("Sfx bus volume    : %d%%", (int)floor(gSoloud.getVolume(gSfxbusHandle) * 100));
		ImGui::Text("Active voices     : %d", gSoloud.getActiveVoiceCount());
		ImGui::End();

		ONCE(ImGui::SetNextWindowPos(ImVec2(20, 20)));
		ImGui::Begin("Control");
		if (ImGui::SliderFloat("Speech bus volume", &gSpeechvol, 0, 2))
		{
			gSoloud.setVolume(gSpeechbusHandle, gSpeechvol);
		}
		if (ImGui::SliderFloat("Music bus volume", &gMusicvol, 0, 2))
		{
			gSoloud.setVolume(gMusicbusHandle, gMusicvol);
		}
		if (ImGui::SliderFloat("Sfx bus volume", &gSfxvol, 0, 2))
		{
			gSoloud.setVolume(gSfxbusHandle, gSfxvol);
		}
		ImGui::End();
		DemoUpdateEnd();
	}
示例#14
0
namespace mixbusses
{

	SoLoud::Soloud gSoloud;			// SoLoud engine core
	SoLoud::Speech gSpeech[10];
	SoLoud::Wav gSfxloop, gMusicloop;
	SoLoud::Bus gSfxbus, gMusicbus, gSpeechbus;

	int gSfxbusHandle, gMusicbusHandle, gSpeechbusHandle;

	float gSfxvol = 1, gMusicvol = 1, gSpeechvol = 1;

	int DemoEntry(int argc, char *argv[])
	{
		gSoloud.init(SoLoud::Soloud::CLIP_ROUNDOFF | SoLoud::Soloud::ENABLE_VISUALIZATION);
		gSoloud.setGlobalVolume(0.75);
		gSoloud.setPostClipScaler(0.75);

		gSpeechbusHandle = gSoloud.play(gSpeechbus);
		gSfxbusHandle = gSoloud.play(gSfxbus);
		gMusicbusHandle = gSoloud.play(gMusicbus);

		gSpeech[0].setText("There is flaky pastry in my volkswagon.");
		gSpeech[1].setText("The fragmentation of empiricism is hardly influential in its interdependence.");
		gSpeech[2].setText("Sorry, my albatros is not inflatable.");
		gSpeech[3].setText("The clairvoyance of omnipotence is in fact quite closed-minded in its ecology.");
		gSpeech[4].setText("Cheese is quite nice.");
		gSpeech[5].setText("Pineapple Scones with Squash and Pastrami Sandwich");
		gSpeech[6].setText("The smart trader nowadays will be sure not to prorate OTC special-purpose entities.");
		gSpeech[7].setText("The penguins are in the toilets.");
		gSpeech[8].setText("Don't look, but there is a mountain lion stalking your children");
		gSpeech[9].setText("The train has already gone, would you like to hire a bicycle?");

		gSfxloop.load("audio/war_loop.ogg");
		gSfxloop.setLooping(1);
		gMusicloop.load("audio/algebra_loop.ogg");
		gMusicloop.setLooping(1);

		gSfxbus.play(gSfxloop);
		gMusicbus.play(gMusicloop);
		return 0;
	}

	int speechtick = 0;
	int speechcount = 0;

	void DemoMainloop()
	{
		DemoUpdateStart();

		if (speechtick < DemoTick())
		{
			int h = gSpeechbus.play(gSpeech[speechcount % 10], (rand() % 200) / 50.0f + 2, (rand() % 20) / 10.0f - 1);
			speechcount++;
			gSoloud.setRelativePlaySpeed(h, (rand() % 100) / 200.0f + 0.75f);
			gSoloud.fadePan(h, (rand() % 20) / 10.0f - 1, 2);
			speechtick = DemoTick() + 4000;
		}

		float *buf = gSoloud.getWave();
		float *fft = gSoloud.calcFFT();

		ONCE(ImGui::SetNextWindowPos(ImVec2(500, 20)));
		ImGui::Begin("Output");
		ImGui::PlotLines("##Wave", buf, 256, 0, "Wave", -1, 1, ImVec2(264, 80));
		ImGui::PlotHistogram("##FFT", fft, 256 / 2, 0, "FFT", 0, 10, ImVec2(264, 80), 8);
		ImGui::Text("Speech bus volume : %d%%", (int)floor(gSoloud.getVolume(gSpeechbusHandle) * 100));
		ImGui::Text("Music bus volume  : %d%%", (int)floor(gSoloud.getVolume(gMusicbusHandle) * 100));
		ImGui::Text("Sfx bus volume    : %d%%", (int)floor(gSoloud.getVolume(gSfxbusHandle) * 100));
		ImGui::Text("Active voices     : %d", gSoloud.getActiveVoiceCount());
		ImGui::End();

		ONCE(ImGui::SetNextWindowPos(ImVec2(20, 20)));
		ImGui::Begin("Control");
		if (ImGui::SliderFloat("Speech bus volume", &gSpeechvol, 0, 2))
		{
			gSoloud.setVolume(gSpeechbusHandle, gSpeechvol);
		}
		if (ImGui::SliderFloat("Music bus volume", &gMusicvol, 0, 2))
		{
			gSoloud.setVolume(gMusicbusHandle, gMusicvol);
		}
		if (ImGui::SliderFloat("Sfx bus volume", &gSfxvol, 0, 2))
		{
			gSoloud.setVolume(gSfxbusHandle, gSfxvol);
		}
		ImGui::End();
		DemoUpdateEnd();
	}
}
示例#15
0
文件: main.cpp 项目: neilogd/soloud
void DemoMainloop()
{
    gSoloud.setFilterParameter(gMusichandle, 0, 0, filter_param0[0]);
    gSoloud.setFilterParameter(gMusichandle, 1, 0, filter_param0[1]);
    gSoloud.setFilterParameter(gMusichandle, 2, 0, filter_param0[2]);
    gSoloud.setFilterParameter(gMusichandle, 3, 0, filter_param0[3]);

    gSoloud.setFilterParameter(gMusichandle, 0, 2, filter_param1[0]);
    gSoloud.setFilterParameter(gMusichandle, 0, 3, filter_param2[0]);
    gSoloud.setFilterParameter(gMusichandle, 1, 1, filter_param1[1]);
    gSoloud.setFilterParameter(gMusichandle, 1, 2, filter_param2[1]);

    DemoUpdateStart();

    float *buf = gSoloud.getWave();
    float *fft = gSoloud.calcFFT();

    ONCE(ImGui::SetNextWindowPos(ImVec2(500, 20)));
    ImGui::Begin("Output");
    ImGui::PlotLines("##Wave", buf, 256, 0, "Wave", -1, 1, ImVec2(264, 80));
    ImGui::PlotHistogram("##FFT", fft, 256/2, 0, "FFT", 0, 10, ImVec2(264,80),8);
    ImGui::Text("Music volume     : %d%%", (int)floor(gSoloud.getVolume(gMusichandle) * 100));
    ImGui::Text("Active voices    : %d", gSoloud.getActiveVoiceCount());
    ImGui::End();

    ONCE(ImGui::SetNextWindowPos(ImVec2(20, 20)));

    ImGui::Begin("Control");
    if (ImGui::SliderInt("Channels", &hwchannels, 1, 4))
    {
        gMusic.setParams(hwchannels, waveform);
    }
    if (ImGui::CollapsingHeader("Waveform", (const char*)0, true, false))
    {
        if (ImGui::RadioButton("Square", waveform == SoLoud::Monotone::SQUARE))
        {
            waveform = SoLoud::Monotone::SQUARE;
            gMusic.setParams(hwchannels, waveform);
        }
        if (ImGui::RadioButton("Saw", waveform == SoLoud::Monotone::SAW))
        {
            waveform = SoLoud::Monotone::SAW;
            gMusic.setParams(hwchannels, waveform);
        }
        if (ImGui::RadioButton("Sin", waveform == SoLoud::Monotone::SIN))
        {
            waveform = SoLoud::Monotone::SIN;
            gMusic.setParams(hwchannels, waveform);
        }
        if (ImGui::RadioButton("SawSin", waveform == SoLoud::Monotone::SAWSIN))
        {
            waveform = SoLoud::Monotone::SAWSIN;
            gMusic.setParams(hwchannels, waveform);
        }
    }
    ImGui::Separator();
    ImGui::Text("Biquad filter (lowpass)");
    ImGui::SliderFloat("Wet##4", &filter_param0[0], 0, 1);
    ImGui::SliderFloat("Frequency##4", &filter_param1[0], 0, 8000);
    ImGui::SliderFloat("Resonance##4", &filter_param2[0], 1, 20);
    ImGui::Separator();
    ImGui::Text("Lofi filter");
    ImGui::SliderFloat("Wet##2", &filter_param0[1], 0, 1);
    ImGui::SliderFloat("Rate##2", &filter_param1[1], 1000, 8000);
    ImGui::SliderFloat("Bit depth##2", &filter_param2[1], 0, 8);
    ImGui::Separator();
    ImGui::Text("Echo filter");
    ImGui::SliderFloat("Wet##3", &filter_param0[2], 0, 1);
    ImGui::Separator();
    ImGui::Text("DC removal filter");
    ImGui::SliderFloat("Wet##1", &filter_param0[3], 0, 1);
    ImGui::End();
    DemoUpdateEnd();
}
示例#16
0
void Snd_PauseResume(unsigned int handle, bool pause) {
	soloud.setPause(handle, pause);
}
示例#17
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;
}
示例#18
0
文件: main.cpp 项目: Fincodr/soloud
void render()
{   
	// Lock surface if needed
	if (SDL_MUSTLOCK(screen))
		if (SDL_LockSurface(screen) < 0) 
			return;

	// Ask SDL for the time in milliseconds
	int tick = SDL_GetTicks();

	float *buf = gSoloud.getWave();
	float *fft = gSoloud.calcFFT();


	if (buf && fft)
	{
		int i, j;
		for (i = 0; i < 256; i++)
			for (j = 0; j < 400; j++)
				putpixel(j, i, 0);

		int last = 0;
		for (i = 0; i < 256; i++)
		{			
			int v = 256-(int)floor(fft[i] * 127);
			if (v < 0) v = 0;
			if (v > 256) v = 256;
			for (j = v; j < 256; j++)
			{
				putpixel(i,j,0x0000ff);
			}

			v = (int)floor(buf[i] * 127 + 128);
			if (v < 0) v = 0;
			if (v > 256) v = 256;
			for (j = 0; j < 6; j++)
			{
				putpixel(i,j+v,0xff0000);
			}

			putpixel(200 + v,128+(v-last),0x00ff00);
			last = v;
		}
	}

	drawstring("1-6: sfxr sound effects",0,0);
	drawstring("7-8: switch music",0,16);
	drawstring("9-0: slow down/speed up",0,32);

	char temp[256];
	sprintf(temp, "Music1 volume: %d%%", (int)floor(gSoloud.getVolume(gMusichandle1) * 100));
	drawstring(temp,0,48);
	sprintf(temp, "Music2 volume: %d%%", (int)floor(gSoloud.getVolume(gMusichandle2) * 100));
	drawstring(temp,0,64);
	sprintf(temp, "Music rel. speed: %d%%", (int)floor(gSoloud.getRelativePlaySpeed(gMusichandle2) * 100));
	drawstring(temp,0,80);
	sprintf(temp, "Active voices: %d", gSoloud.getActiveVoiceCount());
	drawstring(temp,0,96);

	// Unlock if needed
	if (SDL_MUSTLOCK(screen)) 
		SDL_UnlockSurface(screen);

	// Tell SDL to update the whole screen
	SDL_UpdateRect(screen, 0, 0, 400, 256);    
}
示例#19
0
// Entry point
int main(int argc, char *argv[])
{
	DemoInit();

	gMusic.load("audio/Jakim - Aboriginal Derivatives.mon");
	gMusic.setParams(10);

	gEcho.setParams(0.2f, 0.5f, 0.05f);
	gBiquad.setParams(SoLoud::BiquadResonantFilter::LOWPASS, 44100, 4000, 2);

	gMusic.setLooping(1);	
	gMusic.setFilter(0, &gBiquad);
	gMusic.setFilter(1, &gLofi);
	gMusic.setFilter(2, &gEcho);
	gMusic.setFilter(3, &gDCRemoval);

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

	gMusichandle = gSoloud.play(gMusic);


	float filter_param0[4] = { 0, 0, 0, 0 };
	float filter_param1[4] = { 1000, 8000, 0, 0 };
	float filter_param2[4] = { 2, 3,  0, 0 };
	
	int hwchannels = 4;
	int waveform = 0;

	// Main loop: loop forever.
	while (1)
	{
		gSoloud.setFilterParameter(gMusichandle, 0, 0, filter_param0[0]);
		gSoloud.setFilterParameter(gMusichandle, 1, 0, filter_param0[1]);
		gSoloud.setFilterParameter(gMusichandle, 2, 0, filter_param0[2]);
		gSoloud.setFilterParameter(gMusichandle, 3, 0, filter_param0[3]);

		gSoloud.setFilterParameter(gMusichandle, 0, 2, filter_param1[0]);
		gSoloud.setFilterParameter(gMusichandle, 0, 3, filter_param2[0]);
		gSoloud.setFilterParameter(gMusichandle, 1, 1, filter_param1[1]);
		gSoloud.setFilterParameter(gMusichandle, 1, 2, filter_param2[1]);

		DemoUpdateStart();

		float *buf = gSoloud.getWave();
		float *fft = gSoloud.calcFFT();

		ONCE(ImGui::SetNextWindowPos(ImVec2(500, 20)));
		ImGui::Begin("Output");
		ImGui::PlotLines("##Wave", buf, 256, 0, "Wave", -1, 1, ImVec2(264, 80));
		ImGui::PlotHistogram("##FFT", fft, 256/2, 0, "FFT", 0, 10, ImVec2(264,80),8);
		ImGui::Text("Music volume     : %d%%", (int)floor(gSoloud.getVolume(gMusichandle) * 100));
		ImGui::Text("Active voices    : %d", gSoloud.getActiveVoiceCount());
		ImGui::End();

		ONCE(ImGui::SetNextWindowPos(ImVec2(20, 20)));
		
		ImGui::Begin("Control");
		if (ImGui::SliderInt("Channels", &hwchannels, 1, 4))
		{
			gMusic.setParams(hwchannels, waveform);
		}
		if (ImGui::CollapsingHeader("Waveform", (const char*)0, true, false))
		{
			if (ImGui::RadioButton("Square", waveform == SoLoud::Monotone::SQUARE))
			{
				waveform = SoLoud::Monotone::SQUARE;
				gMusic.setParams(hwchannels, waveform);
			}
			if (ImGui::RadioButton("Saw", waveform == SoLoud::Monotone::SAW))
			{
				waveform = SoLoud::Monotone::SAW;
				gMusic.setParams(hwchannels, waveform);
			}
			if (ImGui::RadioButton("Sin", waveform == SoLoud::Monotone::SIN))
			{
				waveform = SoLoud::Monotone::SIN;
				gMusic.setParams(hwchannels, waveform);
			}
			if (ImGui::RadioButton("SawSin", waveform == SoLoud::Monotone::SAWSIN))
			{
				waveform = SoLoud::Monotone::SAWSIN;
				gMusic.setParams(hwchannels, waveform);
			}
		}
		ImGui::Separator();
		ImGui::Text("Biquad filter (lowpass)");
		ImGui::SliderFloat("Wet##4", &filter_param0[0], 0, 1);
		ImGui::SliderFloat("Frequency##4", &filter_param1[0], 0, 8000);
		ImGui::SliderFloat("Resonance##4", &filter_param2[0], 1, 20);
		ImGui::Separator();
		ImGui::Text("Lofi filter");
		ImGui::SliderFloat("Wet##2", &filter_param0[1], 0, 1);
		ImGui::SliderFloat("Rate##2", &filter_param1[1], 1000, 8000);
		ImGui::SliderFloat("Bit depth##2", &filter_param2[1], 0, 8);
		ImGui::Separator();
		ImGui::Text("Echo filter");
		ImGui::SliderFloat("Wet##3", &filter_param0[2], 0, 1);
		ImGui::Separator();
		ImGui::Text("DC removal filter");
		ImGui::SliderFloat("Wet##1", &filter_param0[3], 0, 1);
		ImGui::End();
		DemoUpdateEnd();
	}
	return 0;
}
示例#20
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;
}