Mercurial > spc_convert
comparison 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 |
comparison
equal
deleted
inserted
replaced
2:c3248c71ae74 | 3:95cdedd01422 |
---|---|
1 /* Records SPC into wave file. Uses dsp_filter to give more authentic sound. | 1 /* Records SPC into wave file. Uses dsp_filter to give more authentic sound. |
2 | 2 |
3 Usage: play_spc [-s seconds] input.spc output.wav | 3 Usage: spc_convert -s seconds -i input.spc -o output.wav |
4 */ | 4 */ |
5 | 5 |
6 #include "snes_spc/spc.h" | 6 #include "snes_spc/spc.h" |
7 | 7 |
8 #include "demo/wave_writer.h" | 8 #include "demo/wave_writer.h" |
12 { | 12 { |
13 /* Create emulator and filter */ | 13 /* Create emulator and filter */ |
14 SNES_SPC* snes_spc = spc_new(); | 14 SNES_SPC* snes_spc = spc_new(); |
15 SPC_Filter* filter = spc_filter_new(); | 15 SPC_Filter* filter = spc_filter_new(); |
16 if ( !snes_spc || !filter ) error( "Out of memory" ); | 16 if ( !snes_spc || !filter ) error( "Out of memory" ); |
17 | 17 |
18 int seconds = atoi(argv[2]); | |
19 | |
20 if (seconds <=0){ | |
21 error("seconds must be positive."); | |
22 } | |
23 | |
24 if (argc != 7) { | |
25 error("Incorrect Arguments\n Sample invocation: \n spc_convert -s 5 -i input.spc -o output.wav"); | |
26 } | |
18 /* Load SPC */ | 27 /* Load SPC */ |
19 { | 28 { |
20 /* Load file into memory */ | 29 /* Load file into memory */ |
21 long spc_size; | 30 long spc_size; |
22 void* spc = load_file( (argc > 1) ? argv [1] : "test.spc", &spc_size ); | 31 void* spc = load_file( argv[4] , &spc_size ); |
23 | 32 |
24 /* Load SPC data into emulator */ | 33 /* Load SPC data into emulator */ |
25 error( spc_load_spc( snes_spc, spc, spc_size ) ); | 34 error( spc_load_spc( snes_spc, spc, spc_size ) ); |
26 free( spc ); /* emulator makes copy of data */ | 35 free( spc ); /* emulator makes copy of data */ |
27 | 36 |
31 /* Clear filter before playing */ | 40 /* Clear filter before playing */ |
32 spc_filter_clear( filter ); | 41 spc_filter_clear( filter ); |
33 } | 42 } |
34 | 43 |
35 /* Record 20 seconds to wave file */ | 44 /* Record 20 seconds to wave file */ |
36 wave_open( spc_sample_rate, "out.wav" ); | 45 wave_open( spc_sample_rate, argv[6] ); |
37 wave_enable_stereo(); | 46 wave_enable_stereo(); |
38 while ( wave_sample_count() < 20 * spc_sample_rate * 2 ) | 47 while ( wave_sample_count() < seconds * spc_sample_rate * 2 ) |
39 { | 48 { |
40 /* Play into buffer */ | 49 /* Play into buffer */ |
41 #define BUF_SIZE 2048 | 50 #define BUF_SIZE 2048 |
42 short buf [BUF_SIZE]; | 51 short buf [BUF_SIZE]; |
43 error( spc_play( snes_spc, BUF_SIZE, buf ) ); | 52 error( spc_play( snes_spc, BUF_SIZE, buf ) ); |