2015-10-10 02:16:12 +00:00
|
|
|
inline auto DSP::voiceOutput(Voice& v, bool channel) -> void {
|
2010-08-09 13:28:56 +00:00
|
|
|
//apply left/right volume
|
2015-10-10 02:16:12 +00:00
|
|
|
signed amp = (state._output * (int8)VREG(VOLL + channel)) >> 7;
|
2010-08-09 13:28:56 +00:00
|
|
|
|
|
|
|
//add to output total
|
2015-10-10 02:16:12 +00:00
|
|
|
state._mainOut[channel] += amp;
|
|
|
|
state._mainOut[channel] = sclamp<16>(state._mainOut[channel]);
|
2010-08-09 13:28:56 +00:00
|
|
|
|
|
|
|
//optionally add to echo total
|
2015-10-10 02:16:12 +00:00
|
|
|
if(state._eon & v.vbit) {
|
|
|
|
state._echoOut[channel] += amp;
|
|
|
|
state._echoOut[channel] = sclamp<16>(state._echoOut[channel]);
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-10 02:16:12 +00:00
|
|
|
auto DSP::voice1(Voice& v) -> void {
|
|
|
|
state._dirAddress = (state._dir << 8) + (state._srcn << 2);
|
|
|
|
state._srcn = VREG(SRCN);
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
|
|
|
|
2015-10-10 02:16:12 +00:00
|
|
|
auto DSP::voice2(Voice& v) -> void {
|
2010-08-09 13:28:56 +00:00
|
|
|
//read sample pointer (ignored if not needed)
|
2015-10-10 02:16:12 +00:00
|
|
|
uint16 addr = state._dirAddress;
|
|
|
|
if(!v.konDelay) addr += 2;
|
Update to v074r11 release.
byuu says:
Changelog:
- debugger compiles on all three profiles
- libsnes compiles on all three platforms (no API changes to libsnes)
- memory.cpp : namespace memory removed (wram -> cpu, apuram -> smp,
vram, oam, cgram -> ppu)
- sa1.cpp : namespace memory removed (SA-1 specific functions merged
inline to SA1::bus_read,write)
- GameBoy: added serial link support with interrupts and proper 8192hz
timing, but obviously it acts as if no other GB is connected to it
- GameBoy: added STAT OAM interrupt, and better STAT d1,d0 mode values
- UI: since Qt is dead, I've renamed the config files back to bsnes.cfg
and bsnes-geometry.cfg
- SA1: IRAM was not syncing to CPU on SA-1 side
- PPU/Accuracy and PPU/Performance needed Sprite oam renamed to Sprite
sprite; so that I could add uint8 oam[544]
- makes more sense anyway, OAM = object attribute memory, obj or
sprite are better names for Sprite rendering class
- more cleanup
2011-01-24 09:03:17 +00:00
|
|
|
uint8 lo = smp.apuram[(uint16)(addr + 0)];
|
|
|
|
uint8 hi = smp.apuram[(uint16)(addr + 1)];
|
2015-10-10 02:16:12 +00:00
|
|
|
state._brrNextAddress = ((hi << 8) + lo);
|
2010-08-09 13:28:56 +00:00
|
|
|
|
2015-10-10 02:16:12 +00:00
|
|
|
state._adsr0 = VREG(ADSR0);
|
2010-08-09 13:28:56 +00:00
|
|
|
|
|
|
|
//read pitch, spread over two clocks
|
2015-10-10 02:16:12 +00:00
|
|
|
state._pitch = VREG(PITCHL);
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
|
|
|
|
2015-10-10 02:16:12 +00:00
|
|
|
auto DSP::voice3(Voice& v) -> void {
|
|
|
|
voice3a(v);
|
|
|
|
voice3b(v);
|
|
|
|
voice3c(v);
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
|
|
|
|
2015-10-10 02:16:12 +00:00
|
|
|
auto DSP::voice3a(Voice& v) -> void {
|
|
|
|
state._pitch += (VREG(PITCHH) & 0x3f) << 8;
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
|
|
|
|
2015-10-10 02:16:12 +00:00
|
|
|
auto DSP::voice3b(Voice& v) -> void {
|
|
|
|
state._brrByte = smp.apuram[(uint16)(v.brrAddress + v.brrOffset)];
|
|
|
|
state._brrHeader = smp.apuram[(uint16)(v.brrAddress)];
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
|
|
|
|
2015-10-10 02:16:12 +00:00
|
|
|
auto DSP::voice3c(Voice& v) -> void {
|
2010-08-09 13:28:56 +00:00
|
|
|
//pitch modulation using previous voice's output
|
|
|
|
|
2015-10-10 02:16:12 +00:00
|
|
|
if(state._pmon & v.vbit) {
|
|
|
|
state._pitch += ((state._output >> 5) * state._pitch) >> 10;
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
|
|
|
|
2015-10-10 02:16:12 +00:00
|
|
|
if(v.konDelay) {
|
2010-08-09 13:28:56 +00:00
|
|
|
//get ready to start BRR decoding on next sample
|
2015-10-10 02:16:12 +00:00
|
|
|
if(v.konDelay == 5) {
|
|
|
|
v.brrAddress = state._brrNextAddress;
|
|
|
|
v.brrOffset = 1;
|
|
|
|
v.bufferOffset = 0;
|
|
|
|
state._brrHeader = 0; //header is ignored on this sample
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//envelope is never run during KON
|
2015-10-10 02:16:12 +00:00
|
|
|
v.envelope = 0;
|
|
|
|
v.hiddenEnvelope = 0;
|
2010-08-09 13:28:56 +00:00
|
|
|
|
|
|
|
//disable BRR decoding until last three samples
|
2015-10-10 02:16:12 +00:00
|
|
|
v.gaussianOffset = 0;
|
|
|
|
v.konDelay--;
|
|
|
|
if(v.konDelay & 3) v.gaussianOffset = 0x4000;
|
2010-08-09 13:28:56 +00:00
|
|
|
|
|
|
|
//pitch is never added during KON
|
2015-10-10 02:16:12 +00:00
|
|
|
state._pitch = 0;
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//gaussian interpolation
|
2015-10-10 02:16:12 +00:00
|
|
|
signed output = gaussianInterpolate(v);
|
2010-08-09 13:28:56 +00:00
|
|
|
|
|
|
|
//noise
|
2015-10-10 02:16:12 +00:00
|
|
|
if(state._non & v.vbit) {
|
2010-08-09 13:28:56 +00:00
|
|
|
output = (int16)(state.noise << 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
//apply envelope
|
2015-10-10 02:16:12 +00:00
|
|
|
state._output = ((output * v.envelope) >> 11) & ~1;
|
|
|
|
v._envxOut = v.envelope >> 4;
|
2010-08-09 13:28:56 +00:00
|
|
|
|
|
|
|
//immediate silence due to end of sample or soft reset
|
2015-10-10 02:16:12 +00:00
|
|
|
if(REG(FLG) & 0x80 || (state._brrHeader & 3) == 1) {
|
|
|
|
v.envelopeMode = EnvelopeRelease;
|
|
|
|
v.envelope = 0;
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
|
|
|
|
2015-10-10 02:16:12 +00:00
|
|
|
if(state.everyOtherSample) {
|
2010-08-09 13:28:56 +00:00
|
|
|
//KOFF
|
2015-10-10 02:16:12 +00:00
|
|
|
if(state._koff & v.vbit) {
|
|
|
|
v.envelopeMode = EnvelopeRelease;
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//KON
|
|
|
|
if(state.kon & v.vbit) {
|
2015-10-10 02:16:12 +00:00
|
|
|
v.konDelay = 5;
|
|
|
|
v.envelopeMode = EnvelopeAttack;
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//run envelope for next sample
|
2015-10-10 02:16:12 +00:00
|
|
|
if(!v.konDelay) envelopeRun(v);
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
|
|
|
|
2015-10-10 02:16:12 +00:00
|
|
|
auto DSP::voice4(Voice& v) -> void {
|
2010-08-09 13:28:56 +00:00
|
|
|
//decode BRR
|
2015-10-10 02:16:12 +00:00
|
|
|
state._looped = 0;
|
|
|
|
if(v.gaussianOffset >= 0x4000) {
|
|
|
|
brrDecode(v);
|
|
|
|
v.brrOffset += 2;
|
|
|
|
if(v.brrOffset >= 9) {
|
2010-08-09 13:28:56 +00:00
|
|
|
//start decoding next BRR block
|
2015-10-10 02:16:12 +00:00
|
|
|
v.brrAddress = (uint16)(v.brrAddress + 9);
|
|
|
|
if(state._brrHeader & 1) {
|
|
|
|
v.brrAddress = state._brrNextAddress;
|
|
|
|
state._looped = v.vbit;
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
2015-10-10 02:16:12 +00:00
|
|
|
v.brrOffset = 1;
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//apply pitch
|
2015-10-10 02:16:12 +00:00
|
|
|
v.gaussianOffset = (v.gaussianOffset & 0x3fff) + state._pitch;
|
2010-08-09 13:28:56 +00:00
|
|
|
|
|
|
|
//keep from getting too far ahead (when using pitch modulation)
|
2015-10-10 02:16:12 +00:00
|
|
|
if(v.gaussianOffset > 0x7fff) v.gaussianOffset = 0x7fff;
|
2010-08-09 13:28:56 +00:00
|
|
|
|
|
|
|
//output left
|
2015-10-10 02:16:12 +00:00
|
|
|
voiceOutput(v, 0);
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
|
|
|
|
2015-10-10 02:16:12 +00:00
|
|
|
auto DSP::voice5(Voice& v) -> void {
|
2010-08-09 13:28:56 +00:00
|
|
|
//output right
|
2015-10-10 02:16:12 +00:00
|
|
|
voiceOutput(v, 1);
|
2010-08-09 13:28:56 +00:00
|
|
|
|
|
|
|
//ENDX, OUTX and ENVX won't update if you wrote to them 1-2 clocks earlier
|
2015-10-10 02:16:12 +00:00
|
|
|
state.endxBuffer = REG(ENDX) | state._looped;
|
2010-08-09 13:28:56 +00:00
|
|
|
|
|
|
|
//clear bit in ENDX if KON just began
|
2015-10-10 02:16:12 +00:00
|
|
|
if(v.konDelay == 5) state.endxBuffer &= ~v.vbit;
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
|
|
|
|
2015-10-10 02:16:12 +00:00
|
|
|
auto DSP::voice6(Voice& v) -> void {
|
|
|
|
state.outxBuffer = state._output >> 8;
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
|
|
|
|
2015-10-10 02:16:12 +00:00
|
|
|
auto DSP::voice7(Voice& v) -> void {
|
2010-08-09 13:28:56 +00:00
|
|
|
//update ENDX
|
2015-10-10 02:16:12 +00:00
|
|
|
REG(ENDX) = (uint8)state.endxBuffer;
|
|
|
|
state.envxBuffer = v._envxOut;
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
|
|
|
|
2015-10-10 02:16:12 +00:00
|
|
|
auto DSP::voice8(Voice& v) -> void {
|
2010-08-09 13:28:56 +00:00
|
|
|
//update OUTX
|
2015-10-10 02:16:12 +00:00
|
|
|
VREG(OUTX) = (uint8)state.outxBuffer;
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
|
|
|
|
2015-10-10 02:16:12 +00:00
|
|
|
auto DSP::voice9(Voice& v) -> void {
|
2010-08-09 13:28:56 +00:00
|
|
|
//update ENVX
|
2015-10-10 02:16:12 +00:00
|
|
|
VREG(ENVX) = (uint8)state.envxBuffer;
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|