annotate convert/spc_convert.c @ 9:477c36226481 tip

added old scripts for historical interest.
author Robert McIntyre <rlm@mit.edu>
date Fri, 21 Oct 2011 07:46:18 -0700
parents a37863126396
children
rev   line source
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@8 20 if (argc != 7) {
rlm@8 21 error("Incorrect Arguments\n Sample invocation: \n spc_convert -s 5 -i input.spc -o output.wav");
rlm@8 22 }
rlm@8 23
rlm@3 24 if (seconds <=0){
rlm@3 25 error("seconds must be positive.");
rlm@3 26 }
rlm@3 27
rlm@2 28 /* Load SPC */
rlm@2 29 {
rlm@2 30 /* Load file into memory */
rlm@2 31 long spc_size;
rlm@3 32 void* spc = load_file( argv[4] , &spc_size );
rlm@2 33
rlm@2 34 /* Load SPC data into emulator */
rlm@2 35 error( spc_load_spc( snes_spc, spc, spc_size ) );
rlm@2 36 free( spc ); /* emulator makes copy of data */
rlm@2 37
rlm@2 38 /* Most SPC files have garbage data in the echo buffer, so clear that */
rlm@2 39 spc_clear_echo( snes_spc );
rlm@2 40
rlm@2 41 /* Clear filter before playing */
rlm@2 42 spc_filter_clear( filter );
rlm@2 43 }
rlm@2 44
rlm@2 45 /* Record 20 seconds to wave file */
rlm@3 46 wave_open( spc_sample_rate, argv[6] );
rlm@2 47 wave_enable_stereo();
rlm@3 48 while ( wave_sample_count() < seconds * spc_sample_rate * 2 )
rlm@2 49 {
rlm@2 50 /* Play into buffer */
rlm@2 51 #define BUF_SIZE 2048
rlm@2 52 short buf [BUF_SIZE];
rlm@2 53 error( spc_play( snes_spc, BUF_SIZE, buf ) );
rlm@2 54
rlm@2 55 /* Filter samples */
rlm@2 56 spc_filter_run( filter, buf, BUF_SIZE );
rlm@2 57
rlm@2 58 wave_write( buf, BUF_SIZE );
rlm@2 59 }
rlm@2 60
rlm@2 61 /* Cleanup */
rlm@2 62 spc_filter_delete( filter );
rlm@2 63 spc_delete( snes_spc );
rlm@2 64 wave_close();
rlm@2 65
rlm@2 66 return 0;
rlm@2 67 }