changeset 3:95cdedd01422

allow user to select number of seconds to convert
author Robert McIntyre <rlm@mit.edu>
date Fri, 21 Oct 2011 06:44:35 -0700
parents c3248c71ae74
children 87e64f302234
files Makefile convert/spc_convert.c
diffstat 2 files changed, 17 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
     1.1 --- a/Makefile	Fri Oct 21 06:21:33 2011 -0700
     1.2 +++ b/Makefile	Fri Oct 21 06:44:35 2011 -0700
     1.3 @@ -1,6 +1,3 @@
     1.4 -
     1.5 -
     1.6 -
     1.7  all : build/spc_convert
     1.8  
     1.9  build/spc_convert : snes_core demo_utils build/spc_convert.o
    1.10 @@ -18,12 +15,10 @@
    1.11  build/wave_writer.o : demo/wave_writer.c
    1.12  	g++ -c demo/wave_writer.c -o build/wave_writer.o
    1.13  
    1.14 -
    1.15  snes_core : build/dsp.o build/SNES_SPC.o build/SNES_SPC_misc.o \
    1.16              build/SNES_SPC_state.o build/spc.o build/SPC_DSP.o \
    1.17              build/SPC_Filter.o
    1.18  
    1.19 -
    1.20  build/dsp.o : snes_spc/dsp.cpp
    1.21  	g++ -c snes_spc/dsp.cpp -o build/dsp.o
    1.22  
    1.23 @@ -45,10 +40,8 @@
    1.24  build/SPC_Filter.o : snes_spc/SPC_Filter.cpp
    1.25  	g++ -c snes_spc/SPC_Filter.cpp -o build/SPC_Filter.o
    1.26  
    1.27 -
    1.28 -
    1.29 -
    1.30 -
    1.31  clean: 
    1.32  	find . \( -name "*.o" -print0 \) -o \
    1.33 -               \( -name "spc" -print0 \) | xargs -t -0 rm
    1.34 \ No newline at end of file
    1.35 +               \( -name "spc" -print0 \) -o \
    1.36 +               \( -name "*.wav" -print0 \) \
    1.37 +		| xargs -t -0 rm
    1.38 \ No newline at end of file
     2.1 --- a/convert/spc_convert.c	Fri Oct 21 06:21:33 2011 -0700
     2.2 +++ b/convert/spc_convert.c	Fri Oct 21 06:44:35 2011 -0700
     2.3 @@ -1,6 +1,6 @@
     2.4  /* Records SPC into wave file. Uses dsp_filter to give more authentic sound.
     2.5  
     2.6 -   Usage: play_spc [-s seconds] input.spc output.wav
     2.7 +   Usage: spc_convert -s seconds -i input.spc -o output.wav
     2.8  */
     2.9  
    2.10  #include "snes_spc/spc.h"
    2.11 @@ -14,12 +14,21 @@
    2.12    SNES_SPC* snes_spc = spc_new();
    2.13    SPC_Filter* filter = spc_filter_new();
    2.14    if ( !snes_spc || !filter ) error( "Out of memory" );
    2.15 -	
    2.16 +  
    2.17 +  int seconds = atoi(argv[2]);
    2.18 +
    2.19 +  if (seconds <=0){
    2.20 +    error("seconds must be positive.");
    2.21 +  }
    2.22 +
    2.23 +  if (argc != 7) { 
    2.24 +    error("Incorrect Arguments\n Sample invocation: \n  spc_convert -s 5 -i input.spc -o output.wav");
    2.25 +  }
    2.26    /* Load SPC */
    2.27    {
    2.28      /* Load file into memory */
    2.29      long spc_size;
    2.30 -    void* spc = load_file( (argc > 1) ? argv [1] : "test.spc", &spc_size );
    2.31 +    void* spc = load_file( argv[4] , &spc_size );
    2.32  		
    2.33      /* Load SPC data into emulator */
    2.34      error( spc_load_spc( snes_spc, spc, spc_size ) );
    2.35 @@ -33,9 +42,9 @@
    2.36    }
    2.37  	
    2.38    /* Record 20 seconds to wave file */
    2.39 -  wave_open( spc_sample_rate, "out.wav" );
    2.40 +  wave_open( spc_sample_rate, argv[6] );
    2.41    wave_enable_stereo();
    2.42 -  while ( wave_sample_count() < 20 * spc_sample_rate * 2 )
    2.43 +  while ( wave_sample_count() < seconds * spc_sample_rate * 2 )
    2.44      {
    2.45        /* Play into buffer */
    2.46  #define BUF_SIZE 2048