Mercurial > otakunoraifu
comparison music2/music.cc @ 37:f88d47a4bf87
* Modernize configure.ac
* Improve a bit BGM playback
author | thib |
---|---|
date | Tue, 17 Mar 2009 17:47:26 +0000 |
parents | f45da03ca631 |
children | 01aa5ddf7dc8 |
comparison
equal
deleted
inserted
replaced
36:6d1a5b7f0838 | 37:f88d47a4bf87 |
---|---|
186 int count; | 186 int count; |
187 if (chunk->loop_pt == -2) { // 再生終了後 | 187 if (chunk->loop_pt == -2) { // 再生終了後 |
188 memset(stream, 0, len); | 188 memset(stream, 0, len); |
189 return; | 189 return; |
190 } | 190 } |
191 count = chunk->wav->Read( (char*)stream, 4, len/4); | 191 |
192 char* stream_dup = new char[len]; | |
193 count = chunk->wav->Read( (char*)stream_dup, 4, len/4); | |
192 | 194 |
193 if (count != len/4) { | 195 if (count != len/4) { |
194 memset(stream+count*4, 0, len-count*4); | |
195 // 最後まで再生した | 196 // 最後まで再生した |
196 if (chunk->loop_pt == -1) { // 終了 | 197 if (chunk->loop_pt == -1) { // 終了 |
197 chunk->loop_pt = -2; | 198 chunk->loop_pt = -2; |
199 memset(stream_dup+count*4, 0, len-count*4); | |
198 } else { | 200 } else { |
199 chunk->wav->Seek(chunk->loop_pt); | 201 chunk->wav->Seek(chunk->loop_pt); |
200 chunk->wav->Read( (char*)(stream+count*4), 4, len/4-count); | 202 chunk->wav->Read( (char*)(stream_dup+count*4), 4, len/4-count); |
201 } | 203 } |
202 } | 204 } |
203 | 205 |
204 int cur_vol = (*chunk->volmod)*SDL_MIX_MAXVOLUME/255; | 206 int cur_vol = (*chunk->volmod)*SDL_MIX_MAXVOLUME/255; |
205 | 207 |
207 // 音楽を停止中 (fade out) | 209 // 音楽を停止中 (fade out) |
208 int count_total = fadetime_total*(WAVFILE::freq/1000); | 210 int count_total = fadetime_total*(WAVFILE::freq/1000); |
209 if (fadecount > count_total || fadetime_total == 1) { // 音楽停止 | 211 if (fadecount > count_total || fadetime_total == 1) { // 音楽停止 |
210 chunk->loop_pt = -2; | 212 chunk->loop_pt = -2; |
211 memset(stream, 0, len); | 213 memset(stream, 0, len); |
214 delete[] stream_dup; | |
212 return; | 215 return; |
213 } | 216 } |
214 // int cur_vol = 256*(count_total-fadecount)/count_total; | |
215 cur_vol = cur_vol*(count_total-fadecount)/count_total; | 217 cur_vol = cur_vol*(count_total-fadecount)/count_total; |
216 fadecount += len/4; | 218 fadecount += len/4; |
217 } | 219 } |
218 | 220 |
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); | 221 SDL_MixAudio(stream, (Uint8*)stream_dup, len, cur_vol); |
223 delete[] stream_dup; | 222 delete[] stream_dup; |
224 | 223 |
225 return; | 224 return; |
226 } | 225 } |
227 void bgm_fadeout(int time) { | 226 void bgm_fadeout(int time) { |
228 fadecount = 0; | 227 fadecount = 0; |
229 if (time <= 0) time = 1; | 228 if (time <= 0) time = 1; |