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

latencyHint on actual AudioContext #658

Closed
JackCA opened this issue Apr 28, 2020 · 7 comments
Closed

latencyHint on actual AudioContext #658

JackCA opened this issue Apr 28, 2020 · 7 comments

Comments

@JackCA
Copy link
Contributor

JackCA commented Apr 28, 2020

The web audio api itself supports latencyHint as a constructor option and after a bit of digging, it seems like that's entirely separate from the Tone.js latencyHint option (there are no options passed into the AudioContext constructor).

Is it correct to say that the latencyHint on the real AudioContext is not being set? If so, how could Tone.js be instructed to use it? The Tone.js API allows for writes on the value after initialized, but I don't think the real AudioContext does.

@tambien
Copy link
Contributor

tambien commented Apr 29, 2020

I think the right move would be to mimic the native AudioContext and move all that stuff into the constructor instead of an attribute. To give some backstory, i had added that feature a long time ago while it was still in flux how it was going to be handled in the specification (i believe at some point it was a settable attribute like i have it).

The only small complication is that Tone.js creates the AudioContext when the page loads, so you'll have to create a new Context if you'd like to access this feature, which isn't ideal.

@JackCA
Copy link
Contributor Author

JackCA commented May 1, 2020

I think the right move would be to mimic the native AudioContext

That seems like a great idea to me!

The only small complication is that Tone.js creates the AudioContext when the page loads

I'd personally prefer to manually call the initialization and do avoid anything with side-effects.

Is that feature designed around ergonomics for users? Could it be disabled somehow?

tambien added a commit that referenced this issue May 12, 2020
BREAK: the latencyHint can only be set in the constructor, no longer settable after construction

addresses #658
@tambien
Copy link
Contributor

tambien commented May 12, 2020

Once the next version is published, you should be able to take advantage of this by doing something like this:

Tone.setContext({
  context : new Tone.Context({ latencyHint : "playback" })
})

I think for now i won't disable creating an AudioContext on startup. It's been around since the first version and would change the user experience and break a lot of people's code.

@tambien tambien closed this as completed May 12, 2020
@JackCA
Copy link
Contributor Author

JackCA commented May 14, 2020

that works great! Trying it out shortly. Thank you so much

@JackCA
Copy link
Contributor Author

JackCA commented May 14, 2020

I think the API is actually Tone.setContext(new Tone.Context()) (without the inner context:), right?

@tambien
Copy link
Contributor

tambien commented May 15, 2020

whoops! yeah you're totally right

Tone.setContext(new Tone.Context({ latencyHint : "playback" }))

@jhurliman
Copy link

It would be helpful to update the docs reflecting this new usage. I had to Google around for a bit to stumble upon this closed ticket.

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

No branches or pull requests

3 participants