Mercurial > otakunoraifu
changeset 3:c4af1e9ab8d1
music volume can be changed (harcorded constant atm)
author | thib |
---|---|
date | Fri, 01 Aug 2008 20:07:29 +0000 |
parents | 422f3cb3614b |
children | 9fb4609a5372 |
files | music2/music.cc |
diffstat | 1 files changed, 13 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/music2/music.cc +++ b/music2/music.cc @@ -43,6 +43,8 @@ using namespace std; +#define MUSIC_VOLUME 0.2 + int pcm_enable = 0; Mix_Chunk *play_chunk[MIX_PCM_SIZE]; @@ -198,6 +200,9 @@ void WavChunk::callback(void *userdata, chunk->wav->Read( (char*)(stream+count*4), 4, len/4-count); } } + + int cur_vol = MUSIC_VOLUME*SDL_MIX_MAXVOLUME; + if (fadetime_total) { // ²»³Ú¤òÄä»ßÃæ (fade out) int count_total = fadetime_total*(WAVFILE::freq/1000); @@ -207,13 +212,15 @@ void WavChunk::callback(void *userdata, return; } // int cur_vol = 256*(count_total-fadecount)/count_total; - int cur_vol = SDL_MIX_MAXVOLUME*(count_total-fadecount)/count_total; - char* stream_dup = new char[len]; - memcpy(stream_dup, stream, len); - memset(stream, 0, len); - SDL_MixAudio(stream, (Uint8*)stream_dup, len, cur_vol); + cur_vol = cur_vol*(count_total-fadecount)/count_total; fadecount += len/4; } + + char* stream_dup = new char[len]; + memcpy(stream_dup, stream, len); + memset(stream, 0, len); + SDL_MixAudio(stream, (Uint8*)stream_dup, len, cur_vol); + return; } void bgm_fadeout(int time) { @@ -242,7 +249,7 @@ fprintf(stderr,"bgm start %s\n",path); fadetime_total = 0; fadecount = 0; Mix_HookMusic( &(WavChunk::callback), (void*)&wav_playing); - Mix_VolumeMusic(128); + Mix_VolumeMusic(MUSIC_VOLUME*MIX_MAX_VOLUME); return; }