From: Holger Schemel Date: Sun, 21 Apr 2002 19:55:59 +0000 (+0200) Subject: rnd-20020421-1-src X-Git-Tag: 2.1.0^2~55 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=2c03953e712c427c94c02cdb1e15cd9e99e9e116;p=rocksndiamonds.git rnd-20020421-1-src --- diff --git a/src/init.c b/src/init.c index 733df29c..69008db6 100644 --- a/src/init.c +++ b/src/init.c @@ -159,8 +159,10 @@ void InitSound() for(i=0; idata_len = 0; + snd_info->data_ptr = NULL; +#if 0 snd_info->name = sound_name; +#endif - filename = getPath2((is_music ? options.music_directory : - options.sounds_directory), snd_info->name); + if (is_music) + filename = getPath2(options.music_directory, sound_name); + else + filename = getStringCopy(sound_name); #if defined(TARGET_SDL) if ((snd_info->mix_chunk = Mix_LoadWAV(filename)) == NULL) { - Error(ERR_WARN, "cannot read sound file '%s' -- no sounds", filename); + Error(ERR_WARN, "cannot read sound file '%s'", filename); free(filename); return FALSE; } @@ -976,14 +983,14 @@ static boolean LoadSoundExt(char *sound_name, boolean is_music) if ((file = fopen(filename, MODE_READ)) == NULL) { - Error(ERR_WARN, "cannot open sound file '%s' -- no sounds", filename); + Error(ERR_WARN, "cannot open sound file '%s'", filename); free(filename); return FALSE; } - /* read chunk "RIFF" */ - getFileChunk(file, chunk, &chunk_size, BYTE_ORDER_LITTLE_ENDIAN); - if (strcmp(chunk, "RIFF") != 0) + /* read chunk id "RIFF" */ + getFileChunk(file, chunk_name, &chunk_size, BYTE_ORDER_LITTLE_ENDIAN); + if (strcmp(chunk_name, "RIFF") != 0) { Error(ERR_WARN, "missing 'RIFF' chunk of sound file '%s'", filename); fclose(file); @@ -991,45 +998,64 @@ static boolean LoadSoundExt(char *sound_name, boolean is_music) return FALSE; } - /* read chunk "WAVE" */ - getFileChunk(file, chunk, &dummy, BYTE_ORDER_LITTLE_ENDIAN); - if (strcmp(chunk, "WAVE") != 0) + /* read "RIFF" type id "WAVE" */ + getFileChunk(file, chunk_name, NULL, BYTE_ORDER_LITTLE_ENDIAN); + if (strcmp(chunk_name, "WAVE") != 0) { - Error(ERR_WARN, "missing 'WAVE' chunk of sound file '%s'", filename); + Error(ERR_WARN, "missing 'WAVE' type ID of sound file '%s'", filename); fclose(file); free(filename); return FALSE; } - /* read header information */ - for (i=0; i WAV_HEADER_SIZE) + ReadUnusedBytesFromFile(file, chunk_size - WAV_HEADER_SIZE); + } + else if (strcmp(chunk_name, "data") == 0) + { + snd_info->data_len = chunk_size; + snd_info->data_ptr = checked_malloc(snd_info->data_len); + + /* read sound data */ + if (fread(snd_info->data_ptr, 1, snd_info->data_len, file) != + snd_info->data_len) + { + Error(ERR_WARN,"cannot read 'data' chunk of sound file '%s'",filename); + fclose(file); + free(filename); + return FALSE; + } + + /* check for odd number of sample bytes (data chunk is word aligned) */ + if ((chunk_size % 2) == 1) + ReadUnusedBytesFromFile(file, 1); + } + else /* unknown chunk -- ignore */ + ReadUnusedBytesFromFile(file, chunk_size); } - snd_info->data_len = chunk_size; - snd_info->data_ptr = checked_malloc(snd_info->data_len); + fclose(file); - /* read sound data */ - if (fread(snd_info->data_ptr, 1, snd_info->data_len, file) != - snd_info->data_len) + if (snd_info->data_ptr == NULL) { - Error(ERR_WARN, "cannot read sound file '%s' -- no sounds", filename); - fclose(file); + Error(ERR_WARN, "missing 'data' chunk of sound file '%s'", filename); free(filename); return FALSE; } - fclose(file); - for (i=0; idata_len; i++) snd_info->data_ptr[i] = snd_info->data_ptr[i] ^ 0x80; @@ -1038,7 +1064,7 @@ static boolean LoadSoundExt(char *sound_name, boolean is_music) snd_info->sample_ptr = load_sample(filename); if (!snd_info->sample_ptr) { - Error(ERR_WARN, "cannot read sound file '%s' -- no sounds", filename); + Error(ERR_WARN, "cannot read sound file '%s'", filename); return FALSE; } @@ -1054,6 +1080,19 @@ boolean LoadSound(char *sound_name) return LoadSoundExt(sound_name, FALSE); } +boolean LoadCustomSound(char *basename) +{ + char *filename = getCustomSoundFilename(basename); + + if (filename == NULL) + { + Error(ERR_WARN, "cannot find sound file '%s' -- no sounds", filename); + return FALSE; + } + + return LoadSound(filename); +} + boolean LoadMod(char *mod_name) { #if defined(TARGET_SDL) diff --git a/src/libgame/sound.h b/src/libgame/sound.h index c45736d3..6ca5f975 100644 --- a/src/libgame/sound.h +++ b/src/libgame/sound.h @@ -160,7 +160,9 @@ struct SoundHeader_8SVX struct SampleInfo { +#if 0 char *name; +#endif byte *data_ptr; long data_len; @@ -209,6 +211,7 @@ void SoundServer(void); void ReloadSounds(void); void ReloadMusic(void); boolean LoadSound(char *); +boolean LoadCustomSound(char *); boolean LoadMod(char *); int LoadMusic(void); void PlayMusic(int); diff --git a/src/timestamp.h b/src/timestamp.h index f7fadf56..4d75abfe 100644 --- a/src/timestamp.h +++ b/src/timestamp.h @@ -1 +1 @@ -#define COMPILE_DATE_STRING "[2002-04-19 23:17]" +#define COMPILE_DATE_STRING "[2002-04-21 21:51]"