(String name, byte[] wav, int wavlength)
| 253 | ============ |
| 254 | */ |
| 255 | static wavinfo_t GetWavinfo(String name, byte[] wav, int wavlength) { |
| 256 | wavinfo_t info = new wavinfo_t(); |
| 257 | int i; |
| 258 | int format; |
| 259 | int samples; |
| 260 | |
| 261 | if (wav == null) |
| 262 | return info; |
| 263 | |
| 264 | iff_data = 0; |
| 265 | iff_end = wavlength; |
| 266 | data_b = wav; |
| 267 | |
| 268 | // find "RIFF" chunk |
| 269 | FindChunk("RIFF"); |
| 270 | String s = new String(data_b, data_p + 8, 4); |
| 271 | if (!s.equals("WAVE")) { |
| 272 | Com.Printf("Missing RIFF/WAVE chunks\n"); |
| 273 | return info; |
| 274 | } |
| 275 | |
| 276 | // get "fmt " chunk |
| 277 | iff_data = data_p + 12; |
| 278 | // DumpChunks (); |
| 279 | |
| 280 | FindChunk("fmt "); |
| 281 | if (data_p == 0) { |
| 282 | Com.Printf("Missing fmt chunk\n"); |
| 283 | return info; |
| 284 | } |
| 285 | data_p += 8; |
| 286 | format = GetLittleShort(); |
| 287 | if (format != 1) { |
| 288 | Com.Printf("Microsoft PCM format only\n"); |
| 289 | return info; |
| 290 | } |
| 291 | |
| 292 | info.channels = GetLittleShort(); |
| 293 | info.rate = GetLittleLong(); |
| 294 | data_p += 4 + 2; |
| 295 | info.width = GetLittleShort() / 8; |
| 296 | |
| 297 | // get cue chunk |
| 298 | FindChunk("cue "); |
| 299 | if (data_p != 0) { |
| 300 | data_p += 32; |
| 301 | info.loopstart = GetLittleLong(); |
| 302 | // Com_Printf("loopstart=%d\n", sfx->loopstart); |
| 303 | |
| 304 | // if the next chunk is a LIST chunk, look for a cue length marker |
| 305 | FindNextChunk("LIST"); |
| 306 | if (data_p != 0) { |
| 307 | if (data_b.length >= data_p + 32) { |
| 308 | s = new String(data_b, data_p + 28, 4); |
| 309 | if (s.equals("MARK")) { // this is not a proper parse, but |
| 310 | // it works with cooledit... |
| 311 | data_p += 24; |
| 312 | i = GetLittleLong(); // samples in loop |
no test coverage detected