annotate 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
rev   line source
rlm@2 1 /* Records SPC into wave file. Uses dsp_filter to give more authentic sound.
rlm@2 2
rlm@2 3 Usage: play_spc [-s seconds] input.spc 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@2 17
rlm@2 18 /* Load SPC */
rlm@2 19 {
rlm@2 20 /* Load file into memory */
rlm@2 21 long spc_size;
rlm@2 22 void* spc = load_file( (argc > 1) ? argv [1] : "test.spc", &spc_size );
rlm@2 23
rlm@2 24 /* Load SPC data into emulator */
rlm@2 25 error( spc_load_spc( snes_spc, spc, spc_size ) );
rlm@2 26 free( spc ); /* emulator makes copy of data */
rlm@2 27
rlm@2 28 /* Most SPC files have garbage data in the echo buffer, so clear that */
rlm@2 29 spc_clear_echo( snes_spc );
rlm@2 30
rlm@2 31 /* Clear filter before playing */
rlm@2 32 spc_filter_clear( filter );
rlm@2 33 }
rlm@2 34
rlm@2 35 /* Record 20 seconds to wave file */
rlm@2 36 wave_open( spc_sample_rate, "out.wav" );
rlm@2 37 wave_enable_stereo();
rlm@2 38 while ( wave_sample_count() < 20 * spc_sample_rate * 2 )
rlm@2 39 {
rlm@2 40 /* Play into buffer */
rlm@2 41 #define BUF_SIZE 2048
rlm@2 42 short buf [BUF_SIZE];
rlm@2 43 error( spc_play( snes_spc, BUF_SIZE, buf ) );
rlm@2 44
rlm@2 45 /* Filter samples */
rlm@2 46 spc_filter_run( filter, buf, BUF_SIZE );
rlm@2 47
rlm@2 48 wave_write( buf, BUF_SIZE );
rlm@2 49 }
rlm@2 50
rlm@2 51 /* Cleanup */
rlm@2 52 spc_filter_delete( filter );
rlm@2 53 spc_delete( snes_spc );
rlm@2 54 wave_close();
rlm@2 55
rlm@2 56 return 0;
rlm@2 57 }