Mercurial > spc_convert
diff convert/spc_convert.c @ 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 | a37863126396 |
line wrap: on
line diff
1.1 --- a/convert/spc_convert.c Fri Oct 21 06:21:33 2011 -0700 1.2 +++ b/convert/spc_convert.c Fri Oct 21 06:44:35 2011 -0700 1.3 @@ -1,6 +1,6 @@ 1.4 /* Records SPC into wave file. Uses dsp_filter to give more authentic sound. 1.5 1.6 - Usage: play_spc [-s seconds] input.spc output.wav 1.7 + Usage: spc_convert -s seconds -i input.spc -o output.wav 1.8 */ 1.9 1.10 #include "snes_spc/spc.h" 1.11 @@ -14,12 +14,21 @@ 1.12 SNES_SPC* snes_spc = spc_new(); 1.13 SPC_Filter* filter = spc_filter_new(); 1.14 if ( !snes_spc || !filter ) error( "Out of memory" ); 1.15 - 1.16 + 1.17 + int seconds = atoi(argv[2]); 1.18 + 1.19 + if (seconds <=0){ 1.20 + error("seconds must be positive."); 1.21 + } 1.22 + 1.23 + if (argc != 7) { 1.24 + error("Incorrect Arguments\n Sample invocation: \n spc_convert -s 5 -i input.spc -o output.wav"); 1.25 + } 1.26 /* Load SPC */ 1.27 { 1.28 /* Load file into memory */ 1.29 long spc_size; 1.30 - void* spc = load_file( (argc > 1) ? argv [1] : "test.spc", &spc_size ); 1.31 + void* spc = load_file( argv[4] , &spc_size ); 1.32 1.33 /* Load SPC data into emulator */ 1.34 error( spc_load_spc( snes_spc, spc, spc_size ) ); 1.35 @@ -33,9 +42,9 @@ 1.36 } 1.37 1.38 /* Record 20 seconds to wave file */ 1.39 - wave_open( spc_sample_rate, "out.wav" ); 1.40 + wave_open( spc_sample_rate, argv[6] ); 1.41 wave_enable_stereo(); 1.42 - while ( wave_sample_count() < 20 * spc_sample_rate * 2 ) 1.43 + while ( wave_sample_count() < seconds * spc_sample_rate * 2 ) 1.44 { 1.45 /* Play into buffer */ 1.46 #define BUF_SIZE 2048