Mercurial > otakunoraifu
comparison music2/music.cc @ 65:4416cfac86ae
Convert EUC-JP files to UTF8
author | Thibaut Girka <thib@sitedethib.com> |
---|---|
date | Fri, 26 Nov 2010 10:53:15 +0100 |
parents | ddbcbd000206 |
children |
comparison
equal
deleted
inserted
replaced
64:045ca45f9610 | 65:4416cfac86ae |
---|---|
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 */ | 26 */ |
27 | 27 |
28 /* music.cc SDL_mixer を用いた音楽再生ルーチン */ | 28 /* music.cc SDL_mixer 恰ソ若 */ |
29 | 29 |
30 | 30 |
31 #include <string.h> | 31 #include <string.h> |
32 #include <stdio.h> | 32 #include <stdio.h> |
33 #include <unistd.h> | 33 #include <unistd.h> |
92 /* name -> track */ | 92 /* name -> track */ |
93 int track =config->track_name.CDTrack(name); | 93 int track =config->track_name.CDTrack(name); |
94 if (track == -1) track = atoi(name); | 94 if (track == -1) track = atoi(name); |
95 if (config->track_name.WaveTrack(name) != NULL) | 95 if (config->track_name.WaveTrack(name) != NULL) |
96 strncpy(wave, config->track_name.WaveTrack(name), 127); | 96 strncpy(wave, config->track_name.WaveTrack(name), 127); |
97 if (wave[0] == 0 && track != 0) { /* DSTRACK が見つからない場合、CDTRACKを使用する */ | 97 if (wave[0] == 0 && track != 0) { /* DSTRACK 荀ゃ翫CDTRACK篏睡 */ |
98 sprintf(wave, "audio_%02d", track); | 98 sprintf(wave, "audio_%02d", track); |
99 } | 99 } |
100 if (wave == 0) return; | 100 if (wave == 0) return; |
101 // BGM 再生 | 101 // BGM |
102 if (!pcm_enable) return; | 102 if (!pcm_enable) return; |
103 if (play_count == 0) | 103 if (play_count == 0) |
104 bgm_start(wave, -1); | 104 bgm_start(wave, -1); |
105 else | 105 else |
106 bgm_start(wave, config->track_name.TrackStart(name)); | 106 bgm_start(wave, config->track_name.TrackStart(name)); |
185 music_enable = 1; | 185 music_enable = 1; |
186 } | 186 } |
187 | 187 |
188 /************************************************************************* | 188 /************************************************************************* |
189 ** | 189 ** |
190 ** ファイル読み込み / 外部コマンド呼び出し | 190 ** <ゃ茯粋昭 / 紊潟潟若喝冴 |
191 */ | 191 */ |
192 | 192 |
193 struct WavChunk { | 193 struct WavChunk { |
194 WAVFILE* wav; | 194 WAVFILE* wav; |
195 int loop_pt; | 195 int loop_pt; |
203 | 203 |
204 void WavChunk::callback(void *userdata, Uint8 *stream, int len) | 204 void WavChunk::callback(void *userdata, Uint8 *stream, int len) |
205 { | 205 { |
206 WavChunk* chunk = (WavChunk*)userdata; | 206 WavChunk* chunk = (WavChunk*)userdata; |
207 int count; | 207 int count; |
208 if (chunk->loop_pt == -2) { // 再生終了後 | 208 if (chunk->loop_pt == -2) { // 腟篋緇 |
209 memset(stream, 0, len); | 209 memset(stream, 0, len); |
210 return; | 210 return; |
211 } | 211 } |
212 | 212 |
213 char* stream_dup = new char[len]; | 213 char* stream_dup = new char[len]; |
214 count = chunk->wav->Read( (char*)stream_dup, 4, len/4); | 214 count = chunk->wav->Read( (char*)stream_dup, 4, len/4); |
215 | 215 |
216 if (count != len/4) { | 216 if (count != len/4) { |
217 // 最後まで再生した | 217 // 緇障у |
218 if (chunk->loop_pt == -1) { // 終了 | 218 if (chunk->loop_pt == -1) { // 腟篋 |
219 chunk->loop_pt = -2; | 219 chunk->loop_pt = -2; |
220 memset(stream_dup+count*4, 0, len-count*4); | 220 memset(stream_dup+count*4, 0, len-count*4); |
221 } else { | 221 } else { |
222 chunk->wav->Seek(chunk->loop_pt); | 222 chunk->wav->Seek(chunk->loop_pt); |
223 chunk->wav->Read( (char*)(stream_dup+count*4), 4, len/4-count); | 223 chunk->wav->Read( (char*)(stream_dup+count*4), 4, len/4-count); |
225 } | 225 } |
226 | 226 |
227 int cur_vol = (*chunk->volmod)*SDL_MIX_MAXVOLUME/255; | 227 int cur_vol = (*chunk->volmod)*SDL_MIX_MAXVOLUME/255; |
228 | 228 |
229 if (fadetime_total) { | 229 if (fadetime_total) { |
230 // 音楽を停止中 (fade out) | 230 // 恰ソ罩≫賢 (fade out) |
231 int count_total = fadetime_total*(WAVFILE::freq/1000); | 231 int count_total = fadetime_total*(WAVFILE::freq/1000); |
232 if (fadecount > count_total || fadetime_total == 1) { // 音楽停止 | 232 if (fadecount > count_total || fadetime_total == 1) { // 恰ソ罩 |
233 chunk->loop_pt = -2; | 233 chunk->loop_pt = -2; |
234 memset(stream, 0, len); | 234 memset(stream, 0, len); |
235 delete[] stream_dup; | 235 delete[] stream_dup; |
236 return; | 236 return; |
237 } | 237 } |
260 WAVFILE* wav = OpenWaveFile(path); | 260 WAVFILE* wav = OpenWaveFile(path); |
261 if (wav == NULL) return; | 261 if (wav == NULL) return; |
262 Mix_PauseMusic(); | 262 Mix_PauseMusic(); |
263 Mix_HaltMusic(); | 263 Mix_HaltMusic(); |
264 Mix_HookMusic(0,0); | 264 Mix_HookMusic(0,0); |
265 /* 前に再生していたのを終了 */ | 265 /* 腟篋 */ |
266 if (wav_playing.wav != NULL) { | 266 if (wav_playing.wav != NULL) { |
267 delete wav_playing.wav; | 267 delete wav_playing.wav; |
268 wav_playing.wav = NULL; | 268 wav_playing.wav = NULL; |
269 } | 269 } |
270 wav_playing.wav = wav; | 270 wav_playing.wav = wav; |
279 MuSys* mu = MuSys::GetInstance(); | 279 MuSys* mu = MuSys::GetInstance(); |
280 | 280 |
281 if (!mu->pcm_enable) return; | 281 if (!mu->pcm_enable) return; |
282 | 282 |
283 SDL_RWops* op = OpenSDLRW(path); | 283 SDL_RWops* op = OpenSDLRW(path); |
284 if (op == NULL) { // ファイルが見付からない | 284 if (op == NULL) { // <ゃ荀篁 |
285 return; | 285 return; |
286 } | 286 } |
287 Mix_Pause(chn); | 287 Mix_Pause(chn); |
288 | 288 |
289 if (mu->play_chunk[chn] != NULL) { | 289 if (mu->play_chunk[chn] != NULL) { |
308 int len = 0; | 308 int len = 0; |
309 AvgKoeInfo koeinfo; | 309 AvgKoeInfo koeinfo; |
310 int chn = MIX_PCM_KOE; | 310 int chn = MIX_PCM_KOE; |
311 | 311 |
312 Mix_Pause(chn); | 312 Mix_Pause(chn); |
313 Mix_HaltChannel(chn); // これで RWop が解放されるはず… | 313 Mix_HaltChannel(chn); // RWop 茹f障 |
314 if (mu->play_chunk[chn] != NULL) { | 314 if (mu->play_chunk[chn] != NULL) { |
315 Mix_FreeChunk(mu->play_chunk[chn]); | 315 Mix_FreeChunk(mu->play_chunk[chn]); |
316 mu->play_chunk[chn] = NULL; | 316 mu->play_chunk[chn] = NULL; |
317 } | 317 } |
318 | 318 |
339 /* if (global_system.Version() >= 2) */ radix *= 10; | 339 /* if (global_system.Version() >= 2) */ radix *= 10; |
340 AvgKoeInfo info; | 340 AvgKoeInfo info; |
341 info.stream = NULL; | 341 info.stream = NULL; |
342 info.length = 0; | 342 info.length = 0; |
343 info.offset = 0; | 343 info.offset = 0; |
344 if (isdigit(path[0]) && strchr(path,'.') == NULL) { // 数値 (拡張子等なし) | 344 if (isdigit(path[0]) && strchr(path,'.') == NULL) { // 医 (≦宍絖膈) |
345 /* avg32 形式の音声アーカイブのキャッシュを検索 */ | 345 /* avg32 綵√喝0≪若ゃc激ャ罎膣 */ |
346 int pointer = atoi(path); | 346 int pointer = atoi(path); |
347 int file_no = pointer / radix; | 347 int file_no = pointer / radix; |
348 int index = pointer % radix; | 348 int index = pointer % radix; |
349 info = FindKoe(file_no, index); | 349 info = FindKoe(file_no, index); |
350 } else { // ファイル | 350 } else { // <ゃ |
351 int length; | 351 int length; |
352 ARCINFO* arcinfo = FileSearcher::GetInstance()->Find(FileSearcher::KOE, path, ".WPD"); | 352 ARCINFO* arcinfo = FileSearcher::GetInstance()->Find(FileSearcher::KOE, path, ".WPD"); |
353 if (arcinfo == NULL) return info; | 353 if (arcinfo == NULL) return info; |
354 info.stream = arcinfo->OpenFile(&length); | 354 info.stream = arcinfo->OpenFile(&length); |
355 info.rate = 22050; | 355 info.rate = 22050; |
360 } | 360 } |
361 return info; | 361 return info; |
362 } | 362 } |
363 | 363 |
364 static SDL_RWops* OpenSDLRW(const char* path) { | 364 static SDL_RWops* OpenSDLRW(const char* path) { |
365 /* まず wav ファイルを探す */ | 365 /* 障 wav <ゃ「 */ |
366 FileSearcher* file_searcher = FileSearcher::GetInstance(); | 366 FileSearcher* file_searcher = FileSearcher::GetInstance(); |
367 ARCINFO* info = file_searcher->Find(FileSearcher::WAV, path, ".wav"); | 367 ARCINFO* info = file_searcher->Find(FileSearcher::WAV, path, ".wav"); |
368 if (info == NULL) { | 368 if (info == NULL) { |
369 info = file_searcher->Find(FileSearcher::WAV, path, ".nwa"); | 369 info = file_searcher->Find(FileSearcher::WAV, path, ".nwa"); |
370 if (info == NULL) info = file_searcher->Find(FileSearcher::BGM, path, "nwa"); | 370 if (info == NULL) info = file_searcher->Find(FileSearcher::BGM, path, "nwa"); |
390 } | 390 } |
391 return NULL; | 391 return NULL; |
392 } | 392 } |
393 | 393 |
394 static WAVFILE* OpenWaveFile(const char* path) { | 394 static WAVFILE* OpenWaveFile(const char* path) { |
395 /* まず wav ファイルを探す */ | 395 /* 障 wav <ゃ「 */ |
396 FileSearcher* file_searcher = FileSearcher::GetInstance(); | 396 FileSearcher* file_searcher = FileSearcher::GetInstance(); |
397 ARCINFO* info = file_searcher->Find(FileSearcher::WAV, path, ".wav"); | 397 ARCINFO* info = file_searcher->Find(FileSearcher::WAV, path, ".wav"); |
398 if (info == NULL) info = file_searcher->Find(FileSearcher::BGM, path, "wav"); | 398 if (info == NULL) info = file_searcher->Find(FileSearcher::BGM, path, "wav"); |
399 if (info != NULL) { | 399 if (info != NULL) { |
400 int size; | 400 int size; |
402 delete info; | 402 delete info; |
403 if (f == NULL) return NULL; | 403 if (f == NULL) return NULL; |
404 WAVFILE* w = WAVFILE::MakeConverter(new WAVFILE_Stream(f, size)); | 404 WAVFILE* w = WAVFILE::MakeConverter(new WAVFILE_Stream(f, size)); |
405 return w; | 405 return w; |
406 } | 406 } |
407 /* 次に nwa ファイル */ | 407 /* 罨< nwa <ゃ */ |
408 info = file_searcher->Find(FileSearcher::WAV, path, ".nwa"); | 408 info = file_searcher->Find(FileSearcher::WAV, path, ".nwa"); |
409 if (info == NULL) info = file_searcher->Find(FileSearcher::BGM, path, "nwa"); | 409 if (info == NULL) info = file_searcher->Find(FileSearcher::BGM, path, "nwa"); |
410 if (info != NULL) { | 410 if (info != NULL) { |
411 int size; | 411 int size; |
412 FILE* f = info->OpenFile(&size); | 412 FILE* f = info->OpenFile(&size); |
414 if (f == NULL) return NULL; | 414 if (f == NULL) return NULL; |
415 WAVFILE* w = WAVFILE::MakeConverter(new NWAFILE(f)); | 415 WAVFILE* w = WAVFILE::MakeConverter(new NWAFILE(f)); |
416 return w; | 416 return w; |
417 } | 417 } |
418 | 418 |
419 /* 次に mp3 ファイル */ | 419 /* 罨< mp3 <ゃ */ |
420 info = file_searcher->Find(FileSearcher::WAV, path, ".mp3"); | 420 info = file_searcher->Find(FileSearcher::WAV, path, ".mp3"); |
421 if (info == NULL) info = file_searcher->Find(FileSearcher::BGM, path, "mp3"); | 421 if (info == NULL) info = file_searcher->Find(FileSearcher::BGM, path, "mp3"); |
422 if (info != NULL) { | 422 if (info != NULL) { |
423 int size; | 423 int size; |
424 FILE* f = info->OpenFile(&size); | 424 FILE* f = info->OpenFile(&size); |
429 return WAVFILE::MakeConverter(w); | 429 return WAVFILE::MakeConverter(w); |
430 } | 430 } |
431 delete w; | 431 delete w; |
432 } | 432 } |
433 | 433 |
434 /* 次に ogg ファイル */ | 434 /* 罨< ogg <ゃ */ |
435 info = file_searcher->Find(FileSearcher::WAV, path, ".ogg"); | 435 info = file_searcher->Find(FileSearcher::WAV, path, ".ogg"); |
436 if (info == NULL) info = file_searcher->Find(FileSearcher::BGM, path, "ogg"); | 436 if (info == NULL) info = file_searcher->Find(FileSearcher::BGM, path, "ogg"); |
437 if (info != NULL) { | 437 if (info != NULL) { |
438 int size; | 438 int size; |
439 FILE* f = info->OpenFile(&size); | 439 FILE* f = info->OpenFile(&size); |