I’m working on creating a Ricoh 2a03/GameBoy DMG noise channel that’s faithful to the original and I’ve seen lots of attempts at this where someone basically packs some random numbers into a wavetable or someone downsamples/bitcrushes white noise but this isn’t what I’m after and I’m trying to figure out a few matters mostly related to the use of logic in SC that I don’t really understand.

Here’s a brief overview of how the noise channel works:

It’s a 15 bit LFSR that always starts with a value of 1 and uses a seeded random to populate each initial bit.

A timing pulse set to one of a particular set of frequencies drives the LFSR. When a pulse is received the following happens:

Bit 0 is output as a signal (if the amplitude envelope is open).

Bits 1 and 0 are XOR’d and the value of the XOR is the new value to continue the sequence.

If the noise channel is in “width mode”, the sequence is 7 bits rather than 15.

What I have so far:

I am starting with an array of the integer 1 because the sequence always starts with 1 and am concatenating this array with a seeded random that generates a 14 bit sequence of the integers 1 or 0.

For the sake of efficiency, I want to store the original array as a variable and have the LFSR process iterate over a new array with the initial state being the the original array.

Then I would store the value of the output bit in a new array (the signal array) to be converted to a wavetable (then offset by -0.5 for DC correction).

In order to create the signal array, I would have to create a process where each new iteration of the LFSR process is compared to the original array and then if they are the same (because the result of the XOR would yield a repeating pattern), stop adding new points, set the size of the signal array to the number of iterations needed for the sequence to repeat for that particular seed, and then fill the array with each of the output bit values.

I assume I would need to use a routine or loop to make this happen, but the documentation is confusing when it comes to logic. Can I do an XOR on 1 and 0 integers? I suppose I could set up something like shift everything right and

“if index 0 + index 1 = 1, index 15 is 1, else index 15 is 0”

And is there a way to basically make a conditional loop that makes the LFSR run through the steps until

array a == array b

then extract the number of iterations and stop the routine? I do not understand the documentation on stopping a routine/loop unless you know in advance how long you want it to run for. And the documentation under control structures seems to conflict other documentation on using these in SC.

Thanks in advance!