Mercurial > spc_convert
view demo/play_spc.c @ 5:b6e64e348e47
script will restore lost files now
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Fri, 21 Oct 2011 07:12:40 -0700 |
parents | e38dacceb958 |
children |
line wrap: on
line source
1 /* Records SPC into wave file. Uses dsp_filter to give more authentic sound.3 Usage: play_spc [test.spc]4 */6 #include "snes_spc/spc.h"8 #include "wave_writer.h"9 #include "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 /* 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 );24 /* Load SPC data into emulator */25 error( spc_load_spc( snes_spc, spc, spc_size ) );26 free( spc ); /* emulator makes copy of data */28 /* Most SPC files have garbage data in the echo buffer, so clear that */29 spc_clear_echo( snes_spc );31 /* Clear filter before playing */32 spc_filter_clear( filter );33 }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 204842 short buf [BUF_SIZE];43 error( spc_play( snes_spc, BUF_SIZE, buf ) );45 /* Filter samples */46 spc_filter_run( filter, buf, BUF_SIZE );48 wave_write( buf, BUF_SIZE );49 }51 /* Cleanup */52 spc_filter_delete( filter );53 spc_delete( snes_spc );54 wave_close();56 return 0;57 }