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

Render audio graph without emitting to the speakers #234

Merged
merged 8 commits into from
Nov 13, 2022

Conversation

orottier
Copy link
Owner

@orottier orottier commented Nov 3, 2022

This is the third PR for #216
There are some leftover To-dos and your review comments that I will address soon. Thanks for having a look!

/// The audio output device - use `None` for the default device
pub sink_id: Option<String>,

/// The audio output device
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This API is terrible and I know it. The spec is not much better. I will explore other options

@orottier orottier force-pushed the feature/none-sink-id branch from d3d5269 to 2cbab59 Compare November 6, 2022 09:12
@orottier orottier changed the base branch from feature/set-sink-id to main November 6, 2022 09:13
Before: `Option<Option<String>>`
/// - use `None` for the default device
/// - use `Some(None)` to process the audio graph without playing through an audio output device.
/// - use `Some(Some(sinkId))` to use the specified audio sink id, obtained with `enumerate_devices`

After: `Option<String>`
/// - use `None` to process the audio graph without playing through an audio output device.
/// - use `Some("")` for the default audio output device
/// - use `Some(sinkId)` to use the specified audio sink id, obtained with `enumerate_devices`

We now require the user to specify `Some("")` for the default audio
device. In the docs we suggest to use the `::default()` implementation
so you are not required to think about it for most usecases.
@orottier
Copy link
Owner Author

orottier commented Nov 6, 2022

Hi @b-ma I would love your opinion on my latest API-compliance decision:

commit 3e33da3636f7712474a798ac1ab5a00dcea8a886 

    Drop double `Option` from AudioContextOptions.sink_id

    Before: `Option<Option<String>>`
    /// - use `None` for the default device
    /// - use `Some(None)` to process the audio graph without playing through an audio output device.
    /// - use `Some(Some(sinkId))` to use the specified audio sink id, obtained with `enumerate_devices`

    After: `Option<String>`
    /// - use `None` to process the audio graph without playing through an audio output device.
    /// - use `Some("")` for the default audio output device
    /// - use `Some(sinkId)` to use the specified audio sink id, obtained with `enumerate_devices`

    We now require the user to specify `Some("")` for the default audio
    device. In the docs we suggest to use the `::default()` implementation
    so you are not required to think about it for most usecases.

@github-actions

This comment was marked as outdated.

@b-ma
Copy link
Collaborator

b-ma commented Nov 7, 2022

Hey! yup I try to check that today or tomorrow

@b-ma
Copy link
Collaborator

b-ma commented Nov 8, 2022

Hey, after reading the spec (which I'm really not sure I understood well) and read again (...a bit fast) WebAudio/web-audio-api#2400, I would personally go for the very simple:

`String`
    /// - use `""` for the default audio output device
    /// - use `"none"` to process the audio graph without playing through an audio output device.
    /// - use `sinkId` to use the specified audio sink id, obtained with `enumerate_devices`

This is not very elegant, but much more simple in my opinion... and as the sinkIds are generated by the enumerate_devices code, we can guarantee there won't be any conflicts (but I must also admit I don't really get why these AudioSyncInfo and AudioSyncOptions types are defined in the spec)

Maybe we should mark the whole thing as unstable until this is implemented in Chrome or Firefox so that we can compare with what they did, to see if we didn't miss something?

@@ -9,6 +11,20 @@ use crate::AudioRenderCapacity;
use std::error::Error;
use std::sync::Mutex;

/// Check if the provided sink_id is available for playback
///
/// It should be `None` of `Some(sinkId)` where `sinkId` is returned from `enumerate_devices`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be None of or Some(sinkId) ?

No more nested `Option`, just a plain `String`:
- use `""` for the default audio output device
- use `"none"` to process the audio graph without playing through an audio output device.
- use `"sinkId"` to use the specified audio sink id, obtained with [`enumerate_devices`]
@orottier
Copy link
Owner Author

orottier commented Nov 9, 2022

Thanks for the suggestion. Way simpler indeed.
I will leave it this way for the 0.x versions

@github-actions
Copy link

github-actions bot commented Nov 9, 2022

Benchmark result:


bench_ctor
  Instructions:              867108 (+2.451923%)
  L1 Accesses:              1757368 (+2.040380%)
  L2 Accesses:                 7847 (+0.153159%)
  RAM Accesses:               10396 (-0.325983%)
  Estimated Cycles:         2160463 (+1.599377%)

bench_sine
  Instructions:             8578920 (+0.164627%)
  L1 Accesses:             13000415 (+0.181469%)
  L2 Accesses:                29861 (-0.668618%)
  RAM Accesses:               12496 (-0.327032%)
  Estimated Cycles:        13587080 (+0.155603%)

bench_sine_gain
  Instructions:             9091153 (+0.168579%)
  L1 Accesses:             13771784 (+0.179733%)
  L2 Accesses:                33859 (-0.636812%)
  RAM Accesses:               12649 (-0.323089%)
  Estimated Cycles:        14383794 (+0.154495%)

bench_sine_gain_delay
  Instructions:            16204265 (+0.097619%)
  L1 Accesses:             23504553 (+0.110624%)
  L2 Accesses:                70216 (-1.505141%)
  RAM Accesses:               12813 (-0.334474%)
  Estimated Cycles:        24304088 (+0.078662%)

bench_buffer_src
  Instructions:            10957390 (+0.152705%)
  L1 Accesses:             18018839 (+0.156743%)
  L2 Accesses:                52619 (-0.022800%)
  RAM Accesses:               37233 (-0.069782%)
  Estimated Cycles:        19585089 (+0.139223%)

bench_buffer_src_iir
  Instructions:            19986258 (+0.085767%)
  L1 Accesses:             29919751 (+0.094431%)
  L2 Accesses:                48087 (+0.777517%)
  RAM Accesses:               37325 (-0.066934%)
  Estimated Cycles:        31466561 (+0.092905%)

bench_buffer_src_biquad
  Instructions:            15321929 (+0.115458%)
  L1 Accesses:             23636730 (+0.122744%)
  L2 Accesses:                67720 (+2.260544%)
  RAM Accesses:               37426 (-0.080094%)
  Estimated Cycles:        25285240 (+0.140246%)


@orottier orottier merged commit 52cfc95 into main Nov 13, 2022
@orottier orottier deleted the feature/none-sink-id branch November 15, 2022 07:07
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

Successfully merging this pull request may close these issues.

2 participants