#include <dsp.h>
Public Member Functions | |
Dsp (std::vector< uint8_t > &aram) | |
void | NewFrame () |
void | Reset () |
void | Cycle () |
void | HandleEcho () |
void | CycleChannel (int ch) |
void | HandleNoise () |
void | HandleGain (int ch) |
bool | CheckCounter (int rate) |
void | DecodeBrr (int ch) |
uint8_t | Read (uint8_t adr) |
void | Write (uint8_t adr, uint8_t val) |
int16_t | GetSample (int ch) |
void | GetSamples (int16_t *sample_data, int samples_per_frame, bool pal_timing) |
Private Attributes | |
int16_t | sample_buffer_ [0x400 *2] |
int16_t | sample_offset_ |
std::vector< uint8_t > & | aram_ |
uint8_t | ram [0x80] |
DspChannel | channel [8] |
uint16_t | counter |
uint16_t | dirPage |
bool | evenCycle |
bool | mute |
bool | reset |
int8_t | masterVolumeL |
int8_t | masterVolumeR |
int16_t | sampleOutL |
int16_t | sampleOutR |
int16_t | echoOutL |
int16_t | echoOutR |
int16_t | noiseSample |
uint8_t | noiseRate |
bool | echoWrites |
int8_t | echoVolumeL |
int8_t | echoVolumeR |
int8_t | feedbackVolume |
uint16_t | echoBufferAdr |
uint16_t | echoDelay |
uint16_t | echoLength |
uint16_t | echoBufferIndex |
uint8_t | firBufferIndex |
int8_t | firValues [8] |
int16_t | firBufferL [8] |
int16_t | firBufferR [8] |
int16_t | sampleBuffer [0x400 *2] |
uint16_t | sampleOffset |
uint32_t | lastFrameBoundary |
The S-DSP is a digital signal processor generating the sound data.
A DSP register can be selected with $F2, after which it can be read or written at $F3. Often it is useful to load the register address into A, and the value to send in Y, so that MOV $F2, YA can be used to do both in one 16-bit instruction.
The DSP register address space only has 7 bits. The high bit of $F2, if set, will make the selected register read-only via $F3.
When initializing the DSP registers for the first time, take care not to accidentally enable echo writeback via FLG, because it will immediately begin overwriting values in RAM.
Voices There are 8 voices, numbered 0 to 7. Each voice X has 10 registers in the range $X0-$X9.
| Name | Address | Bits | Notes | |------—|------—|--------—|-----------------------------------------------------—| | VOL (L) | $X0 | SVVV VVVV | Left channel volume, signed. | | VOL (R) | $X1 | SVVV VVVV | Right channel volume, signed. | | P (L) | $X2 | LLLL LLLL | Low 8 bits of sample pitch. | | P (H) | $X3 | –HH HHHH | High 6 bits of sample pitch. | | SCRN | $X4 | SSSS SSSS | Selects a sample source entry from the directory. | | ADSR (1)| $X5 | EDDD AAAA | ADSR enable (E), decay rate (D), attack rate (A). | | ADSR (2)| $X6 | SSSR RRRR | Sustain level (S), release rate (R). | | GAIN | $X7 | 0VVV VVVV 1MMV VVVV | Mode (M), value (V). | | ENVX | $X8 | 0VVV VVVV | Reads current 7-bit value of ADSR/GAIN envelope. | | OUTX | $X9 | SVVV VVVV | Reads signed 8-bit value of current sample wave | | | | | multiplied by ENVX, before applying VOL. |
|
inline |
void yaze::app::emu::audio::Dsp::NewFrame | ( | ) |
Definition at line 132 of file dsp.cc.
References lastFrameBoundary, and sampleOffset.
void yaze::app::emu::audio::Dsp::Reset | ( | ) |
Definition at line 71 of file dsp.cc.
References yaze::app::emu::audio::DspChannel::adsrState, yaze::app::emu::audio::DspChannel::blockOffset, yaze::app::emu::audio::DspChannel::brrHeader, yaze::app::emu::audio::DspChannel::bufferOffset, channel, counter, yaze::app::emu::audio::DspChannel::decodeOffset, yaze::app::emu::audio::DspChannel::directGain, dirPage, echoBufferAdr, echoBufferIndex, echoDelay, yaze::app::emu::audio::DspChannel::echoEnable, echoLength, echoOutL, echoOutR, echoVolumeL, echoVolumeR, echoWrites, evenCycle, feedbackVolume, firBufferIndex, firBufferL, firBufferR, firValues, yaze::app::emu::audio::DspChannel::gain, yaze::app::emu::audio::DspChannel::gainMode, yaze::app::emu::audio::DspChannel::gainSustainLevel, yaze::app::emu::audio::DspChannel::gainValue, yaze::app::emu::audio::DspChannel::keyOff, yaze::app::emu::audio::DspChannel::keyOn, masterVolumeL, masterVolumeR, mute, noiseRate, noiseSample, yaze::app::emu::audio::DspChannel::pitch, yaze::app::emu::audio::DspChannel::pitchCounter, yaze::app::emu::audio::DspChannel::pitchModulation, yaze::app::emu::audio::DspChannel::preclampGain, ram, reset, sampleBuffer, sampleOffset, yaze::app::emu::audio::DspChannel::sampleOut, sampleOutL, sampleOutR, yaze::app::emu::audio::DspChannel::srcn, yaze::app::emu::audio::DspChannel::startDelay, yaze::app::emu::audio::DspChannel::sustainLevel, yaze::app::emu::audio::DspChannel::useGain, yaze::app::emu::audio::DspChannel::useNoise, yaze::app::emu::audio::DspChannel::volumeL, and yaze::app::emu::audio::DspChannel::volumeR.
Referenced by yaze::app::emu::audio::Apu::Reset().
void yaze::app::emu::audio::Dsp::Cycle | ( | ) |
Definition at line 136 of file dsp.cc.
References counter, CycleChannel(), echoOutL, echoOutR, evenCycle, HandleEcho(), HandleNoise(), mute, sampleBuffer, sampleOffset, sampleOutL, and sampleOutR.
Referenced by yaze::app::emu::audio::Apu::Cycle().
void yaze::app::emu::audio::Dsp::HandleEcho | ( | ) |
Definition at line 169 of file dsp.cc.
References aram_, echoBufferAdr, echoBufferIndex, echoDelay, echoLength, echoOutL, echoOutR, echoVolumeL, echoVolumeR, echoWrites, feedbackVolume, firBufferIndex, firBufferL, firBufferR, firValues, masterVolumeL, masterVolumeR, sampleOutL, and sampleOutR.
Referenced by Cycle().
void yaze::app::emu::audio::Dsp::CycleChannel | ( | int | ch | ) |
Definition at line 217 of file dsp.cc.
References yaze::app::emu::audio::DspChannel::adsrState, aram_, yaze::app::emu::audio::DspChannel::blockOffset, yaze::app::emu::audio::DspChannel::brrHeader, yaze::app::emu::audio::DspChannel::bufferOffset, channel, DecodeBrr(), yaze::app::emu::audio::DspChannel::decodeOffset, dirPage, echoOutL, echoOutR, evenCycle, yaze::app::emu::audio::DspChannel::gain, GetSample(), HandleGain(), yaze::app::emu::audio::DspChannel::keyOn, noiseSample, yaze::app::emu::audio::DspChannel::pitch, yaze::app::emu::audio::DspChannel::pitchCounter, ram, reset, yaze::app::emu::audio::DspChannel::sampleOut, sampleOutL, sampleOutR, yaze::app::emu::audio::DspChannel::srcn, and yaze::app::emu::audio::DspChannel::startDelay.
Referenced by Cycle().
void yaze::app::emu::audio::Dsp::HandleNoise | ( | ) |
Definition at line 425 of file dsp.cc.
References CheckCounter(), noiseRate, and noiseSample.
Referenced by Cycle().
void yaze::app::emu::audio::Dsp::HandleGain | ( | int | ch | ) |
Definition at line 306 of file dsp.cc.
References yaze::app::emu::audio::DspChannel::adsrRates, yaze::app::emu::audio::DspChannel::adsrState, channel, CheckCounter(), yaze::app::emu::audio::DspChannel::gain, yaze::app::emu::audio::DspChannel::gainSustainLevel, yaze::app::emu::audio::DspChannel::gainValue, yaze::app::emu::audio::DspChannel::preclampGain, yaze::app::emu::audio::DspChannel::sustainLevel, and yaze::app::emu::audio::DspChannel::useGain.
Referenced by CycleChannel().
bool yaze::app::emu::audio::Dsp::CheckCounter | ( | int | rate | ) |
Definition at line 164 of file dsp.cc.
References counter.
Referenced by HandleGain(), and HandleNoise().
void yaze::app::emu::audio::Dsp::DecodeBrr | ( | int | ch | ) |
Definition at line 383 of file dsp.cc.
References aram_, yaze::app::emu::audio::DspChannel::blockOffset, yaze::app::emu::audio::DspChannel::brrHeader, yaze::app::emu::audio::DspChannel::bufferOffset, channel, yaze::app::emu::audio::DspChannel::decodeBuffer, and yaze::app::emu::audio::DspChannel::decodeOffset.
Referenced by CycleChannel().
uint8_t yaze::app::emu::audio::Dsp::Read | ( | uint8_t | adr | ) |
Definition at line 432 of file dsp.cc.
References ram.
Referenced by yaze::app::emu::audio::Apu::Read().
void yaze::app::emu::audio::Dsp::Write | ( | uint8_t | adr, |
uint8_t | val ) |
Definition at line 434 of file dsp.cc.
References yaze::app::emu::audio::DspChannel::adsrRates, channel, yaze::app::emu::audio::DspChannel::directGain, dirPage, echoBufferAdr, echoDelay, yaze::app::emu::audio::DspChannel::echoEnable, echoVolumeL, echoVolumeR, echoWrites, feedbackVolume, firValues, yaze::app::emu::audio::DspChannel::gainMode, yaze::app::emu::audio::DspChannel::gainSustainLevel, yaze::app::emu::audio::DspChannel::gainValue, yaze::app::emu::audio::DspChannel::keyOff, yaze::app::emu::audio::DspChannel::keyOn, masterVolumeL, masterVolumeR, mute, noiseRate, yaze::app::emu::audio::DspChannel::pitch, yaze::app::emu::audio::DspChannel::pitchModulation, ram, reset, yaze::app::emu::audio::DspChannel::srcn, yaze::app::emu::audio::DspChannel::sustainLevel, yaze::app::emu::audio::DspChannel::useGain, yaze::app::emu::audio::DspChannel::useNoise, yaze::app::emu::audio::DspChannel::volumeL, and yaze::app::emu::audio::DspChannel::volumeR.
Referenced by yaze::app::emu::audio::Apu::Write().
int16_t yaze::app::emu::audio::Dsp::GetSample | ( | int | ch | ) |
Definition at line 369 of file dsp.cc.
References channel, yaze::app::emu::audio::DspChannel::decodeBuffer, and yaze::app::emu::audio::DspChannel::pitchCounter.
Referenced by CycleChannel().
void yaze::app::emu::audio::Dsp::GetSamples | ( | int16_t * | sample_data, |
int | samples_per_frame, | ||
bool | pal_timing ) |
Definition at line 621 of file dsp.cc.
References lastFrameBoundary, and sample_buffer_.
|
private |
Definition at line 114 of file dsp.h.
Referenced by GetSamples().
|
private |
Definition at line 117 of file dsp.h.
Referenced by CycleChannel(), DecodeBrr(), and HandleEcho().
|
private |
|
private |
Definition at line 122 of file dsp.h.
Referenced by CycleChannel(), DecodeBrr(), GetSample(), HandleGain(), Reset(), and Write().
|
private |
Definition at line 124 of file dsp.h.
Referenced by CheckCounter(), Cycle(), and Reset().
|
private |
Definition at line 125 of file dsp.h.
Referenced by CycleChannel(), Reset(), and Write().
|
private |
Definition at line 126 of file dsp.h.
Referenced by Cycle(), CycleChannel(), and Reset().
|
private |
|
private |
Definition at line 128 of file dsp.h.
Referenced by CycleChannel(), Reset(), and Write().
|
private |
Definition at line 129 of file dsp.h.
Referenced by HandleEcho(), Reset(), and Write().
|
private |
Definition at line 130 of file dsp.h.
Referenced by HandleEcho(), Reset(), and Write().
|
private |
Definition at line 132 of file dsp.h.
Referenced by Cycle(), CycleChannel(), HandleEcho(), and Reset().
|
private |
Definition at line 133 of file dsp.h.
Referenced by Cycle(), CycleChannel(), HandleEcho(), and Reset().
|
private |
Definition at line 134 of file dsp.h.
Referenced by Cycle(), CycleChannel(), HandleEcho(), and Reset().
|
private |
Definition at line 135 of file dsp.h.
Referenced by Cycle(), CycleChannel(), HandleEcho(), and Reset().
|
private |
Definition at line 137 of file dsp.h.
Referenced by CycleChannel(), HandleNoise(), and Reset().
|
private |
Definition at line 138 of file dsp.h.
Referenced by HandleNoise(), Reset(), and Write().
|
private |
Definition at line 140 of file dsp.h.
Referenced by HandleEcho(), Reset(), and Write().
|
private |
Definition at line 141 of file dsp.h.
Referenced by HandleEcho(), Reset(), and Write().
|
private |
Definition at line 142 of file dsp.h.
Referenced by HandleEcho(), Reset(), and Write().
|
private |
Definition at line 143 of file dsp.h.
Referenced by HandleEcho(), Reset(), and Write().
|
private |
Definition at line 144 of file dsp.h.
Referenced by HandleEcho(), Reset(), and Write().
|
private |
Definition at line 145 of file dsp.h.
Referenced by HandleEcho(), Reset(), and Write().
|
private |
Definition at line 146 of file dsp.h.
Referenced by HandleEcho(), and Reset().
|
private |
Definition at line 147 of file dsp.h.
Referenced by HandleEcho(), and Reset().
|
private |
Definition at line 148 of file dsp.h.
Referenced by HandleEcho(), and Reset().
|
private |
Definition at line 149 of file dsp.h.
Referenced by HandleEcho(), Reset(), and Write().
|
private |
Definition at line 150 of file dsp.h.
Referenced by HandleEcho(), and Reset().
|
private |
Definition at line 151 of file dsp.h.
Referenced by HandleEcho(), and Reset().
|
private |
|
private |
Definition at line 154 of file dsp.h.
Referenced by Cycle(), NewFrame(), and Reset().
|
private |
Definition at line 155 of file dsp.h.
Referenced by GetSamples(), and NewFrame().