/* ----------------------------------------------------------------------------- Function: CA_SaveAudioChunk() -Decode and save audio data. Parameters: chunk -[in] Chunk number to cache. filename -[in] Save as filename. BuffChunk -[in] Sound data to decode. BuffWav -[in] Allocated memory block to hold decoded data. Returns: Nothing. Notes: ----------------------------------------------------------------------------- */ PRIVATE void CA_SaveAudioChunk( W32 chunk, const char *filename, W8 *BuffChunk, W8 *BuffWav ) { W32 length; if( ! filename || ! *filename ) { return; } if( ! CA_CacheAudioChunk( chunk, BuffChunk ) ) { return; } if( ADLIB_DecodeSound( (AdLibSound *)BuffChunk, BuffWav, &length ) == 0 ) { return; } write_wav( filename, BuffWav, length, 1, 22050, 2 ); }
/** * \brief Decode sound fx. * \param[in] start Start of sound fx chunks. * \param[in] end End of sound fx chunks. * \param[in] path Directory path to save file to. * \return On success true, otherwise false. */ PUBLIC wtBoolean AudioFile_ReduxDecodeSound( const W32 start, const W32 end, const char *path ) { SW8 *buffChunk; void *buffWav; W32 i; W32 length; char filename[ 1024 ]; printf( "Decoding Sound FX..." ); if( ! ADLIB_Init( 22050 ) ) { return false; } for( i = start ; i < end ; ++i ) { buffChunk = (PSW8) AudioFile_CacheAudioChunk( i ); if( buffChunk == NULL ) { continue; } buffWav = ADLIB_DecodeSound( (AdLibSound *)buffChunk, &length ); if( buffWav == NULL ) { MM_FREE( buffChunk ); continue; } #ifdef BIG_ENDIAN_SYSTEM AudioFile_dataByteSwap( buffWav, length ); #endif if( _saveAudioAsWav ) { wt_snprintf( filename, sizeof( filename ), "%s%c%.3d.wav", path, PATH_SEP, GetSoundMappedIndex( i - start ) ); wav_write( filename, buffWav, length, 1, 22050, 2 ); } else { wt_snprintf( filename, sizeof( filename ), "%s%c%.3d.ogg", path, PATH_SEP, GetSoundMappedIndex( i - start ) ); vorbis_encode( filename, buffWav, length, 1, 16, 22050, 0, 0, 0 ); } MM_FREE( buffWav ); MM_FREE( buffChunk ); } ADLIB_Shutdown(); printf( "Done\n" ); return true; }