Files
ComSquare/sources/APU/DSP/Gauss.cpp
Melefo b0fb1e3351 new MemoryMap architecture
starting to working of voices and so on BRR, Envelopes, Gauss and Timers as they use each others
2021-02-04 00:06:39 +01:00

30 lines
915 B
C++

//
// Created by melefo on 2/3/21.
//
#include <algorithm>
#include <cstdint>
#include "DSP.hpp"
namespace ComSquare::APU::DSP
{
int32_t DSP::interpolate(const Voice &voice)
{
int32_t interpolated;
uint8_t offset = voice.gaussOffset >> 4;
int forward = 255 - offset;
int reverse = offset;
offset = (voice.sampleOffset + (voice.gaussOffset >> 12)) % 12;
interpolated = this->_gauss[forward] * voice.samples[offset++] >> 11;
offset %= 12;
interpolated += this->_gauss[forward + 256] * voice.samples[offset++] >> 11;
offset %= 12;
interpolated += this->_gauss[reverse + 256] * voice.samples[offset++] >> 11;
offset %= 12;
interpolated = static_cast<int16_t>(interpolated);
interpolated += this->_gauss[reverse] * voice.samples[offset] >> 11;
return std::clamp(interpolated, 0, 16) & ~1;
}
}