Skip to content

Commit

Permalink
Merge pull request #5 from 5mdt/feature/fix-noise-loop
Browse files Browse the repository at this point in the history
[NoiseProcessor]: rewrote noise processor
  • Loading branch information
nett00n authored Nov 7, 2023
2 parents f9c4a4f + fcf39f6 commit 213587f
Show file tree
Hide file tree
Showing 4 changed files with 300 additions and 263 deletions.
45 changes: 45 additions & 0 deletions LICENSE.TLDR.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# The MIT License (MIT)

A short, permissive software license. Basically, you can do whatever you want as long as you include the original copyright and license notice in any copy of the software/source.

## Can

- Commercial Use
- Modify
- Distribute
- Sublicense
- Private Use

## Cannot

- Hold lible

## Must

- Include Copyright
- Include License

---

**Disclaimer:** This TL;DR summary is provided for convenience and informational
purposes only. It is not a substitute for the
[full text of the Apache License 2.0](LICENSE). The full license should be
consulted for a comprehensive understanding of your rights and obligations.
In the event of any discrepancies or legal questions, the full license text
takes precedence.

TL;DR for this licence was taken from
[TLDRLegal](https://www.tldrlegal.com/license/apache-license-2-0-apache-2-0)


---

**Disclaimer:** This TL;DR summary is provided for convenience and informational
purposes only. It is not a substitute for the
[full text of the License](LICENSE). The full license should be
consulted for a comprehensive understanding of your rights and obligations.
In the event of any discrepancies or legal questions, the full license text
takes precedence.

TL;DR for this licence was taken from
[TLDRLegal](https://www.tldrlegal.com/license/mit-license)
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

The 5mdt Noise Generator is a web-based application that generates different types of noises locally, including brown, white, and pink noise. It allows users to play these noises and control their volume.

There is no tracking, ads or even cookies here. It's absolutely free to use and modify
There is no tracking, ads or even cookies here. It's absolutely free to use and modify.

## Demo

Expand All @@ -33,10 +33,12 @@ To use the 5mdt Noise Generator, simply open the `index.html` file in a web brow

This project is licensed under the [MIT License](LICENSE).

## Authors
## Authors (alphabetically)

- [@nett00n](https://github.com/nett00n)
- [@akamenskiy](https://github.com/akamenskiy)
- [@kawaiier](https://github.com/kawaiier)
- [@nett00n](https://github.com/nett00n)

---

2023, Tbilisi, Sakartvelo
2023
78 changes: 78 additions & 0 deletions RandomNoiseProcessor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
const tempo = 30;
const types = {
pink: "pink",
brown: "brown",
white: "white",
}

function generateBrownNoise(buffer) {
let lastOut = 0.0;

for (let i = 0; i < buffer.length; i++) {
const whiteNoise = (Math.random() * 2 - 1) / tempo;
buffer[i] = (lastOut + (0.02 * whiteNoise)) / 1.02;
lastOut = buffer[i];
buffer[i] *= 3.5; // Amplify the sound
}
}

// Function to generate Pink noise
function generatePinkNoise(buffer) {
let b0 = 0;
let b1 = 0;
let b2 = 0;
let b3 = 0;
let b4 = 0;
let b5 = 0;
let b6 = 0;

for (let i = 0; i < buffer.length; i++) {
const whiteNoise = (Math.random() * 2 - 1) / tempo;
b0 = 0.99886 * b0 + whiteNoise * 0.0555179;
b1 = 0.99332 * b1 + whiteNoise * 0.0750759;
b2 = 0.96900 * b2 + whiteNoise * 0.1538520;
b3 = 0.86650 * b3 + whiteNoise * 0.3104856;
b4 = 0.55000 * b4 + whiteNoise * 0.5329522;
b5 = -0.7616 * b5 - whiteNoise * 0.0168980;
buffer[i] = b0 + b1 + b2 + b3 + b4 + b5 + b6 + whiteNoise * 0.5362;
buffer[i] *= 0.11; // Amplify the sound
b6 = whiteNoise * 0.115926;
}
}

// Function to generate White noise
function generateWhiteNoise(buffer) {

for (let i = 0; i < buffer.length; i++) {
buffer[i] = (Math.random() * 2 - 1) / tempo;
}
}


class RandomNoiseProcessor extends AudioWorkletProcessor {
constructor (options) {
super();
this.type = options.processorOptions.type;
};
process(inputs, outputs) {
const output = outputs[0];
output.forEach((channel) => {
switch (this.type) {
case types.brown:
generateBrownNoise(channel);
break;
case types.pink:
generatePinkNoise(channel);
break;
case types.white:
generateWhiteNoise(channel);
break;
default:
break;
}
});
return true;
}
}

registerProcessor("RandomNoiseProcessor", RandomNoiseProcessor);
Loading

0 comments on commit 213587f

Please sign in to comment.