<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Noise Generator based on LFSR (Linear Feedback Shift Register)]]></title><description><![CDATA[<p>I am working on a Noise Generator that uses the Linear Feedback Shift Register algorithm, but I am stuck. LFSR was used for the Noise channel in the NES and GameBoy, and that's the sound I am going for. LFSR generates a pseudorandom sequence through bit shift. The feedback loop works like this:</p>
<p>You start with a fixed-length register as the seed (I am using 15 bits in the example). And then, every time the LSFR is triggered, it does the following:</p>
<p>XOR bits 0 and 1 (the two right-most bits in the sequence)<br />
Right-shift the sequence (It's now 1 bit shorter)<br />
Put the XOR result into the empty last bit (the left-most bit)</p>
<p>I got it to work in Message Land with no problem:<br />
[Left: verbose version - Right: condensed version]<br />
<img src="/uploads/files/1780352534275-lfsr_message.png" alt="lfsr_message.png" class="img-responsive img-markdown" /></p>
<p>But I am stuck trying to move this to signal, mostly because I don't fully understand fexpr~:<br />
I guess I should use fexpr~ since I am using feedback here? Also because every bit in the sequence corresponds to a sample and I need to look up earlier samples to generate the next step (Again, guessing). I am also unsure about the difference between $x and $y. I am guessing I would have to use $y too for this, not just $x. But how do I send an output back as an input, to keep the loop running?</p>
<p>Here's an attempt at converting the above message version to signal, but it obviously doesn't work (I stubbornly tried to connect the right-most outlet to the left-most inlet but that gives a DSP Loop Error of course):<br />
<img src="/uploads/files/1780353605179-lfsr_sig.png" alt="lfsr_sig.png" class="img-responsive img-markdown" /><br />
I would also like to be able to control the clock speed for this, but that would probably just be with sample and hold once the main part is done.</p>
<p>Here's the patch so far:<br />
<a href="/uploads/files/1780351543908-lfsr_expr_stuck.pd">lfsr_expr_stuck.pd</a></p>
<p>Thanks for having a look!</p>
<p>And here are the websites I used as sources if anyone is interested:<br />
<a href="https://gbadev.net/gbadoc/audio/sound4.html" rel="nofollow">https://gbadev.net/gbadoc/audio/sound4.html</a><br />
<a href="https://gbdev.gg8.se/wiki/articles/Gameboy_sound_hardware" rel="nofollow">https://gbdev.gg8.se/wiki/articles/Gameboy_sound_hardware</a><br />
<a href="https://www.mjsyts.com/development/lfsr-noise-part-1/" rel="nofollow">https://www.mjsyts.com/development/lfsr-noise-part-1/</a></p>
]]></description><link>http://forum.pdpatchrepo.info/topic/15902/noise-generator-based-on-lfsr-linear-feedback-shift-register</link><generator>RSS for Node</generator><lastBuildDate>Tue, 02 Jun 2026 16:04:53 GMT</lastBuildDate><atom:link href="http://forum.pdpatchrepo.info/topic/15902.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 01 Jun 2026 22:48:16 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Noise Generator based on LFSR (Linear Feedback Shift Register) on Mon, 01 Jun 2026 22:48:16 GMT]]></title><description><![CDATA[<p>I am working on a Noise Generator that uses the Linear Feedback Shift Register algorithm, but I am stuck. LFSR was used for the Noise channel in the NES and GameBoy, and that's the sound I am going for. LFSR generates a pseudorandom sequence through bit shift. The feedback loop works like this:</p>
<p>You start with a fixed-length register as the seed (I am using 15 bits in the example). And then, every time the LSFR is triggered, it does the following:</p>
<p>XOR bits 0 and 1 (the two right-most bits in the sequence)<br />
Right-shift the sequence (It's now 1 bit shorter)<br />
Put the XOR result into the empty last bit (the left-most bit)</p>
<p>I got it to work in Message Land with no problem:<br />
[Left: verbose version - Right: condensed version]<br />
<img src="/uploads/files/1780352534275-lfsr_message.png" alt="lfsr_message.png" class="img-responsive img-markdown" /></p>
<p>But I am stuck trying to move this to signal, mostly because I don't fully understand fexpr~:<br />
I guess I should use fexpr~ since I am using feedback here? Also because every bit in the sequence corresponds to a sample and I need to look up earlier samples to generate the next step (Again, guessing). I am also unsure about the difference between $x and $y. I am guessing I would have to use $y too for this, not just $x. But how do I send an output back as an input, to keep the loop running?</p>
<p>Here's an attempt at converting the above message version to signal, but it obviously doesn't work (I stubbornly tried to connect the right-most outlet to the left-most inlet but that gives a DSP Loop Error of course):<br />
<img src="/uploads/files/1780353605179-lfsr_sig.png" alt="lfsr_sig.png" class="img-responsive img-markdown" /><br />
I would also like to be able to control the clock speed for this, but that would probably just be with sample and hold once the main part is done.</p>
<p>Here's the patch so far:<br />
<a href="/uploads/files/1780351543908-lfsr_expr_stuck.pd">lfsr_expr_stuck.pd</a></p>
<p>Thanks for having a look!</p>
<p>And here are the websites I used as sources if anyone is interested:<br />
<a href="https://gbadev.net/gbadoc/audio/sound4.html" rel="nofollow">https://gbadev.net/gbadoc/audio/sound4.html</a><br />
<a href="https://gbdev.gg8.se/wiki/articles/Gameboy_sound_hardware" rel="nofollow">https://gbdev.gg8.se/wiki/articles/Gameboy_sound_hardware</a><br />
<a href="https://www.mjsyts.com/development/lfsr-noise-part-1/" rel="nofollow">https://www.mjsyts.com/development/lfsr-noise-part-1/</a></p>
]]></description><link>http://forum.pdpatchrepo.info/topic/15902/noise-generator-based-on-lfsr-linear-feedback-shift-register</link><guid isPermaLink="true">http://forum.pdpatchrepo.info/topic/15902/noise-generator-based-on-lfsr-linear-feedback-shift-register</guid><dc:creator><![CDATA[Ice-Ice]]></dc:creator><pubDate>Mon, 01 Jun 2026 22:48:16 GMT</pubDate></item><item><title><![CDATA[Reply to Noise Generator based on LFSR (Linear Feedback Shift Register) on Tue, 02 Jun 2026 06:12:07 GMT]]></title><description><![CDATA[<p>If you want to feed your signal back to the same object, you must use a [s~]/[r~] pair, otherwise Pd will correctly complain about a DSP loop. Also, I don't see any real reason for using [fexpr~], as you only reference the current sample of the input with <code>x1[0]</code>. If you did something like <code>x1[-1]</code> to reference the last sample. it would make sense, but the way you wrote this, [expr~] with $v1 should suffice.</p>
]]></description><link>http://forum.pdpatchrepo.info/topic/15902/noise-generator-based-on-lfsr-linear-feedback-shift-register/2</link><guid isPermaLink="true">http://forum.pdpatchrepo.info/topic/15902/noise-generator-based-on-lfsr-linear-feedback-shift-register/2</guid><dc:creator><![CDATA[alexandros]]></dc:creator><pubDate>Tue, 02 Jun 2026 06:12:07 GMT</pubDate></item><item><title><![CDATA[Reply to Noise Generator based on LFSR (Linear Feedback Shift Register) on Tue, 02 Jun 2026 12:59:57 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-a" href="http://forum.pdpatchrepo.info/user/ice-ice">@Ice-Ice</a> Ha! I went down this same rabbit hole but I was thinking about the TR-909<br />
<a href="https://electricdruid.net/tr-909-noise-generator/" rel="nofollow">https://electricdruid.net/tr-909-noise-generator/</a><br />
and I didn't use fexpr~ or expr~. The algorithm definitely requires feedback.<br />
<a href="/uploads/files/1780396330815-tr909-lfsr.zip">TR909 LFSR.zip</a><br />
It might not be the most efficient way, but I like how the patch looks like the circuit.</p>
<p>Edit: Thanks for the fun problem. I tried to make the example in the last link you posted using [fexpr~], see what you think.<br />
<a href="/uploads/files/1780403938760-srnoisefexpr.pd">srNoiseFexpr~.pd</a>  (use [metro~] from the zipfile I uploaded earlier)</p>
<p><img src="/uploads/files/1780403996864-screenshot-2026-06-02-083707.png" alt="Screenshot 2026-06-02 083707.png" class="img-responsive img-markdown" /><br />
Edit 2: Hmm, there might be something wrong with the expression for the first outlet of fexpr~. See how it references the last value of the 2nd outlet? I don't think that value is calculated yet, and so it's using 1 sample old data. Maybe I should've xor'd the 2 bits that are 1 bit to the left?</p>
]]></description><link>http://forum.pdpatchrepo.info/topic/15902/noise-generator-based-on-lfsr-linear-feedback-shift-register/3</link><guid isPermaLink="true">http://forum.pdpatchrepo.info/topic/15902/noise-generator-based-on-lfsr-linear-feedback-shift-register/3</guid><dc:creator><![CDATA[jameslo]]></dc:creator><pubDate>Tue, 02 Jun 2026 12:59:57 GMT</pubDate></item><item><title><![CDATA[Reply to Noise Generator based on LFSR (Linear Feedback Shift Register) on Tue, 02 Jun 2026 14:50:14 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-a" href="http://forum.pdpatchrepo.info/user/jameslo">@jameslo</a> Thanks a lot! I really appreciate your help. I have spent quite some time now looking at your initial 909 version (always takes me a bit to understand code written by someone else). I like the approach you're taking in the [shiftReg16~] abstraction, this makes all the taps accessible which gives some flexible routing possibilities for trying different combinations.</p>
<p>Now I'm looking at your edit. I think I am finally understanding how $x and $y are related! So $x and a $y of the same number are the respective input and output of the samples in one block of a discrete &quot;stream&quot;, and then $x2 creates a new, separate stream of samples and so on (stream might not be proper terminology). So now I also understand why the fexpr~ version doesn't need a block size of 1 (which your 909 version requires).<br />
And I can see what you mean by using 1 sample old data, it would indeed be the case. It does sound right to me when I listen to it though, but then, my hearing isn't sample-accurate <img class="emoji emoji-extended" src="http://forum.pdpatchrepo.info/plugins/nodebb-plugin-emoji-extended/images/wink.png" title=";)" alt=";)" /> Thanks for this, I've come a bit closer to understanding fexpr~ now through your help, never used fexpr~ before.</p>
<p><a class="plugin-mentions-a" href="http://forum.pdpatchrepo.info/user/alexandros">@alexandros</a> I understand what you mean, it was a naive attempt at porting from the message version to a signal version. I think I will try an expr~ version to see if I can make it work, thanks for your input.</p>
]]></description><link>http://forum.pdpatchrepo.info/topic/15902/noise-generator-based-on-lfsr-linear-feedback-shift-register/4</link><guid isPermaLink="true">http://forum.pdpatchrepo.info/topic/15902/noise-generator-based-on-lfsr-linear-feedback-shift-register/4</guid><dc:creator><![CDATA[Ice-Ice]]></dc:creator><pubDate>Tue, 02 Jun 2026 14:50:14 GMT</pubDate></item></channel></rss>