VERA: Run noise generation in each channel update

This commit is contained in:
Natt Akuma 2022-06-27 19:37:45 +07:00
parent fc489239c2
commit e2449d91f1

View file

@ -20,8 +20,8 @@ void
psg_reset(struct VERA_PSG* psg)
{
memset(psg->channels, 0, sizeof(psg->channels));
psg->noiseState=1;
psg->noiseOut = 0;
psg->noiseState = 1;
}
void
@ -54,10 +54,14 @@ render(struct VERA_PSG* psg, int16_t *left, int16_t *right)
{
int l = 0;
int r = 0;
for (int i = 0; i < 16; i++) {
// In FPGA implementation, noise values are generated every system clock and
// the channel update is run sequentially. So, even if both two channels are
// fetching a noise value in the same sample, they should have different values
psg->noiseOut = ((psg->noiseOut << 1) | (psg->noiseState & 1)) & 63;
psg->noiseState = (psg->noiseState << 1) | (((psg->noiseState >> 1) ^ (psg->noiseState >> 2) ^ (psg->noiseState >> 4) ^ (psg->noiseState >> 15)) & 1);
for (int i = 0; i < 16; i++) {
struct VERAChannel *ch = &psg->channels[i];
unsigned new_phase = (ch->phase + ch->freq) & 0x1FFFF;