+ const nodes = this._createNodes(context);
+
+ this._activatedNodes = [];
+ },
+
+ _createNodes(context) {
+
+ const delayNode = context.createDelay(1.0);
+
+ const convolverNode = context.createConvolver();
+ this._initializeConvolverNode(convolverNode);
+
+ const loPassFilterNode = context.createBiquadFilter();
+ loPassFilterNode.type = 'lowpass';
+ loPassFilterNode.frequency.value = 1000;
+ loPassFilterNode.gain.value = 25;
+
+ const hiPassFilterNode = context.createBiquadFilter();
+ hiPassFilterNode.type = 'highpass';
+ hiPassFilterNode.frequency.value = 3000;
+ hiPassFilterNode.gain.value = 25;
+
+ const bandPassFilterNode = context.createBiquadFilter();
+ bandPassFilterNode.type = 'bandpass';
+ bandPassFilterNode.frequency.value = 2000;
+ bandPassFilterNode.gain.value = 25;
+
+ const distortionNode = context.createWaveShaper();
+ distortionNode.curve = this._generateDistortion(400);
+ distortionNode.oversample = '4x';
+ }
+
+ // Generates a wave to be used with the distortion wave shaper node
+
+ _generateDistortion(amount = 50) {
+
+ const sampleRate = 44100;
+ const curve = new Float32Array(sampleRate);
+ const angle = Math.PI / 180;
+
+ for (let i = 0; i < sampleRate; ++i) {
+ const x = i * 2 / sampleRate - 1;
+ curve[i] = ( 3 + amount ) * x * 20 * angle / ( Math.PI + amount * Math.abs(x) );
+ }
+
+ return curve;
+ },
+
+ // Initializes a convolver node by requesting the reverb sound,
+ // decoding it, and attaching it
+
+ _initializeConvolverNode(node) {
+
+ const request = new XMLHttpRequest();
+ request.open(config.convolverNode.requestMethod, config.convolverNode.requestLocation);
+ request.responseType = config.convolverNode.responseType;
+ request.addEventListener('load', (event) => {
+
+ node.context.decodeAudioData(event.target.response, (buffer) => {
+
+ node.buffer = buffer;
+ });
+ });
+ request.send();
+ }
+
+ // Handles the XHR response to the reverb file
+
+
+
+ if (!this.source) {
+ this._getUserMedia({
+ audio : true
+ }, this._onUserMedia.bind(this), this._onUserMediaError.bind(this))
+ }
+
+ this.element.html(this.constructor.INNER_HTML);
+
+ this.controlButton = this.element.find('.record-button');
+ this.clearButton = this.element.find('.record-clear');
+ this.audioElement = this.element.find('audio');
+ this.progressBarContainer = this.element.find('.record-progress-bar-container');
+ this.progressBar = this.element.find('.record-progress-bar');
+ this.switches = this.element.find('.filter-switch');
+
+ this._bindEvents();
+};
+
+const Pepperoni.prototype = {
+
+ _createNodes() {
+
+ }
+
+ maxSize : 1048576,
+ recording : false,
+ source : null,
+ recorder : null,
+ context : null,
+ _delayNode : null,
+ _bandPassFilterNode : null,
+ _hiPassFilterNode : null,
+ _loPassFilterNode : null,
+ _convolverNode : null,
+ _distortionNode : null,
+ _activatedNodes : null,
+ workerPath : '/js/vendor/recorderjs/recorderWorker.js',
+ init : function init(config) {
+ },
+
+ record : function record() {
+ if (this.recorder && !this.recording) {
+ this._canRecord(function handleCanRecord(canRecord) {
+ if (canRecord) {
+ this.recording = true;
+ this.controlButton.addClass('recording')
+ this.controlButton.html(this.constructor.PAUSE);
+ this._interval = setInterval(this._onRecordCheck.bind(this), 100);
+ this.recorder.record();
+ }
+ }.bind(this));
+ }
+ },
+
+ stop : function stop() {
+ if (this.recorder && this.recording) {
+ this.recording = false;
+ this.controlButton.removeClass('recording')
+ this.controlButton.html(this.constructor.RECORD);
+ clearInterval(this._interval);
+ this.recorder.stop();
+ this.recorder.exportWAV();
+ }
+ },
+
+ clear : function clear() {
+ if (this.recorder) {
+ this.progressBar.width(0);
+ this.audioElement.attr('src', '');
+ this.audioElement[0].load();
+ this.recorder.clear()
+ }
+ },
+
+ finalize : function finalize(callback) {
+ if (this.recorder) {
+ this.recorder.exportWAV(callback);
+ }
+ },
+
+ getBuffer : function getBuffer(callback) {
+ if (this.recorder) {
+ this.recorder.getBuffer(callback);
+ }
+ },
+
+ _bindEvents : function bindEvents() {
+ var pepperoni = this;
+
+ this.controlButton.on('click', function () {
+ if (this.recording) {
+ this.stop();
+ } else {
+ this.record();