/**
 * \brief Decode music chunks
 * \param[in] start Start of music chunks. 
 * \param[in] end End of music chunks.
 * \param[in] songNames Song titles.
 * \return On success true, otherwise false.
 */
PUBLIC wtBoolean AudioFile_ReduxDecodeMusic( const W32 start, const W32 end, const char *path, char *songNames[] )
{
	SW8 *buffChunk;
	void *buffWav;
	W32 i;
	W32 length;
	char filename[ 1024 ];
	W32 uncompr_length;


	printf( "Decoding Music (This could take a while)..." );

	if( ! ADLIB_Init( 44100 ) )
	{			
		return false;
	}



	for( i = start ; i < end ; ++i )
	{
		buffChunk = (PSW8) AudioFile_CacheAudioChunk( i );
		if( buffChunk == NULL )
		{
			continue;
		}


		uncompr_length = ADLIB_getLength( buffChunk );
		if( uncompr_length <= 1 )
		{
			MM_FREE( buffChunk );

			continue;	
		}


		ADLIB_LoadMusic( buffChunk );

		
		buffWav = MM_MALLOC( uncompr_length * 64 * 2 );
		if( buffWav == NULL )
		{
			MM_FREE( buffChunk );

			continue;
		}

		length = ADLIB_UpdateMusic( uncompr_length, buffWav );


		
	
#ifdef BIG_ENDIAN_SYSTEM
		
		AudioFile_dataByteSwap( buffWav, length );

#endif
		
		
        // Save audio buffer
        if( _saveMusicAsWav )
        {

            if( songNames )
		    {
			    wt_snprintf( filename, sizeof( filename ), "%s%c%s.wav", path, PATH_SEP, songNames[ i - start ] );
		    }
		    else
		    {
			    wt_snprintf( filename, sizeof( filename ), "%s%c%d.wav", path, PATH_SEP, i - start );
		    }

            wav_write( filename, buffWav, length, 1, 44100, 2 );
        }
        else
        {

            if( songNames )
		    {
			    wt_snprintf( filename, sizeof( filename ), "%s%c%s.ogg", path, PATH_SEP, songNames[ i - start ] );
		    }
		    else
		    {
			    wt_snprintf( filename, sizeof( filename ), "%s%c%d.ogg", path, PATH_SEP, i - start );
		    }

		    vorbis_encode( filename, buffWav, length, 1, 16, 44100, 0, 0, 0 );
        }
		

		
		MM_FREE( buffWav );
		MM_FREE( buffChunk );
	}


	ADLIB_Shutdown();
	
    printf( "Done\n" );

	return true;
}
示例#2
0
/*
-----------------------------------------------------------------------------
 Function: AudioRipper() -Interface to audio decoder.
 
 Parameters: fextension -[in] file extension string.
			 start -[in] Chunk number for start of audio data.
			 end -[in] Chunk number for end of audio data.
 
 Returns: Nothing.
 
 Notes: 
-----------------------------------------------------------------------------
*/
PUBLIC _boolean AudioRipper( const char *fextension, 
						W32 start, W32 end, W16 version )
{
    W32 i, j;
	char filename[ 64 ];
	W8 *buffChunk;
	W8 *buffWav;
	W32 startofmusic = WL6_STARTMUSIC - 1;
	W32 endofmusic = LASTMUSIC;

//
// Setup
//

	if( version == SOD_PAK || version == SDM_PAK )
	{
		if( 0 == FS_Mkdir( SODLSFXDIR ) )
		{
			printf( "[%s] Could not create directory (%s)!\n", "wolf_aud.c", SODLSFXDIR );
			
			return false;
		}

		startofmusic = SOD_STARTMUSIC;
		endofmusic = SOD_LASTMUSIC;
	}
	else
	{
		if( 0 == FS_Mkdir( LSFXDIR ) )
		{
			printf( "[%s] Could not create directory (%s)!\n", "wolf_aud.c", LSFXDIR );
			
			return false;
		}
	}
	

	if( 0 == FS_Mkdir( MUSICDIR ) )
	{
		printf( "[%s] Could not create directory (%s)!\n", "wolf_aud.c", LSFXDIR );
		
		return false;
	}




	
    if( ! CAL_SetupAudioFile( fextension ) )
    {
		CAL_ShutdownAudioFile();
        
		return false;
    }		

    if( ! ADLIB_Init( 22050 ) )
	{
		CAL_ShutdownAudioFile();
		
		return false;
	}

//
// Allocate buffers
//

	buffChunk = MM_MALLOC( MAX_CHUNK_SIZE );
	if( buffChunk == NULL )
	{
		ADLIB_Shutdown();
		CAL_ShutdownAudioFile();
		
		return false;
	}

	buffWav = MM_MALLOC( MAX_WAV_SIZE );
	if( buffWav == NULL )
	{
		ADLIB_Shutdown();
		CAL_ShutdownAudioFile();
		MM_FREE( buffChunk );
		
		return false;
	} 

//
// Decode Audio data
//
   
	printf( "Decoding Audio Data...\n" );
    
	for( i = start, j = 0; i < end; ++i, ++j )
    {        
		if( version == SOD_PAK || version == SDM_PAK )
		{
			cs_snprintf( filename, sizeof( filename ), "%s/%.3d.wav", SODLSFXDIR, j );
		}
		else
		{
			cs_snprintf( filename, sizeof( filename ), "%s/%.3d.wav", LSFXDIR, j );
		}

		CA_SaveAudioChunk( i, filename, buffChunk, buffWav );
    }

	ADLIB_Shutdown();

	MM_FREE( buffWav );
	MM_FREE( buffChunk );


//
//	Decode Music data
//

	if( ! ADLIB_Init( 44100 ) )
	{
		CAL_ShutdownAudioFile();
		
		return false;
	}

	printf( "Decoding Music Data...\n" );

	for( i = 0 ; i < endofmusic ; ++i )
	{
		if( version == SOD_PAK || version == SDM_PAK )
		{
			cs_snprintf( filename, sizeof( filename ), "%s/%s.ogg", MUSICDIR, GetMusicFileName_SOD( i ) );
		}
		else
		{
			cs_snprintf( filename, sizeof( filename ), "%s/%s.ogg", MUSICDIR, GetMusicFileName_WL6( i ) );
		}

		CA_SaveMusicChunk( startofmusic + i, filename );
	}

	ADLIB_Shutdown();

//
// Shutdown
//	
    
    
    CAL_ShutdownAudioFile();
    
    
    
    return true;
}
/**
 * \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;
}