changeset 2:c3248c71ae74

begin convert program
author Robert McIntyre <rlm@mit.edu>
date Fri, 21 Oct 2011 06:21:33 -0700
parents 2ad543b339f1
children 95cdedd01422
files .hgignore Makefile convert/spc_convert.c
diffstat 3 files changed, 75 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
     1.1 --- a/.hgignore	Fri Oct 21 06:03:53 2011 -0700
     1.2 +++ b/.hgignore	Fri Oct 21 06:21:33 2011 -0700
     1.3 @@ -1,2 +1,4 @@
     1.4  syntax : glob
     1.5  build*
     1.6 +
     1.7 +test-files*
     2.1 --- a/Makefile	Fri Oct 21 06:03:53 2011 -0700
     2.2 +++ b/Makefile	Fri Oct 21 06:21:33 2011 -0700
     2.3 @@ -1,7 +1,22 @@
     2.4  
     2.5  
     2.6  
     2.7 -all : snes_core
     2.8 +all : build/spc_convert
     2.9 +
    2.10 +build/spc_convert : snes_core demo_utils build/spc_convert.o
    2.11 +	g++ build/*.o -o build/spc_convert
    2.12 +
    2.13 +build/spc_convert.o : convert/spc_convert.c
    2.14 +	g++ -I . -c convert/spc_convert.c -o build/spc_convert.o
    2.15 +
    2.16 +
    2.17 +demo_utils : build/demo_util.o build/wave_writer.o
    2.18 +
    2.19 +build/demo_util.o : demo/demo_util.c
    2.20 +	g++ -c demo/demo_util.c -o build/demo_util.o
    2.21 +
    2.22 +build/wave_writer.o : demo/wave_writer.c
    2.23 +	g++ -c demo/wave_writer.c -o build/wave_writer.o
    2.24  
    2.25  
    2.26  snes_core : build/dsp.o build/SNES_SPC.o build/SNES_SPC_misc.o \
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/convert/spc_convert.c	Fri Oct 21 06:21:33 2011 -0700
     3.3 @@ -0,0 +1,57 @@
     3.4 +/* Records SPC into wave file. Uses dsp_filter to give more authentic sound.
     3.5 +
     3.6 +   Usage: play_spc [-s seconds] input.spc output.wav
     3.7 +*/
     3.8 +
     3.9 +#include "snes_spc/spc.h"
    3.10 +
    3.11 +#include "demo/wave_writer.h"
    3.12 +#include "demo/demo_util.h" /* error(), load_file() */
    3.13 +
    3.14 +int main( int argc, char** argv )
    3.15 +{
    3.16 +  /* Create emulator and filter */
    3.17 +  SNES_SPC* snes_spc = spc_new();
    3.18 +  SPC_Filter* filter = spc_filter_new();
    3.19 +  if ( !snes_spc || !filter ) error( "Out of memory" );
    3.20 +	
    3.21 +  /* Load SPC */
    3.22 +  {
    3.23 +    /* Load file into memory */
    3.24 +    long spc_size;
    3.25 +    void* spc = load_file( (argc > 1) ? argv [1] : "test.spc", &spc_size );
    3.26 +		
    3.27 +    /* Load SPC data into emulator */
    3.28 +    error( spc_load_spc( snes_spc, spc, spc_size ) );
    3.29 +    free( spc ); /* emulator makes copy of data */
    3.30 +		
    3.31 +    /* Most SPC files have garbage data in the echo buffer, so clear that */
    3.32 +    spc_clear_echo( snes_spc );
    3.33 +		
    3.34 +    /* Clear filter before playing */
    3.35 +    spc_filter_clear( filter );
    3.36 +  }
    3.37 +	
    3.38 +  /* Record 20 seconds to wave file */
    3.39 +  wave_open( spc_sample_rate, "out.wav" );
    3.40 +  wave_enable_stereo();
    3.41 +  while ( wave_sample_count() < 20 * spc_sample_rate * 2 )
    3.42 +    {
    3.43 +      /* Play into buffer */
    3.44 +#define BUF_SIZE 2048
    3.45 +      short buf [BUF_SIZE];
    3.46 +      error( spc_play( snes_spc, BUF_SIZE, buf ) );
    3.47 +		
    3.48 +      /* Filter samples */
    3.49 +      spc_filter_run( filter, buf, BUF_SIZE );
    3.50 +		
    3.51 +      wave_write( buf, BUF_SIZE );
    3.52 +    }
    3.53 +	
    3.54 +  /* Cleanup */
    3.55 +  spc_filter_delete( filter );
    3.56 +  spc_delete( snes_spc );
    3.57 +  wave_close();
    3.58 +	
    3.59 +  return 0;
    3.60 +}