VICE Noise

You need an actual VIC.

Moderator: Moderators

Post Reply
User avatar
JonBrawn
Vic 20 Devotee
Posts: 225
Joined: Sat Sep 11, 2021 10:47 pm
Website: http://youtube.com/@vicenary
Location: Austin TX USA
Occupation: CPU design engineer

VICE Noise

Post 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?)
Working on FPGA replacement for 6560/6561
https://youtube.com/@vicenary
User avatar
chysn
Vic 20 Scientist
Posts: 1205
Joined: Tue Oct 22, 2019 12:36 pm
Website: http://www.beigemaze.com
Location: Michigan, USA
Occupation: Software Dev Manager

Re: VICE Noise

Post 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.
VIC-20 Projects: wAx Assembler, TRBo: Turtle RescueBot, Helix Colony, Sub Med, Trolley Problem, Dungeon of Dance, ZEPTOPOLIS, MIDI KERNAL, The Archivist, Ed for Prophet-5

WIP: MIDIcast BASIC extension

he/him/his
nippur72
de Lagash
Posts: 574
Joined: Thu Sep 07, 2006 8:35 am

Re: VICE Noise

Post 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
Post Reply