Mercurial > otakunoraifu
comparison music2/music.cc @ 3:c4af1e9ab8d1
music volume can be changed (harcorded constant atm)
author | thib |
---|---|
date | Fri, 01 Aug 2008 20:07:29 +0000 |
parents | 223b71206888 |
children | fa8511a21d05 |
comparison
equal
deleted
inserted
replaced
2:422f3cb3614b | 3:c4af1e9ab8d1 |
---|---|
41 #include<SDL_mixer.h> | 41 #include<SDL_mixer.h> |
42 #include"wavfile.h" | 42 #include"wavfile.h" |
43 | 43 |
44 using namespace std; | 44 using namespace std; |
45 | 45 |
46 #define MUSIC_VOLUME 0.2 | |
47 | |
46 int pcm_enable = 0; | 48 int pcm_enable = 0; |
47 Mix_Chunk *play_chunk[MIX_PCM_SIZE]; | 49 Mix_Chunk *play_chunk[MIX_PCM_SIZE]; |
48 | 50 |
49 MuSys::MuSys(AyuSysConfig& _config) : config(_config), movie_id(-1), music_enable(1) { | 51 MuSys::MuSys(AyuSysConfig& _config) : config(_config), movie_id(-1), music_enable(1) { |
50 int i; | 52 int i; |
196 } else { | 198 } else { |
197 chunk->wav->Seek(chunk->loop_pt); | 199 chunk->wav->Seek(chunk->loop_pt); |
198 chunk->wav->Read( (char*)(stream+count*4), 4, len/4-count); | 200 chunk->wav->Read( (char*)(stream+count*4), 4, len/4-count); |
199 } | 201 } |
200 } | 202 } |
203 | |
204 int cur_vol = MUSIC_VOLUME*SDL_MIX_MAXVOLUME; | |
205 | |
201 if (fadetime_total) { | 206 if (fadetime_total) { |
202 // 不弛を匿贿面 (fade out) | 207 // 不弛を匿贿面 (fade out) |
203 int count_total = fadetime_total*(WAVFILE::freq/1000); | 208 int count_total = fadetime_total*(WAVFILE::freq/1000); |
204 if (fadecount > count_total || fadetime_total == 1) { // 不弛匿贿 | 209 if (fadecount > count_total || fadetime_total == 1) { // 不弛匿贿 |
205 chunk->loop_pt = -2; | 210 chunk->loop_pt = -2; |
206 memset(stream, 0, len); | 211 memset(stream, 0, len); |
207 return; | 212 return; |
208 } | 213 } |
209 // int cur_vol = 256*(count_total-fadecount)/count_total; | 214 // int cur_vol = 256*(count_total-fadecount)/count_total; |
210 int cur_vol = SDL_MIX_MAXVOLUME*(count_total-fadecount)/count_total; | 215 cur_vol = cur_vol*(count_total-fadecount)/count_total; |
211 char* stream_dup = new char[len]; | |
212 memcpy(stream_dup, stream, len); | |
213 memset(stream, 0, len); | |
214 SDL_MixAudio(stream, (Uint8*)stream_dup, len, cur_vol); | |
215 fadecount += len/4; | 216 fadecount += len/4; |
216 } | 217 } |
218 | |
219 char* stream_dup = new char[len]; | |
220 memcpy(stream_dup, stream, len); | |
221 memset(stream, 0, len); | |
222 SDL_MixAudio(stream, (Uint8*)stream_dup, len, cur_vol); | |
223 | |
217 return; | 224 return; |
218 } | 225 } |
219 void bgm_fadeout(int time) { | 226 void bgm_fadeout(int time) { |
220 fadecount = 0; | 227 fadecount = 0; |
221 if (time <= 0) time = 1; | 228 if (time <= 0) time = 1; |
240 wav_playing.wav = wav; | 247 wav_playing.wav = wav; |
241 wav_playing.loop_pt = loop_pt; | 248 wav_playing.loop_pt = loop_pt; |
242 fadetime_total = 0; | 249 fadetime_total = 0; |
243 fadecount = 0; | 250 fadecount = 0; |
244 Mix_HookMusic( &(WavChunk::callback), (void*)&wav_playing); | 251 Mix_HookMusic( &(WavChunk::callback), (void*)&wav_playing); |
245 Mix_VolumeMusic(128); | 252 Mix_VolumeMusic(MUSIC_VOLUME*MIX_MAX_VOLUME); |
246 return; | 253 return; |
247 } | 254 } |
248 | 255 |
249 void effec_start(int chn, const char* path, int loop, int fadein_time) { | 256 void effec_start(int chn, const char* path, int loop, int fadein_time) { |
250 if (! pcm_enable) return; | 257 if (! pcm_enable) return; |