cleanup
[drnoksnes] / sounduxnew.h
1 /*
2  * Snes9x - Portable Super Nintendo Entertainment System (TM) emulator.
3  *
4  * (c) Copyright 1996 - 2001 Gary Henderson (gary.henderson@ntlworld.com) and
5  *                           Jerremy Koot (jkoot@snes9x.com)
6  *
7  * Super FX C emulator code 
8  * (c) Copyright 1997 - 1999 Ivar (ivar@snes9x.com) and
9  *                           Gary Henderson.
10  * Super FX assembler emulator code (c) Copyright 1998 zsKnight and _Demo_.
11  *
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).
15  *
16  * DOS port code contains the works of other authors. See headers in
17  * individual files.
18  *
19  * Snes9x homepage: http://www.snes9x.com
20  *
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.
25  *
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.
29  *
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.
33  *
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
36  * in future versions.
37  *
38  * Super NES and Super Nintendo Entertainment System are trademarks of
39  * Nintendo Co., Limited and its subsidiary companies.
40  */
41 #ifndef _SOUND_H_
42 #define _SOUND_H_
43
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};
49
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};
53
54 #define MAX_ENVELOPE_HEIGHT 127
55 #define ENVELOPE_SHIFT 7
56 #define MAX_VOLUME 127
57 #define VOLUME_SHIFT 7
58 #define VOL_DIV 128
59 #define SOUND_DECODE_LENGTH 16
60
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)
65
66 #define SOUND_BUFS      4
67
68 #ifdef __sgi
69 //#  include <audio.h>
70 #endif /* __sgi */
71
72 typedef struct {
73     int                 sound_fd;
74     int                 sound_switch;
75     int                 playback_rate;
76     int                 buffer_size;
77     int                 noise_gen;
78     bool8_32    mute_sound;
79     int                 stereo;
80     bool8_32    sixteen_bit;
81     bool8_32    encoded;
82 #ifdef __sun
83     int                 last_eof;
84 #endif
85 #ifdef __sgi
86     ALport              al_port;
87 #endif /* __sgi */
88     int32               samples_mixed_so_far;
89     int32               play_position;
90     uint32              err_counter;
91     uint32              err_rate;
92 } SoundStatus;
93
94 EXTERN_C volatile SoundStatus so;
95
96 typedef struct {
97     int                                 state;
98     int                                 type;
99     short                               volume_left;
100     short                               volume_right;
101     uint32                              hertz;
102     uint32                              frequency;
103     uint32                              count;
104     bool8_32                    loop;
105     int                                 envx;
106     short                               left_vol_level;
107     short                               right_vol_level;
108     short                               envx_target;
109     unsigned long int   env_error;
110     unsigned long               erate;
111     int                                 direction;
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;
117     signed short                sample;
118     signed short                decoded [16];
119     signed short                previous16 [2];
120     signed short                *block;
121     uint16                              sample_number;
122     bool8_32                    last_block;
123     bool8_32                    needs_decode;
124     uint32                              block_pointer;
125     uint32                              sample_pointer;
126     int                                 *echo_buf_ptr;
127     int                                 mode;
128     int32                               envxx;
129     signed short                next_sample;
130     int32                               interpolate;
131     int32                               previous [2];
132     // Just incase they are needed in the future, for snapshot compatibility.
133     uint32                              dummy [8];
134 } Channel;
135
136 typedef struct
137 {
138     short               master_volume_left;
139     short               master_volume_right;
140     short               echo_volume_left;
141     short               echo_volume_right;
142     int                 echo_enable;
143     int                 echo_feedback;
144     int                 echo_ptr;
145     int                 echo_buffer_size;
146     int                 echo_write_enabled;
147     int                 echo_channel_enable;
148     int                 pitch_mod;
149     // Just incase they are needed in the future, for snapshot compatibility.
150     uint32              dummy [3];
151     Channel             channels [NUM_CHANNELS];
152     bool8_32    no_filter;
153     int                 master_volume [2];
154     int                 echo_volume [2];
155     int                 noise_hertz;
156 } SSoundData;
157
158 EXTERN_C SSoundData SoundData;
159
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,
183                          int target);
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);
192
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);
197 #endif