mirror of
https://github.com/yquake2/yquake2remaster.git
synced 2025-02-17 01:21:12 +00:00
- Formatiere Code neu
- Vereinfache Code
This commit is contained in:
parent
90101b4dec
commit
ebe4cb1b45
1 changed files with 94 additions and 78 deletions
|
@ -27,164 +27,180 @@
|
|||
#include "../header/client.h"
|
||||
#include "header/local.h"
|
||||
|
||||
byte *data_p;
|
||||
byte *iff_end;
|
||||
byte *last_chunk;
|
||||
byte *iff_data;
|
||||
int iff_chunk_len;
|
||||
byte *data_p;
|
||||
byte *iff_end;
|
||||
byte *last_chunk;
|
||||
byte *iff_data;
|
||||
int iff_chunk_len;
|
||||
|
||||
short GetLittleShort(void) {
|
||||
short
|
||||
GetLittleShort ( void )
|
||||
{
|
||||
short val = 0;
|
||||
|
||||
val = *data_p;
|
||||
val = val + (*(data_p+1)<<8);
|
||||
val = val + ( *( data_p + 1 ) << 8 );
|
||||
data_p += 2;
|
||||
return val;
|
||||
return ( val );
|
||||
}
|
||||
|
||||
int GetLittleLong(void) {
|
||||
int
|
||||
GetLittleLong ( void )
|
||||
{
|
||||
int val = 0;
|
||||
|
||||
val = *data_p;
|
||||
val = val + (*(data_p+1)<<8);
|
||||
val = val + (*(data_p+2)<<16);
|
||||
val = val + (*(data_p+3)<<24);
|
||||
val = val + ( *( data_p + 1 ) << 8 );
|
||||
val = val + ( *( data_p + 2 ) << 16 );
|
||||
val = val + ( *( data_p + 3 ) << 24 );
|
||||
data_p += 4;
|
||||
return val;
|
||||
return ( val );
|
||||
}
|
||||
|
||||
void FindNextChunk(char *name) {
|
||||
while (1) {
|
||||
data_p=last_chunk;
|
||||
void
|
||||
FindNextChunk ( char *name )
|
||||
{
|
||||
while ( 1 )
|
||||
{
|
||||
data_p = last_chunk;
|
||||
data_p += 4;
|
||||
|
||||
if (data_p >= iff_end)
|
||||
if ( data_p >= iff_end )
|
||||
{
|
||||
data_p = NULL;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
iff_chunk_len = GetLittleLong();
|
||||
|
||||
if (iff_chunk_len < 0) {
|
||||
if ( iff_chunk_len < 0 )
|
||||
{
|
||||
data_p = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
data_p -= 8;
|
||||
last_chunk = data_p + 8 + ( (iff_chunk_len + 1) & ~1 );
|
||||
last_chunk = data_p + 8 + ( ( iff_chunk_len + 1 ) & ~1 );
|
||||
|
||||
if (!strncmp((const char *)data_p, name, 4))
|
||||
if ( !strncmp( (const char *) data_p, name, 4 ) )
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FindChunk(char *name) {
|
||||
void
|
||||
FindChunk ( char *name )
|
||||
{
|
||||
last_chunk = iff_data;
|
||||
FindNextChunk (name);
|
||||
FindNextChunk( name );
|
||||
}
|
||||
|
||||
void DumpChunks(void) {
|
||||
char str[5];
|
||||
wavinfo_t
|
||||
GetWavinfo ( char *name, byte *wav, int wavlength )
|
||||
{
|
||||
wavinfo_t info;
|
||||
int i;
|
||||
int format;
|
||||
int samples;
|
||||
|
||||
str[4] = 0;
|
||||
data_p=iff_data;
|
||||
memset( &info, 0, sizeof ( info ) );
|
||||
|
||||
do {
|
||||
memcpy (str, data_p, 4);
|
||||
data_p += 4;
|
||||
iff_chunk_len = GetLittleLong();
|
||||
Com_Printf ("0x%x : %s (%d)\n", data_p - 4, str, iff_chunk_len);
|
||||
data_p += (iff_chunk_len + 1) & ~1;
|
||||
} while (data_p < iff_end);
|
||||
}
|
||||
|
||||
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;
|
||||
if ( !wav )
|
||||
{
|
||||
return ( info );
|
||||
}
|
||||
|
||||
iff_data = wav;
|
||||
iff_end = wav + wavlength;
|
||||
|
||||
/* find "RIFF" chunk */
|
||||
FindChunk("RIFF");
|
||||
FindChunk( "RIFF" );
|
||||
|
||||
if (!(data_p && !strncmp((const char *)data_p+8, "WAVE", 4))) {
|
||||
Com_Printf("Missing RIFF/WAVE chunks\n");
|
||||
return info;
|
||||
if ( !( data_p && !strncmp( (const char *) data_p + 8, "WAVE", 4 ) ) )
|
||||
{
|
||||
Com_Printf( "Missing RIFF/WAVE chunks\n" );
|
||||
return ( info );
|
||||
}
|
||||
|
||||
/* get "fmt " chunk */
|
||||
iff_data = data_p + 12;
|
||||
|
||||
FindChunk("fmt ");
|
||||
FindChunk( "fmt " );
|
||||
|
||||
if (!data_p) {
|
||||
Com_Printf("Missing fmt chunk\n");
|
||||
return info;
|
||||
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;
|
||||
if ( format != 1 )
|
||||
{
|
||||
Com_Printf( "Microsoft PCM format only\n" );
|
||||
return ( info );
|
||||
}
|
||||
|
||||
info.channels = GetLittleShort();
|
||||
info.rate = GetLittleLong();
|
||||
data_p += 4+2;
|
||||
data_p += 4 + 2;
|
||||
info.width = GetLittleShort() / 8;
|
||||
|
||||
/* get cue chunk */
|
||||
FindChunk("cue ");
|
||||
FindChunk( "cue " );
|
||||
|
||||
if (data_p) {
|
||||
if ( data_p )
|
||||
{
|
||||
data_p += 32;
|
||||
info.loopstart = GetLittleLong();
|
||||
|
||||
/* if the next chunk is a LIST chunk, look for a cue length marker */
|
||||
FindNextChunk ("LIST");
|
||||
FindNextChunk( "LIST" );
|
||||
|
||||
if (data_p) {
|
||||
if ((data_p - wav) + 32 <= wavlength && !strncmp ((const char *)data_p + 28, "mark", 4))
|
||||
if ( data_p )
|
||||
{
|
||||
if ( ( ( data_p - wav ) + 32 <= wavlength ) && !strncmp( (const 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 */
|
||||
i = GetLittleLong(); /* samples in loop */
|
||||
info.samples = info.loopstart + i;
|
||||
}
|
||||
}
|
||||
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
info.loopstart = -1;
|
||||
}
|
||||
|
||||
/* find data chunk */
|
||||
FindChunk("data");
|
||||
FindChunk( "data" );
|
||||
|
||||
if (!data_p) {
|
||||
Com_Printf("Missing data chunk\n");
|
||||
return info;
|
||||
if ( !data_p )
|
||||
{
|
||||
Com_Printf( "Missing data chunk\n" );
|
||||
return ( info );
|
||||
}
|
||||
|
||||
data_p += 4;
|
||||
samples = GetLittleLong () / info.width;
|
||||
samples = GetLittleLong() / info.width;
|
||||
|
||||
if (info.samples) {
|
||||
if (samples < info.samples)
|
||||
Com_Error (ERR_DROP, "Sound %s has a bad loop length", name);
|
||||
|
||||
} else
|
||||
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 = (int)(data_p - wav);
|
||||
info.dataofs = (int) ( data_p - wav );
|
||||
|
||||
return info;
|
||||
return ( info );
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue