detritus

AudioMixerclass

Mixes multiple PCM sources (e.g. each user's decoded voice) into one continuous stream Packets are placed using their RTP timestamps, so jitter and bursts don't smear the audio Emits data with one mixed PCM frame (of format.frameDuration) at a steady rate while running Only signed 16-bit little-endian interleaved PCM is supported (what opus decoders output)

On this page

Mixes multiple PCM sources (e.g. each user's decoded voice) into one continuous stream Packets are placed using their RTP timestamps, so jitter and bursts don't smear the audio Emits data with one mixed PCM frame (of format.frameDuration) at a steady rate while running Only signed 16-bit little-endian interleaved PCM is supported (what opus decoders output)

import { MediaMixer } from 'detritus-client-socket';

MediaMixer.AudioMixer;
EventEmitterEventSpewerAudioMixer
13 properties18 methodssrc/mediamixer.ts:90

Constructor

Properties

buffer
Int32Array
bufferSamples
number
delaySamples
number
position
number

Sample position (per channel) of the next frame to be emitted

Default 0
running
boolean
Default false
skipSilence
boolean
sources
Map<string, AudioMixerSource>
sourceTimeout
number
startedAt
number
Default 0
ticks
number
Default 0
timeout
Timeout | null
Default null
userIds
Set<string> | null

Users to mix, null means everyone. push() doesn't check this, check isMixing() before pushing

Default null

Methods

on()

src/mediamixer.ts:438
on(event: string | symbol, listener: (...args: any[]) => void): this

Adds the listener function to the end of the listeners array for the event named eventName. No checks are made to see if the listener has already been added. Multiple calls passing the same combination of eventName and listener will result in the listener being added, and called, multiple times.

server.on('connection', (stream) => {
  console.log('someone connected!');
});

Returns a reference to the EventEmitter, so that calls can be chained.

By default, event listeners are invoked in the order they are added. The emitter.prependListener() method can be used as an alternative to add the event listener to the beginning of the listeners array.

import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.on('foo', () => console.log('a'));
myEE.prependListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
//   b
//   a

Since v0.1.101

event
string | symbol
listener
(...args: any[]) => void

The callback function

on(event: "data", listener: (frame: Buffer) => any): this
Overrides EventSpewer.on

push()

src/mediamixer.ts:183
push(sourceId: string, pcm: Buffer, rtpTimestamp?: number): void

Adds a PCM frame from a source into the mix rtpTimestamp is optional, without it the frame is placed right after the source's previous frame

setUserIds()

src/mediamixer.ts:142
setUserIds(userIds: Iterable<string, any, any> | null): void

Only mix these users, pass null to mix everyone