yaze 0.2.0
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
dsp.h
Go to the documentation of this file.
1#ifndef YAZE_APP_EMU_AUDIO_S_DSP_H
2#define YAZE_APP_EMU_AUDIO_S_DSP_H
3
4#include <cstdint>
5#include <functional>
6#include <vector>
7
10
11namespace yaze {
12namespace app {
13namespace emu {
14namespace audio {
15
16typedef struct DspChannel {
17 // pitch
18 uint16_t pitch;
19 uint16_t pitchCounter;
21 // brr decoding
22 int16_t decodeBuffer[12];
23 uint8_t bufferOffset;
24 uint8_t srcn;
25 uint16_t decodeOffset;
26 uint8_t blockOffset; // offset within brr block
27 uint8_t brrHeader;
29 uint8_t startDelay;
30 // adsr, envelope, gain
31 uint8_t adsrRates[4]; // attack, decay, sustain, gain
32 uint8_t adsrState; // 0: attack, 1: decay, 2: sustain, 3: release
33 uint8_t sustainLevel;
35 bool useGain;
36 uint8_t gainMode;
38 uint16_t gainValue; // for direct gain
39 uint16_t preclampGain; // for bent increase
40 uint16_t gain;
41 // keyon/off
42 bool keyOn;
43 bool keyOff;
44 // output
45 int16_t sampleOut; // final sample, to be multiplied by channel volume
46 int8_t volumeL;
47 int8_t volumeR;
50
86class Dsp {
87 public:
88 Dsp(std::vector<uint8_t>& aram) : aram_(aram) {}
89
90 void NewFrame();
91
92 void Reset();
93
94 void Cycle();
95
96 void HandleEcho();
97 void CycleChannel(int ch);
98
99 void HandleNoise();
100 void HandleGain(int ch);
101
102 bool CheckCounter(int rate);
103
104 void DecodeBrr(int ch);
105
106 uint8_t Read(uint8_t adr);
107 void Write(uint8_t adr, uint8_t val);
108
109 int16_t GetSample(int ch);
110
111 void GetSamples(int16_t* sample_data, int samples_per_frame, bool pal_timing);
112
113 private:
114 int16_t sample_buffer_[0x400 * 2]; // (1024 samples, *2 for stereo)
115 int16_t sample_offset_; // current offset in samplebuffer
116
117 std::vector<uint8_t>& aram_;
118
119 // mirror ram
120 uint8_t ram[0x80];
121 // 8 channels
123 // overarching
124 uint16_t counter;
125 uint16_t dirPage;
127 bool mute;
128 bool reset;
131 // accumulation
132 int16_t sampleOutL;
133 int16_t sampleOutR;
134 int16_t echoOutL;
135 int16_t echoOutR;
136 // noise
137 int16_t noiseSample;
138 uint8_t noiseRate;
139 // echo
145 uint16_t echoDelay;
146 uint16_t echoLength;
149 int8_t firValues[8];
150 int16_t firBufferL[8];
151 int16_t firBufferR[8];
152 // sample ring buffer (1024 samples, *2 for stereo)
153 int16_t sampleBuffer[0x400 * 2];
154 uint16_t sampleOffset; // current offset in samplebuffer
156};
157
158} // namespace audio
159} // namespace emu
160} // namespace app
161} // namespace yaze
162
163#endif // YAZE_APP_EMU_AUDIO_S_DSP_H
DspChannel channel[8]
Definition dsp.h:122
std::vector< uint8_t > & aram_
Definition dsp.h:117
int16_t sampleBuffer[0x400 *2]
Definition dsp.h:153
void HandleGain(int ch)
Definition dsp.cc:306
bool CheckCounter(int rate)
Definition dsp.cc:164
uint8_t ram[0x80]
Definition dsp.h:120
int16_t sample_buffer_[0x400 *2]
Definition dsp.h:114
void CycleChannel(int ch)
Definition dsp.cc:217
void Write(uint8_t adr, uint8_t val)
Definition dsp.cc:434
int16_t GetSample(int ch)
Definition dsp.cc:369
uint8_t Read(uint8_t adr)
Definition dsp.cc:432
int16_t firBufferR[8]
Definition dsp.h:151
void DecodeBrr(int ch)
Definition dsp.cc:383
Dsp(std::vector< uint8_t > &aram)
Definition dsp.h:88
int16_t firBufferL[8]
Definition dsp.h:150
void GetSamples(int16_t *sample_data, int samples_per_frame, bool pal_timing)
Definition dsp.cc:621
uint16_t echoBufferIndex
Definition dsp.h:147
uint32_t lastFrameBoundary
Definition dsp.h:155
struct yaze::app::emu::audio::DspChannel DspChannel
Definition common.cc:22