2 * Snes9x - Portable Super Nintendo Entertainment System (TM) emulator.
4 * (c) Copyright 1996 - 2001 Gary Henderson (gary.henderson@ntlworld.com) and
5 * Jerremy Koot (jkoot@snes9x.com)
7 * Super FX C emulator code
8 * (c) Copyright 1997 - 1999 Ivar (ivar@snes9x.com) and
10 * Super FX assembler emulator code (c) Copyright 1998 zsKnight and _Demo_.
12 * DSP1 emulator code (c) Copyright 1998 Ivar, _Demo_ and Gary Henderson.
13 * C4 asm and some C emulation code (c) Copyright 2000 zsKnight and _Demo_.
14 * C4 C code (c) Copyright 2001 Gary Henderson (gary.henderson@ntlworld.com).
16 * DOS port code contains the works of other authors. See headers in
19 * Snes9x homepage: http://www.snes9x.com
21 * Permission to use, copy, modify and distribute Snes9x in both binary and
22 * source form, for non-commercial purposes, is hereby granted without fee,
23 * providing that this license information and copyright notice appear with
24 * all copies and any derived work.
26 * This software is provided 'as-is', without any express or implied
27 * warranty. In no event shall the authors be held liable for any damages
28 * arising from the use of this software.
30 * Snes9x is freeware for PERSONAL USE only. Commercial users should
31 * seek permission of the copyright holders first. Commercial use includes
32 * charging money for Snes9x or software derived from Snes9x.
34 * The copyright holders request that bug fixes and improvements to the code
35 * should be forwarded to them so everyone can benefit from the modifications
38 * Super NES and Super Nintendo Entertainment System are trademarks of
39 * Nintendo Co., Limited and its subsidiary companies.
44 enum { SOUND_SAMPLE = 0, SOUND_NOISE, SOUND_EXTRA_NOISE, SOUND_MUTE };
45 enum { SOUND_SILENT, SOUND_ATTACK, SOUND_DECAY, SOUND_SUSTAIN,
46 SOUND_RELEASE, SOUND_GAIN, SOUND_INCREASE_LINEAR,
47 SOUND_INCREASE_BENT_LINE, SOUND_DECREASE_LINEAR,
48 SOUND_DECREASE_EXPONENTIAL};
50 enum { MODE_NONE = SOUND_SILENT, MODE_ADSR, MODE_RELEASE = SOUND_RELEASE,
51 MODE_GAIN, MODE_INCREASE_LINEAR, MODE_INCREASE_BENT_LINE,
52 MODE_DECREASE_LINEAR, MODE_DECREASE_EXPONENTIAL};
54 #define MAX_ENVELOPE_HEIGHT 127
55 #define ENVELOPE_SHIFT 7
56 #define MAX_VOLUME 127
57 #define VOLUME_SHIFT 7
59 #define SOUND_DECODE_LENGTH 16
61 #define NUM_CHANNELS 8
62 #define SOUND_BUFFER_SIZE (1024 * 16)
63 #define MAX_BUFFER_SIZE SOUND_BUFFER_SIZE
64 #define SOUND_BUFFER_SIZE_MASK (SOUND_BUFFER_SIZE - 1)
88 int32 samples_mixed_so_far;
94 EXTERN_C volatile SoundStatus so;
106 short left_vol_level;
107 short right_vol_level;
109 unsigned long int env_error;
112 unsigned long attack_rate;
113 unsigned long decay_rate;
114 unsigned long sustain_rate;
115 unsigned long release_rate;
116 unsigned long sustain_level;
118 signed short decoded [16];
119 signed short previous16 [2];
121 uint16 sample_number;
123 bool8_32 needs_decode;
124 uint32 block_pointer;
125 uint32 sample_pointer;
129 signed short next_sample;
132 // Just incase they are needed in the future, for snapshot compatibility.
138 short master_volume_left;
139 short master_volume_right;
140 short echo_volume_left;
141 short echo_volume_right;
145 int echo_buffer_size;
146 int echo_write_enabled;
147 int echo_channel_enable;
149 // Just incase they are needed in the future, for snapshot compatibility.
151 Channel channels [NUM_CHANNELS];
153 int master_volume [2];
158 EXTERN_C SSoundData SoundData;
160 void S9xSetSoundVolume (int channel, short volume_left, short volume_right);
161 void S9xSetSoundFrequency (int channel, int hertz);
162 void S9xSetSoundHertz (int channel, int hertz);
163 void S9xSetSoundType (int channel, int type_of_sound);
164 void S9xSetMasterVolume (short master_volume_left, short master_volume_right);
165 void S9xSetEchoVolume (short echo_volume_left, short echo_volume_right);
166 void S9xSetSoundControl (int sound_switch);
167 bool8_32 S9xSetSoundMute (bool8_32 mute);
168 void S9xSetEnvelopeHeight (int channel, int height);
169 void S9xSetSoundADSR (int channel, int attack, int decay, int sustain,
170 int sustain_level, int release);
171 void S9xSetSoundKeyOff (int channel);
172 void S9xSetSoundDecayMode (int channel);
173 void S9xSetSoundAttachMode (int channel);
174 void S9xSoundStartEnvelope (Channel *);
175 void S9xSetSoundSample (int channel, uint16 sample_number);
176 void S9xSetEchoFeedback (int echo_feedback);
177 void S9xSetEchoEnable (uint8 byte);
178 void S9xSetEchoDelay (int byte);
179 void S9xSetEchoWriteEnable (uint8 byte);
180 void S9xSetFilterCoefficient (int tap, int value);
181 void S9xSetFrequencyModulationEnable (uint8 byte);
182 void S9xSetEnvelopeRate (int channel, unsigned long rate, int direction,
184 bool8_32 S9xSetSoundMode (int channel, int mode);
185 int S9xGetEnvelopeHeight (int channel);
186 void S9xResetSound (bool8_32 full);
187 void S9xFixSoundAfterSnapshotLoad ();
188 void S9xPlaybackSoundSetting (int channel);
189 void S9xPlaySample (int channel);
190 void S9xFixEnvelope (int channel, uint8 gain, uint8 adsr1, uint8 adsr2);
191 void S9xStartSample (int channel);
193 EXTERN_C void S9xMixSamples (uint8 *buffer, int sample_count);
194 EXTERN_C void S9xMixSamplesO (uint8 *buffer, int sample_count, int byte_offset);
195 bool8_32 S9xOpenSoundDevice (int, bool8_32, int);
196 void S9xSetPlaybackRate (uint32 rate);