Coder Social home page Coder Social logo

Comments (5)

 avatar commented on May 16, 2024 1

from virtual-audio-graph.

 avatar commented on May 16, 2024 1

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.

benji6 avatar benji6 commented on May 16, 2024

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.

 avatar commented on May 16, 2024

from virtual-audio-graph.

benji6 avatar benji6 commented on May 16, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.