Mercurial > spc_convert
comparison convert/spc_convert.c @ 2:c3248c71ae74
begin convert program
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Fri, 21 Oct 2011 06:21:33 -0700 |
parents | |
children | 95cdedd01422 |
comparison
equal
deleted
inserted
replaced
1:2ad543b339f1 | 2:c3248c71ae74 |
---|---|
1 /* Records SPC into wave file. Uses dsp_filter to give more authentic sound. | |
2 | |
3 Usage: play_spc [-s seconds] input.spc output.wav | |
4 */ | |
5 | |
6 #include "snes_spc/spc.h" | |
7 | |
8 #include "demo/wave_writer.h" | |
9 #include "demo/demo_util.h" /* error(), load_file() */ | |
10 | |
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" ); | |
17 | |
18 /* Load SPC */ | |
19 { | |
20 /* Load file into memory */ | |
21 long spc_size; | |
22 void* spc = load_file( (argc > 1) ? argv [1] : "test.spc", &spc_size ); | |
23 | |
24 /* Load SPC data into emulator */ | |
25 error( spc_load_spc( snes_spc, spc, spc_size ) ); | |
26 free( spc ); /* emulator makes copy of data */ | |
27 | |
28 /* Most SPC files have garbage data in the echo buffer, so clear that */ | |
29 spc_clear_echo( snes_spc ); | |
30 | |
31 /* Clear filter before playing */ | |
32 spc_filter_clear( filter ); | |
33 } | |
34 | |
35 /* Record 20 seconds to wave file */ | |
36 wave_open( spc_sample_rate, "out.wav" ); | |
37 wave_enable_stereo(); | |
38 while ( wave_sample_count() < 20 * spc_sample_rate * 2 ) | |
39 { | |
40 /* Play into buffer */ | |
41 #define BUF_SIZE 2048 | |
42 short buf [BUF_SIZE]; | |
43 error( spc_play( snes_spc, BUF_SIZE, buf ) ); | |
44 | |
45 /* Filter samples */ | |
46 spc_filter_run( filter, buf, BUF_SIZE ); | |
47 | |
48 wave_write( buf, BUF_SIZE ); | |
49 } | |
50 | |
51 /* Cleanup */ | |
52 spc_filter_delete( filter ); | |
53 spc_delete( snes_spc ); | |
54 wave_close(); | |
55 | |
56 return 0; | |
57 } |