Mercurial > otakunoraifu
annotate music2/music.cc @ 66:d112357a0ec1
Fix a bug with savegames introduced with changeset c7bcc0ec2267.
Warning: savegames created since c7bcc0ec2267 are probably corrupted,
you may have to start the game over.
If you chose not to do so, you should replace all occurrences of 'TextWindow' by 'TextImplWindow',
and 'Text Window' by 'TextImpl Window' in your save files.
author | Thibaut Girka <thib@sitedethib.com> |
---|---|
date | Sat, 11 Dec 2010 18:36:20 +0100 |
parents | 4416cfac86ae |
children |
rev | line source |
---|---|
0 | 1 /* |
2 * Copyright (c) 2004-2006 Kazunori "jagarl" Ueno | |
3 * All rights reserved. | |
4 * | |
5 * Redistribution and use in source and binary forms, with or without | |
6 * modification, are permitted provided that the following conditions | |
7 * are met: | |
8 * 1. Redistributions of source code must retain the above copyright | |
9 * notice, this list of conditions and the following disclaimer. | |
10 * 2. Redistributions in binary form must reproduce the above copyright | |
11 * notice, this list of conditions and the following disclaimer in the | |
12 * documentation and/or other materials provided with the distribution. | |
13 * 3. The name of the author may not be used to endorse or promote products | |
14 * derived from this software without specific prior written permission. | |
15 * | |
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | |
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | |
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | |
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | |
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
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 | |
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
26 */ | |
27 | |
65
4416cfac86ae
Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents:
53
diff
changeset
|
28 /* music.cc SDL_mixer を用いた音楽再生ルーチン */ |
0 | 29 |
30 | |
31 #include <string.h> | |
32 #include <stdio.h> | |
33 #include <unistd.h> | |
34 #include <fcntl.h> | |
35 #include <ctype.h> | |
36 #include <signal.h> | |
53
ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents:
52
diff
changeset
|
37 #include "system/system_config.h" |
ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents:
52
diff
changeset
|
38 #include "system/file.h" |
0 | 39 #include "music.h" |
52 | 40 #include <SDL.h> |
41 #include <SDL_mixer.h> | |
42 #include "wavfile.h" | |
0 | 43 |
44 using namespace std; | |
45 | |
53
ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents:
52
diff
changeset
|
46 MuSys * MuSys::_singleton = NULL; |
ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents:
52
diff
changeset
|
47 |
ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents:
52
diff
changeset
|
48 MuSys* MuSys::GetInstance(void) |
ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents:
52
diff
changeset
|
49 { |
ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents:
52
diff
changeset
|
50 if (_singleton == NULL) |
ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents:
52
diff
changeset
|
51 _singleton = new MuSys; |
ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents:
52
diff
changeset
|
52 return _singleton; |
ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents:
52
diff
changeset
|
53 } |
0 | 54 |
53
ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents:
52
diff
changeset
|
55 void MuSys::Quit(void) |
ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents:
52
diff
changeset
|
56 { |
ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents:
52
diff
changeset
|
57 if (_singleton != NULL) { |
ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents:
52
diff
changeset
|
58 _singleton->FinalizeMusic(); |
ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents:
52
diff
changeset
|
59 delete _singleton; |
ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents:
52
diff
changeset
|
60 _singleton = NULL; |
ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents:
52
diff
changeset
|
61 } |
ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents:
52
diff
changeset
|
62 } |
ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents:
52
diff
changeset
|
63 |
ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents:
52
diff
changeset
|
64 MuSys::MuSys() : movie_id(-1), music_enable(1) { |
0 | 65 int i; |
53
ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents:
52
diff
changeset
|
66 config = AyuSysConfig::GetInstance(); |
0 | 67 for (i=0; i<MIX_PCM_SIZE; i++) |
68 play_chunk[i] = 0; | |
69 cdrom_track[0] = 0; | |
70 effec_track[0] = 0; | |
71 } | |
72 | |
73 | |
74 // #define delete fprintf(stderr,"smus.cc: %d.",__LINE__), delete | |
75 | |
53
ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents:
52
diff
changeset
|
76 void bgm_start(const char* path, int loop_pt); |
ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents:
52
diff
changeset
|
77 void effec_start(int chn, const char* path, int loop, int fadein_time); |
0 | 78 void bgm_fadeout(int time); |
79 | |
80 void MuSys::PlayCDROM(char* name, int play_count) { | |
53
ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents:
52
diff
changeset
|
81 config->GetParam("#VOLMOD", 4, &volmod[0], &volmod[1], &volmod[2], &volmod[3]); |
52 | 82 |
83 char wave[128]; | |
84 wave[127] = '\0'; | |
85 wave[0] = '\0'; | |
0 | 86 |
87 strcpy(cdrom_track, name); | |
88 | |
89 StopCDROM(0); | |
90 strcpy(cdrom_track, name); | |
91 | |
92 /* name -> track */ | |
53
ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents:
52
diff
changeset
|
93 int track =config->track_name.CDTrack(name); |
0 | 94 if (track == -1) track = atoi(name); |
53
ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents:
52
diff
changeset
|
95 if (config->track_name.WaveTrack(name) != NULL) |
ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents:
52
diff
changeset
|
96 strncpy(wave, config->track_name.WaveTrack(name), 127); |
65
4416cfac86ae
Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents:
53
diff
changeset
|
97 if (wave[0] == 0 && track != 0) { /* DSTRACK が見つからない場合、CDTRACKを使用する */ |
52 | 98 sprintf(wave, "audio_%02d", track); |
0 | 99 } |
100 if (wave == 0) return; | |
65
4416cfac86ae
Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents:
53
diff
changeset
|
101 // BGM 再生 |
0 | 102 if (!pcm_enable) return; |
103 if (play_count == 0) | |
53
ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents:
52
diff
changeset
|
104 bgm_start(wave, -1); |
0 | 105 else |
53
ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents:
52
diff
changeset
|
106 bgm_start(wave, config->track_name.TrackStart(name)); |
0 | 107 return; |
108 } | |
109 | |
110 void MuSys::StopCDROM(int time) | |
111 { | |
112 cdrom_track[0] = '\0'; | |
113 if (!pcm_enable) return; | |
114 bgm_fadeout(time); | |
115 } | |
116 | |
117 void MuSys::PlaySE(const char* se, int loop_flag, int channel) { | |
52 | 118 if (!pcm_enable) return; |
0 | 119 if (loop_flag) |
53
ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents:
52
diff
changeset
|
120 effec_start(MIX_PCM_EFFEC, se, 10000, 0); |
0 | 121 else |
53
ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents:
52
diff
changeset
|
122 effec_start(MIX_PCM_EFFEC, se, 0, 0); |
0 | 123 return; |
124 } | |
125 void MuSys::PlaySE(int number) { | |
126 if (! pcm_enable) return; | |
53
ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents:
52
diff
changeset
|
127 const char* se_name = config->track_name.SETrack(number); |
52 | 128 if (se_name == NULL) return; |
53
ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents:
52
diff
changeset
|
129 effec_start(MIX_PCM_EFFEC, se_name, 0, 0); |
0 | 130 return; |
131 } | |
132 void MuSys::StopSE(int time) { | |
52 | 133 if (!pcm_enable) return; |
0 | 134 if (time == 0) |
135 Mix_HaltChannel(MIX_PCM_EFFEC); | |
136 else | |
137 Mix_FadeOutChannel(MIX_PCM_EFFEC, time); | |
138 } | |
139 bool MuSys::IsStopSE(void) { | |
52 | 140 if (!pcm_enable) return true; |
0 | 141 if (Mix_Playing(MIX_PCM_EFFEC) != 0) return false; |
142 return true; | |
143 } | |
144 | |
145 void MuSys::StopKoe(int time) { | |
52 | 146 if (!pcm_enable) return; |
0 | 147 if (time == 0) Mix_HaltChannel(MIX_PCM_KOE); |
148 else Mix_FadeOutChannel(MIX_PCM_KOE, time); | |
149 } | |
150 | |
151 void MuSys::InitMusic(void) | |
152 { | |
153 if (music_enable != 1) return; | |
154 cdrom_track[0] = '\0'; | |
155 if ( Mix_OpenAudio( 44100, MIX_DEFAULT_FORMAT, MIX_DEFAULT_CHANNELS, DEFAULT_AUDIOBUF ) < 0 ){ | |
156 // if ( Mix_OpenAudio( 48000, MIX_DEFAULT_FORMAT, MIX_DEFAULT_CHANNELS, DEFAULT_AUDIOBUF ) < 0 ){ | |
157 return; | |
158 } | |
159 int freq, channels; Uint16 format; | |
160 if ( Mix_QuerySpec(&freq, &format, &channels) ) { | |
161 WAVFILE::freq = freq; | |
162 WAVFILE::format = format; | |
163 WAVFILE::channels = channels; | |
164 } | |
165 pcm_enable = 1; | |
166 Mix_AllocateChannels( MIX_PCM_SIZE); | |
167 music_enable = 2; | |
168 } | |
53
ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents:
52
diff
changeset
|
169 |
0 | 170 void MuSys::FinalizeMusic(void) |
171 { | |
172 if (music_enable != 2) return; | |
173 int i; | |
174 for (i=0; i<MIX_PCM_SIZE; i++) { | |
175 Mix_HaltChannel(i); | |
176 if (play_chunk[i]) { | |
177 Mix_FreeChunk(play_chunk[i]); | |
178 } | |
179 play_chunk[i] = 0; | |
180 } | |
181 Mix_HaltMusic(); | |
182 Mix_HookMusic(0,0); | |
183 Mix_CloseAudio(); | |
184 pcm_enable = 0; | |
185 music_enable = 1; | |
186 } | |
187 | |
188 /************************************************************************* | |
189 ** | |
65
4416cfac86ae
Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents:
53
diff
changeset
|
190 ** ファイル読み込み / 外部コマンド呼び出し |
0 | 191 */ |
192 | |
193 struct WavChunk { | |
194 WAVFILE* wav; | |
195 int loop_pt; | |
26 | 196 int *volmod; |
0 | 197 static void callback(void* userdata, Uint8* stream, int len); |
198 }; | |
52 | 199 |
0 | 200 WavChunk wav_playing; |
201 static int fadetime_total; | |
202 static int fadecount; | |
203 | |
204 void WavChunk::callback(void *userdata, Uint8 *stream, int len) | |
205 { | |
206 WavChunk* chunk = (WavChunk*)userdata; | |
207 int count; | |
65
4416cfac86ae
Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents:
53
diff
changeset
|
208 if (chunk->loop_pt == -2) { // 再生終了後 |
0 | 209 memset(stream, 0, len); |
210 return; | |
211 } | |
37 | 212 |
213 char* stream_dup = new char[len]; | |
214 count = chunk->wav->Read( (char*)stream_dup, 4, len/4); | |
0 | 215 |
216 if (count != len/4) { | |
65
4416cfac86ae
Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents:
53
diff
changeset
|
217 // 最後まで再生した |
4416cfac86ae
Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents:
53
diff
changeset
|
218 if (chunk->loop_pt == -1) { // 終了 |
0 | 219 chunk->loop_pt = -2; |
37 | 220 memset(stream_dup+count*4, 0, len-count*4); |
0 | 221 } else { |
222 chunk->wav->Seek(chunk->loop_pt); | |
37 | 223 chunk->wav->Read( (char*)(stream_dup+count*4), 4, len/4-count); |
0 | 224 } |
225 } | |
3 | 226 |
26 | 227 int cur_vol = (*chunk->volmod)*SDL_MIX_MAXVOLUME/255; |
3 | 228 |
0 | 229 if (fadetime_total) { |
65
4416cfac86ae
Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents:
53
diff
changeset
|
230 // 音楽を停止中 (fade out) |
0 | 231 int count_total = fadetime_total*(WAVFILE::freq/1000); |
65
4416cfac86ae
Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents:
53
diff
changeset
|
232 if (fadecount > count_total || fadetime_total == 1) { // 音楽停止 |
0 | 233 chunk->loop_pt = -2; |
234 memset(stream, 0, len); | |
37 | 235 delete[] stream_dup; |
0 | 236 return; |
237 } | |
3 | 238 cur_vol = cur_vol*(count_total-fadecount)/count_total; |
0 | 239 fadecount += len/4; |
240 } | |
37 | 241 |
3 | 242 SDL_MixAudio(stream, (Uint8*)stream_dup, len, cur_vol); |
7 | 243 delete[] stream_dup; |
37 | 244 |
0 | 245 return; |
246 } | |
247 void bgm_fadeout(int time) { | |
248 fadecount = 0; | |
249 if (time <= 0) time = 1; | |
250 fadetime_total = time; | |
251 } | |
252 | |
253 static SDL_RWops* OpenSDLRW(const char* path); | |
254 static WAVFILE* OpenWaveFile(const char* path); | |
53
ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents:
52
diff
changeset
|
255 void bgm_start(const char* path, int loop_pt) { |
ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents:
52
diff
changeset
|
256 MuSys* mu = MuSys::GetInstance(); |
ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents:
52
diff
changeset
|
257 |
ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents:
52
diff
changeset
|
258 if (!mu->pcm_enable) return; |
0 | 259 fprintf(stderr,"bgm start %s\n",path); |
260 WAVFILE* wav = OpenWaveFile(path); | |
52 | 261 if (wav == NULL) return; |
0 | 262 Mix_PauseMusic(); |
263 Mix_HaltMusic(); | |
264 Mix_HookMusic(0,0); | |
65
4416cfac86ae
Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents:
53
diff
changeset
|
265 /* 前に再生していたのを終了 */ |
52 | 266 if (wav_playing.wav != NULL) { |
0 | 267 delete wav_playing.wav; |
52 | 268 wav_playing.wav = NULL; |
0 | 269 } |
270 wav_playing.wav = wav; | |
271 wav_playing.loop_pt = loop_pt; | |
53
ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents:
52
diff
changeset
|
272 wav_playing.volmod = mu->volmod; |
0 | 273 fadetime_total = 0; |
274 fadecount = 0; | |
275 Mix_HookMusic( &(WavChunk::callback), (void*)&wav_playing); | |
276 } | |
277 | |
53
ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents:
52
diff
changeset
|
278 void effec_start(int chn, const char* path, int loop, int fadein_time) { |
ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents:
52
diff
changeset
|
279 MuSys* mu = MuSys::GetInstance(); |
ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents:
52
diff
changeset
|
280 |
ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents:
52
diff
changeset
|
281 if (!mu->pcm_enable) return; |
ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents:
52
diff
changeset
|
282 |
0 | 283 SDL_RWops* op = OpenSDLRW(path); |
65
4416cfac86ae
Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents:
53
diff
changeset
|
284 if (op == NULL) { // ファイルが見付からない |
0 | 285 return; |
286 } | |
287 Mix_Pause(chn); | |
288 | |
53
ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents:
52
diff
changeset
|
289 if (mu->play_chunk[chn] != NULL) { |
ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents:
52
diff
changeset
|
290 Mix_FreeChunk(mu->play_chunk[chn]); |
0 | 291 } |
53
ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents:
52
diff
changeset
|
292 mu->play_chunk[chn] = Mix_LoadWAV_RW(op, 1); |
0 | 293 if (fadein_time <= 0) { |
53
ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents:
52
diff
changeset
|
294 Mix_Volume(chn, mu->volmod[3]*SDL_MIX_MAXVOLUME/255); |
ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents:
52
diff
changeset
|
295 Mix_PlayChannel(chn, mu->play_chunk[chn], loop); |
0 | 296 } else { |
53
ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents:
52
diff
changeset
|
297 Mix_Volume(chn, mu->volmod[3]*SDL_MIX_MAXVOLUME/255); |
ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents:
52
diff
changeset
|
298 Mix_FadeInChannel(chn, mu->play_chunk[chn], loop, fadein_time); |
0 | 299 } |
300 } | |
301 | |
302 void MuSys::PlayKoe(const char* path) { | |
52 | 303 if (!pcm_enable) return; |
53
ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents:
52
diff
changeset
|
304 |
ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents:
52
diff
changeset
|
305 MuSys* mu = MuSys::GetInstance(); |
ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents:
52
diff
changeset
|
306 |
52 | 307 static char* playing_koedata = NULL; |
0 | 308 int len = 0; |
309 AvgKoeInfo koeinfo; | |
310 int chn = MIX_PCM_KOE; | |
311 | |
312 Mix_Pause(chn); | |
65
4416cfac86ae
Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents:
53
diff
changeset
|
313 Mix_HaltChannel(chn); // これで RWop が解放されるはず… |
53
ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents:
52
diff
changeset
|
314 if (mu->play_chunk[chn] != NULL) { |
ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents:
52
diff
changeset
|
315 Mix_FreeChunk(mu->play_chunk[chn]); |
ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents:
52
diff
changeset
|
316 mu->play_chunk[chn] = NULL; |
0 | 317 } |
318 | |
53
ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents:
52
diff
changeset
|
319 if (playing_koedata != NULL) { |
7 | 320 free(playing_koedata); |
53
ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents:
52
diff
changeset
|
321 playing_koedata = NULL; |
0 | 322 } |
323 | |
324 koeinfo = OpenKoeFile(path); | |
325 | |
52 | 326 if (koeinfo.stream == NULL) return; |
0 | 327 playing_koedata = decode_koe(koeinfo, &len); |
328 fclose(koeinfo.stream); | |
52 | 329 if (playing_koedata == NULL) { |
0 | 330 return; |
331 } | |
53
ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents:
52
diff
changeset
|
332 Mix_Volume(chn, mu->volmod[1]*SDL_MIX_MAXVOLUME/255); |
ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents:
52
diff
changeset
|
333 mu->play_chunk[chn] = Mix_LoadWAV_RW(SDL_RWFromMem(playing_koedata, len+0x2c), 1); |
ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents:
52
diff
changeset
|
334 Mix_PlayChannel(chn, mu->play_chunk[chn], 0); |
0 | 335 } |
52 | 336 |
0 | 337 AvgKoeInfo OpenKoeFile(const char* path) { |
338 int radix = 10000; | |
339 /* if (global_system.Version() >= 2) */ radix *= 10; | |
340 AvgKoeInfo info; | |
52 | 341 info.stream = NULL; |
342 info.length = 0; | |
343 info.offset = 0; | |
65
4416cfac86ae
Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents:
53
diff
changeset
|
344 if (isdigit(path[0]) && strchr(path,'.') == NULL) { // 数値 (拡張子等なし) |
4416cfac86ae
Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents:
53
diff
changeset
|
345 /* avg32 形式の音声アーカイブのキャッシュを検索 */ |
0 | 346 int pointer = atoi(path); |
347 int file_no = pointer / radix; | |
348 int index = pointer % radix; | |
349 info = FindKoe(file_no, index); | |
65
4416cfac86ae
Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents:
53
diff
changeset
|
350 } else { // ファイル |
0 | 351 int length; |
53
ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents:
52
diff
changeset
|
352 ARCINFO* arcinfo = FileSearcher::GetInstance()->Find(FileSearcher::KOE, path, ".WPD"); |
52 | 353 if (arcinfo == NULL) return info; |
0 | 354 info.stream = arcinfo->OpenFile(&length); |
355 info.rate = 22050; | |
356 info.length = length; | |
357 info.offset = ftell(info.stream); | |
358 info.type = koe_unknown; | |
359 delete arcinfo; | |
360 } | |
361 return info; | |
362 } | |
363 | |
364 static SDL_RWops* OpenSDLRW(const char* path) { | |
65
4416cfac86ae
Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents:
53
diff
changeset
|
365 /* まず wav ファイルを探す */ |
53
ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents:
52
diff
changeset
|
366 FileSearcher* file_searcher = FileSearcher::GetInstance(); |
ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents:
52
diff
changeset
|
367 ARCINFO* info = file_searcher->Find(FileSearcher::WAV, path, ".wav"); |
52 | 368 if (info == NULL) { |
53
ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents:
52
diff
changeset
|
369 info = file_searcher->Find(FileSearcher::WAV, path, ".nwa"); |
ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents:
52
diff
changeset
|
370 if (info == NULL) info = file_searcher->Find(FileSearcher::BGM, path, "nwa"); |
52 | 371 if (info != NULL) { // read NWA file |
0 | 372 int dummy; |
373 FILE* f = info->OpenFile(&dummy); | |
374 static char* d = 0; | |
375 int sz; | |
376 if (d != 0) delete[] d; | |
377 d = NWAFILE::ReadAll(f, sz); | |
378 return SDL_RWFromMem(d, sz); | |
379 } | |
380 } | |
53
ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents:
52
diff
changeset
|
381 if (info == NULL) info = file_searcher->Find(FileSearcher::BGM, path, "wav"); |
ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents:
52
diff
changeset
|
382 if (info == NULL) info = file_searcher->Find(FileSearcher::WAV, path, ".ogg"); |
52 | 383 if (info != NULL) { |
0 | 384 int dummy; |
385 FILE* f = info->OpenFile(&dummy); | |
386 delete info; | |
52 | 387 if (f == NULL) return NULL; |
0 | 388 SDL_RWops* op = SDL_RWFromFP(f, 1); |
389 return op; | |
390 } | |
52 | 391 return NULL; |
0 | 392 } |
393 | |
394 static WAVFILE* OpenWaveFile(const char* path) { | |
65
4416cfac86ae
Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents:
53
diff
changeset
|
395 /* まず wav ファイルを探す */ |
53
ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents:
52
diff
changeset
|
396 FileSearcher* file_searcher = FileSearcher::GetInstance(); |
ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents:
52
diff
changeset
|
397 ARCINFO* info = file_searcher->Find(FileSearcher::WAV, path, ".wav"); |
ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents:
52
diff
changeset
|
398 if (info == NULL) info = file_searcher->Find(FileSearcher::BGM, path, "wav"); |
52 | 399 if (info != NULL) { |
0 | 400 int size; |
401 FILE* f = info->OpenFile(&size); | |
402 delete info; | |
52 | 403 if (f == NULL) return NULL; |
0 | 404 WAVFILE* w = WAVFILE::MakeConverter(new WAVFILE_Stream(f, size)); |
405 return w; | |
406 } | |
65
4416cfac86ae
Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents:
53
diff
changeset
|
407 /* 次に nwa ファイル */ |
53
ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents:
52
diff
changeset
|
408 info = file_searcher->Find(FileSearcher::WAV, path, ".nwa"); |
ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents:
52
diff
changeset
|
409 if (info == NULL) info = file_searcher->Find(FileSearcher::BGM, path, "nwa"); |
52 | 410 if (info != NULL) { |
0 | 411 int size; |
412 FILE* f = info->OpenFile(&size); | |
413 delete info; | |
52 | 414 if (f == NULL) return NULL; |
0 | 415 WAVFILE* w = WAVFILE::MakeConverter(new NWAFILE(f)); |
416 return w; | |
417 } | |
418 | |
65
4416cfac86ae
Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents:
53
diff
changeset
|
419 /* 次に mp3 ファイル */ |
53
ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents:
52
diff
changeset
|
420 info = file_searcher->Find(FileSearcher::WAV, path, ".mp3"); |
ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents:
52
diff
changeset
|
421 if (info == NULL) info = file_searcher->Find(FileSearcher::BGM, path, "mp3"); |
52 | 422 if (info != NULL) { |
0 | 423 int size; |
424 FILE* f = info->OpenFile(&size); | |
425 delete info; | |
52 | 426 if (f == NULL) return NULL; |
0 | 427 MP3FILE* w = new MP3FILE(f, size); |
52 | 428 if (w->pimpl != NULL) { |
0 | 429 return WAVFILE::MakeConverter(w); |
430 } | |
431 delete w; | |
432 } | |
433 | |
65
4416cfac86ae
Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents:
53
diff
changeset
|
434 /* 次に ogg ファイル */ |
53
ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents:
52
diff
changeset
|
435 info = file_searcher->Find(FileSearcher::WAV, path, ".ogg"); |
ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents:
52
diff
changeset
|
436 if (info == NULL) info = file_searcher->Find(FileSearcher::BGM, path, "ogg"); |
52 | 437 if (info != NULL) { |
0 | 438 int size; |
439 FILE* f = info->OpenFile(&size); | |
440 delete info; | |
52 | 441 if (f == NULL) return NULL; |
0 | 442 OggFILE* w = new OggFILE(f, size); |
52 | 443 if (w->pimpl != NULL) { |
0 | 444 return WAVFILE::MakeConverter(w); |
445 } | |
446 delete w; | |
447 } | |
52 | 448 return NULL; |
0 | 449 } |
450 |