# HG changeset patch # User thib # Date 1217621249 0 # Node ID c4af1e9ab8d1b800021964f2c445c52c52922085 # Parent 422f3cb3614b9b76bb9ca600c48d28736c56031e music volume can be changed (harcorded constant atm) diff --git a/music2/music.cc b/music2/music.cc --- 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; }