Class AudioDevice

Represents an audio output device wrapper that owns an AudioContext and helps create and manage Channel and Master routing objects. Usually constructed when calling ResolveDefaultAudioOutputDevice().

Example

import { AudioDevice } from "@fluex/fluexgl-dsp";

// MediaDeviceInfo is typically retrieved from navigator.mediaDevices.enumerateDevices()
const deviceInfo = myMediaDeviceInfo;

const device = new AudioDevice(deviceInfo);
const channel = device.CreateChannel();

// Create an additional master bus and set it as active
const master = device.CreateMasterChannel();
device.SetMasterChannel(master);

Constructor

Constructs a new AudioDevice for the given output device and creates an internal AudioContext along with its default master channel.

new AudioDevice(public deviceInfo: MediaDeviceInfo): AudioDevice;

Arguments

  • deviceInfo: MediaDeviceInfo - The selected output device information (from enumerateDevices()).

Properties

id: string

A unique id for this AudioDevice instance. Automatically generated when constructing the device. Should NOT be changed.

timestamp: number

Creation timestamp (Date.now()) for this AudioDevice instance.

context: AudioContext

The AudioContext owned by this device. Used for creating channels and master busses.

masterChannel: Master

The currently selected active Master channel for this device.

masterChannels: Master[]

All created Master channels owned by this device.


Methods

GetMasterChannel(): Master

Returns the currently active Master channel.

Arguments

No arguments

Returns

SetMasterChannel(channel: Master): void

Sets the active Master channel. This is typically one of the entries in masterChannels.

Arguments

  • channel: Master - The master channel to set as active.

Returns

  • void

CreateMasterChannel(): Master

Creates a new Master channel using this device’s AudioContext, stores it in masterChannels, and returns it.

Arguments

No arguments

Returns

GetContext(): AudioContext

Returns this device’s AudioContext.

Arguments

No arguments

Returns

  • AudioContext

CreateChannel(): Channel

Creates and returns a new Channel using this device’s AudioContext.

Arguments

No arguments

Returns

Events

This class does not emit custom events.

Getters and setters

This class does not define public getters or setters.

Examples

Example 1: creating channels and routing them into the active master

const device = new AudioDevice(deviceInfo);

const a = device.CreateChannel();
const b = device.CreateChannel();

// Route a into b, and b into the active master
a.Send(b);
b.Send(device.GetMasterChannel());

Example 2: creating multiple master busses

const device = new AudioDevice(deviceInfo);

const masterA = device.GetMasterChannel();
const masterB = device.CreateMasterChannel();

// Switch active master
device.SetMasterChannel(masterB);

// You can still keep references to older master channels
console.log(masterA.id, masterB.id);