What's the difference between audioContext.destination and audioContext.createMediaStreamDestination?

Viewed 25

I'm wondering what the difference is between audioContext.destination and audioContext.createMediaStreamDestination().

Streams that generated from destination do behave a bit differently when they are played on browser pages. So I would like to know the best practice to use them separately and why.

1 Answers

BaseAudioContext.destination (note it's actually from BaseAudioContext which AudioContext extends) is not a stream. It's a AudioDestinationNode. Per the doc, it usually represents a real output device:

The destination property of the BaseAudioContext interface returns an AudioDestinationNode representing the final destination of all audio in the context. It often represents an actual audio-rendering device such as your device's speakers.

In the other hand, AudioContext.createMediaStreamDestination() actually creates an audio stream in which you can, for example, save to file or stream it futher through RTC. The result is a MediaStreamAudioDestinationNode which actually does not have any relationship with AudioDestinationNode except both of them have the same parent interface AudioNode.

The createMediaStreamDestination() method of the AudioContext Interface is used to create a new MediaStreamAudioDestinationNode object associated with a WebRTC MediaStream representing an audio stream, which may be stored in a local file or sent to another computer.

In short: destination represents an (usually) real output device, while createMediaStreamDestination creates an output stream that you can further process that stream/data/information.

Related