Page 1 of 1

VICE Noise

Posted: Sun Nov 06, 2022 4:19 pm
by JonBrawn
Am I going mad?

I've been looking at the VICE vic20sound.c file for VICE 3.6.1, and I cannot for the life of me see how the LFSR for the noise channel ever changes from zero. The relevant code looks like this:

Code: Select all

if(j == 3) {
   int bit3  = (noise_LFSR >> 3) & 1;
   int bit12 = (noise_LFSR >> 12) & 1;
   int bit14 = (noise_LFSR >> 14) & 1;
   int bit15 = (noise_LFSR >> 15) & 1;
   int gate1 = bit3 ^ bit12;
   int gate2 = bit14 ^ bit15;
   int gate3 = (gate1 ^ gate2) ^ 1;
   int gate4 = (gate3 & enabled) ^ 1;
   noise_LFSR0_old = noise_LFSR & 1;
   noise_LFSR = (noise_LFSR << 1) | gate4;
}
If noise_LFSR starts off as $0000 then bits 3, 12, 14 and 15 will all be zero.
gate1 will be 0 ex-or 0, i.e. 0
gate 2 will be 0 ex-or 0, i.e. 0
gate 3 will be 0 ex-or 0 ex-or 1, i.e. 1
gate 4 will be (1 & 1) ex-or 1, i.e. 1 ex-or 1, i.e. 0
So gate 4, zero, will be shifted into the LFSR, so it remains zero forever.

What have I missed, or does the noise voice really not work on VICE 3.6.1? (Answer: yes it does work, how?)

Re: VICE Noise

Posted: Sun Nov 06, 2022 8:49 pm
by chysn
It looks like the value of enabled can vary in that for(i) loop, so your gate4 calculation result isn't necessarily always 0, see line 360:

Code: Select all

enabled = (snd.ch[j].reg & 128) >> 7;
I haven't looked at it super-closely, but it seems like that's where the variance from 0 might start.

Re: VICE Noise

Posted: Sun Aug 20, 2023 11:56 am
by nippur72
I'm a bit late to this post, but yes it's the enabled equal to zero that causes the first bit shifted in the LFSR. Note that once the LFSR<>0 it never gets 0 again but loops over the 65535 values (65536 less one).

Check out the following threads from where the current implementation in VICE comes from:

http://sleepingelephant.com/ipw-web/bul ... php?t=8733
http://sleepingelephant.com/ipw-web/bul ... php?t=9330