Opus Generated by Doxygen Thu May :22:05

Similar documents
Opus, a free, high-quality speech and audio codec

Internet Engineering Task Force (IETF) Category: Standards Track. Mozilla Corporation April 2016

This document describes the presence of OPUS codec, which was not available earlier, in Cisco Unified Communications Manager (CUCM) version 11.

libtheora Reference Manual

Open AMR Initiative. Technical Documentation. Version 1.0 Revision

For Mac and iphone. James McCartney Core Audio Engineer. Eric Allamanche Core Audio Engineer

Optical Storage Technology. MPEG Data Compression

SPEEX CODEC IMPLEMENTATION ON THE RPB RX210

Digital Speech Coding

Introducing Audio Signal Processing & Audio Coding. Dr Michael Mason Senior Manager, CE Technology Dolby Australia Pty Ltd

The MPEG-4 General Audio Coder

5: Music Compression. Music Coding. Mark Handley

elastique efficient time stretching SDK by zplane.development (c) 2017 zplane.development GmbH & Co. KG

Introducing Audio Signal Processing & Audio Coding. Dr Michael Mason Snr Staff Eng., Team Lead (Applied Research) Dolby Australia Pty Ltd

GSM Network and Services

Date. Next Generation in Speech Quality ETSI STQ Workshop, Nov 2012 Dr. Imre Varga Qualcomm Inc.

Audio-coding standards

How to achieve low latency audio/video streaming over IP network?

Compressed Audio Demystified by Hendrik Gideonse and Connor Smith. All Rights Reserved.

Nokia Q. Xie Motorola April 2007

POLYTECH CLERMONT-FERRAND. Application Note. Implementation of a SPEEX decoder on RX62N RENESAS microcontroller 22/01/2012

MPEG-4 General Audio Coding

VS1063 ENCODER DEMONSTRATION

HD Radio Air Interface Design Description Layer 2 Channel Multiplex Rev. I August 23, 2011

Audio Compression. Audio Compression. Absolute Threshold. CD quality audio:

HD Radio Air Interface Design Description Layer 2 Channel Multiplex Rev. J December 14, 2016

Armide Documentation. Release Kyle Mayes

Robust Programming. Style of programming that prevents abnormal termination and unexpected actions

ETSI TS V ( )

Lecture 16 Perceptual Audio Coding

AUDIO. Henning Schulzrinne Dept. of Computer Science Columbia University Spring 2015

Audio-coding standards

the gamedesigninitiative at cornell university Lecture 15 Game Audio

14th European Signal Processing Conference (EUSIPCO 2006), Florence, Italy, September 4-8, 2006, copyright by EURASIP

Configure Core Settings for Device Pools

The following bit rates are recommended for broadcast contribution employing the most commonly used audio coding schemes:

Perceptual coding. A psychoacoustic model is used to identify those signals that are influenced by both these effects.

Speech-Coding Techniques. Chapter 3

Principles of Audio Coding

Pro Tools Addendum. Version for LE Systems on Windows or Macintosh. Digidesign

Transporting audio-video. over the Internet

Synopsis of Basic VoIP Concepts

ANSI/SCTE

Visual Profiler. User Guide

Inspirel. YAMI4 Requirements. For YAMI4Industry, v page 1

Request for Comments: 4425 Category: Standards Track February 2006

Both LPC and CELP are used primarily for telephony applications and hence the compression of a speech signal.

IP Telephony - Quality-of-Service Aspects. Bruce Pettitt

CSE351 Spring 2010 Final Exam (9 June 2010)

CSE351 Spring 2010 Final Exam (9 June 2010)

ELL 788 Computational Perception & Cognition July November 2015

Introduction to LAN/WAN. Application Layer 4

Quality Assurance for Broadcast Audio Contribution over IP

HD Radio Air Interface Design Description - Layer 2 Channel Multiplex

Speech and audio coding

Nabto Serial Link Protocol

Skill Area 325: Deliver the Multimedia content through various media. Multimedia and Web Design (MWD)

Machine Problem 1: A Simple Memory Allocator

Configure Core Settings for Device Pools

PCM30U-ROK 2 048/256 kbps Broadcast Codec Brief Overview

Parametric Coding of Spatial Audio

Fragmenting and Interleaving Real-Time and Nonreal-Time Packets

CSCI-243 Exam 1 Review February 22, 2015 Presented by the RIT Computer Science Community

CHAPTER 10: SOUND AND VIDEO EDITING

Determination of Bit-Rate Adaptation Thresholds for the Opus Codec for VoIP Services

elastique Pro time stretching SDK DirectAPI by zplane.development (c) 2017 zplane.development GmbH & Co. KG

6MPEG-4 audio coding tools

Dynamic Data Structures. CSCI 112: Programming in C

Chapter 9. Multimedia Networking. Computer Networking: A Top Down Approach

Memory Corruption 101 From Primitives to Exploit

The Steganography In Inactive Frames Of Voip

Perceptual Coding. Lossless vs. lossy compression Perceptual models Selecting info to eliminate Quantization and entropy encoding

Structures. Basics of Structures (6.1) EECS l Now struct point is a valid type. l Defining struct variables: struct point { int x; int y; };

Audio Codecs. ... for reporting, Audio distribution and Studio-Transmitter-Links

Voice Over LTE (VoLTE) Technology. July 23, 2018 Tim Burke

2.4 Audio Compression

3GPP TS V6.2.0 ( )

ETSI TS V ( )

Annex (informative) to A001 Rev. 6: Guidelines for the Implementation of DTS Coded Audio in DVB Compliant Transport Streams

PERFORMANCE EVALUATION OF SPEECH QUALITY FOR VOIP ON THE INTERNET LIU XIAOMIN

INTERNATIONAL ORGANISATION FOR STANDARDISATION ORGANISATION INTERNATIONALE DE NORMALISATION ISO/IEC JTC1/SC29/WG11 CODING OF MOVING PICTURES AND AUDIO

Performance Analysis of Voice Call using Skype

Internet Streaming Media

Important Encoder Settings for Your Live Stream

The BroadVoice Speech Coding Algorithm. Juin-Hwey (Raymond) Chen, Ph.D. Senior Technical Director Broadcom Corporation March 22, 2010

Mumble Protocol. Release alpha

Audio Fundamentals, Compression Techniques & Standards. Hamid R. Rabiee Mostafa Salehi, Fatemeh Dabiran, Hoda Ayatollahi Spring 2011

robotics/ openel.h File Reference Macros Macro Definition Documentation Typedefs Functions

Troubleshooting Packet Loss. Steven van Houttum

Presents 2006 IMTC Forum ITU-T T Workshop

UM1641 User manual. Sampling rate conversion SRC236 library software expansion for STM32Cube. Introduction

/ / _ / _ / _ / / / / /_/ _/_/ _/_/ _/_/ _\ / All-American-Advanced-Audio-Codec

SpiNNaker Application Programming Interface (API)

SmartHeap for Multi-Core

Using MV/SAD information from DM365 encoder in application

Understanding RoIP Networks

ITP 342 Mobile App Dev. Audio

ATSC Standard: A/342 Part 2, AC-4 System

libacarsd documentation 12. December 2003 libacarsd 1.46 ACARS Decoder Library ,2004 by KjM

CSE 333 Midterm Exam 5/10/13

Transcription:

Opus 0.9.14 Generated by Doxygen 1.7.1 Thu May 17 2012 15:22:05

Contents 1 Opus 1 2 Module Index 3 2.1 Modules................................. 3 3 File Index 5 3.1 File List................................. 5 4 Module Documentation 7 4.1 Opus Encoder.............................. 7 4.1.1 Detailed Description...................... 8 4.1.2 Typedef Documentation.................... 9 4.1.2.1 OpusEncoder.................... 9 4.1.3 Function Documentation.................... 10 4.1.3.1 opus_encode..................... 10 4.1.3.2 opus_encode_float.................. 10 4.1.3.3 opus_encoder_create................ 11 4.1.3.4 opus_encoder_ctl.................. 11 4.1.3.5 opus_encoder_destroy................ 11 4.1.3.6 opus_encoder_get_size............... 12 4.1.3.7 opus_encoder_init.................. 12 4.2 Opus Decoder.............................. 12 4.2.1 Detailed Description...................... 14 4.2.2 Typedef Documentation.................... 15 4.2.2.1 OpusDecoder.................... 15 4.2.3 Function Documentation.................... 15

ii CONTENTS 4.2.3.1 opus_decode..................... 15 4.2.3.2 opus_decode_float.................. 15 4.2.3.3 opus_decoder_create................ 16 4.2.3.4 opus_decoder_ctl.................. 16 4.2.3.5 opus_decoder_destroy................ 16 4.2.3.6 opus_decoder_get_nb_samples........... 16 4.2.3.7 opus_decoder_get_size............... 17 4.2.3.8 opus_decoder_init.................. 17 4.2.3.9 opus_packet_get_bandwidth............ 18 4.2.3.10 opus_packet_get_nb_channels........... 18 4.2.3.11 opus_packet_get_nb_frames............ 18 4.2.3.12 opus_packet_get_samples_per_frame........ 19 4.2.3.13 opus_packet_parse.................. 19 4.3 Repacketizer.............................. 20 4.3.1 Detailed Description...................... 20 4.3.2 Typedef Documentation.................... 21 4.3.2.1 OpusRepacketizer.................. 21 4.3.3 Function Documentation.................... 21 4.3.3.1 opus_repacketizer_cat................ 21 4.3.3.2 opus_repacketizer_create.............. 21 4.3.3.3 opus_repacketizer_destroy............. 21 4.3.3.4 opus_repacketizer_get_nb_frames......... 21 4.3.3.5 opus_repacketizer_get_size............. 21 4.3.3.6 opus_repacketizer_init................ 21 4.3.3.7 opus_repacketizer_out................ 21 4.3.3.8 opus_repacketizer_out_range............ 21 4.4 Error codes............................... 21 4.4.1 Define Documentation..................... 22 4.4.1.1 OPUS_ALLOC_FAIL................ 22 4.4.1.2 OPUS_BAD_ARG................. 22 4.4.1.3 OPUS_BUFFER_TOO_SMALL.......... 22 4.4.1.4 OPUS_INTERNAL_ERROR............ 22 4.4.1.5 OPUS_INVALID_PACKET............. 22 4.4.1.6 OPUS_INVALID_STATE.............. 22

CONTENTS iii 4.4.1.7 OPUS_OK...................... 22 4.4.1.8 OPUS_UNIMPLEMENTED............ 22 4.5 Pre-defined values for CTL interface.................. 23 4.5.1 Detailed Description...................... 23 4.5.2 Define Documentation..................... 24 4.5.2.1 OPUS_APPLICATION_AUDIO.......... 24 4.5.2.2 OPUS_APPLICATION_RESTRICTED_- LOWDELAY.................... 24 4.5.2.3 OPUS_APPLICATION_VOIP........... 24 4.5.2.4 OPUS_AUTO.................... 24 4.5.2.5 OPUS_BANDWIDTH_FULLBAND........ 24 4.5.2.6 OPUS_BANDWIDTH_MEDIUMBAND...... 24 4.5.2.7 OPUS_BANDWIDTH_NARROWBAND..... 24 4.5.2.8 OPUS_BANDWIDTH_SUPERWIDEBAND.... 24 4.5.2.9 OPUS_BANDWIDTH_WIDEBAND........ 24 4.5.2.10 OPUS_BITRATE_MAX.............. 25 4.5.2.11 OPUS_SIGNAL_MUSIC.............. 25 4.5.2.12 OPUS_SIGNAL_VOICE.............. 25 4.6 Encoder related CTLs.......................... 25 4.6.1 Detailed Description...................... 27 4.6.2 Define Documentation..................... 27 4.6.2.1 OPUS_GET_APPLICATION............ 27 4.6.2.2 OPUS_GET_BITRATE............... 27 4.6.2.3 OPUS_GET_COMPLEXITY............ 27 4.6.2.4 OPUS_GET_DTX.................. 28 4.6.2.5 OPUS_GET_FORCE_CHANNELS........ 28 4.6.2.6 OPUS_GET_INBAND_FEC............ 28 4.6.2.7 OPUS_GET_LOOKAHEAD............ 29 4.6.2.8 OPUS_GET_MAX_BANDWIDTH........ 29 4.6.2.9 OPUS_GET_PACKET_LOSS_PERC....... 29 4.6.2.10 OPUS_GET_SIGNAL................ 29 4.6.2.11 OPUS_GET_VBR.................. 30 4.6.2.12 OPUS_GET_VBR_CONSTRAINT......... 30 4.6.2.13 OPUS_SET_APPLICATION............ 30

iv CONTENTS 4.6.2.14 OPUS_SET_BANDWIDTH............ 31 4.6.2.15 OPUS_SET_BITRATE............... 31 4.6.2.16 OPUS_SET_COMPLEXITY............ 31 4.6.2.17 OPUS_SET_DTX.................. 31 4.6.2.18 OPUS_SET_FORCE_CHANNELS......... 32 4.6.2.19 OPUS_SET_INBAND_FEC............ 32 4.6.2.20 OPUS_SET_MAX_BANDWIDTH......... 32 4.6.2.21 OPUS_SET_PACKET_LOSS_PERC........ 33 4.6.2.22 OPUS_SET_SIGNAL................ 33 4.6.2.23 OPUS_SET_VBR.................. 33 4.6.2.24 OPUS_SET_VBR_CONSTRAINT......... 34 4.7 Generic CTLs.............................. 34 4.7.1 Detailed Description...................... 34 4.7.2 Define Documentation..................... 35 4.7.2.1 OPUS_GET_BANDWIDTH............ 35 4.7.2.2 OPUS_GET_FINAL_RANGE........... 35 4.7.2.3 OPUS_GET_PITCH................. 35 4.7.2.4 OPUS_RESET_STATE............... 36 4.8 Opus library information functions................... 36 4.8.1 Function Documentation.................... 36 4.8.1.1 opus_get_version_string............... 36 4.8.1.2 opus_strerror..................... 36 5 File Documentation 37 5.1 opus.h File Reference.......................... 37 5.1.1 Detailed Description...................... 39 5.2 opus_defines.h File Reference..................... 39 5.2.1 Detailed Description...................... 43 5.3 opus_multistream.h File Reference................... 43 5.3.1 Detailed Description...................... 45 5.3.2 Define Documentation..................... 45 5.3.2.1 opus_check_decstate_ptr............. 45 5.3.2.2 opus_check_encstate_ptr............. 45 5.3.2.3 OPUS_MULTISTREAM_GET_DECODER_STATE 45

CONTENTS v 5.3.2.4 OPUS_MULTISTREAM_GET_DECODER_- STATE_REQUEST................. 45 5.3.2.5 OPUS_MULTISTREAM_GET_ENCODER_STATE 45 5.3.2.6 OPUS_MULTISTREAM_GET_ENCODER_- STATE_REQUEST................. 45 5.3.3 Typedef Documentation.................... 45 5.3.3.1 OpusMSDecoder.................. 45 5.3.3.2 OpusMSEncoder................... 45 5.3.4 Function Documentation.................... 45 5.3.4.1 opus_multistream_decode.............. 45 5.3.4.2 opus_multistream_decode_float........... 46 5.3.4.3 opus_multistream_decoder_create......... 46 5.3.4.4 opus_multistream_decoder_ctl........... 46 5.3.4.5 opus_multistream_decoder_destroy......... 47 5.3.4.6 opus_multistream_decoder_get_size........ 47 5.3.4.7 opus_multistream_decoder_init........... 47 5.3.4.8 opus_multistream_encode.............. 47 5.3.4.9 opus_multistream_encode_float........... 48 5.3.4.10 opus_multistream_encoder_create......... 48 5.3.4.11 opus_multistream_encoder_ctl........... 48 5.3.4.12 opus_multistream_encoder_destroy......... 48 5.3.4.13 opus_multistream_encoder_get_size........ 49 5.3.4.14 opus_multistream_encoder_init........... 49 5.4 opus_types.h File Reference...................... 49 5.4.1 Detailed Description...................... 50 5.4.2 Define Documentation..................... 50 5.4.2.1 opus_int....................... 50 5.4.2.2 opus_int64...................... 50 5.4.2.3 opus_int8...................... 50 5.4.2.4 opus_uint...................... 50 5.4.2.5 opus_uint64..................... 50 5.4.2.6 opus_uint8...................... 50 5.4.3 Typedef Documentation.................... 50 5.4.3.1 opus_int16...................... 50

vi CONTENTS 5.4.3.2 opus_int32...................... 50 5.4.3.3 opus_uint16..................... 50 5.4.3.4 opus_uint32..................... 50

Chapter 1 Opus The Opus codec is designed for interactive speech and audio transmission over the Internet. It is designed by the IETF Codec Working Group and incorporates technology from Skype s SILK codec and Xiph.Org s CELT codec. The Opus codec is designed to handle a wide range of interactive audio applications, including Voice over IP, videoconferencing, in-game chat, and even remote live music performances. It can scale from low bit-rate narrowband speech to very high quality stereo music. Its main features are: Sampling rates from 8 to 48 khz Bit-rates from 6 kb/s 510 kb/s Support for both constant bit-rate (CBR) and variable bit-rate (VBR) Audio bandwidth from narrowband to full-band Support for speech and music Support for mono and stereo Frame sizes from 2.5 ms to 60 ms Good loss robustness and packet loss concealment (PLC) Floating point and fixed-point implementation Documentation sections: Opus Encoder Opus Decoder Repacketizer Opus library information functions

2 Opus

Chapter 2 Module Index 2.1 Modules Here is a list of all modules: Opus Encoder.................................. 7 Opus Decoder.................................. 12 Repacketizer................................... 20 Error codes................................... 21 Pre-defined values for CTL interface...................... 23 Encoder related CTLs.............................. 25 Generic CTLs.................................. 34 Opus library information functions....................... 36

4 Module Index

Chapter 3 File Index 3.1 File List Here is a list of all files with brief descriptions: opus.h (Opus reference implementation API )................. 37 opus_defines.h (Opus reference implementation constants ).......... 39 opus_multistream.h (Opus reference implementation multistream API )... 43 opus_types.h (Opus reference implementation types )............. 49

6 File Index

Chapter 4 Module Documentation 4.1 Opus Encoder Since Opus is a stateful codec, the encoding process starts with creating an encoder state. Typedefs typedef struct OpusEncoder OpusEncoder Opus encoder state. Functions int opus_encoder_get_size (int channels) OpusEncoder opus_encoder_create (opus_int32 Fs, int channels, int application, int error) Allocates and initializes an encoder state. int opus_encoder_init (OpusEncoder st, opus_int32 Fs, int channels, int application) Initializes a previously allocated encoder state The memory pointed to by st must be the size returned by opus_encoder_get_size. int opus_encode (OpusEncoder st, const opus_int16 pcm, int frame_size, unsigned char data, int max_data_bytes) Encodes an Opus frame. int opus_encode_float (OpusEncoder st, const float pcm, int frame_size, unsigned char data, int max_data_bytes) Encodes an Opus frame from floating point input.

8 Module Documentation void opus_encoder_destroy (OpusEncoder st) Frees an OpusEncoder allocated by opus_encoder_create. int opus_encoder_ctl (OpusEncoder st, int request,...) Perform a CTL function on an Opus encoder. 4.1.1 Detailed Description Since Opus is a stateful codec, the encoding process starts with creating an encoder state. This can be done with: int error; OpusEncoder *enc; enc = opus_encoder_create(fs, channels, application, &error); From this point, enc can be used for encoding an audio stream. An encoder state must not be used for more than one stream at the same time. Similarly, the encoder state must not be re-initialized for each frame. While opus_encoder_create() allocates memory for the state, it s also possible to initialize pre-allocated memory: int size; int error; OpusEncoder *enc; size = opus_encoder_get_size(channels); enc = malloc(size); error = opus_encoder_init(enc, Fs, channels, application); where opus_encoder_get_size() returns the required size for the encoder state. Note that future versions of this code may change the size, so no assuptions should be made about it. The encoder state is always continuous in memory and only a shallow copy is sufficient to copy it (e.g. memcpy()) It is possible to change some of the encoder s settings using the opus_encoder_ctl() interface. All these settings already default to the recommended value, so they should only be changed when necessary. The most common settings one may want to change are: opus_encoder_ctl(enc, OPUS_SET_BITRATE(bitrate)); opus_encoder_ctl(enc, OPUS_SET_COMPLEXITY(complexity)); opus_encoder_ctl(enc, OPUS_SET_SIGNAL(signal_type)); where bitrate is in bits per second (b/s)

4.1 Opus Encoder 9 complexity is a value from 1 to 10, where 1 is the lowest complexity and 10 is the highest signal_type is either OPUS_AUTO (default), OPUS_SIGNAL_VOICE, or OPUS_SIGNAL_MUSIC See Encoder related CTLs and Generic CTLs for a complete list of parameters that can be set or queried. Most parameters can be set or changed at any time during a stream. To encode a frame, opus_encode() or opus_encode_float() must be called with exactly one frame (2.5, 5, 10, 20, 40 or 60 ms) of audio data: len = opus_encode(enc, audio_frame, frame_size, packet, max_packet); where audio_frame is the audio data in opus_int16 (or float for opus_encode_float()) frame_size is the duration of the frame in samples (per channel) packet is the byte array to which the compressed data is written max_packet is the maximum number of bytes that can be written in the packet (1276 bytes is recommended) opus_encode() and opus_encode_frame() return the number of bytes actually written to the packet. The return value can be negative, which indicates that an error has occurred. If the return value is 1 byte, then the packet does not need to be transmitted (DTX). Once the encoder state if no longer needed, it can be destroyed with opus_encoder_destroy(enc); If the encoder was created with opus_encoder_init() rather than opus_encoder_create(), then no action is required aside from potentially freeing the memory that was manually allocated for it (calling free(enc) for the example above) 4.1.2 Typedef Documentation 4.1.2.1 typedef struct OpusEncoder OpusEncoder Opus encoder state. This contains the complete state of an Opus encoder. It is position independent and can be freely copied. See also opus_encoder_create,opus_encoder_init

10 Module Documentation 4.1.3 Function Documentation 4.1.3.1 int opus_encode ( OpusEncoder st, const opus_int16 pcm, int frame_size, unsigned char data, int max_data_bytes ) Encodes an Opus frame. The passed frame_size must an opus frame size for the encoder s sampling rate. For example, at 48kHz the permitted values are 120, 240, 480, or 960. Passing in a duration of less than 10ms (480 samples at 48kHz) will prevent the encoder from using the LPC or hybrid modes. Returns [in] st OpusEncoder : Encoder state [in] pcm opus_int16 : Input signal (interleaved if 2 channels). length is frame_size channels sizeof(opus_int16) [in] frame_size int: Number of samples per frame of input signal [out] data char : Output payload (at least max_data_bytes long) [in] max_data_bytes int: Allocated memory for payload; don t use for controlling bitrate length of the data payload (in bytes) or Error codes 4.1.3.2 int opus_encode_float ( OpusEncoder st, const float pcm, int frame_size, unsigned char data, int max_data_bytes ) Encodes an Opus frame from floating point input. The passed frame_size must an opus frame size for the encoder s sampling rate. For example, at 48kHz the permitted values are 120, 240, 480, or 960. Passing in a duration of less than 10ms (480 samples at 48kHz) will prevent the encoder from using the LPC or hybrid modes. Returns [in] st OpusEncoder : Encoder state [in] pcm float : Input signal (interleaved if 2 channels). length is frame_- size channels sizeof(float) [in] frame_size int: Number of samples per frame of input signal [out] data char : Output payload (at least max_data_bytes long) [in] max_data_bytes int: Allocated memory for payload; don t use for controlling bitrate length of the data payload (in bytes) or Error codes

4.1 Opus Encoder 11 4.1.3.3 OpusEncoder opus_encoder_create ( opus_int32 Fs, int channels, int application, int error ) Allocates and initializes an encoder state. There are three coding modes: OPUS_APPLICATION_VOIP gives best quality at a given bitrate for voice signals. It enhances the input signal by high-pass filtering and emphasizing formants and harmonics. Optionally it includes in-band forward error correction to protect against packet loss. Use this mode for typical VoIP applications. Because of the enhancement, even at high bitrates the output may sound different from the input. OPUS_APPLICATION_AUDIO gives best quality at a given bitrate for most nonvoice signals like music. Use this mode for music and mixed (music/voice) content, broadcast, and applications requiring less than 15 ms of coding delay. OPUS_APPLICATION_RESTRICTED_LOWDELAY configures low-delay mode that disables the speech-optimized mode in exchange for slightly reduced delay. This is useful when the caller knows that the speech-optimized modes will not be needed (use with caution). Note [in] Fs opus_int32: Sampling rate of input signal (Hz) [in] channels int: Number of channels (1/2) in input signal [in] application int: Coding mode (OPUS_APPLICATION_VOIP/OPUS_- APPLICATION_AUDIO/OPUS_APPLICATION_RESTRICTED_- LOWDELAY) [out] error int : Error codes Regardless of the sampling rate and number channels selected, the Opus encoder can switch to a lower audio audio bandwidth or number of channels if the bitrate selected is too low. This also means that it is safe to always use 48 khz stereo input and let the encoder optimize the encoding. 4.1.3.4 int opus_encoder_ctl ( OpusEncoder st, int request,... ) Perform a CTL function on an Opus encoder. Generally the request and subsequent arguments are generated by a convenience macro. See also Encoder related CTLs 4.1.3.5 void opus_encoder_destroy ( OpusEncoder st ) Frees an OpusEncoder allocated by opus_encoder_create.

12 Module Documentation [in] st OpusEncoder : State to be freed. 4.1.3.6 int opus_encoder_get_size ( int channels ) 4.1.3.7 int opus_encoder_init ( OpusEncoder st, opus_int32 Fs, int channels, int application ) Initializes a previously allocated encoder state The memory pointed to by st must be the size returned by opus_encoder_get_size. This is intended for applications which use their own allocator instead of malloc. See also opus_encoder_create(),opus_encoder_get_size() To reset a previously initialized state use the OPUS_RESET_STATE CTL. [in] st OpusEncoder : Encoder state [in] Fs opus_int32: Sampling rate of input signal (Hz) [in] channels int: Number of channels (1/2) in input signal [in] application int: Coding mode (OPUS_APPLICATION_VOIP/OPUS_- APPLICATION_AUDIO/OPUS_APPLICATION_RESTRICTED_- LOWDELAY) Return values OPUS_OK Success or Error codes 4.2 Opus Decoder The decoding process also starts with creating a decoder state. Typedefs typedef struct OpusDecoder OpusDecoder Opus decoder state. Functions int opus_decoder_get_size (int channels) Gets the size of an OpusDecoder structure.

4.2 Opus Decoder 13 OpusDecoder opus_decoder_create (opus_int32 Fs, int channels, int error) Allocates and initializes a decoder state. int opus_decoder_init (OpusDecoder st, opus_int32 Fs, int channels) Initializes a previously allocated decoder state. int opus_decode (OpusDecoder st, const unsigned char data, int len, opus_- int16 pcm, int frame_size, int decode_fec) Decode an Opus frame. int opus_decode_float (OpusDecoder st, const unsigned char data, int len, float pcm, int frame_size, int decode_fec) Decode an opus frame with floating point output. int opus_decoder_ctl (OpusDecoder st, int request,...) Perform a CTL function on an Opus decoder. void opus_decoder_destroy (OpusDecoder st) Frees an OpusDecoder allocated by opus_decoder_create. int opus_packet_parse (const unsigned char data, int len, unsigned char out_- toc, const unsigned char frames[48], short size[48], int payload_offset) Parse an opus packet into one or more frames. int opus_packet_get_bandwidth (const unsigned char data) Gets the bandwidth of an Opus packet. int opus_packet_get_samples_per_frame (const unsigned char data, opus_int32 Fs) Gets the number of samples per frame from an Opus packet. int opus_packet_get_nb_channels (const unsigned char data) Gets the number of channels from an Opus packet. int opus_packet_get_nb_frames (const unsigned char packet[ ], int len) Gets the number of frames in an Opus packet. int opus_decoder_get_nb_samples (const OpusDecoder dec, const unsigned char packet[ ], int len) Gets the number of samples of an Opus packet.

14 Module Documentation 4.2.1 Detailed Description The decoding process also starts with creating a decoder state. This can be done with: int error; OpusDecoder *dec; dec = opus_decoder_create(fs, channels, &error); where Fs is the sampling rate and must be 8000, 12000, 16000, 24000, or 48000 channels is the number of channels (1 or 2) error will hold the error code in case or failure (or OPUS_OK on success) the return value is a newly created decoder state to be used for decoding While opus_decoder_create() allocates memory for the state, it s also possible to initialize pre-allocated memory: int size; int error; OpusDecoder *dec; size = opus_decoder_get_size(channels); dec = malloc(size); error = opus_decoder_init(dec, Fs, channels); where opus_decoder_get_size() returns the required size for the decoder state. Note that future versions of this code may change the size, so no assuptions should be made about it. The decoder state is always continuous in memory and only a shallow copy is sufficient to copy it (e.g. memcpy()) To decode a frame, opus_decode() or opus_decode_float() must be called with a packet of compressed audio data: frame_size = opus_decode(enc, packet, len, decoded, max_size); where packet is the byte array containing the compressed data len is the exact number of bytes contained in the packet decoded is the decoded audio data in opus_int16 (or float for opus_decode_- float()) max_size is the max duration of the frame in samples (per channel) that can fit into the decoded_frame array opus_decode() and opus_decode_frame() return the number of samples ()per channel) decoded from the packet. If that value is negative, then an error has occured. This can occur if the packet is corrupted or if the audio buffer is too small to hold the decoded audio.

4.2 Opus Decoder 15 4.2.2 Typedef Documentation 4.2.2.1 typedef struct OpusDecoder OpusDecoder Opus decoder state. This contains the complete state of an Opus decoder. It is position independent and can be freely copied. See also opus_decoder_create,opus_decoder_init 4.2.3 Function Documentation 4.2.3.1 int opus_decode ( OpusDecoder st, const unsigned char data, int len, opus_int16 pcm, int frame_size, int decode_fec ) Decode an Opus frame. Returns [in] st OpusDecoder : Decoder state [in] data char : Input payload. Use a NULL pointer to indicate packet loss [in] len int: Number of bytes in payload [out] pcm opus_int16 : Output signal (interleaved if 2 channels). length is frame_size channels sizeof(opus_int16) [in] frame_size Number of samples per channel of available space in pcm, if less than the maximum frame size (120ms) some frames can not be decoded [in] decode_fec int: Flag (0/1) to request that any in-band forward error correction data be decoded. If no such data is available the frame is decoded as if it were lost. Number of decoded samples or Error codes 4.2.3.2 int opus_decode_float ( OpusDecoder st, const unsigned char data, int len, float pcm, int frame_size, int decode_fec ) Decode an opus frame with floating point output. [in] st OpusDecoder : Decoder state [in] data char : Input payload. Use a NULL pointer to indicate packet loss [in] len int: Number of bytes in payload

16 Module Documentation Returns [out] pcm float : Output signal (interleaved if 2 channels). length is frame_- size channels sizeof(float) [in] frame_size Number of samples per channel of available space in pcm, if less than the maximum frame size (120ms) some frames can not be decoded [in] decode_fec int: Flag (0/1) to request that any in-band forward error correction data be decoded. If no such data is available the frame is decoded as if it were lost. Number of decoded samples or Error codes 4.2.3.3 OpusDecoder opus_decoder_create ( opus_int32 Fs, int channels, int error ) Allocates and initializes a decoder state. [in] Fs opus_int32: Sampling rate of input signal (Hz) [in] channels int: Number of channels (1/2) in input signal [out] error int : OPUS_OK Success or Error codes 4.2.3.4 int opus_decoder_ctl ( OpusDecoder st, int request,... ) Perform a CTL function on an Opus decoder. Generally the request and subsequent arguments are generated by a convenience macro. See also Generic CTLs 4.2.3.5 void opus_decoder_destroy ( OpusDecoder st ) Frees an OpusDecoder allocated by opus_decoder_create. [in] st OpusDecoder : State to be freed. 4.2.3.6 int opus_decoder_get_nb_samples ( const OpusDecoder dec, const unsigned char packet[ ], int len ) Gets the number of samples of an Opus packet.

4.2 Opus Decoder 17 Returns [in] dec OpusDecoder : Decoder state [in] packet char : Opus packet [in] len int: Length of packet Number of samples Return values OPUS_INVALID_PACKET The compressed data passed is corrupted or of an unsupported type 4.2.3.7 int opus_decoder_get_size ( int channels ) Gets the size of an OpusDecoder structure. [in] channels int: Number of channels Returns size 4.2.3.8 int opus_decoder_init ( OpusDecoder st, opus_int32 Fs, int channels ) Initializes a previously allocated decoder state. The state must be the size returned by opus_decoder_get_size. This is intended for applications which use their own allocator instead of malloc. See also opus_decoder_create,opus_decoder_get_size To reset a previously initialized state use the OPUS_RESET_STATE CTL. [in] st OpusDecoder : Decoder state. [in] Fs opus_int32: Sampling rate of input signal (Hz) [in] channels int: Number of channels (1/2) in input signal Return values OPUS_OK Success or Error codes

18 Module Documentation 4.2.3.9 int opus_packet_get_bandwidth ( const unsigned char data ) Gets the bandwidth of an Opus packet. [in] data char : Opus packet Return values OPUS_BANDWIDTH_NARROWBAND Narrowband (4kHz bandpass) OPUS_BANDWIDTH_MEDIUMBAND Mediumband (6kHz bandpass) OPUS_BANDWIDTH_WIDEBAND Wideband (8kHz bandpass) OPUS_BANDWIDTH_SUPERWIDEBAND Superwideband (12kHz bandpass) OPUS_BANDWIDTH_FULLBAND Fullband (20kHz bandpass) OPUS_INVALID_PACKET The compressed data passed is corrupted or of an unsupported type 4.2.3.10 int opus_packet_get_nb_channels ( const unsigned char data ) Gets the number of channels from an Opus packet. Returns [in] data char : Opus packet Number of channels Return values OPUS_INVALID_PACKET The compressed data passed is corrupted or of an unsupported type 4.2.3.11 int opus_packet_get_nb_frames ( const unsigned char packet[ ], int len ) Gets the number of frames in an Opus packet. Returns [in] packet char : Opus packet [in] len int: Length of packet Number of frames

4.2 Opus Decoder 19 Return values OPUS_INVALID_PACKET The compressed data passed is corrupted or of an unsupported type 4.2.3.12 int opus_packet_get_samples_per_frame ( const unsigned char data, opus_int32 Fs ) Gets the number of samples per frame from an Opus packet. Returns [in] data char : Opus packet [in] Fs opus_int32: Sampling rate in Hz Number of samples per frame Return values OPUS_INVALID_PACKET The compressed data passed is corrupted or of an unsupported type 4.2.3.13 int opus_packet_parse ( const unsigned char data, int len, unsigned char out_toc, const unsigned char frames[48], short size[48], int payload_offset ) Parse an opus packet into one or more frames. Opus_decode will perform this operation internally so most applications do not need to use this function. This function does not copy the frames, the returned pointers are pointers into the input packet. [in] data char : Opus packet to be parsed [in] len int: size of data [out] out_toc char : TOC pointer [out] frames char [48] encapsulated frames [out] size short[48] sizes of the encapsulated frames [out] payload_offset int : packet (in bytes) Returns number of frames returns the position of the payload within the

20 Module Documentation 4.3 Repacketizer The repacketizer can be used to merge multiple Opus packets into a single packet or alternatively to split Opus packets that have previously been merged. Typedefs typedef struct OpusRepacketizer OpusRepacketizer Functions int opus_repacketizer_get_size (void) OpusRepacketizer opus_repacketizer_init (OpusRepacketizer rp) OpusRepacketizer opus_repacketizer_create (void) void opus_repacketizer_destroy (OpusRepacketizer rp) int opus_repacketizer_cat (OpusRepacketizer rp, const unsigned char data, int len) opus_int32 opus_repacketizer_out_range (OpusRepacketizer rp, int begin, int end, unsigned char data, int maxlen) int opus_repacketizer_get_nb_frames (OpusRepacketizer rp) opus_int32 opus_repacketizer_out (OpusRepacketizer rp, unsigned char data, int maxlen) 4.3.1 Detailed Description The repacketizer can be used to merge multiple Opus packets into a single packet or alternatively to split Opus packets that have previously been merged.

4.4 Error codes 21 4.3.2 Typedef Documentation 4.3.2.1 typedef struct OpusRepacketizer OpusRepacketizer 4.3.3 Function Documentation 4.3.3.1 int opus_repacketizer_cat ( OpusRepacketizer rp, const unsigned char data, int len ) 4.3.3.2 OpusRepacketizer opus_repacketizer_create ( void ) 4.3.3.3 void opus_repacketizer_destroy ( OpusRepacketizer rp ) 4.3.3.4 int opus_repacketizer_get_nb_frames ( OpusRepacketizer rp ) 4.3.3.5 int opus_repacketizer_get_size ( void ) 4.3.3.6 OpusRepacketizer opus_repacketizer_init ( OpusRepacketizer rp ) 4.3.3.7 opus_int32 opus_repacketizer_out ( OpusRepacketizer rp, unsigned char data, int maxlen ) 4.3.3.8 opus_int32 opus_repacketizer_out_range ( OpusRepacketizer rp, int begin, int end, unsigned char data, int maxlen ) 4.4 Error codes Defines #define OPUS_OK No error. #define OPUS_BAD_ARG One or more invalid/out of range arguments. #define OPUS_BUFFER_TOO_SMALL The mode struct passed is invalid. #define OPUS_INTERNAL_ERROR An internal error was detected. #define OPUS_INVALID_PACKET The compressed data passed is corrupted. #define OPUS_UNIMPLEMENTED Invalid/unsupported request number.

22 Module Documentation #define OPUS_INVALID_STATE An encoder or decoder structure is invalid or already freed. #define OPUS_ALLOC_FAIL Memory allocation has failed. 4.4.1 Define Documentation 4.4.1.1 #define OPUS_ALLOC_FAIL Memory allocation has failed. 4.4.1.2 #define OPUS_BAD_ARG One or more invalid/out of range arguments. 4.4.1.3 #define OPUS_BUFFER_TOO_SMALL The mode struct passed is invalid. 4.4.1.4 #define OPUS_INTERNAL_ERROR An internal error was detected. 4.4.1.5 #define OPUS_INVALID_PACKET The compressed data passed is corrupted. 4.4.1.6 #define OPUS_INVALID_STATE An encoder or decoder structure is invalid or already freed. 4.4.1.7 #define OPUS_OK No error. 4.4.1.8 #define OPUS_UNIMPLEMENTED Invalid/unsupported request number.

4.5 Pre-defined values for CTL interface 23 4.5 Pre-defined values for CTL interface Defines #define OPUS_AUTO Auto/default setting. #define OPUS_BITRATE_MAX Maximum bitrate. #define OPUS_APPLICATION_VOIP Best for most VoIP/videoconference applications where listening quality and intelligibility matter most. #define OPUS_APPLICATION_AUDIO Best for broadcast/high-fidelity application where the decoded audio should be as close as possible to the input. #define OPUS_APPLICATION_RESTRICTED_LOWDELAY Only use when lowest-achievable latency is what matters most. #define OPUS_SIGNAL_VOICE 3001 Signal being encoded is voice. #define OPUS_SIGNAL_MUSIC 3002 Signal being encoded is music. #define OPUS_BANDWIDTH_NARROWBAND 4kHz bandpass #define OPUS_BANDWIDTH_MEDIUMBAND 6kHz bandpass #define OPUS_BANDWIDTH_WIDEBAND 8kHz bandpass #define OPUS_BANDWIDTH_SUPERWIDEBAND 12kHz bandpass #define OPUS_BANDWIDTH_FULLBAND 20kHz bandpass 4.5.1 Detailed Description See also Generic CTLs, Encoder related CTLs

24 Module Documentation 4.5.2 Define Documentation 4.5.2.1 #define OPUS_APPLICATION_AUDIO Best for broadcast/high-fidelity application where the decoded audio should be as close as possible to the input. 4.5.2.2 #define OPUS_APPLICATION_RESTRICTED_LOWDELAY Only use when lowest-achievable latency is what matters most. Voice-optimized modes cannot be used. 4.5.2.3 #define OPUS_APPLICATION_VOIP Best for most VoIP/videoconference applications where listening quality and intelligibility matter most. 4.5.2.4 #define OPUS_AUTO Auto/default setting. 4.5.2.5 #define OPUS_BANDWIDTH_FULLBAND 20kHz bandpass 4.5.2.6 #define OPUS_BANDWIDTH_MEDIUMBAND 6kHz bandpass 4.5.2.7 #define OPUS_BANDWIDTH_NARROWBAND 4kHz bandpass 4.5.2.8 #define OPUS_BANDWIDTH_SUPERWIDEBAND 12kHz bandpass 4.5.2.9 #define OPUS_BANDWIDTH_WIDEBAND 8kHz bandpass

4.6 Encoder related CTLs 25 4.5.2.10 #define OPUS_BITRATE_MAX Maximum bitrate. 4.5.2.11 #define OPUS_SIGNAL_MUSIC 3002 Signal being encoded is music. 4.5.2.12 #define OPUS_SIGNAL_VOICE 3001 Signal being encoded is voice. 4.6 Encoder related CTLs These are convenience macros for use with the opus_encode_ctl interface. Defines #define OPUS_SET_COMPLEXITY(x) Configures the encoder s computational complexity. #define OPUS_GET_COMPLEXITY(x) Gets the encoder s complexity configuration,. #define OPUS_SET_BITRATE(x) Configures the bitrate in the encoder. #define OPUS_GET_BITRATE(x) Gets the encoder s bitrate configuration,. #define OPUS_SET_VBR(x) Configures VBR in the encoder. #define OPUS_GET_VBR(x) Gets the encoder s VBR configuration,. #define OPUS_SET_VBR_CONSTRAINT(x) Configures constrained VBR in the encoder. #define OPUS_GET_VBR_CONSTRAINT(x) Gets the encoder s constrained VBR configuration. #define OPUS_SET_FORCE_CHANNELS(x) Configures mono/stereo forcing in the encoder.

26 Module Documentation #define OPUS_GET_FORCE_CHANNELS(x) Gets the encoder s forced channel configuration,. #define OPUS_SET_MAX_BANDWIDTH(x) Configures the encoder s maximum bandpass allowed,. #define OPUS_GET_MAX_BANDWIDTH(x) Gets the encoder s configured maximum bandpass allowed,. #define OPUS_SET_BANDWIDTH(x) Configures the encoder s bandpass,. #define OPUS_SET_SIGNAL(x) Configures the type of signal being encoded. #define OPUS_GET_SIGNAL(x) Gets the encoder s configured signal type,. #define OPUS_SET_APPLICATION(x) Configures the encoder s intended application. #define OPUS_GET_APPLICATION(x) Gets the encoder s configured application,. #define OPUS_GET_LOOKAHEAD(x) Gets the total samples of delay added by the entire codec. #define OPUS_SET_INBAND_FEC(x) Configures the encoder s use of inband forward error correction. #define OPUS_GET_INBAND_FEC(x) Gets encoder s configured use of inband forward error correction,. #define OPUS_SET_PACKET_LOSS_PERC(x) Configures the encoder s expected packet loss percentage. #define OPUS_GET_PACKET_LOSS_PERC(x) Gets the encoder s configured packet loss percentage,. #define OPUS_SET_DTX(x) Configures the encoder s use of discontinuous transmission. #define OPUS_GET_DTX(x) Gets encoder s configured use of discontinuous transmission,.

4.6 Encoder related CTLs 27 4.6.1 Detailed Description These are convenience macros for use with the opus_encode_ctl interface. They are used to generate the appropriate series of arguments for that call, passing the correct type, size and so on as expected for each particular request. Some usage examples: int ret; ret = opus_encoder_ctl(enc_ctx, OPUS_SET_BANDWIDTH(OPUS_AUTO)); if (ret!= OPUS_OK) return ret; int rate; opus_encoder_ctl(enc_ctx, OPUS_GET_BANDWIDTH(&rate)); opus_encoder_ctl(enc_ctx, OPUS_RESET_STATE); See also Generic CTLs, Opus Encoder 4.6.2 Define Documentation 4.6.2.1 #define OPUS_GET_APPLICATION( x ) Gets the encoder s configured application,. See also OPUS_SET_APPLICATION [out] x int : Application value 4.6.2.2 #define OPUS_GET_BITRATE( x ) Gets the encoder s bitrate configuration,. See also OPUS_SET_BITRATE [out] x opus_int32 : bitrate in bits per second. 4.6.2.3 #define OPUS_GET_COMPLEXITY( x ) Gets the encoder s complexity configuration,.

28 Module Documentation See also OPUS_SET_COMPLEXITY [out] x int : 0-10, inclusive 4.6.2.4 #define OPUS_GET_DTX( x ) Gets encoder s configured use of discontinuous transmission,. See also OPUS_SET_DTX [out] x int : DTX flag 4.6.2.5 #define OPUS_GET_FORCE_CHANNELS( x ) Gets the encoder s forced channel configuration,. See also OPUS_SET_FORCE_CHANNELS [out] x int : OPUS_AUTO; 0; 1 4.6.2.6 #define OPUS_GET_INBAND_FEC( x ) Gets encoder s configured use of inband forward error correction,. See also OPUS_SET_INBAND_FEC [out] x int : FEC flag

4.6 Encoder related CTLs 29 4.6.2.7 #define OPUS_GET_LOOKAHEAD( x ) Gets the total samples of delay added by the entire codec. This can be queried by the encoder and then the provided number of samples can be skipped on from the start of the decoder s output to provide time aligned input and output. From the perspective of a decoding application the real data begins this many samples late. The decoder contribution to this delay is identical for all decoders, but the encoder portion of the delay may vary from implementation to implementation, version to version, or even depend on the encoder s initial configuration. Applications needing delay compensation should call this CTL rather than hard-coding a value. [out] x int : Number of lookahead samples 4.6.2.8 #define OPUS_GET_MAX_BANDWIDTH( x ) Gets the encoder s configured maximum bandpass allowed,. See also OPUS_SET_MAX_BANDWIDTH [out] x int : Bandwidth value 4.6.2.9 #define OPUS_GET_PACKET_LOSS_PERC( x ) Gets the encoder s configured packet loss percentage,. See also OPUS_SET_PACKET_LOSS_PERC [out] x int : Loss percentage in the range 0-100, inclusive. 4.6.2.10 #define OPUS_GET_SIGNAL( x ) Gets the encoder s configured signal type,. See also OPUS_SET_SIGNAL

30 Module Documentation [out] x int : Signal type 4.6.2.11 #define OPUS_GET_VBR( x ) Gets the encoder s VBR configuration,. See also OPUS_SET_VBR [out] x int : 0; 1 4.6.2.12 #define OPUS_GET_VBR_CONSTRAINT( x ) Gets the encoder s constrained VBR configuration. See also OPUS_SET_VBR_CONSTRAINT [out] x int : 0; 1 4.6.2.13 #define OPUS_SET_APPLICATION( x ) Configures the encoder s intended application. The initial value is a mandatory argument to the encoder_create function. The supported values are: OPUS_APPLICATION_VOIP Process signal for improved speech intelligibility OPUS_APPLICATION_AUDIO Favor faithfulness to the original input OPUS_APPLICATION_RESTRICTED_LOWDELAY Configure the minimum possible coding delay [in] x int: Application value

4.6 Encoder related CTLs 31 4.6.2.14 #define OPUS_SET_BANDWIDTH( x ) Configures the encoder s bandpass,. See also OPUS_GET_BANDWIDTH The supported values are: OPUS_AUTO (default) OPUS_BANDWIDTH_NARROWBAND 4kHz passband OPUS_BANDWIDTH_MEDIUMBAND 6kHz passband OPUS_BANDWIDTH_WIDEBAND 8kHz passband OPUS_BANDWIDTH_SUPERWIDEBAND 12kHz passband OPUS_BANDWIDTH_FULLBAND 20kHz passband [in] x int: Bandwidth value 4.6.2.15 #define OPUS_SET_BITRATE( x ) Configures the bitrate in the encoder. Rates from 500 to 512000 bits per second are meaningful as well as the special values OPUS_BITRATE_AUTO and OPUS_BITRATE_MAX. The value OPUS_- BITRATE_MAX can be used to cause the codec to use as much rate as it can, which is useful for controlling the rate by adjusting the output buffer size. [in] x opus_int32: bitrate in bits per second. 4.6.2.16 #define OPUS_SET_COMPLEXITY( x ) Configures the encoder s computational complexity. The supported range is 0-10 inclusive with 10 representing the highest complexity. The default value is 10. [in] x int: 0-10, inclusive 4.6.2.17 #define OPUS_SET_DTX( x ) Configures the encoder s use of discontinuous transmission.

32 Module Documentation Note This is only applicable to the LPC layer [in] x int: DTX flag, 0 (disabled) is default 4.6.2.18 #define OPUS_SET_FORCE_CHANNELS( x ) Configures mono/stereo forcing in the encoder. This is useful when the caller knows that the input signal is currently a mono source embedded in a stereo stream. [in] x int: OPUS_AUTO (default); 1 (forced mono); 2 (forced stereo) 4.6.2.19 #define OPUS_SET_INBAND_FEC( x ) Configures the encoder s use of inband forward error correction. Note This is only applicable to the LPC layer [in] x int: FEC flag, 0 (disabled) is default 4.6.2.20 #define OPUS_SET_MAX_BANDWIDTH( x ) Configures the encoder s maximum bandpass allowed,. See also OPUS_GET_MAX_BANDWIDTH The supported values are: OPUS_BANDWIDTH_NARROWBAND 4kHz passband OPUS_BANDWIDTH_MEDIUMBAND 6kHz passband OPUS_BANDWIDTH_WIDEBAND 8kHz passband OPUS_BANDWIDTH_SUPERWIDEBAND 12kHz passband OPUS_BANDWIDTH_FULLBAND 20kHz passband (default) [in] x int: Bandwidth value

4.6 Encoder related CTLs 33 4.6.2.21 #define OPUS_SET_PACKET_LOSS_PERC( x ) Configures the encoder s expected packet loss percentage. Higher values with trigger progressively more loss resistant behavior in the encoder at the expense of quality at a given bitrate in the lossless case, but greater quality under loss. [in] x int: Loss percentage in the range 0-100, inclusive. 4.6.2.22 #define OPUS_SET_SIGNAL( x ) Configures the type of signal being encoded. This is a hint which helps the encoder s mode selection. The supported values are: OPUS_SIGNAL_AUTO (default) OPUS_SIGNAL_VOICE OPUS_SIGNAL_MUSIC [in] x int: Signal type 4.6.2.23 #define OPUS_SET_VBR( x ) Configures VBR in the encoder. The following values are currently supported: 0 CBR 1 VBR (default) The configured bitrate may not be met exactly because frames must be an integer number of bytes in length. Warning Only the MDCT mode of Opus can provide hard CBR behavior. [in] x int: 0; 1 (default)

34 Module Documentation 4.6.2.24 #define OPUS_SET_VBR_CONSTRAINT( x ) Configures constrained VBR in the encoder. The following values are currently supported: 0 Unconstrained VBR (default) 1 Maximum one frame buffering delay assuming transport with a serialization speed of the nominal bitrate This setting is irrelevant when the encoder is in CBR mode. Warning Only the MDCT mode of Opus currently heeds the constraint. Speech mode ignores it completely, hybrid mode may fail to obey it if the LPC layer uses more bitrate than the constraint would have permitted. [in] x int: 0 (default); 1 4.7 Generic CTLs These macros are used with the opus_decoder_ctl and opus_encoder_ctl calls to generate a particular request. Defines #define OPUS_RESET_STATE Resets the codec state to be equivalent to a freshly initialized state. #define OPUS_GET_FINAL_RANGE(x) Gets the final state of the codec s entropy coder. #define OPUS_GET_PITCH(x) Gets the pitch of the last decoded frame, if available. #define OPUS_GET_BANDWIDTH(x) Gets the encoder s configured bandpass or the decoder s last bandpass,. 4.7.1 Detailed Description These macros are used with the opus_decoder_ctl and opus_encoder_ctl calls to generate a particular request. When called on an OpusDecoder they apply to that particular decoder instance. When called on an OpusEncoder they apply to the corresponding setting on that encoder instance, if present. Some usage examples:

4.7 Generic CTLs 35 int ret; opus_int32 pitch; ret = opus_decoder_ctl(dec_ctx, OPUS_GET_PITCH(&pitch)); if (ret == OPUS_OK) return ret; opus_encoder_ctl(enc_ctx, OPUS_RESET_STATE); opus_decoder_ctl(dec_ctx, OPUS_RESET_STATE); opus_int32 enc_bw, dec_bw; opus_encoder_ctl(enc_ctx, OPUS_GET_BANDWIDTH(&enc_bw)); opus_decoder_ctl(dec_ctx, OPUS_GET_BANDWIDTH(&dec_bw)); if (enc_bw!= dec_bw) { printf("packet bandwidth mismatch!\n"); } See also Opus Encoder, opus_decoder_ctl, opus_encoder_ctl 4.7.2 Define Documentation 4.7.2.1 #define OPUS_GET_BANDWIDTH( x ) Gets the encoder s configured bandpass or the decoder s last bandpass,. See also OPUS_SET_BANDWIDTH [out] x int : Bandwidth value 4.7.2.2 #define OPUS_GET_FINAL_RANGE( x ) Gets the final state of the codec s entropy coder. This is used for testing purposes, The encoder and decoder state should be identical after coding a payload (assuming no data corruption or software bugs) [out] x opus_uint32 : Entropy coder state 4.7.2.3 #define OPUS_GET_PITCH( x ) Gets the pitch of the last decoded frame, if available. This can be used for any post-processing algorithm requiring the use of pitch, e.g. time stretching/shortening. If the last frame was not voiced, or if the pitch was not coded in the frame, then zero is returned. This CTL is only implemented for decoder instances.

36 Module Documentation [out] x opus_int32 : pitch period at 48 khz (or 0 if not available) 4.7.2.4 #define OPUS_RESET_STATE Resets the codec state to be equivalent to a freshly initialized state. This should be called when switching streams in order to prevent the back to back decoding from giving different results from one at a time decoding. 4.8 Opus library information functions Functions const char opus_strerror (int error) Converts an opus error code into a human readable string. const char opus_get_version_string (void) Gets the libopus version string. 4.8.1 Function Documentation 4.8.1.1 const char opus_get_version_string ( void ) Gets the libopus version string. Returns Version string 4.8.1.2 const char opus_strerror ( int error ) Converts an opus error code into a human readable string. [in] error int: Error number Returns Error string

Chapter 5 File Documentation 5.1 opus.h File Reference Opus reference implementation API. #include "opus_types.h" #include "opus_defines.h" Typedefs typedef struct OpusEncoder OpusEncoder Opus encoder state. typedef struct OpusDecoder OpusDecoder Opus decoder state. typedef struct OpusRepacketizer OpusRepacketizer Functions int opus_encoder_get_size (int channels) OpusEncoder opus_encoder_create (opus_int32 Fs, int channels, int application, int error) Allocates and initializes an encoder state. int opus_encoder_init (OpusEncoder st, opus_int32 Fs, int channels, int application) Initializes a previously allocated encoder state The memory pointed to by st must be the size returned by opus_encoder_get_size. int opus_encode (OpusEncoder st, const opus_int16 pcm, int frame_size, unsigned char data, int max_data_bytes)

38 File Documentation Encodes an Opus frame. int opus_encode_float (OpusEncoder st, const float pcm, int frame_size, unsigned char data, int max_data_bytes) Encodes an Opus frame from floating point input. void opus_encoder_destroy (OpusEncoder st) Frees an OpusEncoder allocated by opus_encoder_create. int opus_encoder_ctl (OpusEncoder st, int request,...) Perform a CTL function on an Opus encoder. int opus_decoder_get_size (int channels) Gets the size of an OpusDecoder structure. OpusDecoder opus_decoder_create (opus_int32 Fs, int channels, int error) Allocates and initializes a decoder state. int opus_decoder_init (OpusDecoder st, opus_int32 Fs, int channels) Initializes a previously allocated decoder state. int opus_decode (OpusDecoder st, const unsigned char data, int len, opus_- int16 pcm, int frame_size, int decode_fec) Decode an Opus frame. int opus_decode_float (OpusDecoder st, const unsigned char data, int len, float pcm, int frame_size, int decode_fec) Decode an opus frame with floating point output. int opus_decoder_ctl (OpusDecoder st, int request,...) Perform a CTL function on an Opus decoder. void opus_decoder_destroy (OpusDecoder st) Frees an OpusDecoder allocated by opus_decoder_create. int opus_packet_parse (const unsigned char data, int len, unsigned char out_- toc, const unsigned char frames[48], short size[48], int payload_offset) Parse an opus packet into one or more frames. int opus_packet_get_bandwidth (const unsigned char data) Gets the bandwidth of an Opus packet. int opus_packet_get_samples_per_frame (const unsigned char data, opus_int32 Fs) Gets the number of samples per frame from an Opus packet. int opus_packet_get_nb_channels (const unsigned char data)

5.2 opus_defines.h File Reference 39 Gets the number of channels from an Opus packet. int opus_packet_get_nb_frames (const unsigned char packet[ ], int len) Gets the number of frames in an Opus packet. int opus_decoder_get_nb_samples (const OpusDecoder dec, const unsigned char packet[ ], int len) Gets the number of samples of an Opus packet. int opus_repacketizer_get_size (void) OpusRepacketizer opus_repacketizer_init (OpusRepacketizer rp) OpusRepacketizer opus_repacketizer_create (void) void opus_repacketizer_destroy (OpusRepacketizer rp) int opus_repacketizer_cat (OpusRepacketizer rp, const unsigned char data, int len) opus_int32 opus_repacketizer_out_range (OpusRepacketizer rp, int begin, int end, unsigned char data, int maxlen) int opus_repacketizer_get_nb_frames (OpusRepacketizer rp) opus_int32 opus_repacketizer_out (OpusRepacketizer rp, unsigned char data, int maxlen) 5.1.1 Detailed Description Opus reference implementation API. 5.2 opus_defines.h File Reference Opus reference implementation constants. #include "opus_types.h" Defines #define OPUS_OK No error. #define OPUS_BAD_ARG One or more invalid/out of range arguments. #define OPUS_BUFFER_TOO_SMALL The mode struct passed is invalid. #define OPUS_INTERNAL_ERROR An internal error was detected.

40 File Documentation #define OPUS_INVALID_PACKET The compressed data passed is corrupted. #define OPUS_UNIMPLEMENTED Invalid/unsupported request number. #define OPUS_INVALID_STATE An encoder or decoder structure is invalid or already freed. #define OPUS_ALLOC_FAIL Memory allocation has failed. #define OPUS_AUTO Auto/default setting. #define OPUS_BITRATE_MAX Maximum bitrate. #define OPUS_APPLICATION_VOIP Best for most VoIP/videoconference applications where listening quality and intelligibility matter most. #define OPUS_APPLICATION_AUDIO Best for broadcast/high-fidelity application where the decoded audio should be as close as possible to the input. #define OPUS_APPLICATION_RESTRICTED_LOWDELAY Only use when lowest-achievable latency is what matters most. #define OPUS_SIGNAL_VOICE 3001 Signal being encoded is voice. #define OPUS_SIGNAL_MUSIC 3002 Signal being encoded is music. #define OPUS_BANDWIDTH_NARROWBAND 4kHz bandpass #define OPUS_BANDWIDTH_MEDIUMBAND 6kHz bandpass #define OPUS_BANDWIDTH_WIDEBAND 8kHz bandpass #define OPUS_BANDWIDTH_SUPERWIDEBAND 12kHz bandpass

5.2 opus_defines.h File Reference 41 #define OPUS_BANDWIDTH_FULLBAND 20kHz bandpass #define OPUS_SET_COMPLEXITY(x) Configures the encoder s computational complexity. #define OPUS_GET_COMPLEXITY(x) Gets the encoder s complexity configuration,. #define OPUS_SET_BITRATE(x) Configures the bitrate in the encoder. #define OPUS_GET_BITRATE(x) Gets the encoder s bitrate configuration,. #define OPUS_SET_VBR(x) Configures VBR in the encoder. #define OPUS_GET_VBR(x) Gets the encoder s VBR configuration,. #define OPUS_SET_VBR_CONSTRAINT(x) Configures constrained VBR in the encoder. #define OPUS_GET_VBR_CONSTRAINT(x) Gets the encoder s constrained VBR configuration. #define OPUS_SET_FORCE_CHANNELS(x) Configures mono/stereo forcing in the encoder. #define OPUS_GET_FORCE_CHANNELS(x) Gets the encoder s forced channel configuration,. #define OPUS_SET_MAX_BANDWIDTH(x) Configures the encoder s maximum bandpass allowed,. #define OPUS_GET_MAX_BANDWIDTH(x) Gets the encoder s configured maximum bandpass allowed,. #define OPUS_SET_BANDWIDTH(x) Configures the encoder s bandpass,. #define OPUS_SET_SIGNAL(x) Configures the type of signal being encoded.