Mercurial > spc_convert
view convert/spc_convert.c @ 9:477c36226481 tip
added old scripts for historical interest.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Fri, 21 Oct 2011 07:46:18 -0700 |
parents | a37863126396 |
children |
line wrap: on
line source
1 /* Records SPC into wave file. Uses dsp_filter to give more authentic sound.3 Usage: spc_convert -s seconds -i input.spc -o output.wav4 */6 #include "snes_spc/spc.h"8 #include "demo/wave_writer.h"9 #include "demo/demo_util.h" /* error(), load_file() */11 int main( int argc, char** argv )12 {13 /* Create emulator and filter */14 SNES_SPC* snes_spc = spc_new();15 SPC_Filter* filter = spc_filter_new();16 if ( !snes_spc || !filter ) error( "Out of memory" );18 int seconds = atoi(argv[2]);20 if (argc != 7) {21 error("Incorrect Arguments\n Sample invocation: \n spc_convert -s 5 -i input.spc -o output.wav");22 }24 if (seconds <=0){25 error("seconds must be positive.");26 }28 /* Load SPC */29 {30 /* Load file into memory */31 long spc_size;32 void* spc = load_file( argv[4] , &spc_size );34 /* Load SPC data into emulator */35 error( spc_load_spc( snes_spc, spc, spc_size ) );36 free( spc ); /* emulator makes copy of data */38 /* Most SPC files have garbage data in the echo buffer, so clear that */39 spc_clear_echo( snes_spc );41 /* Clear filter before playing */42 spc_filter_clear( filter );43 }45 /* Record 20 seconds to wave file */46 wave_open( spc_sample_rate, argv[6] );47 wave_enable_stereo();48 while ( wave_sample_count() < seconds * spc_sample_rate * 2 )49 {50 /* Play into buffer */51 #define BUF_SIZE 204852 short buf [BUF_SIZE];53 error( spc_play( snes_spc, BUF_SIZE, buf ) );55 /* Filter samples */56 spc_filter_run( filter, buf, BUF_SIZE );58 wave_write( buf, BUF_SIZE );59 }61 /* Cleanup */62 spc_filter_delete( filter );63 spc_delete( snes_spc );64 wave_close();66 return 0;67 }