rlm@0: /* SNES SPC-700 DSP emulator C interface (also usable from C++) */ rlm@0: rlm@0: /* snes_spc 0.9.0 */ rlm@0: #ifndef DSP_H rlm@0: #define DSP_H rlm@0: rlm@0: #include rlm@0: rlm@0: #ifdef __cplusplus rlm@0: extern "C" { rlm@0: #endif rlm@0: rlm@0: typedef struct SPC_DSP SPC_DSP; rlm@0: rlm@0: /* Creates new DSP emulator. NULL if out of memory. */ rlm@0: SPC_DSP* spc_dsp_new( void ); rlm@0: rlm@0: /* Frees DSP emulator */ rlm@0: void spc_dsp_delete( SPC_DSP* ); rlm@0: rlm@0: /* Initializes DSP and has it use the 64K RAM provided */ rlm@0: void spc_dsp_init( SPC_DSP*, void* ram_64k ); rlm@0: rlm@0: /* Sets destination for output samples. If out is NULL or out_size is 0, rlm@0: doesn't generate any. */ rlm@0: typedef short spc_dsp_sample_t; rlm@0: void spc_dsp_set_output( SPC_DSP*, spc_dsp_sample_t* out, int out_size ); rlm@0: rlm@0: /* Number of samples written to output since it was last set, always rlm@0: a multiple of 2. Undefined if more samples were generated than rlm@0: output buffer could hold. */ rlm@0: int spc_dsp_sample_count( SPC_DSP const* ); rlm@0: rlm@0: rlm@0: /**** Emulation *****/ rlm@0: rlm@0: /* Resets DSP to power-on state */ rlm@0: void spc_dsp_reset( SPC_DSP* ); rlm@0: rlm@0: /* Emulates pressing reset switch on SNES */ rlm@0: void spc_dsp_soft_reset( SPC_DSP* ); rlm@0: rlm@0: /* Reads/writes DSP registers. For accuracy, you must first call spc_dsp_run() */ rlm@0: /* to catch the DSP up to present. */ rlm@0: int spc_dsp_read ( SPC_DSP const*, int addr ); rlm@0: void spc_dsp_write( SPC_DSP*, int addr, int data ); rlm@0: rlm@0: /* Runs DSP for specified number of clocks (~1024000 per second). Every 32 clocks */ rlm@0: /* a pair of samples is be generated. */ rlm@0: void spc_dsp_run( SPC_DSP*, int clock_count ); rlm@0: rlm@0: rlm@0: /**** Sound control *****/ rlm@0: rlm@0: /* Mutes voices corresponding to non-zero bits in mask. Reduces emulation accuracy. */ rlm@0: enum { spc_dsp_voice_count = 8 }; rlm@0: void spc_dsp_mute_voices( SPC_DSP*, int mask ); rlm@0: rlm@0: /* If true, prevents channels and global volumes from being phase-negated. rlm@0: Only supported by fast DSP; has no effect on accurate DSP. */ rlm@0: void spc_dsp_disable_surround( SPC_DSP*, int disable ); rlm@0: rlm@0: rlm@0: /**** State save/load *****/ rlm@0: rlm@0: /* Resets DSP and uses supplied values to initialize registers */ rlm@0: enum { spc_dsp_register_count = 128 }; rlm@0: void spc_dsp_load( SPC_DSP*, unsigned char const regs [spc_dsp_register_count] ); rlm@0: rlm@0: /* Saves/loads exact emulator state (accurate DSP only) */ rlm@0: enum { spc_dsp_state_size = 640 }; /* maximum space needed when saving */ rlm@0: typedef void (*spc_dsp_copy_func_t)( unsigned char** io, void* state, size_t ); rlm@0: void spc_dsp_copy_state( SPC_DSP*, unsigned char** io, spc_dsp_copy_func_t ); rlm@0: rlm@0: /* Returns non-zero if new key-on events occurred since last call (accurate DSP only) */ rlm@0: int spc_dsp_check_kon( SPC_DSP* ); rlm@0: rlm@0: rlm@0: #ifdef __cplusplus rlm@0: } rlm@0: #endif rlm@0: rlm@0: #endif