Mercurial > spc_convert
comparison 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 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:e38dacceb958 |
---|---|
1 /* SNES SPC-700 APU emulator C interface (also usable from C++) */ | |
2 | |
3 /* snes_spc 0.9.0 */ | |
4 #ifndef SPC_H | |
5 #define SPC_H | |
6 | |
7 #include <stddef.h> | |
8 | |
9 #ifdef __cplusplus | |
10 extern "C" { | |
11 #endif | |
12 | |
13 /* Error string return. NULL if success, otherwise error message. */ | |
14 typedef const char* spc_err_t; | |
15 | |
16 typedef struct SNES_SPC SNES_SPC; | |
17 | |
18 /* Creates new SPC emulator. NULL if out of memory. */ | |
19 SNES_SPC* spc_new( void ); | |
20 | |
21 /* Frees SPC emulator */ | |
22 void spc_delete( SNES_SPC* ); | |
23 | |
24 /* Sample pairs generated per second */ | |
25 enum { spc_sample_rate = 32000 }; | |
26 | |
27 | |
28 /**** Emulator use ****/ | |
29 | |
30 /* Sets IPL ROM data. Library does not include ROM data. Most SPC music files | |
31 don't need ROM, but a full emulator must provide this. */ | |
32 enum { spc_rom_size = 0x40 }; | |
33 void spc_init_rom( SNES_SPC*, unsigned char const rom [spc_rom_size] ); | |
34 | |
35 /* Sets destination for output samples */ | |
36 typedef short spc_sample_t; | |
37 void spc_set_output( SNES_SPC*, spc_sample_t* out, int out_size ); | |
38 | |
39 /* Number of samples written to output since last set */ | |
40 int spc_sample_count( SNES_SPC const* ); | |
41 | |
42 /* Resets SPC to power-on state. This resets your output buffer, so you must | |
43 call spc_set_output() after this. */ | |
44 void spc_reset( SNES_SPC* ); | |
45 | |
46 /* Emulates pressing reset switch on SNES. This resets your output buffer, so | |
47 you must call spc_set_output() after this. */ | |
48 void spc_soft_reset( SNES_SPC* ); | |
49 | |
50 /* 1024000 SPC clocks per second, sample pair every 32 clocks */ | |
51 typedef int spc_time_t; | |
52 enum { spc_clock_rate = 1024000 }; | |
53 enum { spc_clocks_per_sample = 32 }; | |
54 | |
55 /* Reads/writes port at specified time */ | |
56 enum { spc_port_count = 4 }; | |
57 int spc_read_port ( SNES_SPC*, spc_time_t, int port ); | |
58 void spc_write_port( SNES_SPC*, spc_time_t, int port, int data ); | |
59 | |
60 /* Runs SPC to end_time and starts a new time frame at 0 */ | |
61 void spc_end_frame( SNES_SPC*, spc_time_t end_time ); | |
62 | |
63 | |
64 /**** Sound control ****/ | |
65 | |
66 /*Mutes voices corresponding to non-zero bits in mask. Reduces emulation accuracy. */ | |
67 enum { spc_voice_count = 8 }; | |
68 void spc_mute_voices( SNES_SPC*, int mask ); | |
69 | |
70 /* If true, prevents channels and global volumes from being phase-negated. | |
71 Only supported by fast DSP; has no effect on accurate DSP. */ | |
72 void spc_disable_surround( SNES_SPC*, int disable ); | |
73 | |
74 /* Sets tempo, where spc_tempo_unit = normal, spc_tempo_unit / 2 = half speed, etc. */ | |
75 enum { spc_tempo_unit = 0x100 }; | |
76 void spc_set_tempo( SNES_SPC*, int ); | |
77 | |
78 | |
79 /**** SPC music playback *****/ | |
80 | |
81 /* Loads SPC data into emulator. Returns NULL on success, otherwise error string. */ | |
82 spc_err_t spc_load_spc( SNES_SPC*, void const* spc_in, long size ); | |
83 | |
84 /* Clears echo region. Useful after loading an SPC as many have garbage in echo. */ | |
85 void spc_clear_echo( SNES_SPC* ); | |
86 | |
87 /* Plays for count samples and write samples to out. Discards samples if out | |
88 is NULL. Count must be a multiple of 2 since output is stereo. */ | |
89 spc_err_t spc_play( SNES_SPC*, int count, short* out ); | |
90 | |
91 /* Skips count samples. Several times faster than spc_play(). */ | |
92 spc_err_t spc_skip( SNES_SPC*, int count ); | |
93 | |
94 | |
95 /**** State save/load (only available with accurate DSP) ****/ | |
96 | |
97 /* Saves/loads exact emulator state */ | |
98 enum { spc_state_size = 67 * 1024L }; /* maximum space needed when saving */ | |
99 typedef void (*spc_copy_func_t)( unsigned char** io, void* state, size_t ); | |
100 void spc_copy_state( SNES_SPC*, unsigned char** io, spc_copy_func_t ); | |
101 | |
102 /* Writes minimal SPC file header to spc_out */ | |
103 void spc_init_header( void* spc_out ); | |
104 | |
105 /* Saves emulator state as SPC file data. Writes spc_file_size bytes to spc_out. | |
106 Does not set up SPC header; use spc_init_header() for that. */ | |
107 enum { spc_file_size = 0x10200 }; /* spc_out must have this many bytes allocated */ | |
108 void spc_save_spc( SNES_SPC*, void* spc_out ); | |
109 | |
110 /* Returns non-zero if new key-on events occurred since last check. Useful for | |
111 trimming silence while saving an SPC. */ | |
112 int spc_check_kon( SNES_SPC* ); | |
113 | |
114 | |
115 /**** SPC_Filter ****/ | |
116 | |
117 typedef struct SPC_Filter SPC_Filter; | |
118 | |
119 /* Creates new filter. NULL if out of memory. */ | |
120 SPC_Filter* spc_filter_new( void ); | |
121 | |
122 /* Frees filter */ | |
123 void spc_filter_delete( SPC_Filter* ); | |
124 | |
125 /* Filters count samples of stereo sound in place. Count must be a multiple of 2. */ | |
126 void spc_filter_run( SPC_Filter*, spc_sample_t* io, int count ); | |
127 | |
128 /* Clears filter to silence */ | |
129 void spc_filter_clear( SPC_Filter* ); | |
130 | |
131 /* Sets gain (volume), where spc_filter_gain_unit is normal. Gains greater than | |
132 spc_filter_gain_unit are fine, since output is clamped to 16-bit sample range. */ | |
133 enum { spc_filter_gain_unit = 0x100 }; | |
134 void spc_filter_set_gain( SPC_Filter*, int gain ); | |
135 | |
136 /* Sets amount of bass (logarithmic scale) */ | |
137 enum { spc_filter_bass_none = 0 }; | |
138 enum { spc_filter_bass_norm = 8 }; /* normal amount */ | |
139 enum { spc_filter_bass_max = 31 }; | |
140 void spc_filter_set_bass( SPC_Filter*, int bass ); | |
141 | |
142 | |
143 #ifdef __cplusplus | |
144 } | |
145 #endif | |
146 | |
147 #endif |