| version 1.1 | | version 1.2 |
|---|
| | |
| #include "sounds.h" | | #include "sounds.h" |
| #include "digi.h" | | #include "digi.h" |
| #include "altsound.h" | | #include "altsound.h" |
| | | #include "types.h" |
| | | #include "d_io.h" |
| | | |
| int use_alt_sounds=0; | | int use_alt_sounds=0; |
| altsound_data altsound_list[MAX_SOUNDS]; | | altsound_data altsound_list[MAX_SOUNDS]; |
| | |
| void read_alt_soundlist(char *soundfile_list) | | void read_alt_soundlist(char *soundfile_list) |
| { | | { |
| FILE *f; | | FILE *f; |
| char *line,*word; | | char *line,word[64]; |
| int i; | | int i; |
| | | |
| #ifdef SHAREWARE | | #ifdef SHAREWARE |
| | |
| line=fsplitword(f,'\n'); | | line=fsplitword(f,'\n'); |
| if(line) | | if(line) |
| { | | { |
| word=splitword(line,'='); | | if((line[0]!='#') && sscanf(line,"%i=%s\n",&i,word)==2) |
| if(word) | | |
| { | | { |
| i=atoi(word); | | if(strlen(word) <= 13) |
| if(i>=0 && i<MAX_SOUNDS) | | |
| { | | { |
| | | sprintf(altsound_list[i].file,"%s",word); |
| altsound_list[i].soundnum = i; | | altsound_list[i].soundnum = i; |
| sprintf(altsound_list[i].file,"%s",line); | | |
| use_alt_sounds++; | | use_alt_sounds++; |
| } | | } |
| free(word); | | |
| } | | } |
| free(line); | | free(line); |
| } | | } |
| | |
| | | |
| int use_alt_sound(int soundnum) | | int use_alt_sound(int soundnum) |
| { | | { |
| return (altsound_list[soundnum].soundnum < 0); | | return (altsound_list[soundnum].soundnum != -1); |
| | | } |
| | | |
| | | int get_alt_sound_size(int soundnum) |
| | | { |
| | | return altsound_list[soundnum].datsize; |
| } | | } |
| | | |
| char * load_alt_sound_info(int soundnum, digi_sound *snd) | | char * load_alt_sound_info(int soundnum, digi_sound *snd) |
| { | | { |
| | | FILE *snd_file; |
| | | int smplsize; |
| | | |
| if(!use_alt_sound(soundnum)) | | if(!use_alt_sound(soundnum)) |
| return NULL; | | return NULL; |
| | | |
| | | snd_file=fopen(altsound_list[soundnum].file,"rb"); |
| | | |
| | | if(!snd_file) |
| | | { |
| | | altsound_list[soundnum].soundnum = -1; |
| | | return NULL; |
| | | } |
| | | |
| // read info from wav file; if error, return 0 | | // read info from wav file; if error, return 0 |
| snd->bits=0; | | fseek(snd_file,34,SEEK_SET); |
| snd->freq=0; | | fread(&(snd->bits),sizeof(u_int16_t),1,snd_file); |
| | | fseek(snd_file,24,SEEK_SET); |
| | | fread(&(snd->freq),sizeof(u_int32_t),1,snd_file); |
| | | // fseek(snd_file,22,SEEK_SET); // # channels |
| | | // fread(&(),sizeof(u_int16_t),1,snd_file); |
| | | |
| | | fseek(snd_file,34,SEEK_SET); |
| | | fread(&smplsize,sizeof(u_int16_t),1,snd_file); |
| | | fseek(snd_file,40,SEEK_SET); |
| | | fread(&(altsound_list[soundnum].datsize),sizeof(u_int32_t),1,snd_file); |
| | | |
| #ifdef ALLEGRO | | #ifdef ALLEGRO |
| snd->len=0; | | snd->len=(altsound_list[soundnum].datsize*8)/smplsize; |
| #else | | #else |
| snd->length=0; | | snd->length=(altsound_list[soundnum].datsize*8)/smplsize; |
| #endif | | #endif |
| | | |
| | | fclose(snd_file); |
| | | |
| | | if(ferror(snd_file)) |
| | | { |
| | | altsound_list[soundnum].soundnum = -1; |
| | | return NULL; |
| | | } |
| | | |
| return altsound_list[soundnum].file; | | return altsound_list[soundnum].file; |
| } | | } |
| | | |
| int load_alt_sound(int soundnum, digi_sound *snd) | | int load_alt_sound(int soundnum, digi_sound *snd) |
| { | | { |
| | | FILE *snd_file; |
| | | |
| if(!use_alt_sound(soundnum)) | | if(!use_alt_sound(soundnum)) |
| return 0; | | return 0; |
| | | |
| | | snd_file=fopen(altsound_list[soundnum].file,"rb"); |
| | | |
| | | if(!snd_file) |
| | | { |
| | | altsound_list[soundnum].soundnum = -1; |
| | | return 0; |
| | | } |
| | | |
| | | |
| // read data from file and store in *data; if error, return 0 | | // read data from file and store in *data; if error, return 0 |
| | | fseek(snd_file,44,SEEK_SET); |
| | | fread(snd->data,altsound_list[soundnum].datsize,1,snd_file); |
| | | |
| | | fclose(snd_file); |
| | | |
| | | if(ferror(snd_file)) |
| | | { |
| | | altsound_list[soundnum].soundnum = -1; |
| | | return NULL; |
| | | } |
| | | |
| return 0; | | return 0; |
| } | | } |
| | | |