Commit bf40b8d7 authored by Karan Goel's avatar Karan Goel
Browse files

added a custom filter as a sample

parent 59e85365
......@@ -51,14 +51,26 @@ var SoundCloudAudioSource = function(player) {
analyser.fftSize = 256;
var source = audioCtx.createMediaElementSource(player);
source.connect(analyser);
analyser.connect(audioCtx.destination);
// Create the filter
var filter = audioCtx.createBiquadFilter();
// Create the audio graph.
analyser.connect(filter);
filter.connect(audioCtx.destination);
// Create and specify parameters for the low-pass filter.
filter.type = 'lowpass'; // Low-pass filter. See BiquadFilterNode docs
filter.frequency.value = 440; // Set cutoff to 440 HZ
// Playback the sound.
// source.start(0);
// analyser.connect(audioCtx.destination);
var sampleAudioStream = function() {
analyser.getByteFrequencyData(self.streamData);
// calculate an overall volume value
var total = 0;
for (var i = 0; i < 80; i++) { // get the volume from the first 80 bins, else it gets too loud with treble
if (!player || !player.eegData) player.eegData.eegPower = self.streamData[i];
total += (self.streamData[i] + player.eegData.eegPower.beta) / 2;
total += (self.streamData[i] + player.eegData.eegPower.beta) / 5;
}
self.volume = total;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment