Octoroom.Audio (octoroom v0.1.0)

Copy Markdown View Source

Conversions between room PCM (48 kHz stereo s16le, Opus's own format, 20 ms frames) and the format a worker asks for. Rates must divide 48 kHz (8, 12, 16, 24 or 48 kHz) and channels must be 1 or 2.

Summary

Functions

Room PCM to rate/channels. Each run of 48_000 / rate frames is averaged into one, which also low-passes before decimating. Returns {pcm, rest}, where rest belongs in front of the next call's input.

Converts s16le PCM between 1 and 2 channels (mono is copied to both; stereo is averaged).

PCM at rate/channels to room PCM, by linear interpolation. prev is the last frame of the previous call as {left, right} ({0, 0} to start); returns {pcm, last_frame}. A trailing partial frame is dropped.

Raises unless rate and channels can be converted.

Functions

frame_bytes()

from_room(pcm, rate, channels)

Room PCM to rate/channels. Each run of 48_000 / rate frames is averaged into one, which also low-passes before decimating. Returns {pcm, rest}, where rest belongs in front of the next call's input.

rechannel(pcm, same, same)

Converts s16le PCM between 1 and 2 channels (mono is copied to both; stereo is averaged).

room_rate()

to_room(pcm, rate, channels, prev \\ {0, 0})

PCM at rate/channels to room PCM, by linear interpolation. prev is the last frame of the previous call as {left, right} ({0, 0} to start); returns {pcm, last_frame}. A trailing partial frame is dropped.

validate!(rate, channels)

Raises unless rate and channels can be converted.