rlm@2
|
1 /* Records SPC into wave file. Uses dsp_filter to give more authentic sound.
|
rlm@2
|
2
|
rlm@3
|
3 Usage: spc_convert -s seconds -i input.spc -o output.wav
|
rlm@2
|
4 */
|
rlm@2
|
5
|
rlm@2
|
6 #include "snes_spc/spc.h"
|
rlm@2
|
7
|
rlm@2
|
8 #include "demo/wave_writer.h"
|
rlm@2
|
9 #include "demo/demo_util.h" /* error(), load_file() */
|
rlm@2
|
10
|
rlm@2
|
11 int main( int argc, char** argv )
|
rlm@2
|
12 {
|
rlm@2
|
13 /* Create emulator and filter */
|
rlm@2
|
14 SNES_SPC* snes_spc = spc_new();
|
rlm@2
|
15 SPC_Filter* filter = spc_filter_new();
|
rlm@2
|
16 if ( !snes_spc || !filter ) error( "Out of memory" );
|
rlm@3
|
17
|
rlm@3
|
18 int seconds = atoi(argv[2]);
|
rlm@3
|
19
|
rlm@3
|
20 if (seconds <=0){
|
rlm@3
|
21 error("seconds must be positive.");
|
rlm@3
|
22 }
|
rlm@3
|
23
|
rlm@3
|
24 if (argc != 7) {
|
rlm@3
|
25 error("Incorrect Arguments\n Sample invocation: \n spc_convert -s 5 -i input.spc -o output.wav");
|
rlm@3
|
26 }
|
rlm@2
|
27 /* Load SPC */
|
rlm@2
|
28 {
|
rlm@2
|
29 /* Load file into memory */
|
rlm@2
|
30 long spc_size;
|
rlm@3
|
31 void* spc = load_file( argv[4] , &spc_size );
|
rlm@2
|
32
|
rlm@2
|
33 /* Load SPC data into emulator */
|
rlm@2
|
34 error( spc_load_spc( snes_spc, spc, spc_size ) );
|
rlm@2
|
35 free( spc ); /* emulator makes copy of data */
|
rlm@2
|
36
|
rlm@2
|
37 /* Most SPC files have garbage data in the echo buffer, so clear that */
|
rlm@2
|
38 spc_clear_echo( snes_spc );
|
rlm@2
|
39
|
rlm@2
|
40 /* Clear filter before playing */
|
rlm@2
|
41 spc_filter_clear( filter );
|
rlm@2
|
42 }
|
rlm@2
|
43
|
rlm@2
|
44 /* Record 20 seconds to wave file */
|
rlm@3
|
45 wave_open( spc_sample_rate, argv[6] );
|
rlm@2
|
46 wave_enable_stereo();
|
rlm@3
|
47 while ( wave_sample_count() < seconds * spc_sample_rate * 2 )
|
rlm@2
|
48 {
|
rlm@2
|
49 /* Play into buffer */
|
rlm@2
|
50 #define BUF_SIZE 2048
|
rlm@2
|
51 short buf [BUF_SIZE];
|
rlm@2
|
52 error( spc_play( snes_spc, BUF_SIZE, buf ) );
|
rlm@2
|
53
|
rlm@2
|
54 /* Filter samples */
|
rlm@2
|
55 spc_filter_run( filter, buf, BUF_SIZE );
|
rlm@2
|
56
|
rlm@2
|
57 wave_write( buf, BUF_SIZE );
|
rlm@2
|
58 }
|
rlm@2
|
59
|
rlm@2
|
60 /* Cleanup */
|
rlm@2
|
61 spc_filter_delete( filter );
|
rlm@2
|
62 spc_delete( snes_spc );
|
rlm@2
|
63 wave_close();
|
rlm@2
|
64
|
rlm@2
|
65 return 0;
|
rlm@2
|
66 }
|