/* ============ GetWavinfo ============ */ static wavinfo_t GetWavinfo( char *name, byte *wav, int wavlength ) { wavinfo_t info; Com_Memset( &info, 0, sizeof( info ) ); if ( !wav ) { return info; } iff_data = wav; iff_end = wav + wavlength; // find "RIFF" chunk FindChunk( "RIFF" ); if ( !( data_p && !strncmp( (char *)data_p + 8, "WAVE", 4 ) ) ) { Com_Printf( "Missing RIFF/WAVE chunks\n" ); return info; } // get "fmt " chunk iff_data = data_p + 12; // DumpChunks (); FindChunk( "fmt " ); if ( !data_p ) { Com_Printf( "Missing fmt chunk\n" ); return info; } data_p += 8; info.format = GetLittleShort(); info.channels = GetLittleShort(); info.rate = GetLittleLong(); data_p += 4 + 2; info.width = GetLittleShort() / 8; if ( info.format != 1 ) { #if defined RTCW_ET Com_Printf( "Unsupported format: %s\n", GetWaveFormatName( info.format ) ); #endif // RTCW_XX Com_Printf( "Microsoft PCM format only\n" ); return info; } // find data chunk FindChunk( "data" ); if ( !data_p ) { Com_Printf( "Missing data chunk\n" ); return info; } data_p += 4; info.samples = GetLittleLong() / info.width; info.dataofs = data_p - wav; return info; }
void FindNextChunk(char *name) { while (1) { data_p=last_chunk; if (data_p >= iff_end) { // didn't find the chunk data_p = NULL; return; } data_p += 4; iff_chunk_len = GetLittleLong(); if (iff_chunk_len < 0) { data_p = NULL; return; } // if (iff_chunk_len > 1024*1024) // Sys_Error ("FindNextChunk: %i length is past the 1 meg sanity limit", iff_chunk_len); data_p -= 8; last_chunk = data_p + 8 + ( (iff_chunk_len + 1) & ~1 ); if (!strncmp((char *)data_p, name, 4)) return; } }
static void FindNextChunk(char *name) { while (1) { data_p=last_chunk; if (data_p >= iff_end) { // didn't find the chunk data_p = NULL; return; } data_p += 4; iff_chunk_len = GetLittleLong(); if (iff_chunk_len < 0) { data_p = NULL; return; } data_p -= 8; last_chunk = data_p + 8 + ( (iff_chunk_len + 1) & ~1 ); if (!strncmp((char *)data_p, name, 4)) return; } }
static void FindNextChunk(const char *name, const char *filename) { while (1) { /* Need at least 8 bytes for a chunk */ if (last_chunk + 8 >= iff_end) { data_p = NULL; return; } data_p = last_chunk + 4; iff_chunk_len = GetLittleLong(); if (iff_chunk_len < 0 || iff_chunk_len > iff_end - data_p) { Con_DPrintf("Bad \"%s\" chunk length (%d) in wav file %s\n", name, iff_chunk_len, filename); data_p = NULL; return; } last_chunk = data_p + ((iff_chunk_len + 1) & ~1); data_p -= 8; if (!strncmp((const char *)data_p, name, 4)) return; } }
void FindNextChunk(char *name) { while (1) { data_p = last_chunk; data_p += 4; if (data_p >= iff_end) { data_p = NULL; return; } iff_chunk_len = GetLittleLong(); if (iff_chunk_len < 0) { data_p = NULL; return; } data_p -= 8; last_chunk = data_p + 8 + ((iff_chunk_len + 1) & ~1); if (!strncmp((const char *) data_p, name, 4)) { return; } } }
void DumpChunks(void) { char str[5]; str[4] = 0; data_p = iff_data; do { memcpy(str, data_p, 4); data_p += 4; iff_chunk_len = GetLittleLong(); Con_Printf("%p : %s (%d)\n", (data_p - 4), str, iff_chunk_len); data_p += (iff_chunk_len + 1) & ~1; } while (data_p < iff_end); }
static void FindNextChunk (const char *name) { while (1) { // Need at least 8 bytes for a chunk if (last_chunk + 8 >= iff_end) { data_p = NULL; return; } data_p = last_chunk + 4; iff_chunk_len = GetLittleLong(); if (iff_chunk_len < 0 || iff_chunk_len > iff_end - data_p) { data_p = NULL; return; } last_chunk = data_p + ((iff_chunk_len + 1) & ~1); data_p -= 8; if (!strncmp((char *)data_p, name, 4)) return; } }
/* ============ GetWavinfo ============ */ wavinfo_t GetWavinfo (char *name, byte *wav, int wavlength) { wavinfo_t info; int i; int format; int samples; memset (&info, 0, sizeof(info)); if (!wav) return info; iff_data = wav; iff_end = wav + wavlength; // find "RIFF" chunk FindChunk("RIFF"); if (!(data_p && !strncmp((char *)data_p+8, "WAVE", 4))) { Com_Printf("Missing RIFF/WAVE chunks\n"); return info; } // get "fmt " chunk iff_data = data_p + 12; // DumpChunks (); FindChunk("fmt "); if (!data_p) { Com_Printf("Missing fmt chunk\n"); return info; } data_p += 8; format = GetLittleShort(); if (format != 1) { Com_Printf("Microsoft PCM format only\n"); return info; } info.channels = GetLittleShort(); info.rate = GetLittleLong(); data_p += 4+2; info.width = GetLittleShort() / 8; // get cue chunk FindChunk("cue "); if (data_p) { data_p += 32; info.loopstart = GetLittleLong(); // Com_Printf("loopstart=%d\n", sfx->loopstart); // if the next chunk is a LIST chunk, look for a cue length marker FindNextChunk ("LIST"); if (data_p) { if (!strncmp ((char *)data_p + 28, "mark", 4)) { // this is not a proper parse, but it works with cooledit... data_p += 24; i = GetLittleLong (); // samples in loop info.samples = info.loopstart + i; // Com_Printf("looped length: %i\n", i); } } } else info.loopstart = -1; // find data chunk FindChunk("data"); if (!data_p) { Com_Printf("Missing data chunk\n"); return info; } data_p += 4; samples = GetLittleLong () / info.width; if (info.samples) { if (samples < info.samples) Com_Error (ERR_DROP, "Sound %s has a bad loop length", name); } else info.samples = samples; info.dataofs = data_p - wav; return info; }