Comments (5)
from virtual-audio-graph.
Hi Ben,
I have implemented the audio graph, inspired by your example. Audio is a new world for me and took a bit of experimentation, but it works a treat. Fyi, the actual code is aded below. Basically a file object (stored in a database) is read into an arrayBuffer, converted to audioBuffer and added into the audio graph.
That has led me to one more question: how can I change the graph on-the-fly, ie while audio is playing? The declarative nature allows a detailed setup, but changing the graph with .update() after some event doesn't do what I hope. Basically I'd like the user to control (through a button click) whether the biquadFilter is applied or not.
Any advice is appreciated!
EDIT: Found it. I'm now getting the audio node (by id) and editing the properties. Works great. Thanks again :-)
Thanks
Mark
// After reading file soundtrack file....
fileReader.onload = (event) => {
if (!event) return null
const arrayBuffer = fileReader.result
if (!arrayBuffer || typeof arrayBuffer === 'string') {
console.log('arrayBuffer not expected format:', arrayBuffer)
return null
}
// ... convert the arrayBuffer to an audioBuffer, and ....
audioContext.decodeAudioData(arrayBuffer)
.then((buffer: any) => {
// ... play
virtualAudioGraph.update({
0: gain('output', {gain: 1}),
1: biquadFilter(0, {
type: 'notch',
frequency: 1000,
}),
2: bufferSource(1, {buffer}),
})
})
.catch((response: Error) => {
console.log('decode error', response)
})
}
// Start the actual read
fileReader.readAsArrayBuffer(file)
from virtual-audio-graph.
Hi, I don't currently have any documentation on how to do this, but something like this should work:
async function example() {
const audioContext = new AudioContext()
const virtualAudioGraph = createVirtualAudioGraph({ audioContext })
const response = await fetch('my-audio-sample.wav')
const data = await response.arrayBuffer()
const buffer = await audioContext.decodeAudioData(data)
virtualAudioGraph.update({
0: gain('output', { gain: 0.2 }),
1: bufferSource(0, { buffer }),
})
}
There's some more info on the buffer source node here: https://github.com/benji6/virtual-audio-graph/blob/master/docs/standard-nodes.md#buffersource
Over the next few days I'll look at adding an example to the docs to help with this sort of usecase
from virtual-audio-graph.
from virtual-audio-graph.
I've added a bit in the docs on working with audio files now so people in the future should find it a bit easier (f96fa5f) thanks for the feedback, let me know if you have any other issues!
from virtual-audio-graph.
Related Issues (20)
- AudioContext in Safari always 'suspended' HOT 1
- The automated release is failing 🚨
- create node with no output? HOT 1
- Persisting audio graph definitions using functions HOT 8
- Access to currently playing sound? HOT 2
- The automated release is failing 🚨
- Code in custom node is interpreted in a different way HOT 4
- A custom node inside of a custom node HOT 5
- LFO HOT 1
- Support OfflineAudioContext (repeat #8) HOT 4
- How to use in browser. HOT 2
- Thank you so much for virtual-audio-graph
- The automated release is failing 🚨 HOT 1
- Redundant `exponentialRampToValueAtTime` calls cause click noises HOT 4
- The automated release is failing 🚨
- Only 1 layer of custom nodes? HOT 3
- v1.1.1 release don't include the compiled module HOT 1
- Possible bug with offset HOT 3
- VAG samples not working in safari HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from virtual-audio-graph.