Opus Library
opus.h
Go to the documentation of this file.
1 /* Copyright (c) 2010-2011 Xiph.Org Foundation, Skype Limited
2  Written by Jean-Marc Valin and Koen Vos */
3 /*
4  Redistribution and use in source and binary forms, with or without
5  modification, are permitted provided that the following conditions
6  are met:
7 
8  - Redistributions of source code must retain the above copyright
9  notice, this list of conditions and the following disclaimer.
10 
11  - Redistributions in binary form must reproduce the above copyright
12  notice, this list of conditions and the following disclaimer in the
13  documentation and/or other materials provided with the distribution.
14 
15  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16  ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
19  OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27 
33 #ifndef OPUS_H
34 #define OPUS_H
35 
36 #include "opus_types.h"
37 #include "opus_defines.h"
38 
39 
40 #ifdef ALLOW_FULL_COMPLEXITY
41 
42 #ifdef ALLOW_STEREO
43 
44 #define ENC_DYN_ALLOC_SIZE (2160 + 3332 + 1984 + 2)
45 #else
46 
47 #define ENC_DYN_ALLOC_SIZE (1080 + 3332 + 2)
48 #endif
49 
50 #else
51 
52 #define ENC_DYN_ALLOC_SIZE (1080+(2*21)+960+1216+2)
53 #endif
54 
55 #define DEC_DYN_ALLOC_SIZE (168+960+1216+2)
58 #ifdef __cplusplus
59 extern "C" {
60 #endif
61 
282 typedef struct OpusEncoder OpusEncoder;
283 
292 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_encoder_get_size(int channels, int complexity);
293 
319 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusEncoder *opus_encoder_create(
320  opus_int32 Fs,
321  int channels,
322  int application,
323  int complexity,
324  int *error
325 );
326 
343 OPUS_EXPORT int opus_encoder_init(
344  OpusEncoder *st,
345  opus_int32 Fs,
346  int channels,
347  int application,
348  int complexity
349 ) OPUS_ARG_NONNULL(1);
350 
381 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_encode(
382  OpusEncoder *st,
383  const opus_int16 *pcm,
384  int frame_size,
385  unsigned char *data,
386  opus_int32 max_data_bytes,
387  opus_int32 *Scratch_Buffer
388 ) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2) OPUS_ARG_NONNULL(4);
389 
423 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_encode_float(
424  OpusEncoder *st,
425  const float *pcm,
426  int frame_size,
427  unsigned char *data,
428  opus_int32 max_data_bytes
429 ) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2) OPUS_ARG_NONNULL(4);
430 
434 OPUS_EXPORT void opus_encoder_destroy(OpusEncoder *st);
435 
449 OPUS_EXPORT int opus_encoder_ctl(OpusEncoder *st, int request, ...) OPUS_ARG_NONNULL(1);
520 typedef struct OpusDecoder OpusDecoder;
521 
527 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_decoder_get_size(int channels);
528 
546 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusDecoder *opus_decoder_create(
547  opus_int32 Fs,
548  int channels,
549  int *error
550 );
551 
563 OPUS_EXPORT int opus_decoder_init(
564  OpusDecoder *st,
565  opus_int32 Fs,
566  int channels
567 ) OPUS_ARG_NONNULL(1);
568 
586 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_decode(
587  OpusDecoder *st,
588  const unsigned char *data,
589  opus_int32 len,
590  opus_int16 *pcm,
591  int frame_size,
592  int decode_fec,
593  opus_int32 *Scratch_Buffer
594 ) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4);
595 
612 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_decode_float(
613  OpusDecoder *st,
614  const unsigned char *data,
615  opus_int32 len,
616  float *pcm,
617  int frame_size,
618  int decode_fec
619 ) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4);
620 
635 OPUS_EXPORT int opus_decoder_ctl(OpusDecoder *st, int request, ...) OPUS_ARG_NONNULL(1);
636 
640 OPUS_EXPORT void opus_decoder_destroy(OpusDecoder *st);
641 
655 OPUS_EXPORT int opus_packet_parse(
656  const unsigned char *data,
657  opus_int32 len,
658  unsigned char *out_toc,
659  const unsigned char *frames[48],
660  opus_int16 size[48],
661  int *payload_offset
662 ) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4);
663 
673 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_packet_get_bandwidth(const unsigned char *data) OPUS_ARG_NONNULL(1);
674 
684 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_packet_get_samples_per_frame(const unsigned char *data, opus_int32 Fs) OPUS_ARG_NONNULL(1);
685 
691 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_packet_get_nb_channels(const unsigned char *data) OPUS_ARG_NONNULL(1);
692 
700 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_packet_get_nb_frames(const unsigned char packet[], opus_int32 len) OPUS_ARG_NONNULL(1);
701 
712 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_packet_get_nb_samples(const unsigned char packet[], opus_int32 len, opus_int32 Fs) OPUS_ARG_NONNULL(1);
713 
722 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_decoder_get_nb_samples(const OpusDecoder *dec, const unsigned char packet[], opus_int32 len) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2);
723 
734 OPUS_EXPORT void opus_pcm_soft_clip(float *pcm, int frame_size, int channels, float *softclip_mem);
735 
736 
888 
892 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_repacketizer_get_size(void);
893 
912 OPUS_EXPORT OpusRepacketizer *opus_repacketizer_init(OpusRepacketizer *rp) OPUS_ARG_NONNULL(1);
913 
919 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusRepacketizer *opus_repacketizer_create(void);
920 
925 OPUS_EXPORT void opus_repacketizer_destroy(OpusRepacketizer *rp);
926 
974 OPUS_EXPORT int opus_repacketizer_cat(OpusRepacketizer *rp, const unsigned char *data, opus_int32 len) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2);
975 
976 
1008 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_repacketizer_out_range(OpusRepacketizer *rp, int begin, int end, unsigned char *data, opus_int32 maxlen) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4);
1009 
1020 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_repacketizer_get_nb_frames(OpusRepacketizer *rp) OPUS_ARG_NONNULL(1);
1021 
1051 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_repacketizer_out(OpusRepacketizer *rp, unsigned char *data, opus_int32 maxlen) OPUS_ARG_NONNULL(1);
1052 
1065 OPUS_EXPORT int opus_packet_pad(unsigned char *data, opus_int32 len, opus_int32 new_len);
1066 
1078 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_packet_unpad(unsigned char *data, opus_int32 len);
1079 
1094 OPUS_EXPORT int opus_multistream_packet_pad(unsigned char *data, opus_int32 len, opus_int32 new_len, int nb_streams);
1095 
1109 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_multistream_packet_unpad(unsigned char *data, opus_int32 len, int nb_streams);
1110 
1113 #ifdef __cplusplus
1114 }
1115 #endif
1116 
1117 #endif /* OPUS_H */
OPUS_EXPORT int opus_encoder_ctl(OpusEncoder *st, int request,...) OPUS_ARG_NONNULL(1)
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_encode(OpusEncoder *st, const opus_int16 *pcm, int frame_size, unsigned char *data, opus_int32 max_data_bytes, opus_int32 *Scratch_Buffer) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2) OPUS_ARG_NONNULL(4)
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_packet_get_bandwidth(const unsigned char *data) OPUS_ARG_NONNULL(1)
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusEncoder * opus_encoder_create(opus_int32 Fs, int channels, int application, int complexity, int *error)
Opus reference implementation types.
struct OpusRepacketizer OpusRepacketizer
Definition: opus.h:887
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_packet_get_nb_frames(const unsigned char packet[], opus_int32 len) OPUS_ARG_NONNULL(1)
OPUS_EXPORT void opus_repacketizer_destroy(OpusRepacketizer *rp)
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_repacketizer_get_nb_frames(OpusRepacketizer *rp) OPUS_ARG_NONNULL(1)
short opus_int16
Definition: opus_types.h:144
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_packet_unpad(unsigned char *data, opus_int32 len)
OPUS_EXPORT int opus_decoder_ctl(OpusDecoder *st, int request,...) OPUS_ARG_NONNULL(1)
OPUS_EXPORT int opus_packet_parse(const unsigned char *data, opus_int32 len, unsigned char *out_toc, const unsigned char *frames[48], opus_int16 size[48], int *payload_offset) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4)
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_decode(OpusDecoder *st, const unsigned char *data, opus_int32 len, opus_int16 *pcm, int frame_size, int decode_fec, opus_int32 *Scratch_Buffer) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4)
OPUS_EXPORT int opus_multistream_packet_pad(unsigned char *data, opus_int32 len, opus_int32 new_len, int nb_streams)
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_packet_get_samples_per_frame(const unsigned char *data, opus_int32 Fs) OPUS_ARG_NONNULL(1)
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_repacketizer_out(OpusRepacketizer *rp, unsigned char *data, opus_int32 maxlen) OPUS_ARG_NONNULL(1)
Opus reference implementation constants.
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_multistream_packet_unpad(unsigned char *data, opus_int32 len, int nb_streams)
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusDecoder * opus_decoder_create(opus_int32 Fs, int channels, int *error)
OPUS_EXPORT int opus_packet_pad(unsigned char *data, opus_int32 len, opus_int32 new_len)
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_repacketizer_out_range(OpusRepacketizer *rp, int begin, int end, unsigned char *data, opus_int32 maxlen) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4)
OPUS_EXPORT int opus_repacketizer_cat(OpusRepacketizer *rp, const unsigned char *data, opus_int32 len) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2)
OPUS_EXPORT int opus_encoder_init(OpusEncoder *st, opus_int32 Fs, int channels, int application, int complexity) OPUS_ARG_NONNULL(1)
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_encoder_get_size(int channels, int complexity)
OPUS_EXPORT int opus_decoder_init(OpusDecoder *st, opus_int32 Fs, int channels) OPUS_ARG_NONNULL(1)
int opus_int32
Definition: opus_types.h:146
struct OpusEncoder OpusEncoder
Definition: opus.h:282
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_decoder_get_size(int channels)
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusRepacketizer * opus_repacketizer_create(void)
OPUS_EXPORT void opus_pcm_soft_clip(float *pcm, int frame_size, int channels, float *softclip_mem)
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_encode_float(OpusEncoder *st, const float *pcm, int frame_size, unsigned char *data, opus_int32 max_data_bytes) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2) OPUS_ARG_NONNULL(4)
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_packet_get_nb_channels(const unsigned char *data) OPUS_ARG_NONNULL(1)
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_decoder_get_nb_samples(const OpusDecoder *dec, const unsigned char packet[], opus_int32 len) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2)
OPUS_EXPORT void opus_encoder_destroy(OpusEncoder *st)
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_packet_get_nb_samples(const unsigned char packet[], opus_int32 len, opus_int32 Fs) OPUS_ARG_NONNULL(1)
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_decode_float(OpusDecoder *st, const unsigned char *data, opus_int32 len, float *pcm, int frame_size, int decode_fec) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4)
OPUS_EXPORT void opus_decoder_destroy(OpusDecoder *st)
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_repacketizer_get_size(void)
struct OpusDecoder OpusDecoder
Definition: opus.h:520
OPUS_EXPORT OpusRepacketizer * opus_repacketizer_init(OpusRepacketizer *rp) OPUS_ARG_NONNULL(1)
© Copyright 1995-2020, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale