Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Persisting audio graph definitions using functions #267

Closed
bthj opened this issue Nov 21, 2020 · 8 comments
Closed

Persisting audio graph definitions using functions #267

bthj opened this issue Nov 21, 2020 · 8 comments
Labels

Comments

@bthj
Copy link

bthj commented Nov 21, 2020

Hi

Using versions before v0.20.0, where audio graphs are defined as arrays, it's easy to save the definitions, in e.g. a document database. But after the change to using functions for the audio graph definitions, I'm unsure how to go about persisting them:

Any ideas on how to achieve that?

@benji6
Copy link
Owner

benji6 commented Nov 21, 2020

Apologies if I broke anything with this change, I didn't actually think anyone would have this usecase. Some graphs probably don't translate well to storing server-side - especially when they make use of timing. Would be interested to hear more about how you're using the library?

I think that it would be very straightforward to create a little DSL to get around this issue. For instance if you want to store this graph on the server:

virtualAudioGraph.update({
  0: gain('output', { gain: 0.5 }),
  1: oscillator(0),
})

You could store a data structure like:

const audioGraph = {
  0: ['gain', 'output', { gain: 0.5 }],
  1: ['oscillator', 0]
}

Then use a function that compiles that to a format that virtual-audio-graph understands:

import * as nodes from 'virtual-audio-graph'

const compileAudioGraph = (audioGraph) => Object.fromEntries(
  Object.entries(audioGraph)
    .map(([key, [nodeName, ...nodeArgs]]) => [key, nodes[nodeName](...nodeArgs)])
)

virtualAudioGraph.update(compileAudioGraph(audioGraph))

Haven't actually run that code, but something like that should work. Does that make sense?

@bthj
Copy link
Author

bthj commented Nov 22, 2020

Yes, that makes sense. Thanks for the example compilation function - and no worries about the breaking change, that was clearly documented in the release notes, just wondering if I should stay on < v0.20.0, while it would be good to sync with the latest bugfixes and it's interesting to try out the support for AudioWorklets. That mapping function could be the way to go.

I'm using this library for the synth.is pet project, where it has been super helpful - Thanks! - intro video and another. Haven't been working on this in the past months but hope to find time for another iteration soon, where I would need to revisit the usage of virtual-audio-graph. PauchDB is used for local persistence (initial plan was to use the sync features it offers but that was abandoned and now it's just persisting to IndexedDB) but when audio signal patches are published at synth.is, they are saved in MinIO buckets as plain text files.

@bthj bthj closed this as completed Nov 22, 2020
@benji6
Copy link
Owner

benji6 commented Nov 22, 2020

Cool project!

@bthj
Copy link
Author

bthj commented Dec 27, 2022

Hey @benji6, and happy holidays 🎄

I'm still using that v0.19.9 tag and just made one modification which you might be interested in for the current version of this project:

synth-is@40da5c2

@benji6
Copy link
Owner

benji6 commented Jan 6, 2023

Hi @bthj, thanks for the holiday wishes, hope you had a good time! Apologies for the delay in my response.

OscillatorNodes don't support offset time and it is not listed as supported in the docs. With AudioBufferSourceNodes the offset specifies the offset that the audio clip starts at.

When I try to pass a second parameter to an OscillatorNode start method I'm observing no errors and the node works the same way as if I had passed a single parameter to the start method. I'm not sure how your proposed change will affect the behavior of the library in that case?

@bthj
Copy link
Author

bthj commented Jan 7, 2023

Hi @benji6 - the change I made there to the v0.19.9 code was necessary to have virtual-audio-graph working with the node-web-audio-api implementation. A similar modification to the current virtual-audio-graph code might be interesting, so it may work with non-browser implementations like that one. Actually I haven't yet tried the current version with node-web-audio-api, only assuming the same applies :)

benji6 added a commit that referenced this issue Jan 7, 2023
…d to keep stricly inline with the specification and to avoid bugs in non-browser Web Audio implementations like node-web-audio-api

Fixes #267
@benji6
Copy link
Owner

benji6 commented Jan 7, 2023

Ah I see! I had not tested it with node-web-audio-api - seems like the implementation is different than in the browser. This issue definitely existed in the latest release. I have just pushed a fix f898b09. Latest release should work https://github.com/benji6/virtual-audio-graph/releases/tag/v1.1.9. Thanks for flagging this :)

@github-actions
Copy link

github-actions bot commented Jan 7, 2023

🎉 This issue has been resolved in version 1.1.9 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants