diff options
| -rw-r--r-- | Makefile | 2 | ||||
| -rw-r--r-- | main.cpp | 30 |
2 files changed, 26 insertions, 6 deletions
@@ -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 @@ -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;i<len;i++) { - stream[i]=wavBuffer[sample]; - if(sample>wavLength)stream[i]=0; + if(sample<wavLength) + { + stream[i]+=wavBuffer[sample]; + } + + if(sample2>=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; |
