Skip to content

Remove unsupported methods from offlineAudioContext #308

Closed

Description

@chrislo

The methods

createMediaElementSource
createMediaStreamSource
createMediaStreamDestination

don't make sense in an offlineAudioContext. They should be removed from the spec. Robert O'Callahan suggests adding a baseAudioContext or similar to the spec which AudioContext and offlineAudioContext can inherit from. That seems sensible to me.

more details

Activity

  1. domenic commented on Apr 3, 2014

    @domenic
    Contributor

    Non-constructable base classes is not a good idea.

  2. cwilso commented on Apr 3, 2014

    @cwilso
    Contributor

    Further guidance, then? adding an "implements" of an interface that contains the creation mechanisms of real-time nodes? We'd still need to handle erroring on new() (when we handle new()ing) when given an offline context rather than a realtime one.

    Or we could flip it, make offlineaudiocontext "batchaudiocontext" and have the normal realtimeaudiocontext inherit from it...

  3. domenic commented on Apr 3, 2014

    @domenic
    Contributor

    The latter plan sounds better, but in the end, I am not sure inheritance relationships are useful. What new capabilities do they give programmers?

    The more important thing is that for shared functionality, they share the same methods that accomplish that functionality, so that code that relies on only the shared subset can act on either without any trouble. This could be accomplished in a variety of ways, and inheritance seems to have no impact on that.

  4. cwilso commented on Apr 3, 2014

    @cwilso
    Contributor

    I'm confused. :) The only benefit of the latter idea is that it uses inheritance; it's kinda wacky that it does, in fact, since it kinda flips the ordering. I guess they both do.

    In short - how would you normally structure two objects that are essentially the same class, except the less-commonly-used, special case object type has one subclass of functionality missing (when compared to the more commonly used one)?

  5. domenic commented on Apr 3, 2014

    @domenic
    Contributor

    how would you normally structure two objects that are essentially the same class, except the less-commonly-used, special case object type has one subclass of functionality missing

    I would create two classes, with some methods appearing in both, and some appearing only in one. E.g.

    class MoreCommonlyUsed {
      sharedMethod1() { }
      sharedMethod2() { }
      onlyInThisClass() { }
    }
    
    class LessCommonlyUsed {
      sharedMethod1() { }
      sharedMethod2() { }
    }
  6. cwilso commented on Apr 4, 2014

    @cwilso
    Contributor

    That seems REALLY duplicative, since it would actually be:

    interface AudioContext : EventTarget {
        readonly    attribute AudioDestinationNode destination;
        readonly    attribute float                sampleRate;
        readonly    attribute double               currentTime;
        readonly    attribute AudioListener        listener;
        AudioBuffer                     createBuffer (unsigned long numberOfChannels, unsigned long length, float sampleRate);
        void                            decodeAudioData (ArrayBuffer audioData, DecodeSuccessCallback successCallback, optional DecodeErrorCallback errorCallback);
        AudioBufferSourceNode           createBufferSource ();
        MediaElementAudioSourceNode     createMediaElementSource (HTMLMediaElement mediaElement);
        MediaStreamAudioSourceNode      createMediaStreamSource (MediaStream mediaStream);
        MediaStreamAudioDestinationNode createMediaStreamDestination ();
        ScriptProcessorNode             createScriptProcessor (optional unsigned long bufferSize = 0 , optional unsigned long numberOfInputChannels = 2 , optional unsigned long numberOfOutputChannels = 2 );
        AnalyserNode                    createAnalyser ();
        GainNode                        createGain ();
        DelayNode                       createDelay (optional double maxDelayTime = 1.0 );
        BiquadFilterNode                createBiquadFilter ();
        WaveShaperNode                  createWaveShaper ();
        PannerNode                      createPanner ();
        ConvolverNode                   createConvolver ();
        ChannelSplitterNode             createChannelSplitter (optional unsigned long numberOfOutputs = 6 );
        ChannelMergerNode               createChannelMerger (optional unsigned long numberOfInputs = 6 );
        DynamicsCompressorNode          createDynamicsCompressor ();
        OscillatorNode                  createOscillator ();
        PeriodicWave                    createPeriodicWave (Float32Array real, Float32Array imag);
    };
    
    interface OfflineAudioContext : EventTarget {
        readonly    attribute AudioDestinationNode destination;
        readonly    attribute float                sampleRate;
        readonly    attribute double               currentTime;
        readonly    attribute AudioListener        listener;
        AudioBuffer                     createBuffer (unsigned long numberOfChannels, unsigned long length, float sampleRate);
        void                            decodeAudioData (ArrayBuffer audioData, DecodeSuccessCallback successCallback, optional DecodeErrorCallback errorCallback);
        AudioBufferSourceNode           createBufferSource ();
        ScriptProcessorNode             createScriptProcessor (optional unsigned long bufferSize = 0 , optional unsigned long numberOfInputChannels = 2 , optional unsigned long numberOfOutputChannels = 2 );
        AnalyserNode                    createAnalyser ();
        GainNode                        createGain ();
        DelayNode                       createDelay (optional double maxDelayTime = 1.0 );
        BiquadFilterNode                createBiquadFilter ();
        WaveShaperNode                  createWaveShaper ();
        PannerNode                      createPanner ();
        ConvolverNode                   createConvolver ();
        ChannelSplitterNode             createChannelSplitter (optional unsigned long numberOfOutputs = 6 );
        ChannelMergerNode               createChannelMerger (optional unsigned long numberOfInputs = 6 );
        DynamicsCompressorNode          createDynamicsCompressor ();
        OscillatorNode                  createOscillator ();
        PeriodicWave                    createPeriodicWave (Float32Array real, Float32Array imag);
    };
    
  7. domenic commented on Apr 4, 2014

    @domenic
    Contributor

    I mean, hopefully WebIDL has features that would reduce that duplication. If not, hopefully that can be fixed in WebIDL. You shouldn't impose changes on the JavaScript-visible API just because WebIDL hasn't given you the tools you want.

  8. adelespinasse commented on Jul 24, 2014

    @adelespinasse

    Well, I haven't had any responses on my post to public-audio, so I'll cross-post here. Maybe more of the interested people will see it here.

    I actually think that it does make sense to use a MediaElementAudioSourceNode in an OfflineAudioContext. I would very much like to be able to do this, particularly with a

    Use cases:

    1. A simple case: a web application that lets the user select a video file on their local storage, and uploads just the audio track to a server. It would create a Blob URL for the file, create a video element using that URL, and plug that into the OfflineAudioContext via a MediaElementAudioSourceNode. The audio could be retrieved as one giant buffer when the OfflineAudioContext is done, or as the decoding happens via a ScriptProcessorNode, or maybe sent to the server via WebRTC with a MediaStreamAudioDestinationNode. (Note: for this use case, it should not be necessary to actually decode the video track of the file, but I have no idea how hard it would be to implement this as a browser optimization.)
    2. Similar to the above, but instead of the video track being completely dropped, its resolution and bit rate would be decreased. WebGL or a 2D canvas context can be used for high-quality scaling of each frame. This would be very useful for something like a web-based video editor, where you would like a low-quality version of your source material to be available very quickly for editing; the original high-quality footage can be uploaded later before final high-quality rendering.
    3. More general cases, such as a web-based video editor that does its rendering on the client side (which is actually something I've been working on). In this case, the video source material would come from the server (possibly uploaded as described above). During editing, playback is low-quality and real-time, but when it's time to render the final, high-quality product, it generally has to happen much slower than real time. Of course it might be possible to do the audio and video rendering entirely separately in some cases, but there are cases where the rendered video would depend on the rendered audio and vice versa, such as an oscilloscope effect (audio affects video) or a text-to-speech effect (video affects audio).

    I know I'm probably raising some complicated issues here, having to do with synchronization and worker threads and things I haven't thought of. I don't know a lot about browser implementations. I have read some recent conversations (mainly on this list) having to do with making all ScriptProcessorNode callbacks happen in a worker thread (both for AudioContext and OfflineAudioContext, I believe), which seems like a good idea, but could make some things difficult since the media element feeding a MediaElementAudioSourceNode can't exist in a worker.

    Is any of the above practical? Is there any hope of these scenarios being possible to implement, let alone in an efficient and elegant way? I feel like it should be possible.

  9. cwilso commented on Jul 24, 2014

    @cwilso
    Contributor

    I saw it on public-audio too, just haven't gotten to respond yet.

    Short version: You have no timeline control over media elements from within the web audio timeline, and no ability to run a MediaStream at faster than realtime. If that work were done - faster-than-realtime MediaStreams - that might make this possible, but as it is, we just can't reach back at an appropriate time, and remember that and

    All three of these use cases really seem like they'd be better served by a stronger Media API, not by hacking into Web Audio for processing/re-recording. Particularly case 3, is really video-specific.

  10. adelespinasse commented on Jul 26, 2014

    @adelespinasse

    Wouldn't a stronger media API include the audio API? As in, the video and audio stuff should integrate well?

    I don't see case 3 as all that video-specific. A good video editor needs to support flexible audio processing, including things like effects that would be well handled by the audio API. I would even want it to be able to include a music production system, with synthesizers and sequencing and all that, so I could create a full soundtrack for a movie.

    I think all of what I want could probably be done in a near-future version of standard web APIs, but it might take some really ugly hacks. I need to go reread those threads about AudioWorkers and ScriptProcessorNode/OfflineAudioContext more carefully. I'm afraid that offline rendering might end up being too limited for what I and many other people want to do.

    Possibly what I REALLY want is to be able to use all the standardized browser features (DOM elements, videos, WebGL, WebRTC, ...) in web workers and AudioWorkers (assuming that happens; it sounds like a good idea to me). I don't know if that's likely or what discussion group I'd have to crash to ask about it. I think of it this way: video codecs and WebGL are very powerful compute engines, and it would be a shame not to be able to use them outside the one main UI thread.

  11. joeberkovitz commented on Oct 28, 2014

    @joeberkovitz

    TPAC Resolution: Adopt ROC's original suggestion of making both the offline and realtime AudioContexts inherit from an abstract base class that doesn't contain the methods in question.

    Note: Ask Cameron McCormack to pronounce on best way to describe in WebIDL.

  12. added
    Needs Edits
    and removed on Oct 28, 2014
  13. modified the milestone: on Oct 29, 2014
  14. added a commit that references this issue on Oct 16, 2015
    2ca8e37
  15. self-assigned this
    on Oct 16, 2015
  16. padenot commented on Oct 19, 2015

    @padenot
    Member

    I'm asking heycam for best WebIDL practices before merging.

    In fact, we can ask @heycam right here. Cameron, we have the following setup (in pseudo code):

    class BaseAudioContext {
       ... a lot of methods ...
    };
    
    class AudioContext : inherits BaseAudioContext {
      ... some more AudioContext-specific methods ...
    };
    
    class OfflineAudioContext: inherits BaseAudioContext {
      ... more OfflineAudioContext-specific methods ...
    };
    

    what would be the best way to write that in WebIDL ?

  17. heycam commented on Oct 19, 2015

    @heycam

    You can just mirror that structure in IDL interfaces:

    interface BaseAudioContext {
      ...
    };
    
    [Constructor(...)]
    interface AudioContext : BaseAudioContext {
      ...
    };
    
    [Constructor(...)]
    interface OfflineAudioContext : BaseAudioContext {
      ...
    };

    This does go against what @domenic says earlier about not having non-constructable base classes, but to be honest having the abstract base class not be constructable makes sense to me.

  18. added 2 commits that reference this issue on Nov 12, 2015
    5144074
    cd07656
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Needs Edits

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions