New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

noise-buffer

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

noise-buffer - npm Package Compare versions

Comparing version 1.0.1 to 2.0.0

43

index.js
// courtesy of http://noisehack.com/generate-noise-web-audio-api/
module.exports = function(length) {
module.exports = function(length, type) {
type = type || 'white';
var sampleRate = 44100;

@@ -7,8 +9,41 @@ var samples = length * sampleRate;

var noiseBuffer = context.createBuffer(1, samples, sampleRate);
var output = noiseBuffer.getChannelData(0);
var output = noiseBuffer.getChannelData(0);
for (var i = 0; i < samples; i++) {
output[i] = Math.random() * 2 - 1;
switch(type) {
case 'white':
// http://noisehack.com/generate-noise-web-audio-api/
for (var i = 0; i < samples; i++) {
output[i] = Math.random() * 2 - 1;
}
break;
case 'pink':
// just completely http://noisehack.com/generate-noise-web-audio-api/
var b0, b1, b2, b3, b4, b5, b6;
b0 = b1 = b2 = b3 = b4 = b5 = b6 = 0.0;
for (var i = 0; i < samples; i++) {
var white = Math.random() * 2 - 1;
b0 = 0.99886 * b0 + white * 0.0555179;
b1 = 0.99332 * b1 + white * 0.0750759;
b2 = 0.96900 * b2 + white * 0.1538520;
b3 = 0.86650 * b3 + white * 0.3104856;
b4 = 0.55000 * b4 + white * 0.5329522;
b5 = -0.7616 * b5 - white * 0.0168980;
output[i] = b0 + b1 + b2 + b3 + b4 + b5 + b6 + white * 0.5362;
output[i] *= 0.11; // (roughly) compensate for gain
b6 = white * 0.115926;
}
break;
case 'brown':
// just completely http://noisehack.com/generate-noise-web-audio-api/
var lastOut = 0.0;
for (var i = 0; i < samples; i++) {
var white = Math.random() * 2 - 1;
output[i] = (lastOut + (0.02 * white)) / 1.02;
lastOut = output[i];
output[i] *= 3.5; // (roughly) compensate for gain
}
break;
}
return noiseBuffer;
};

2

package.json
{
"name": "noise-buffer",
"version": "1.0.1",
"version": "2.0.0",
"description": "Generate `AudioBuffer`s of white noise.",

@@ -5,0 +5,0 @@ "repository": "github:itsjoesullivan/noise-buffer",

## NoiseBuffer
Generate `AudioBuffer`s of white noise.
Generate `AudioBuffer`s of noise.
Code taken from [NoiseHack.com](http://noisehack.com/generate-noise-web-audio-api/)
## Usage

@@ -12,4 +14,7 @@

var noise = NoiseBuffer(1); // One second of noise
var noise = NoiseBuffer(1); // One second of white noise
var noise = NoiseBuffer(1, 'pink'); // One second of pink noise
var noise = NoiseBuffer(1, 'brown'); // One second of brown noise
noise instanceof AudioBuffer // true
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc