From 295e5376ca2a765d77b092844ba16f272ea31d7b Mon Sep 17 00:00:00 2001 From: miguel Date: Sat, 23 Sep 2017 11:28:05 +0200 Subject: first mixer (just adding music and coins) --- Makefile | 2 +- main.cpp | 30 +++++++++++++++++++++++++----- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index a5714ec..af6cd3d 100644 --- a/Makefile +++ b/Makefile @@ -15,4 +15,4 @@ clean: browser-game: emcc --std=c++11 -O2 World.cpp -o World.bc emcc --std=c++11 -O2 main.cpp -o main.bc - emcc -O2 World.bc main.bc -o lunatic_out.html -s USE_SDL=2 --preload-file coin.wav --preload-file coin.bmp --preload-file earth01.bmp --preload-file fonts.bmp --preload-file gridder01.bmp --preload-file guy01.bmp --preload-file guy02.bmp --preload-file gridder02.bmp --preload-file gridder03.bmp -s TOTAL_MEMORY=536870912 --shell-file shell_minimal.html + emcc -O2 World.bc main.bc -o lunatic_out.html -s USE_SDL=2 --preload-file music.wav --preload-file coin.wav --preload-file coin.bmp --preload-file earth01.bmp --preload-file fonts.bmp --preload-file gridder01.bmp --preload-file guy01.bmp --preload-file guy02.bmp --preload-file gridder02.bmp --preload-file gridder03.bmp -s TOTAL_MEMORY=536870912 --shell-file shell_minimal.html diff --git a/main.cpp b/main.cpp index 8fda90d..09431e3 100644 --- a/main.cpp +++ b/main.cpp @@ -49,19 +49,35 @@ struct Context static Uint32 wavLength; +static Uint32 wavLength2; static Uint8 *wavBuffer; +static Uint8 *wavBuffer2; int sample=0; +int sample2=0; void audiomixer(void *userdata, Uint8 *stream, int len) { + SDL_memset(stream, 0, len); // make sure this is silence. + int volume=15000; for(int i=0;iwavLength)stream[i]=0; + if(sample=wavLength2) + { + sample2=0; + } + + stream[i]+=wavBuffer2[sample2]; + sample++; + sample2++; } return; @@ -113,11 +129,14 @@ void sdl_play_sound() std::cout << "---desired load wav---" << std::endl; show_AudioSpec(&wavSpec); - SDL_AudioSpec *spec=SDL_LoadWAV("coin.wav", &wavSpec, &wavBuffer, &wavLength); + SDL_LoadWAV("coin.wav", &wavSpec, &wavBuffer, &wavLength); + sample=wavLength; + SDL_LoadWAV("music.wav", &wavSpec, &wavBuffer2, &wavLength2); - std::cout << "---desired load wav---" << std::endl; - show_AudioSpec(&wavSpec); + //std::cout << "---desired load wav---" << std::endl; + //show_AudioSpec(&wavSpec); std::cout << "---wav source data---" << std::endl; +/* if(spec==NULL) { @@ -125,6 +144,7 @@ void sdl_play_sound() exit(-1); } show_AudioSpec(spec); +*/ // open most reasonable default device for playback. std::cout << "---" << std::endl; wavSpec.callback = audiomixer; -- cgit v1.2.3