aboutsummaryrefslogtreecommitdiff
path: root/source/soundux.h
blob: e4cf3ad18f7857ec09531beb4a52ecf5918aff7a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#include "../copyright"

#ifndef USE_BLARGG_APU

#ifndef _SOUND_H_
#define _SOUND_H_

enum { SOUND_SAMPLE = 0, SOUND_NOISE, SOUND_EXTRA_NOISE, SOUND_MUTE };
enum { SOUND_SILENT, SOUND_ATTACK, SOUND_DECAY, SOUND_SUSTAIN,
       SOUND_RELEASE, SOUND_GAIN, SOUND_INCREASE_LINEAR,
       SOUND_INCREASE_BENT_LINE, SOUND_DECREASE_LINEAR,
       SOUND_DECREASE_EXPONENTIAL
     };

enum { MODE_NONE = SOUND_SILENT, MODE_ADSR, MODE_RELEASE = SOUND_RELEASE,
       MODE_GAIN, MODE_INCREASE_LINEAR, MODE_INCREASE_BENT_LINE,
       MODE_DECREASE_LINEAR, MODE_DECREASE_EXPONENTIAL
     };

#define MAX_ENVELOPE_HEIGHT 127
#define ENVELOPE_SHIFT 7
#define MAX_VOLUME 127
#define VOLUME_SHIFT 7
#define SOUND_DECODE_LENGTH 16

#define NUM_CHANNELS    8
#define SOUND_BUFFER_SIZE (2 * 44100 / 50)
#define MAX_BUFFER_SIZE SOUND_BUFFER_SIZE

#define SOUND_BUFS      4

typedef struct
{
   int      playback_rate;
   int      buffer_size;
   uint32_t freqbase; // notaz
   bool     mute_sound;
} SoundStatus;

SoundStatus so;

typedef struct
{
   int      state;
   int      type;
   int16_t  volume_left;
   int16_t  volume_right;
   uint32_t hertz;
   uint32_t frequency;
   uint32_t count;
   bool     loop;
   int      envx;
   int16_t  left_vol_level;
   int16_t  right_vol_level;
   int16_t  envx_target;
   uint32_t env_error;
   uint32_t erate;
   int      direction;
   uint32_t attack_rate;
   uint32_t decay_rate;
   uint32_t sustain_rate;
   uint32_t release_rate;
   uint32_t sustain_level;
   int16_t  sample;
   int16_t  decoded [16];
   int16_t  previous16 [2];
   int16_t* block;
   uint16_t sample_number;
   bool     last_block;
   bool     needs_decode;
   uint32_t block_pointer;
   uint32_t sample_pointer;
   int*     echo_buf_ptr;
   int      mode;
   int32_t  envxx;
   int16_t  next_sample;
   int32_t  interpolate;
   int32_t  previous [2];
   // notaz
   uint8_t  env_ind_attack;
   uint8_t  env_ind_decay;
   uint8_t  env_ind_sustain;
   // Just incase they are needed in the future, for snapshot compatibility.
   uint8_t  dummy [29];
} Channel;

typedef struct
{
   int      echo_enable;
   int      echo_feedback; /* range is -128 .. 127 */
   int      echo_ptr;
   int      echo_buffer_size;
   int      echo_write_enabled;
   int      echo_channel_enable;
   int      pitch_mod;
   // Just incase they are needed in the future, for snapshot compatibility.
   uint32_t dummy [3];
   Channel  channels [NUM_CHANNELS];
   int16_t  master_volume [2]; /* range is -128 .. 127 */
   int16_t  echo_volume [2]; /* range is -128 .. 127 */
   int      noise_hertz;
} SSoundData;

SSoundData SoundData;

void S9xSetSoundVolume(int channel, int16_t volume_left, int16_t volume_right);
void S9xSetSoundFrequency(int channel, int hertz);
void S9xSetSoundHertz(int channel, int hertz);
void S9xSetSoundType(int channel, int type_of_sound);
void S9xSetMasterVolume(int16_t master_volume_left, int16_t master_volume_right);
void S9xSetEchoVolume(int16_t echo_volume_left, int16_t echo_volume_right);
void S9xSetEnvelopeHeight(int channel, int height);
void S9xSetSoundADSR(int channel, int attack, int decay, int sustain, int sustain_level, int release);
void S9xSetSoundKeyOff(int channel);
void S9xSetSoundDecayMode(int channel);
void S9xSetSoundAttachMode(int channel);
void S9xSoundStartEnvelope(Channel*);
void S9xSetEchoFeedback(int echo_feedback);
void S9xSetEchoEnable(uint8_t byte);
void S9xSetEchoDelay(int byte);
void S9xSetEchoWriteEnable(uint8_t byte);
void S9xSetFilterCoefficient(int tap, int value);
void S9xSetFrequencyModulationEnable(uint8_t byte);
void S9xSetEnvelopeRate(int channel, uint32_t rate, int direction, int target, unsigned int mode);
bool S9xSetSoundMode(int channel, int mode);
void S9xResetSound(bool full);
void S9xFixSoundAfterSnapshotLoad();
void S9xPlaybackSoundSetting(int channel);
void S9xPlaySample(int channel);
void S9xFixEnvelope(int channel, uint8_t gain, uint8_t adsr1, uint8_t adsr2);
void S9xStartSample(int channel);

void S9xMixSamples(uint16_t* buffer, int sample_count);
bool S9xOpenSoundDevice(int, bool, int);
void S9xSetPlaybackRate(uint32_t rate);
#endif

#endif