diff options
| author | miguel <miguel@localhost> | 2017-09-23 11:28:05 +0200 |
|---|---|---|
| committer | miguel <miguel@localhost> | 2017-09-23 11:28:05 +0200 |
| commit | 295e5376ca2a765d77b092844ba16f272ea31d7b (patch) | |
| tree | a354346a8bfb264301d77e677c6704f5b339addd /main.cpp | |
| parent | d23b5c21e100c075bf9b806cec45f0ad0f48301d (diff) | |
first mixer (just adding music and coins)
Diffstat (limited to 'main.cpp')
| -rw-r--r-- | main.cpp | 30 |
1 files changed, 25 insertions, 5 deletions
@@ -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; |
