BOOLEAN _ReleaseMusicData (void *data) { TFB_SoundSample **pmus = data; TFB_SoundSample *sample; if (pmus == NULL) return (FALSE); sample = *pmus; assert (sample != 0); if (sample->decoder) { TFB_SoundDecoder *decoder = sample->decoder; LockMutex (soundSource[MUSIC_SOURCE].stream_mutex); if (soundSource[MUSIC_SOURCE].sample == sample) { // Currently playing this sample! Not good. StopStream (MUSIC_SOURCE); } UnlockMutex (soundSource[MUSIC_SOURCE].stream_mutex); sample->decoder = NULL; SoundDecoder_Free (decoder); } TFB_DestroySoundSample (sample); FreeMusicData (data); return (TRUE); }
void destroy_SoundChunk_list (TFB_SoundChunk *chunk) { TFB_SoundChunk *next = NULL; for ( ; chunk; chunk = next) { next = chunk->next; if (chunk->decoder) SoundDecoder_Free (chunk->decoder); HFree (chunk->text); HFree (chunk); } }
BOOLEAN _ReleaseSoundBankData (void *Snd) { STRING_TABLE fxTab = Snd; if (fxTab) { int snd_ct, index; TFB_SoundSample **sptr; snd_ct = fxTab->size; index = 0; while (snd_ct--) { int i; sptr = (TFB_SoundSample **)(fxTab->strings[index].data); for (i = 0; i < NUM_SOUNDSOURCES; ++i) { if (soundSource[i].sample == (*sptr)) { StopSource (i); soundSource[i].sample = NULL; } } if ((*sptr)->decoder) SoundDecoder_Free ((*sptr)->decoder); audio_DeleteBuffers ((*sptr)->num_buffers, (*sptr)->buffer); HFree ((*sptr)->buffer); if ((*sptr)->buffer_tag) HFree ((*sptr)->buffer_tag); HFree (*sptr); *sptr = 0; index++; } FreeStringTable (Snd); return (TRUE); } return (FALSE); }
BOOLEAN _ReleaseSoundBankData (MEM_HANDLE Snd) { STRING_TABLEPTR fxTab; LockStringTable (Snd, &fxTab); if (fxTab) { int snd_ct; TFB_SoundSample **sptr; snd_ct = fxTab->StringCount; sptr = (TFB_SoundSample **)((BYTE *)fxTab + fxTab->StringOffsets[0]); while (snd_ct--) { int i; for (i = 0; i < NUM_SOUNDSOURCES; ++i) { if (soundSource[i].sample == (*sptr)) { StopSource (i); soundSource[i].sample = NULL; } } if ((*sptr)->decoder) SoundDecoder_Free ((*sptr)->decoder); audio_DeleteBuffers ((*sptr)->num_buffers, (*sptr)->buffer); HFree ((*sptr)->buffer); if ((*sptr)->buffer_tag) HFree ((*sptr)->buffer_tag); HFree (*sptr); *sptr++ = 0; } UnlockStringTable (Snd); FreeStringTable (Snd); return (TRUE); } return (FALSE); }
void * _GetMusicData (uio_Stream *fp, DWORD length) { MUSIC_REF h; TFB_SoundSample *sample; TFB_SoundDecoder *decoder; char filename[256]; if (!_cur_resfile_name) return NULL; strncpy (filename, _cur_resfile_name, sizeof(filename) - 1); filename[sizeof(filename) - 1] = '\0'; CheckMusicResName (filename); log_add (log_Info, "_GetMusicData(): loading %s", filename); decoder = SoundDecoder_Load (contentDir, filename, 4096, 0, 0); if (!decoder) { log_add (log_Warning, "_GetMusicData(): couldn't load %s", filename); return NULL; } h = AllocMusicData (sizeof (void *)); if (!h) { SoundDecoder_Free (decoder); return NULL; } sample = TFB_CreateSoundSample (decoder, 64, NULL); *h = sample; log_add (log_Info, " decoder: %s, rate %d format %x", SoundDecoder_GetName (sample->decoder), sample->decoder->frequency, sample->decoder->format); (void) fp; /* satisfy compiler (unused parameter) */ (void) length; /* satisfy compiler (unused parameter) */ return (h); }
MEM_HANDLE _GetSoundBankData (uio_Stream *fp, DWORD length) { int snd_ct, n; DWORD opos; char CurrentLine[1024], filename[1024]; #define MAX_FX 256 TFB_SoundSample *sndfx[MAX_FX]; STRING_TABLE Snd; (void) length; // ignored opos = uio_ftell (fp); { char *s1, *s2; if (_cur_resfile_name == 0 || (((s2 = 0), (s1 = strrchr (_cur_resfile_name, '/')) == 0) && (s2 = strrchr (_cur_resfile_name, '\\')) == 0)) n = 0; else { if (s2 > s1) s1 = s2; n = s1 - _cur_resfile_name + 1; strncpy (filename, _cur_resfile_name, n); } } snd_ct = 0; while (uio_fgets (CurrentLine, sizeof (CurrentLine), fp) && snd_ct < MAX_FX) { if (sscanf(CurrentLine, "%s", &filename[n]) == 1) { log_add (log_Info, "_GetSoundBankData(): loading %s", filename); sndfx[snd_ct] = (TFB_SoundSample *) HCalloc (sizeof (TFB_SoundSample)); sndfx[snd_ct]->decoder = SoundDecoder_Load (contentDir, filename, 4096, 0, 0); if (!sndfx[snd_ct]->decoder) { log_add (log_Warning, "_GetSoundBankData(): couldn't load %s", filename); HFree (sndfx[snd_ct]); } else { uint32 decoded_bytes; decoded_bytes = SoundDecoder_DecodeAll (sndfx[snd_ct]->decoder); log_add (log_Info, "_GetSoundBankData(): decoded_bytes %d", decoded_bytes); sndfx[snd_ct]->num_buffers = 1; sndfx[snd_ct]->buffer = (audio_Object *) HMalloc ( sizeof (audio_Object) * sndfx[snd_ct]->num_buffers); audio_GenBuffers (sndfx[snd_ct]->num_buffers, sndfx[snd_ct]->buffer); audio_BufferData (sndfx[snd_ct]->buffer[0], sndfx[snd_ct]->decoder->format, sndfx[snd_ct]->decoder->buffer, decoded_bytes, sndfx[snd_ct]->decoder->frequency); SoundDecoder_Free (sndfx[snd_ct]->decoder); sndfx[snd_ct]->decoder = NULL; ++snd_ct; } } else { log_add (log_Warning, "_GetSoundBankData: Bad file!"); } // pkunk insult fix 2002/11/12 (ftell shouldn't be needed for loop to terminate) /*if (uio_ftell (fp) - opos >= length) break;*/ } Snd = 0; if (snd_ct && (Snd = AllocStringTable ( sizeof (STRING_TABLE_DESC) + (sizeof (DWORD) * snd_ct) + (sizeof (sndfx[0]) * snd_ct) ))) { STRING_TABLEPTR fxTab; LockStringTable (Snd, &fxTab); if (fxTab == 0) { while (snd_ct--) { if (sndfx[snd_ct]->decoder) SoundDecoder_Free (sndfx[snd_ct]->decoder); HFree (sndfx[snd_ct]); } FreeStringTable (Snd); Snd = 0; } else { DWORD *offs, StringOffs; fxTab->StringCount = snd_ct; fxTab->flags = 0; offs = fxTab->StringOffsets; StringOffs = sizeof (STRING_TABLE_DESC) + (sizeof (DWORD) * snd_ct); memcpy ((BYTE *)fxTab + StringOffs, sndfx, sizeof (sndfx[0]) * snd_ct); do { *offs++ = StringOffs; StringOffs += sizeof (sndfx[0]); } while (snd_ct--); UnlockStringTable (Snd); } } return ((MEM_HANDLE)Snd); }
void * _GetSoundBankData (uio_Stream *fp, DWORD length) { int snd_ct, n; DWORD opos; char CurrentLine[1024], filename[1024]; #define MAX_FX 256 TFB_SoundSample *sndfx[MAX_FX]; STRING_TABLE Snd; (void) length; // ignored opos = uio_ftell (fp); { char *s1, *s2; if (_cur_resfile_name == 0 || (((s2 = 0), (s1 = strrchr (_cur_resfile_name, '/')) == 0) && (s2 = strrchr (_cur_resfile_name, '\\')) == 0)) n = 0; else { if (s2 > s1) s1 = s2; n = s1 - _cur_resfile_name + 1; strncpy (filename, _cur_resfile_name, n); } } snd_ct = 0; while (uio_fgets (CurrentLine, sizeof (CurrentLine), fp) && snd_ct < MAX_FX) { if (sscanf(CurrentLine, "%s", &filename[n]) == 1) { log_add (log_Info, "_GetSoundBankData(): loading %s", filename); sndfx[snd_ct] = (TFB_SoundSample *) HCalloc (sizeof (TFB_SoundSample)); sndfx[snd_ct]->decoder = SoundDecoder_Load (contentDir, filename, 4096, 0, 0); if (!sndfx[snd_ct]->decoder) { log_add (log_Warning, "_GetSoundBankData(): couldn't load %s", filename); HFree (sndfx[snd_ct]); } else { uint32 decoded_bytes; decoded_bytes = SoundDecoder_DecodeAll (sndfx[snd_ct]->decoder); log_add (log_Info, "_GetSoundBankData(): decoded_bytes %d", decoded_bytes); sndfx[snd_ct]->num_buffers = 1; sndfx[snd_ct]->buffer = (audio_Object *) HMalloc ( sizeof (audio_Object) * sndfx[snd_ct]->num_buffers); audio_GenBuffers (sndfx[snd_ct]->num_buffers, sndfx[snd_ct]->buffer); audio_BufferData (sndfx[snd_ct]->buffer[0], sndfx[snd_ct]->decoder->format, sndfx[snd_ct]->decoder->buffer, decoded_bytes, sndfx[snd_ct]->decoder->frequency); SoundDecoder_Free (sndfx[snd_ct]->decoder); sndfx[snd_ct]->decoder = NULL; ++snd_ct; } } else { log_add (log_Warning, "_GetSoundBankData: Bad file!"); } // pkunk insult fix 2002/11/12 (ftell shouldn't be needed for loop to terminate) /*if (uio_ftell (fp) - opos >= length) break;*/ } Snd = NULL; if (snd_ct && (Snd = AllocStringTable (snd_ct, 0))) { STRING_TABLE fxTab = Snd; if (fxTab == 0) { while (snd_ct--) { if (sndfx[snd_ct]->decoder) SoundDecoder_Free (sndfx[snd_ct]->decoder); HFree (sndfx[snd_ct]); } FreeStringTable (Snd); Snd = 0; } else { STRING str; int i; str = fxTab->strings; for (i = 0; i < snd_ct; i++) { TFB_SoundSample **target = HMalloc (sizeof (sndfx[0])); *target = sndfx[i]; str->data = (STRINGPTR)target; str->length = sizeof (sndfx[0]); str++; } } } return Snd; }