Skip to content

Instantly share code, notes, and snippets.

@rssilva
Last active October 9, 2017 03:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rssilva/005cc9ef63c92e7b4ce7a55e1517f1dc to your computer and use it in GitHub Desktop.
Save rssilva/005cc9ef63c92e7b4ce7a55e1517f1dc to your computer and use it in GitHub Desktop.
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