Mercurial > spc_convert
diff snes_spc/spc.h @ 0:e38dacceb958
initial import
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Fri, 21 Oct 2011 05:53:11 -0700 |
parents | |
children |
line wrap: on
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/snes_spc/spc.h Fri Oct 21 05:53:11 2011 -0700 1.3 @@ -0,0 +1,147 @@ 1.4 +/* SNES SPC-700 APU emulator C interface (also usable from C++) */ 1.5 + 1.6 +/* snes_spc 0.9.0 */ 1.7 +#ifndef SPC_H 1.8 +#define SPC_H 1.9 + 1.10 +#include <stddef.h> 1.11 + 1.12 +#ifdef __cplusplus 1.13 + extern "C" { 1.14 +#endif 1.15 + 1.16 +/* Error string return. NULL if success, otherwise error message. */ 1.17 +typedef const char* spc_err_t; 1.18 + 1.19 +typedef struct SNES_SPC SNES_SPC; 1.20 + 1.21 +/* Creates new SPC emulator. NULL if out of memory. */ 1.22 +SNES_SPC* spc_new( void ); 1.23 + 1.24 +/* Frees SPC emulator */ 1.25 +void spc_delete( SNES_SPC* ); 1.26 + 1.27 +/* Sample pairs generated per second */ 1.28 +enum { spc_sample_rate = 32000 }; 1.29 + 1.30 + 1.31 +/**** Emulator use ****/ 1.32 + 1.33 +/* Sets IPL ROM data. Library does not include ROM data. Most SPC music files 1.34 +don't need ROM, but a full emulator must provide this. */ 1.35 +enum { spc_rom_size = 0x40 }; 1.36 +void spc_init_rom( SNES_SPC*, unsigned char const rom [spc_rom_size] ); 1.37 + 1.38 +/* Sets destination for output samples */ 1.39 +typedef short spc_sample_t; 1.40 +void spc_set_output( SNES_SPC*, spc_sample_t* out, int out_size ); 1.41 + 1.42 +/* Number of samples written to output since last set */ 1.43 +int spc_sample_count( SNES_SPC const* ); 1.44 + 1.45 +/* Resets SPC to power-on state. This resets your output buffer, so you must 1.46 +call spc_set_output() after this. */ 1.47 +void spc_reset( SNES_SPC* ); 1.48 + 1.49 +/* Emulates pressing reset switch on SNES. This resets your output buffer, so 1.50 +you must call spc_set_output() after this. */ 1.51 +void spc_soft_reset( SNES_SPC* ); 1.52 + 1.53 +/* 1024000 SPC clocks per second, sample pair every 32 clocks */ 1.54 +typedef int spc_time_t; 1.55 +enum { spc_clock_rate = 1024000 }; 1.56 +enum { spc_clocks_per_sample = 32 }; 1.57 + 1.58 +/* Reads/writes port at specified time */ 1.59 +enum { spc_port_count = 4 }; 1.60 +int spc_read_port ( SNES_SPC*, spc_time_t, int port ); 1.61 +void spc_write_port( SNES_SPC*, spc_time_t, int port, int data ); 1.62 + 1.63 +/* Runs SPC to end_time and starts a new time frame at 0 */ 1.64 +void spc_end_frame( SNES_SPC*, spc_time_t end_time ); 1.65 + 1.66 + 1.67 +/**** Sound control ****/ 1.68 + 1.69 +/*Mutes voices corresponding to non-zero bits in mask. Reduces emulation accuracy. */ 1.70 +enum { spc_voice_count = 8 }; 1.71 +void spc_mute_voices( SNES_SPC*, int mask ); 1.72 + 1.73 +/* If true, prevents channels and global volumes from being phase-negated. 1.74 +Only supported by fast DSP; has no effect on accurate DSP. */ 1.75 +void spc_disable_surround( SNES_SPC*, int disable ); 1.76 + 1.77 +/* Sets tempo, where spc_tempo_unit = normal, spc_tempo_unit / 2 = half speed, etc. */ 1.78 +enum { spc_tempo_unit = 0x100 }; 1.79 +void spc_set_tempo( SNES_SPC*, int ); 1.80 + 1.81 + 1.82 +/**** SPC music playback *****/ 1.83 + 1.84 +/* Loads SPC data into emulator. Returns NULL on success, otherwise error string. */ 1.85 +spc_err_t spc_load_spc( SNES_SPC*, void const* spc_in, long size ); 1.86 + 1.87 +/* Clears echo region. Useful after loading an SPC as many have garbage in echo. */ 1.88 +void spc_clear_echo( SNES_SPC* ); 1.89 + 1.90 +/* Plays for count samples and write samples to out. Discards samples if out 1.91 +is NULL. Count must be a multiple of 2 since output is stereo. */ 1.92 +spc_err_t spc_play( SNES_SPC*, int count, short* out ); 1.93 + 1.94 +/* Skips count samples. Several times faster than spc_play(). */ 1.95 +spc_err_t spc_skip( SNES_SPC*, int count ); 1.96 + 1.97 + 1.98 +/**** State save/load (only available with accurate DSP) ****/ 1.99 + 1.100 +/* Saves/loads exact emulator state */ 1.101 +enum { spc_state_size = 67 * 1024L }; /* maximum space needed when saving */ 1.102 +typedef void (*spc_copy_func_t)( unsigned char** io, void* state, size_t ); 1.103 +void spc_copy_state( SNES_SPC*, unsigned char** io, spc_copy_func_t ); 1.104 + 1.105 +/* Writes minimal SPC file header to spc_out */ 1.106 +void spc_init_header( void* spc_out ); 1.107 + 1.108 +/* Saves emulator state as SPC file data. Writes spc_file_size bytes to spc_out. 1.109 +Does not set up SPC header; use spc_init_header() for that. */ 1.110 +enum { spc_file_size = 0x10200 }; /* spc_out must have this many bytes allocated */ 1.111 +void spc_save_spc( SNES_SPC*, void* spc_out ); 1.112 + 1.113 +/* Returns non-zero if new key-on events occurred since last check. Useful for 1.114 +trimming silence while saving an SPC. */ 1.115 +int spc_check_kon( SNES_SPC* ); 1.116 + 1.117 + 1.118 +/**** SPC_Filter ****/ 1.119 + 1.120 +typedef struct SPC_Filter SPC_Filter; 1.121 + 1.122 +/* Creates new filter. NULL if out of memory. */ 1.123 +SPC_Filter* spc_filter_new( void ); 1.124 + 1.125 +/* Frees filter */ 1.126 +void spc_filter_delete( SPC_Filter* ); 1.127 + 1.128 +/* Filters count samples of stereo sound in place. Count must be a multiple of 2. */ 1.129 +void spc_filter_run( SPC_Filter*, spc_sample_t* io, int count ); 1.130 + 1.131 +/* Clears filter to silence */ 1.132 +void spc_filter_clear( SPC_Filter* ); 1.133 + 1.134 +/* Sets gain (volume), where spc_filter_gain_unit is normal. Gains greater than 1.135 +spc_filter_gain_unit are fine, since output is clamped to 16-bit sample range. */ 1.136 +enum { spc_filter_gain_unit = 0x100 }; 1.137 +void spc_filter_set_gain( SPC_Filter*, int gain ); 1.138 + 1.139 +/* Sets amount of bass (logarithmic scale) */ 1.140 +enum { spc_filter_bass_none = 0 }; 1.141 +enum { spc_filter_bass_norm = 8 }; /* normal amount */ 1.142 +enum { spc_filter_bass_max = 31 }; 1.143 +void spc_filter_set_bass( SPC_Filter*, int bass ); 1.144 + 1.145 + 1.146 +#ifdef __cplusplus 1.147 + } 1.148 +#endif 1.149 + 1.150 +#endif