├── .gitignore ├── .travis.yml ├── @types └── index.d.ts ├── LICENSE ├── index.js ├── package.json ├── readme.md └── test.js /.gitignore: -------------------------------------------------------------------------------- 1 | //this will affect all the git repos 2 | git config --global core.excludesfile ~/.gitignore 3 | 4 | 5 | //update files since .ignore won't if already tracked 6 | git rm --cached 7 | 8 | # Compiled source # 9 | ################### 10 | *.com 11 | *.class 12 | *.dll 13 | *.exe 14 | *.o 15 | *.so 16 | 17 | # Packages # 18 | ############ 19 | # it's better to unpack these files and commit the raw source 20 | # git has its own built in compression methods 21 | *.7z 22 | *.dmg 23 | *.gz 24 | *.iso 25 | *.jar 26 | *.rar 27 | *.tar 28 | *.zip 29 | 30 | # Logs and databases # 31 | ###################### 32 | *.log 33 | *.sql 34 | *.sqlite 35 | 36 | # OS generated files # 37 | ###################### 38 | .DS_Store 39 | .DS_Store? 40 | ._* 41 | .Spotlight-V100 42 | .Trashes 43 | # Icon? 44 | ehthumbs.db 45 | Thumbs.db 46 | .cache 47 | .project 48 | .settings 49 | .tmproj 50 | *.esproj 51 | nbproject 52 | 53 | # Numerous always-ignore extensions # 54 | ##################################### 55 | *.diff 56 | *.err 57 | *.orig 58 | *.rej 59 | *.swn 60 | *.swo 61 | *.swp 62 | *.vi 63 | *~ 64 | *.sass-cache 65 | *.grunt 66 | *.tmp 67 | 68 | # Dreamweaver added files # 69 | ########################### 70 | _notes 71 | dwsync.xml 72 | 73 | # Komodo # 74 | ########################### 75 | *.komodoproject 76 | .komodotools 77 | 78 | # Node # 79 | ##################### 80 | node_modules 81 | 82 | # Bower # 83 | ##################### 84 | bower_components 85 | 86 | # Folders to ignore # 87 | ##################### 88 | .hg 89 | .svn 90 | .CVS 91 | intermediate 92 | publish 93 | .idea 94 | .graphics 95 | _test 96 | _archive 97 | uploads 98 | tmp 99 | 100 | # Vim files to ignore # 101 | ####################### 102 | .VimballRecord 103 | .netrwhist 104 | 105 | bundle.* 106 | 107 | _demo -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: node_js 3 | node_js: 4 | - 'node' 5 | - '6' 6 | - '5' 7 | - '4' 8 | -------------------------------------------------------------------------------- /@types/index.d.ts: -------------------------------------------------------------------------------- 1 | declare module 'audio-biquad' { 2 | interface myParamsInterface{ 3 | type:"bandpass"|"lowpass"|"highpass", 4 | frequency: number, 5 | Q: number, 6 | gain: number, 7 | } 8 | class Biquad { 9 | constructor(params:myParamsInterface); 10 | process(buffer:any); 11 | } 12 | export=Biquad; 13 | } 14 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | Copyright (c) 2018 Deema Yvanow 3 | 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 19 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 20 | OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE 21 | OR OTHER DEALINGS IN THE SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Biquad filter. 3 | * API is a somewhat copy of web-audio BiquadFilterNode. 4 | * 5 | * @module audio-biquad 6 | */ 7 | 8 | 'use strict'; 9 | 10 | var Through = require('audio-through'); 11 | var extend = require('xtend/mutable'); 12 | var inherits = require('inherits'); 13 | 14 | 15 | /** 16 | * Biquad class 17 | * 18 | * @constructor 19 | */ 20 | function Biquad (options) { 21 | if (!(this instanceof Biquad)) return new Biquad(options); 22 | 23 | Through.call(this, options); 24 | 25 | //init values for channels 26 | this.x1 = []; 27 | this.x2 = []; 28 | this.y1 = []; 29 | this.y2 = []; 30 | 31 | //init coefs 32 | this.update(); 33 | } 34 | 35 | inherits(Biquad, Through); 36 | 37 | 38 | /** 39 | * Basic filter params, defaults are the copy of web-audio. 40 | * Can be whether functions or constants. 41 | */ 42 | Biquad.prototype.frequency = 350; 43 | Biquad.prototype.detune = 0; 44 | Biquad.prototype.Q = 1; 45 | Biquad.prototype.gain = 0; 46 | 47 | 48 | /** 49 | * Type of filter: 50 | * lowpass 51 | * highpass 52 | * bandpass 53 | * lowshelf 54 | * highshelf 55 | * peaking 56 | * notch 57 | * allpass 58 | */ 59 | Biquad.prototype.type = 'lowpass'; 60 | 61 | 62 | /** Change filter param - should recalc coefs */ 63 | Biquad.prototype.update = function () { 64 | var method = 'set' + this.type[0].toUpperCase() + this.type.slice(1) + 'Params'; 65 | 66 | var time = this.count / this.format.sampleRate; 67 | 68 | var f = typeof this.frequency === 'function' ? this.frequency(time) : this.frequency; 69 | var nyquist = 0.5 * this.format.sampleRate; 70 | var normalizedFrequency = f / nyquist; 71 | var detune = typeof this.detune === 'function' ? this.detune(time) : this.detune; 72 | if (detune) { 73 | normalizedFrequency *= Math.pow(2, detune / 1200); 74 | } 75 | 76 | var gain = typeof this.gain === 'function' ? this.gain(time) : this.gain; 77 | var Q = typeof this.Q === 'function' ? this.Q(time) : this.Q; 78 | 79 | this[method](normalizedFrequency, Q, gain); 80 | }; 81 | 82 | 83 | /** 84 | * Processing function 85 | */ 86 | Biquad.prototype.process = function (buffer) { 87 | var self = this; 88 | 89 | //handle each channel 90 | for (var channel = 0, l = Math.min(buffer.numberOfChannels, self.format.channels); channel < l; channel++ ) { 91 | processChannel(channel, buffer.getChannelData(channel)); 92 | } 93 | 94 | function processChannel (channel, channelData) { 95 | //create local copies of member variables 96 | var x1 = self.x1[channel] || 0; 97 | var x2 = self.x2[channel] || 0; 98 | var y1 = self.y1[channel] || 0; 99 | var y2 = self.y2[channel] || 0; 100 | var b0 = self.b0; 101 | var b1 = self.b1; 102 | var b2 = self.b2; 103 | var a1 = self.a1; 104 | var a2 = self.a2; 105 | 106 | var x, y; 107 | 108 | for (var i = 0; i < channelData.length; i++) { 109 | x = channelData[i]; 110 | 111 | y = b0*x + b1*x1 + b2*x2 - a1*y1 - a2*y2; 112 | 113 | channelData[i] = y; 114 | 115 | // Update state variables 116 | x2 = x1; 117 | x1 = x; 118 | y2 = y1; 119 | y1 = y; 120 | } 121 | 122 | //save state 123 | self.x1[channel] = x1; 124 | self.x2[channel] = x2; 125 | self.y1[channel] = y1; 126 | self.y2[channel] = y2; 127 | } 128 | } 129 | 130 | 131 | module.exports = Biquad; 132 | 133 | 134 | /** 135 | * The code below is adapted copy-paste of chromium’s source 136 | * https://code.google.com/p/chromium/codesearch#chromium/src/third_party/WebKit/Source/platform/audio/Biquad.cpp 137 | */ 138 | 139 | Biquad.prototype.setNormalizedCoefficients = function (b0, b1, b2, a0, a1, a2) { 140 | var a0Inverse = 1 / a0; 141 | 142 | this.b0 = b0 * a0Inverse; 143 | this.b1 = b1 * a0Inverse; 144 | this.b2 = b2 * a0Inverse; 145 | this.a1 = a1 * a0Inverse; 146 | this.a2 = a2 * a0Inverse; 147 | } 148 | 149 | Biquad.prototype.setLowpassParams = function (cutoff, resonance) { 150 | // Limit cutoff to 0 to 1. 151 | cutoff = Math.max(0.0, Math.min(cutoff, 1.0)); 152 | 153 | if (cutoff == 1) { 154 | // When cutoff is 1, the z-transform is 1. 155 | this.setNormalizedCoefficients(1, 0, 0, 156 | 1, 0, 0); 157 | } else if (cutoff > 0) { 158 | // Compute biquad coefficients for lowpass filter 159 | resonance = Math.max(0.0, resonance); // can't go negative 160 | var g = Math.pow(10.0, 0.05 * resonance); 161 | var d = Math.sqrt((4 - Math.sqrt(16 - 16 / (g * g))) / 2); 162 | 163 | var theta = Math.PI * cutoff; 164 | var sn = 0.5 * d * Math.sin(theta); 165 | var beta = 0.5 * (1 - sn) / (1 + sn); 166 | var gamma = (0.5 + beta) * Math.cos(theta); 167 | var alpha = 0.25 * (0.5 + beta - gamma); 168 | 169 | var b0 = 2 * alpha; 170 | var b1 = 2 * 2 * alpha; 171 | var b2 = 2 * alpha; 172 | var a1 = 2 * -gamma; 173 | var a2 = 2 * beta; 174 | 175 | this.setNormalizedCoefficients(b0, b1, b2, 1, a1, a2); 176 | } else { 177 | // When cutoff is zero, nothing gets through the filter, so set 178 | // coefficients up correctly. 179 | this.setNormalizedCoefficients(0, 0, 0, 180 | 1, 0, 0); 181 | } 182 | } 183 | 184 | Biquad.prototype.setHighpassParams = function (cutoff, resonance) { 185 | // Limit cutoff to 0 to 1. 186 | cutoff = Math.max(0.0, Math.min(cutoff, 1.0)); 187 | 188 | if (cutoff == 1) { 189 | // The z-transform is 0. 190 | this.setNormalizedCoefficients(0, 0, 0, 191 | 1, 0, 0); 192 | } else if (cutoff > 0) { 193 | // Compute biquad coefficients for highpass filter 194 | resonance = Math.max(0.0, resonance); // can't go negative 195 | var g = Math.pow(10.0, 0.05 * resonance); 196 | var d = Math.sqrt((4 - Math.sqrt(16 - 16 / (g * g))) / 2); 197 | 198 | var theta = Math.PI * cutoff; 199 | var sn = 0.5 * d * Math.sin(theta); 200 | var beta = 0.5 * (1 - sn) / (1 + sn); 201 | var gamma = (0.5 + beta) * Math.cos(theta); 202 | var alpha = 0.25 * (0.5 + beta + gamma); 203 | 204 | var b0 = 2 * alpha; 205 | var b1 = 2 * -2 * alpha; 206 | var b2 = 2 * alpha; 207 | var a1 = 2 * -gamma; 208 | var a2 = 2 * beta; 209 | 210 | this.setNormalizedCoefficients(b0, b1, b2, 1, a1, a2); 211 | } else { 212 | // When cutoff is zero, we need to be careful because the above 213 | // gives a quadratic divided by the same quadratic, with poles 214 | // and zeros on the unit circle in the same place. When cutoff 215 | // is zero, the z-transform is 1. 216 | this.setNormalizedCoefficients(1, 0, 0, 217 | 1, 0, 0); 218 | } 219 | } 220 | 221 | Biquad.prototype.setLowShelfParams = function (frequency, Q, dbGain) { 222 | // Clip frequencies to between 0 and 1, inclusive. 223 | frequency = Math.max(0.0, Math.min(frequency, 1.0)); 224 | 225 | var A = Math.pow(10.0, dbGain / 40); 226 | 227 | if (frequency == 1) { 228 | // The z-transform is a constant gain. 229 | this.setNormalizedCoefficients(A * A, 0, 0, 230 | 1, 0, 0); 231 | } else if (frequency > 0) { 232 | var w0 = Math.PI * frequency; 233 | var S = 1; // filter slope (1 is max value) 234 | var alpha = 0.5 * Math.sin(w0) * Math.sqrt((A + 1 / A) * (1 / S - 1) + 2); 235 | var k = Math.cos(w0); 236 | var k2 = 2 * Math.sqrt(A) * alpha; 237 | var aPlusOne = A + 1; 238 | var aMinusOne = A - 1; 239 | 240 | var b0 = A * (aPlusOne - aMinusOne * k + k2); 241 | var b1 = 2 * A * (aMinusOne - aPlusOne * k); 242 | var b2 = A * (aPlusOne - aMinusOne * k - k2); 243 | var a0 = aPlusOne + aMinusOne * k + k2; 244 | var a1 = -2 * (aMinusOne + aPlusOne * k); 245 | var a2 = aPlusOne + aMinusOne * k - k2; 246 | 247 | this.setNormalizedCoefficients(b0, b1, b2, a0, a1, a2); 248 | } else { 249 | // When frequency is 0, the z-transform is 1. 250 | this.setNormalizedCoefficients(1, 0, 0, 251 | 1, 0, 0); 252 | } 253 | } 254 | 255 | Biquad.prototype.setHighShelfParams = function (frequency, Q, dbGain) { 256 | // Clip frequencies to between 0 and 1, inclusive. 257 | frequency = Math.max(0.0, Math.min(frequency, 1.0)); 258 | 259 | var A = Math.pow(10.0, dbGain / 40); 260 | 261 | if (frequency == 1) { 262 | // The z-transform is 1. 263 | this.setNormalizedCoefficients(1, 0, 0, 264 | 1, 0, 0); 265 | } else if (frequency > 0) { 266 | var w0 = Math.PI * frequency; 267 | var S = 1; // filter slope (1 is max value) 268 | var alpha = 0.5 * Math.sin(w0) * Math.sqrt((A + 1 / A) * (1 / S - 1) + 2); 269 | var k = Math.cos(w0); 270 | var k2 = 2 * Math.sqrt(A) * alpha; 271 | var aPlusOne = A + 1; 272 | var aMinusOne = A - 1; 273 | 274 | var b0 = A * (aPlusOne + aMinusOne * k + k2); 275 | var b1 = -2 * A * (aMinusOne + aPlusOne * k); 276 | var b2 = A * (aPlusOne + aMinusOne * k - k2); 277 | var a0 = aPlusOne - aMinusOne * k + k2; 278 | var a1 = 2 * (aMinusOne - aPlusOne * k); 279 | var a2 = aPlusOne - aMinusOne * k - k2; 280 | 281 | this.setNormalizedCoefficients(b0, b1, b2, a0, a1, a2); 282 | } else { 283 | // When frequency = 0, the filter is just a gain, A^2. 284 | this.setNormalizedCoefficients(A * A, 0, 0, 285 | 1, 0, 0); 286 | } 287 | } 288 | 289 | Biquad.prototype.setPeakingParams = function (frequency, Q, dbGain) { 290 | // Clip frequencies to between 0 and 1, inclusive. 291 | frequency = Math.max(0.0, Math.min(frequency, 1.0)); 292 | 293 | // Don't let Q go negative, which causes an unstable filter. 294 | Q = Math.max(0.0, Q); 295 | 296 | var A = Math.pow(10.0, dbGain / 40); 297 | 298 | if (frequency > 0 && frequency < 1) { 299 | if (Q > 0) { 300 | var w0 = Math.PI * frequency; 301 | var alpha = Math.sin(w0) / (2 * Q); 302 | var k = Math.cos(w0); 303 | 304 | var b0 = 1 + alpha * A; 305 | var b1 = -2 * k; 306 | var b2 = 1 - alpha * A; 307 | var a0 = 1 + alpha / A; 308 | var a1 = -2 * k; 309 | var a2 = 1 - alpha / A; 310 | 311 | this.setNormalizedCoefficients(b0, b1, b2, a0, a1, a2); 312 | } else { 313 | // When Q = 0, the above formulas have problems. If we look at 314 | // the z-transform, we can see that the limit as Q->0 is A^2, so 315 | // set the filter that way. 316 | this.setNormalizedCoefficients(A * A, 0, 0, 317 | 1, 0, 0); 318 | } 319 | } else { 320 | // When frequency is 0 or 1, the z-transform is 1. 321 | this.setNormalizedCoefficients(1, 0, 0, 322 | 1, 0, 0); 323 | } 324 | } 325 | 326 | Biquad.prototype.setAllpassParams = function (frequency, Q) { 327 | // Clip frequencies to between 0 and 1, inclusive. 328 | frequency = Math.max(0.0, Math.min(frequency, 1.0)); 329 | 330 | // Don't let Q go negative, which causes an unstable filter. 331 | Q = Math.max(0.0, Q); 332 | 333 | if (frequency > 0 && frequency < 1) { 334 | if (Q > 0) { 335 | var w0 = Math.PI * frequency; 336 | var alpha = Math.sin(w0) / (2 * Q); 337 | var k = Math.cos(w0); 338 | 339 | var b0 = 1 - alpha; 340 | var b1 = -2 * k; 341 | var b2 = 1 + alpha; 342 | var a0 = 1 + alpha; 343 | var a1 = -2 * k; 344 | var a2 = 1 - alpha; 345 | 346 | this.setNormalizedCoefficients(b0, b1, b2, a0, a1, a2); 347 | } else { 348 | // When Q = 0, the above formulas have problems. If we look at 349 | // the z-transform, we can see that the limit as Q->0 is -1, so 350 | // set the filter that way. 351 | this.setNormalizedCoefficients(-1, 0, 0, 352 | 1, 0, 0); 353 | } 354 | } else { 355 | // When frequency is 0 or 1, the z-transform is 1. 356 | this.setNormalizedCoefficients(1, 0, 0, 357 | 1, 0, 0); 358 | } 359 | } 360 | 361 | Biquad.prototype.setNotchParams = function (frequency, Q) { 362 | // Clip frequencies to between 0 and 1, inclusive. 363 | frequency = Math.max(0.0, Math.min(frequency, 1.0)); 364 | 365 | // Don't let Q go negative, which causes an unstable filter. 366 | Q = Math.max(0.0, Q); 367 | 368 | if (frequency > 0 && frequency < 1) { 369 | if (Q > 0) { 370 | var w0 = Math.PI * frequency; 371 | var alpha = Math.sin(w0) / (2 * Q); 372 | var k = Math.cos(w0); 373 | 374 | var b0 = 1; 375 | var b1 = -2 * k; 376 | var b2 = 1; 377 | var a0 = 1 + alpha; 378 | var a1 = -2 * k; 379 | var a2 = 1 - alpha; 380 | 381 | this.setNormalizedCoefficients(b0, b1, b2, a0, a1, a2); 382 | } else { 383 | // When Q = 0, the above formulas have problems. If we look at 384 | // the z-transform, we can see that the limit as Q->0 is 0, so 385 | // set the filter that way. 386 | this.setNormalizedCoefficients(0, 0, 0, 387 | 1, 0, 0); 388 | } 389 | } else { 390 | // When frequency is 0 or 1, the z-transform is 1. 391 | this.setNormalizedCoefficients(1, 0, 0, 392 | 1, 0, 0); 393 | } 394 | } 395 | 396 | Biquad.prototype.setBandpassParams = function (frequency, Q) { 397 | // No negative frequencies allowed. 398 | frequency = Math.max(0.0, frequency); 399 | 400 | // Don't let Q go negative, which causes an unstable filter. 401 | Q = Math.max(0.0, Q); 402 | 403 | if (frequency > 0 && frequency < 1) { 404 | var w0 = Math.PI * frequency; 405 | if (Q > 0) { 406 | var alpha = Math.sin(w0) / (2 * Q); 407 | var k = Math.cos(w0); 408 | 409 | var b0 = alpha; 410 | var b1 = 0; 411 | var b2 = -alpha; 412 | var a0 = 1 + alpha; 413 | var a1 = -2 * k; 414 | var a2 = 1 - alpha; 415 | 416 | this.setNormalizedCoefficients(b0, b1, b2, a0, a1, a2); 417 | } else { 418 | // When Q = 0, the above formulas have problems. If we look at 419 | // the z-transform, we can see that the limit as Q->0 is 1, so 420 | // set the filter that way. 421 | this.setNormalizedCoefficients(1, 0, 0, 422 | 1, 0, 0); 423 | } 424 | } else { 425 | // When the cutoff is zero, the z-transform approaches 0, if Q 426 | // > 0. When both Q and cutoff are zero, the z-transform is 427 | // pretty much undefined. What should we do in this case? 428 | // For now, just make the filter 0. When the cutoff is 1, the 429 | // z-transform also approaches 0. 430 | this.setNormalizedCoefficients(0, 0, 0, 431 | 1, 0, 0); 432 | } 433 | } 434 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "audio-biquad", 3 | "version": "1.1.3", 4 | "description": "Biquad filter for audio streams", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "node test" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "https://github.com/audiojs/audio-biquad" 12 | }, 13 | "keywords": [ 14 | "audio", 15 | "pcm", 16 | "stream", 17 | "sound", 18 | "biquad", 19 | "filter", 20 | "bandpass", 21 | "lowpass", 22 | "highpass", 23 | "lpf", 24 | "hpf", 25 | "bpf", 26 | "web-audio" 27 | ], 28 | "author": "Deema Yvanow ", 29 | "license": "MIT", 30 | "bugs": { 31 | "url": "https://github.com/audiojs/audio-biquad/issues" 32 | }, 33 | "homepage": "https://github.com/audiojs/audio-biquad", 34 | "devDependencies": { 35 | "audio-generator": "^2.0.2", 36 | "pcm-volume": "latest" 37 | }, 38 | "optionalDependencies": { 39 | "audio-speaker": "^1.2.1" 40 | }, 41 | "dependencies": { 42 | "audio-through": "^2.1.4", 43 | "inherits": "^2.0.1", 44 | "xtend": "^4.0.0" 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # audio-biquad [![Build Status](https://travis-ci.org/audiojs/audio-biquad.svg?branch=master)](https://travis-ci.org/audiojs/audio-biquad) [![stable](http://badges.github.io/stability-badges/dist/stable.svg)](http://github.com/badges/stability-badges) 2 | 3 | Biquad filter stream. API is similar to [BiquadFilterNode](https://developer.mozilla.org/en-US/docs/Web/API/BiquadFilterNode). 4 | 5 | [![npm install audio-biquad](https://nodei.co/npm/audio-biquad.png?mini=true)](https://npmjs.org/package/audio-biquad/) 6 | 7 | 8 | ```js 9 | var BiquadFilter = require('audio-biquad'); 10 | var Speaker = require('audio-speaker'); 11 | var Generator = require('audio-generator'); 12 | 13 | Generator(function () { 14 | return Math.random() * 2 - 1; 15 | }, { 16 | duration: 2 17 | }) 18 | .pipe(BiquadFilter({ 19 | type: 'bandpass', 20 | frequency: 440, 21 | Q: 100, 22 | gain: 25 23 | })) 24 | .pipe(Speaker()); 25 | ``` 26 | 27 | > [BiquadFilterNode](https://developer.mozilla.org/en-US/docs/Web/API/BiquadFilterNode) — all the options for the filters.
28 | > [BiquadFilterNode chromium source](https://code.google.com/p/chromium/codesearch#chromium/src/third_party/WebKit/Source/platform/audio/Biquad.cpp&rcl=1443871507&l=283) — source code inspiration.
29 | > [EQ Cookbook](http://www.musicdsp.org/files/Audio-EQ-Cookbook.txt) — description of all the kinds of filters.
30 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | var Generator = require('audio-generator'); 2 | var Speaker = require('audio-speaker'); 3 | var Volume = require('pcm-volume'); 4 | var Filter = require('./index'); 5 | 6 | 7 | Generator({ 8 | generate: function () { 9 | return [Math.random(), Math.random()]; 10 | }, 11 | duration: 2 12 | }) 13 | .pipe(Filter({ 14 | type: 'bandpass', 15 | Q: 1000, 16 | frequency: 440, 17 | gain: 100 18 | })) 19 | .pipe(Volume(100)) 20 | .pipe(Speaker()); 21 | 22 | 23 | setTimeout(function () {}, 2000); 24 | --------------------------------------------------------------------------------