This is a small noise gen circuit I found right around when I started getting into noise in general and HNW in particular.
It gives a fairly good noise in full CCW setting on the pot, and a more digital sounding slightly throaty sound in CW.
I used to have a build of it in a plastic project box hooked straight into a Boss MetalZone, and then into a EQ pedal.
The code:
/**
TinyNoise
*/
// for noise generation
unsigned long int reg;
// pin setup
const int buzzerPin = 0;
const int buttonPin = 1;
const int potPin = 3;
// button controls
boolean noiseOn = false;
boolean stillPushed = false;
long lastUpdateTime = 0;
const long debounce = 200;
void setup() {
pinMode(buzzerPin, OUTPUT);
pinMode(buttonPin, INPUT);
// Arbitrary inital value; must not be zero
reg = 0x55aa55aaL; //The seed for the bitstream. It can be anything except 0.
}
void loop() {
// check for button pushed (on/off control)
boolean buttonPushed = (digitalRead(buttonPin) == LOW);
if (buttonPushed && millis() - lastUpdateTime > debounce) { // wait for noise to clear
noiseOn = !noiseOn;
lastUpdateTime = millis();
}
if (noiseOn) {
// check pot value (volume control)
int potValue = analogRead(potPin); // 0 to 1023
int frequency = map(potValue, 0, 1023, 0, 1000);
generateNoise(frequency);
}
}
void generateNoise(int frequency) {
unsigned long int newr;
unsigned char lobit;
unsigned char b31, b29, b25, b24;
// Extract four chosen bits from the 32-bit register
b31 = (reg & (1L << 31)) >> 31;
b29 = (reg & (1L << 29)) >> 29;
b25 = (reg & (1L << 25)) >> 25;
b24 = (reg & (1L << 24)) >> 24;
// EXOR the four bits together
lobit = b31 ^ b29 ^ b25 ^ b24;
// Shift and incorporate new bit at bit position 0
newr = (reg << 1) | lobit;
// Replace register with new value
reg = newr;
// Drive speaker pin from bit 0 of 'reg'
digitalWrite(buzzerPin, reg & 1);
// Delay (50) corresponds to 20kHz, but the actual frequency of updates
// will be lower, due to computation time and loop overhead
delayMicroseconds(frequency); // Changing this value changes the frequency.
}
