Created
October 10, 2017 02:40
-
-
Save rssilva/70cd12c412c781cf5d018c01ce6febc1 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) => { | |
// vamos criar um buffer vazio | |
const source = audioContext.createBufferSource() | |
// depois atribuir o buffer passado como argumento ao buffer do nó fonte | |
source.buffer = buffer | |
// essa propriedade faz o buffer ser executado em looping | |
source.looping = true | |
return source | |
} | |
const getFilter = (audioContext, type, frequency) => { | |
// criamos um nó filtro | |
const filter = audioContext.createBiquadFilter() | |
// atribuímos a propriedade type que vai receber o tipo do filtro ('lowpass', 'highpass', etc) | |
filter.type = type | |
// setamos a frequência | |
filter.frequency.value = frequency | |
return filter | |
} | |
// agora precisamos criar um nó fonte passando um buffer (como os exemplos anteriores) | |
const sourceNode = getSourceNode(audioContext, buffer) | |
// criamos um nó filtro com a nossa função | |
const filter = getFilter(audioContext, 'lowpass', 400) | |
// conectamos o nó fonte ao filtro | |
sourceNode.connect(filter) | |
// depois conectamos o filtro aos alto-falantes para conseguirmos ouvir o resultado | |
filter.connect(audioContext.destination) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment