view 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 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.wav
4 */
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 (seconds <=0){
21 error("seconds must be positive.");
22 }
24 if (argc != 7) {
25 error("Incorrect Arguments\n Sample invocation: \n spc_convert -s 5 -i input.spc -o output.wav");
26 }
27 /* Load SPC */
28 {
29 /* Load file into memory */
30 long spc_size;
31 void* spc = load_file( argv[4] , &spc_size );
33 /* Load SPC data into emulator */
34 error( spc_load_spc( snes_spc, spc, spc_size ) );
35 free( spc ); /* emulator makes copy of data */
37 /* Most SPC files have garbage data in the echo buffer, so clear that */
38 spc_clear_echo( snes_spc );
40 /* Clear filter before playing */
41 spc_filter_clear( filter );
42 }
44 /* Record 20 seconds to wave file */
45 wave_open( spc_sample_rate, argv[6] );
46 wave_enable_stereo();
47 while ( wave_sample_count() < seconds * spc_sample_rate * 2 )
48 {
49 /* Play into buffer */
50 #define BUF_SIZE 2048
51 short buf [BUF_SIZE];
52 error( spc_play( snes_spc, BUF_SIZE, buf ) );
54 /* Filter samples */
55 spc_filter_run( filter, buf, BUF_SIZE );
57 wave_write( buf, BUF_SIZE );
58 }
60 /* Cleanup */
61 spc_filter_delete( filter );
62 spc_delete( snes_spc );
63 wave_close();
65 return 0;
66 }