-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbiquad-filter.umd.js
224 lines (195 loc) · 22.7 KB
/
biquad-filter.umd.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.BiquadFilter = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
module.exports = require('./dist/biquad-filter');
},{"./dist/biquad-filter":2}],2:[function(require,module,exports){
/**
* @fileoverview Biquad Filter library
* @author Arnau.Julia <Arnau.Julia@gmail.com>
* @version 0.1.0
*/
/**
* @class BiquadFilter
* @public
*/
"use strict";
var _createClass = require("babel-runtime/helpers/create-class")["default"];
var _classCallCheck = require("babel-runtime/helpers/class-call-check")["default"];
Object.defineProperty(exports, "__esModule", {
value: true
});
var BiquadFilter = (function () {
function BiquadFilter() {
_classCallCheck(this, BiquadFilter);
this.coefficients = [];
this.numberOfCascade = 1;
this.resetMemories();
}
/**
* Set biquad filter coefficients
* @public
* @param coef Array of biquad coefficients in the following order: gain, firstBiquad b1, firstBiquad b2, firstBiquad a1, firstBiquad a2, secondBiquad b1, secondBIquad b2, etc.
*/
_createClass(BiquadFilter, [{
key: "setCoefficients",
value: function setCoefficients(coef) {
if (coef) {
// If there is not a number of biquads, we consider that there is only 1 biquad.
this.numberOfCascade = this.getNumberOfCascadeFilters(coef);
// Reset coefficients
this.coefficients = [];
// Global gain
this.coefficients.g = coef[0];
for (var i = 0; i < this.numberOfCascade; i++) {
// Four coefficients for each biquad
this.coefficients[i] = {
b1: coef[1 + i * 4],
b2: coef[2 + i * 4],
a1: coef[3 + i * 4],
a2: coef[4 + i * 4]
};
}
// Need to reset the memories after change the coefficients
this.resetMemories();
return true;
} else {
throw new Error("No coefficients are set");
}
}
/**
* Get the number of cascade filters from the list of coefficients
* @private
*/
}, {
key: "getNumberOfCascadeFilters",
value: function getNumberOfCascadeFilters(coef) {
return (coef.length - 1) / 4;
}
/**
* Reset memories of biquad filters.
* @public
*/
}, {
key: "resetMemories",
value: function resetMemories() {
this.memories = [{
xi1: 0,
xi2: 0,
yi1: 0,
yi2: 0
}];
// see http://stackoverflow.com/a/19892144
for (var i = 1; i < this.numberOfCascade; i++) {
this.memories[i] = {
yi1: 0,
yi2: 0
};
}
}
/**
* Calculate the output of the cascade of biquad filters for an inputBuffer.
* @public
* @param inputBuffer Array of the same length of outputBuffer
* @param outputBuffer Array of the same length of inputBuffer
*/
}, {
key: "process",
value: function process(inputBuffer, outputBuffer) {
var x;
var y = [];
var b1, b2, a1, a2;
var xi1, xi2, yi1, yi2, y1i1, y1i2;
for (var i = 0; i < inputBuffer.length; i++) {
x = inputBuffer[i];
// Save coefficients in local variables
b1 = this.coefficients[0].b1;
b2 = this.coefficients[0].b2;
a1 = this.coefficients[0].a1;
a2 = this.coefficients[0].a2;
// Save memories in local variables
xi1 = this.memories[0].xi1;
xi2 = this.memories[0].xi2;
yi1 = this.memories[0].yi1;
yi2 = this.memories[0].yi2;
// Formula: y[n] = x[n] + b1*x[n-1] + b2*x[n-2] - a1*y[n-1] - a2*y[n-2]
// First biquad
y[0] = x + b1 * xi1 + b2 * xi2 - a1 * yi1 - a2 * yi2;
for (var e = 1; e < this.numberOfCascade; e++) {
// Save coefficients in local variables
b1 = this.coefficients[e].b1;
b2 = this.coefficients[e].b2;
a1 = this.coefficients[e].a1;
a2 = this.coefficients[e].a2;
// Save memories in local variables
y1i1 = this.memories[e - 1].yi1;
y1i2 = this.memories[e - 1].yi2;
yi1 = this.memories[e].yi1;
yi2 = this.memories[e].yi2;
y[e] = y[e - 1] + b1 * y1i1 + b2 * y1i2 - a1 * yi1 - a2 * yi2;
}
// Write the output
outputBuffer[i] = y[this.numberOfCascade - 1] * this.coefficients.g;
// Update the memories
this.memories[0].xi2 = this.memories[0].xi1;
this.memories[0].xi1 = x;
for (var p = 0; p < this.numberOfCascade; p++) {
this.memories[p].yi2 = this.memories[p].yi1;
this.memories[p].yi1 = y[p];
}
}
}
}]);
return BiquadFilter;
})();
exports["default"] = BiquadFilter;
module.exports = exports["default"];
},{"babel-runtime/helpers/class-call-check":4,"babel-runtime/helpers/create-class":5}],3:[function(require,module,exports){
module.exports = { "default": require("core-js/library/fn/object/define-property"), __esModule: true };
},{"core-js/library/fn/object/define-property":6}],4:[function(require,module,exports){
"use strict";
exports["default"] = function (instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
};
exports.__esModule = true;
},{}],5:[function(require,module,exports){
"use strict";
var _Object$defineProperty = require("babel-runtime/core-js/object/define-property")["default"];
exports["default"] = (function () {
function defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
_Object$defineProperty(target, descriptor.key, descriptor);
}
}
return function (Constructor, protoProps, staticProps) {
if (protoProps) defineProperties(Constructor.prototype, protoProps);
if (staticProps) defineProperties(Constructor, staticProps);
return Constructor;
};
})();
exports.__esModule = true;
},{"babel-runtime/core-js/object/define-property":3}],6:[function(require,module,exports){
var $ = require('../../modules/$');
module.exports = function defineProperty(it, key, desc){
return $.setDesc(it, key, desc);
};
},{"../../modules/$":7}],7:[function(require,module,exports){
var $Object = Object;
module.exports = {
create: $Object.create,
getProto: $Object.getPrototypeOf,
isEnum: {}.propertyIsEnumerable,
getDesc: $Object.getOwnPropertyDescriptor,
setDesc: $Object.defineProperty,
setDescs: $Object.defineProperties,
getKeys: $Object.keys,
getNames: $Object.getOwnPropertyNames,
getSymbols: $Object.getOwnPropertySymbols,
each: [].forEach
};
},{}]},{},[1])(1)
});
//# sourceMappingURL=data:application/json;charset:utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5vZGVfbW9kdWxlcy9icm93c2VyaWZ5L25vZGVfbW9kdWxlcy9icm93c2VyLXBhY2svX3ByZWx1ZGUuanMiLCJiaXF1YWQtZmlsdGVyLmpzIiwiZGlzdC9lczYvYmlxdWFkLWZpbHRlci5lczYuanMiLCJub2RlX21vZHVsZXMvYmFiZWwtcnVudGltZS9jb3JlLWpzL29iamVjdC9kZWZpbmUtcHJvcGVydHkuanMiLCJub2RlX21vZHVsZXMvYmFiZWwtcnVudGltZS9oZWxwZXJzL2NsYXNzLWNhbGwtY2hlY2suanMiLCJub2RlX21vZHVsZXMvYmFiZWwtcnVudGltZS9oZWxwZXJzL2NyZWF0ZS1jbGFzcy5qcyIsIm5vZGVfbW9kdWxlcy9iYWJlbC1ydW50aW1lL25vZGVfbW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y8gR2xvYmFsIGdhaW5cbiAgICAgICAgICAgIHRoaXMuY29lZmZpY2llbnRzLmcgPSBjb2VmWzBdO1xuICAgICAgICAgICAgZm9yICh2YXIgaSA9IDA7IGkgPCB0aGlzLm51bWJlck9mQ2FzY2FkZTsgaSsrKSB7XG4gICAgICAgICAgICAgICAgLy8gRm91ciBjb2VmZmljaWVudHMgZm9yIGVhY2ggYmlxdWFkXG4gICAgICAgICAgICAgICAgdGhpcy5jb2VmZmljaWVudHNbaV0gPSB7XG4gICAgICAgICAgICAgICAgICAgIGIxOiBjb2VmWzEgKyBpICogNF0sXG4gICAgICAgICAgICAgICAgICAgIGIyOiBjb2VmWzIgKyBpICogNF0sXG4gICAgICAgICAgICAgICAgICAgIGExOiBjb2VmWzMgKyBpICogNF0sXG4gICAgICAgICAgICAgICAgICAgIGEyOiBjb2VmWzQgKyBpICogNF1cbiAgICAgICAgICAgICAgICB9O1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgLy8gTmVlZCB0byByZXNldCB0aGUgbWVtb3JpZXMgYWZ0ZXIgY2hhbmdlIHRoZSBjb2VmZmljaWVudHNcbiAgICAgICAgICAgIHRoaXMucmVzZXRNZW1vcmllcygpO1xuICAgICAgICAgICAgcmV0dXJuIHRydWU7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICB0aHJvdyBuZXcgRXJyb3IoXCJObyBjb2VmZmljaWVudHMgYXJlIHNldFwiKTtcbiAgICAgICAgfVxuICAgIH1cblxuICAgIC8qKlxuICAgICAqIEdldCB0aGUgbnVtYmVyIG9mIGNhc2NhZGUgZmlsdGVycyBmcm9tIHRoZSBsaXN0IG9mIGNvZWZmaWNpZW50c1xuICAgICAqIEBwcml2YXRlXG4gICAgICovXG4gICAgZ2V0TnVtYmVyT2ZDYXNjYWRlRmlsdGVycyhjb2VmKSB7XG4gICAgICAgIHJldHVybiAoY29lZi5sZW5ndGggLSAxKSAvIDQ7XG4gICAgfVxuXG4gICAgLyoqXG4gICAgIC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eTFpMjtcblxuICAgICAgICBmb3IgKHZhciBpID0gMDsgaSA8IGlucHV0QnVmZmVyLmxlbmd0aDsgaSsrKSB7XG4gICAgICAgICAgICB4ID0gaW5wdXRCdWZmZXJbaV07XG4gICAgICAgICAgICAvLyBTYXZlIGNvZWZmaWNpZW50cyBpbiBsb2NhbCB2YXJpYWJsZXNcbiAgICAgICAgICAgIGIxID0gdGhpcy5jb2VmZmljaWVudHNbMF0uYjE7XG4gICAgICAgICAgICBiMiA9IHRoaXMuY29lZmZpY2llbnRzWzBdLmIyO1xuICAgICAgICAgICAgYTEgPSB0aGlzLmNvZWZmaWNpZW50c1swXS5hMTtcbiAgICAgICAgICAgIGEyID0gdGhpcy5jb2VmZmljaWVudHNbMF0uYTI7XG4gICAgICAgICAgICAvLyBTYXZlIG1lbW9yaWVzIGluIGxvY2FsIHZhcmlhYmxlc1xuICAgICAgICAgICAgeGkxID0gdGhpcy5tZW1vcmllc1swXS54aTE7XG4gICAgICAgICAgICB4aTIgPSB0aGlzLm1lbW9yaWVzWzBdLnhpMjtcbiAgICAgICAgICAgIHlpMSA9IHRoaXMubWVtb3JpZXNbMF0ueWkxO1xuICAgICAgICAgICAgeWkyID0gdGhpcy5tZW1vcmllc1swXS55aTI7XG5cbiAgICAgICAgICAgIC8vIEZvcm11bGE6IHlbbl0gPSB4W25dICsgYjEqeFtuLTFdICsgYjIqeFtuLTJdIC0gYTEqeVtuLTFdIC0gYTIqeVtuLTJdXG4gICAgICAgICAgICAvLyBGaXJzdCBiaXF1YWRcbiAgICAgICAgICAgIHlbMF0gPSB4ICsgYjEgKiB4aTEgKyBiMiAqIHhpMiAtIGExICogeWkxIC0gYTIgKiB5aTI7XG5cbiAgICAgICAgICAgIGZvciAodmFyIGUgPSAxOyBlIDwgdGhpcy5udW1iZXJPZkNhc2NhZGU7IGUrKykge1xuICAgICAgICAgICAgICAgIC8vIFNhdmUgY29lZmZpY2llbnRzIGluIGxvY2FsIHZhcmlhYmxlc1xuICAgICAgICAgICAgICAgIGIxID0gdGhpcy5jb2VmZmljaWVudHNbZV0uYjE7XG4gICAgICAgICAgICAgICAgYjIgPSB0aGlzLmNvZWZmaWNpZW50c1tlXS5iMjtcbiAgICAgICAgICAgICAgICBhMSA9IHRoaXMuY29lZmZpY2llbnRzW2VdLmExO1xuICAgICAgICAgICAgICAgIGEyID0gdGhpcy5jb2VmZmljaWVudHNbZV0uYTI7XG4gICAgICAgICAgICAgICAgLy8gU2F2ZSBtZW1vcmllcyBpbiBsb2NhbCB2YXJpYWJsZXNcbiAgICAgICAgICAgICAgICB5MWkxID0gdGhpcy5tZW1vcmllc1tlIC0gMV0ueWkxO1xuICAgICAgICAgICAgICAgIHkxaTIgPSB0aGlzLm1lbW9yaWVzW2UgLSAxXS55aTI7XG4gICAgICAgICAgICAgICAgeWkxID0gdGhpcy5tZW1vcmllc1tlXS55aTE7XG4gICAgICAgICAgICAgICAgeWkyID0gdGhpcy5tZW1vcmllc1tlXS55aTI7XG5cbiAgICAgICAgICAgICAgICB5W2VdID0geVtlIC0gMV0gKyBiMSAqIHkxaTEgKyBiMiAqIHkxaTIgLSBhMSAqIHlpMSAtIGEyICogeWkyO1xuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAvLyBXcml0ZSB0aGUgb3V0cHV0XG4gICAgICAgICAgICBvdXRwdXRCdWZmZXJbaV0gPSB5W3RoaXMubnVtYmVyT2ZDYXNjYWRlIC0gMV0gKiB0aGlzLmNvZWZmaWNpZW50cy5nO1xuXG4gICAgICAgICAgICAvLyBVcGRhdGUgdGhlIG1lbW9yaWVzXG4gICAgICAgICAgICB0aGlzLm1lbW9yaWVzWzBdLnhpMiA9IHRoaXMubWVtb3JpZXNbMF0ueGkxO1xuICAgICAgICAgICAgdGhpcy5tZW1vcmllc1swXS54aTEgPSB4O1xuXG4gICAgICAgICAgICBmb3IgKHZhciBwID0gMDsgcCA8IHRoaXMubnVtYmVyT2ZDYXNjYWRlOyBwKyspIHtcbiAgICAgICAgICAgICAg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