Help with variable rate LFSR


#1

Having a bit of a logic fart on this, wondered if anyone can help.

I have a LFSR based pseudo random noise generator like so:

if ((inlet_trig > 0) && !(in0 > 0)) {
    bit0 = (lfsr >> 0) & 1;
    mod_bit = (lfsr >> mode) & 1; //  "Mode" 1 (noise) or 6 (93 or 31 step seq)
    lfsr = (lfsr >> 1) | ((bit0 ^ mod_bit) << 14);

    wave = (1<<26) - ((lfsr & 1) << 23);
    hold = wave >> 1;			
} 

in0 = inlet_trig;

outlet_out = hold // some bitshifting to right range;

Right now I'm clocking/holding it on the trig input (based on the factory S&H object but I want to clock and hold it by the srate divided by a period defined in an array (ie lookup based frequency control):

period_table[value]

Not having much luck though, not looking to have my homework done for me :slight_smile: but can anyone give me a hint?


#2

I worked it out, hopefully I learned something!