Last active
October 9, 2017 03:41
-
-
Save rssilva/005cc9ef63c92e7b4ce7a55e1517f1dc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const getSourceNode = (audioContext, buffer) => { | |
// let's create an empty buffer | |
const source = audioContext.createBufferSource() | |
// then we assign the passed buffer to node's buffer | |
source.buffer = buffer | |
// this is will play the buffer in looping | |
source.looping = true | |
return source | |
} | |
const getFilter = (audioContext, type, frequency) => { | |
// let's create a filter node | |
const filter = audioContext.createBiquadFilter() | |
// then we assign the given type ('lowpass', 'highpass', etc) | |
filter.type = type | |
// let's set the frequency | |
filter.frequency.value = frequency | |
return filter | |
} | |
// now we need to create a source node with a buffer (like the previous examples) | |
const sourceNode = getSourceNode(audioContext, buffer) | |
// so we create a filter node | |
const filter = getFilter(audioContext, 'lowpass', 400) | |
// connecting the source node to the filter | |
sourceNode.connect(filter) | |
// and then filter to the speakers we'll be able hear the result | |
filter.connect(audioContext.destination) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment