xref: /aosp_15_r20/external/libopus/include/opus_projection.h (revision a58d3d2adb790c104798cd88c8a3aff4fa8b82cc)
1*a58d3d2aSXin Li /* Copyright (c) 2017 Google Inc.
2*a58d3d2aSXin Li    Written by Andrew Allen */
3*a58d3d2aSXin Li /*
4*a58d3d2aSXin Li    Redistribution and use in source and binary forms, with or without
5*a58d3d2aSXin Li    modification, are permitted provided that the following conditions
6*a58d3d2aSXin Li    are met:
7*a58d3d2aSXin Li 
8*a58d3d2aSXin Li    - Redistributions of source code must retain the above copyright
9*a58d3d2aSXin Li    notice, this list of conditions and the following disclaimer.
10*a58d3d2aSXin Li 
11*a58d3d2aSXin Li    - Redistributions in binary form must reproduce the above copyright
12*a58d3d2aSXin Li    notice, this list of conditions and the following disclaimer in the
13*a58d3d2aSXin Li    documentation and/or other materials provided with the distribution.
14*a58d3d2aSXin Li 
15*a58d3d2aSXin Li    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16*a58d3d2aSXin Li    ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17*a58d3d2aSXin Li    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18*a58d3d2aSXin Li    A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
19*a58d3d2aSXin Li    OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20*a58d3d2aSXin Li    EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21*a58d3d2aSXin Li    PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22*a58d3d2aSXin Li    PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23*a58d3d2aSXin Li    LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24*a58d3d2aSXin Li    NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25*a58d3d2aSXin Li    SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*a58d3d2aSXin Li */
27*a58d3d2aSXin Li 
28*a58d3d2aSXin Li /**
29*a58d3d2aSXin Li  * @file opus_projection.h
30*a58d3d2aSXin Li  * @brief Opus projection reference API
31*a58d3d2aSXin Li  */
32*a58d3d2aSXin Li 
33*a58d3d2aSXin Li #ifndef OPUS_PROJECTION_H
34*a58d3d2aSXin Li #define OPUS_PROJECTION_H
35*a58d3d2aSXin Li 
36*a58d3d2aSXin Li #include "opus_multistream.h"
37*a58d3d2aSXin Li 
38*a58d3d2aSXin Li #ifdef __cplusplus
39*a58d3d2aSXin Li extern "C" {
40*a58d3d2aSXin Li #endif
41*a58d3d2aSXin Li 
42*a58d3d2aSXin Li /** @cond OPUS_INTERNAL_DOC */
43*a58d3d2aSXin Li 
44*a58d3d2aSXin Li /** These are the actual encoder and decoder CTL ID numbers.
45*a58d3d2aSXin Li   * They should not be used directly by applications.c
46*a58d3d2aSXin Li   * In general, SETs should be even and GETs should be odd.*/
47*a58d3d2aSXin Li /**@{*/
48*a58d3d2aSXin Li #define OPUS_PROJECTION_GET_DEMIXING_MATRIX_GAIN_REQUEST    6001
49*a58d3d2aSXin Li #define OPUS_PROJECTION_GET_DEMIXING_MATRIX_SIZE_REQUEST    6003
50*a58d3d2aSXin Li #define OPUS_PROJECTION_GET_DEMIXING_MATRIX_REQUEST         6005
51*a58d3d2aSXin Li /**@}*/
52*a58d3d2aSXin Li 
53*a58d3d2aSXin Li 
54*a58d3d2aSXin Li /** @endcond */
55*a58d3d2aSXin Li 
56*a58d3d2aSXin Li /** @defgroup opus_projection_ctls Projection specific encoder and decoder CTLs
57*a58d3d2aSXin Li   *
58*a58d3d2aSXin Li   * These are convenience macros that are specific to the
59*a58d3d2aSXin Li   * opus_projection_encoder_ctl() and opus_projection_decoder_ctl()
60*a58d3d2aSXin Li   * interface.
61*a58d3d2aSXin Li   * The CTLs from @ref opus_genericctls, @ref opus_encoderctls,
62*a58d3d2aSXin Li   * @ref opus_decoderctls, and @ref opus_multistream_ctls may be applied to a
63*a58d3d2aSXin Li   * projection encoder or decoder as well.
64*a58d3d2aSXin Li   */
65*a58d3d2aSXin Li /**@{*/
66*a58d3d2aSXin Li 
67*a58d3d2aSXin Li /** Gets the gain (in dB. S7.8-format) of the demixing matrix from the encoder.
68*a58d3d2aSXin Li   * @param[out] x <tt>opus_int32 *</tt>: Returns the gain (in dB. S7.8-format)
69*a58d3d2aSXin Li   *                                      of the demixing matrix.
70*a58d3d2aSXin Li   * @hideinitializer
71*a58d3d2aSXin Li   */
72*a58d3d2aSXin Li #define OPUS_PROJECTION_GET_DEMIXING_MATRIX_GAIN(x) OPUS_PROJECTION_GET_DEMIXING_MATRIX_GAIN_REQUEST, __opus_check_int_ptr(x)
73*a58d3d2aSXin Li 
74*a58d3d2aSXin Li 
75*a58d3d2aSXin Li /** Gets the size in bytes of the demixing matrix from the encoder.
76*a58d3d2aSXin Li   * @param[out] x <tt>opus_int32 *</tt>: Returns the size in bytes of the
77*a58d3d2aSXin Li   *                                      demixing matrix.
78*a58d3d2aSXin Li   * @hideinitializer
79*a58d3d2aSXin Li   */
80*a58d3d2aSXin Li #define OPUS_PROJECTION_GET_DEMIXING_MATRIX_SIZE(x) OPUS_PROJECTION_GET_DEMIXING_MATRIX_SIZE_REQUEST, __opus_check_int_ptr(x)
81*a58d3d2aSXin Li 
82*a58d3d2aSXin Li 
83*a58d3d2aSXin Li /** Copies the demixing matrix to the supplied pointer location.
84*a58d3d2aSXin Li   * @param[out] x <tt>unsigned char *</tt>: Returns the demixing matrix to the
85*a58d3d2aSXin Li   *                                         supplied pointer location.
86*a58d3d2aSXin Li   * @param y <tt>opus_int32</tt>: The size in bytes of the reserved memory at the
87*a58d3d2aSXin Li   *                              pointer location.
88*a58d3d2aSXin Li   * @hideinitializer
89*a58d3d2aSXin Li   */
90*a58d3d2aSXin Li #define OPUS_PROJECTION_GET_DEMIXING_MATRIX(x,y) OPUS_PROJECTION_GET_DEMIXING_MATRIX_REQUEST, x, __opus_check_int(y)
91*a58d3d2aSXin Li 
92*a58d3d2aSXin Li 
93*a58d3d2aSXin Li /**@}*/
94*a58d3d2aSXin Li 
95*a58d3d2aSXin Li /** Opus projection encoder state.
96*a58d3d2aSXin Li  * This contains the complete state of a projection Opus encoder.
97*a58d3d2aSXin Li  * It is position independent and can be freely copied.
98*a58d3d2aSXin Li  * @see opus_projection_ambisonics_encoder_create
99*a58d3d2aSXin Li  */
100*a58d3d2aSXin Li typedef struct OpusProjectionEncoder OpusProjectionEncoder;
101*a58d3d2aSXin Li 
102*a58d3d2aSXin Li 
103*a58d3d2aSXin Li /** Opus projection decoder state.
104*a58d3d2aSXin Li   * This contains the complete state of a projection Opus decoder.
105*a58d3d2aSXin Li   * It is position independent and can be freely copied.
106*a58d3d2aSXin Li   * @see opus_projection_decoder_create
107*a58d3d2aSXin Li   * @see opus_projection_decoder_init
108*a58d3d2aSXin Li   */
109*a58d3d2aSXin Li typedef struct OpusProjectionDecoder OpusProjectionDecoder;
110*a58d3d2aSXin Li 
111*a58d3d2aSXin Li 
112*a58d3d2aSXin Li /**\name Projection encoder functions */
113*a58d3d2aSXin Li /**@{*/
114*a58d3d2aSXin Li 
115*a58d3d2aSXin Li /** Gets the size of an OpusProjectionEncoder structure.
116*a58d3d2aSXin Li   * @param channels <tt>int</tt>: The total number of input channels to encode.
117*a58d3d2aSXin Li   *                               This must be no more than 255.
118*a58d3d2aSXin Li   * @param mapping_family <tt>int</tt>: The mapping family to use for selecting
119*a58d3d2aSXin Li   *                                     the appropriate projection.
120*a58d3d2aSXin Li   * @returns The size in bytes on success, or a negative error code
121*a58d3d2aSXin Li   *          (see @ref opus_errorcodes) on error.
122*a58d3d2aSXin Li   */
123*a58d3d2aSXin Li OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_projection_ambisonics_encoder_get_size(
124*a58d3d2aSXin Li     int channels,
125*a58d3d2aSXin Li     int mapping_family
126*a58d3d2aSXin Li );
127*a58d3d2aSXin Li 
128*a58d3d2aSXin Li 
129*a58d3d2aSXin Li /** Allocates and initializes a projection encoder state.
130*a58d3d2aSXin Li   * Call opus_projection_encoder_destroy() to release
131*a58d3d2aSXin Li   * this object when finished.
132*a58d3d2aSXin Li   * @param Fs <tt>opus_int32</tt>: Sampling rate of the input signal (in Hz).
133*a58d3d2aSXin Li   *                                This must be one of 8000, 12000, 16000,
134*a58d3d2aSXin Li   *                                24000, or 48000.
135*a58d3d2aSXin Li   * @param channels <tt>int</tt>: Number of channels in the input signal.
136*a58d3d2aSXin Li   *                               This must be at most 255.
137*a58d3d2aSXin Li   *                               It may be greater than the number of
138*a58d3d2aSXin Li   *                               coded channels (<code>streams +
139*a58d3d2aSXin Li   *                               coupled_streams</code>).
140*a58d3d2aSXin Li   * @param mapping_family <tt>int</tt>: The mapping family to use for selecting
141*a58d3d2aSXin Li   *                                     the appropriate projection.
142*a58d3d2aSXin Li   * @param[out] streams <tt>int *</tt>: The total number of streams that will
143*a58d3d2aSXin Li   *                                     be encoded from the input.
144*a58d3d2aSXin Li   * @param[out] coupled_streams <tt>int *</tt>: Number of coupled (2 channel)
145*a58d3d2aSXin Li   *                                 streams that will be encoded from the input.
146*a58d3d2aSXin Li   * @param application <tt>int</tt>: The target encoder application.
147*a58d3d2aSXin Li   *                                  This must be one of the following:
148*a58d3d2aSXin Li   * <dl>
149*a58d3d2aSXin Li   * <dt>#OPUS_APPLICATION_VOIP</dt>
150*a58d3d2aSXin Li   * <dd>Process signal for improved speech intelligibility.</dd>
151*a58d3d2aSXin Li   * <dt>#OPUS_APPLICATION_AUDIO</dt>
152*a58d3d2aSXin Li   * <dd>Favor faithfulness to the original input.</dd>
153*a58d3d2aSXin Li   * <dt>#OPUS_APPLICATION_RESTRICTED_LOWDELAY</dt>
154*a58d3d2aSXin Li   * <dd>Configure the minimum possible coding delay by disabling certain modes
155*a58d3d2aSXin Li   * of operation.</dd>
156*a58d3d2aSXin Li   * </dl>
157*a58d3d2aSXin Li   * @param[out] error <tt>int *</tt>: Returns #OPUS_OK on success, or an error
158*a58d3d2aSXin Li   *                                   code (see @ref opus_errorcodes) on
159*a58d3d2aSXin Li   *                                   failure.
160*a58d3d2aSXin Li   */
161*a58d3d2aSXin Li OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusProjectionEncoder *opus_projection_ambisonics_encoder_create(
162*a58d3d2aSXin Li     opus_int32 Fs,
163*a58d3d2aSXin Li     int channels,
164*a58d3d2aSXin Li     int mapping_family,
165*a58d3d2aSXin Li     int *streams,
166*a58d3d2aSXin Li     int *coupled_streams,
167*a58d3d2aSXin Li     int application,
168*a58d3d2aSXin Li     int *error
169*a58d3d2aSXin Li ) OPUS_ARG_NONNULL(4) OPUS_ARG_NONNULL(5);
170*a58d3d2aSXin Li 
171*a58d3d2aSXin Li 
172*a58d3d2aSXin Li /** Initialize a previously allocated projection encoder state.
173*a58d3d2aSXin Li   * The memory pointed to by \a st must be at least the size returned by
174*a58d3d2aSXin Li   * opus_projection_ambisonics_encoder_get_size().
175*a58d3d2aSXin Li   * This is intended for applications which use their own allocator instead of
176*a58d3d2aSXin Li   * malloc.
177*a58d3d2aSXin Li   * To reset a previously initialized state, use the #OPUS_RESET_STATE CTL.
178*a58d3d2aSXin Li   * @see opus_projection_ambisonics_encoder_create
179*a58d3d2aSXin Li   * @see opus_projection_ambisonics_encoder_get_size
180*a58d3d2aSXin Li   * @param st <tt>OpusProjectionEncoder*</tt>: Projection encoder state to initialize.
181*a58d3d2aSXin Li   * @param Fs <tt>opus_int32</tt>: Sampling rate of the input signal (in Hz).
182*a58d3d2aSXin Li   *                                This must be one of 8000, 12000, 16000,
183*a58d3d2aSXin Li   *                                24000, or 48000.
184*a58d3d2aSXin Li   * @param channels <tt>int</tt>: Number of channels in the input signal.
185*a58d3d2aSXin Li   *                               This must be at most 255.
186*a58d3d2aSXin Li   *                               It may be greater than the number of
187*a58d3d2aSXin Li   *                               coded channels (<code>streams +
188*a58d3d2aSXin Li   *                               coupled_streams</code>).
189*a58d3d2aSXin Li   * @param streams <tt>int</tt>: The total number of streams to encode from the
190*a58d3d2aSXin Li   *                              input.
191*a58d3d2aSXin Li   *                              This must be no more than the number of channels.
192*a58d3d2aSXin Li   * @param coupled_streams <tt>int</tt>: Number of coupled (2 channel) streams
193*a58d3d2aSXin Li   *                                      to encode.
194*a58d3d2aSXin Li   *                                      This must be no larger than the total
195*a58d3d2aSXin Li   *                                      number of streams.
196*a58d3d2aSXin Li   *                                      Additionally, The total number of
197*a58d3d2aSXin Li   *                                      encoded channels (<code>streams +
198*a58d3d2aSXin Li   *                                      coupled_streams</code>) must be no
199*a58d3d2aSXin Li   *                                      more than the number of input channels.
200*a58d3d2aSXin Li   * @param application <tt>int</tt>: The target encoder application.
201*a58d3d2aSXin Li   *                                  This must be one of the following:
202*a58d3d2aSXin Li   * <dl>
203*a58d3d2aSXin Li   * <dt>#OPUS_APPLICATION_VOIP</dt>
204*a58d3d2aSXin Li   * <dd>Process signal for improved speech intelligibility.</dd>
205*a58d3d2aSXin Li   * <dt>#OPUS_APPLICATION_AUDIO</dt>
206*a58d3d2aSXin Li   * <dd>Favor faithfulness to the original input.</dd>
207*a58d3d2aSXin Li   * <dt>#OPUS_APPLICATION_RESTRICTED_LOWDELAY</dt>
208*a58d3d2aSXin Li   * <dd>Configure the minimum possible coding delay by disabling certain modes
209*a58d3d2aSXin Li   * of operation.</dd>
210*a58d3d2aSXin Li   * </dl>
211*a58d3d2aSXin Li   * @returns #OPUS_OK on success, or an error code (see @ref opus_errorcodes)
212*a58d3d2aSXin Li   *          on failure.
213*a58d3d2aSXin Li   */
214*a58d3d2aSXin Li OPUS_EXPORT int opus_projection_ambisonics_encoder_init(
215*a58d3d2aSXin Li     OpusProjectionEncoder *st,
216*a58d3d2aSXin Li     opus_int32 Fs,
217*a58d3d2aSXin Li     int channels,
218*a58d3d2aSXin Li     int mapping_family,
219*a58d3d2aSXin Li     int *streams,
220*a58d3d2aSXin Li     int *coupled_streams,
221*a58d3d2aSXin Li     int application
222*a58d3d2aSXin Li ) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(5) OPUS_ARG_NONNULL(6);
223*a58d3d2aSXin Li 
224*a58d3d2aSXin Li 
225*a58d3d2aSXin Li /** Encodes a projection Opus frame.
226*a58d3d2aSXin Li   * @param st <tt>OpusProjectionEncoder*</tt>: Projection encoder state.
227*a58d3d2aSXin Li   * @param[in] pcm <tt>const opus_int16*</tt>: The input signal as interleaved
228*a58d3d2aSXin Li   *                                            samples.
229*a58d3d2aSXin Li   *                                            This must contain
230*a58d3d2aSXin Li   *                                            <code>frame_size*channels</code>
231*a58d3d2aSXin Li   *                                            samples.
232*a58d3d2aSXin Li   * @param frame_size <tt>int</tt>: Number of samples per channel in the input
233*a58d3d2aSXin Li   *                                 signal.
234*a58d3d2aSXin Li   *                                 This must be an Opus frame size for the
235*a58d3d2aSXin Li   *                                 encoder's sampling rate.
236*a58d3d2aSXin Li   *                                 For example, at 48 kHz the permitted values
237*a58d3d2aSXin Li   *                                 are 120, 240, 480, 960, 1920, and 2880.
238*a58d3d2aSXin Li   *                                 Passing in a duration of less than 10 ms
239*a58d3d2aSXin Li   *                                 (480 samples at 48 kHz) will prevent the
240*a58d3d2aSXin Li   *                                 encoder from using the LPC or hybrid modes.
241*a58d3d2aSXin Li   * @param[out] data <tt>unsigned char*</tt>: Output payload.
242*a58d3d2aSXin Li   *                                           This must contain storage for at
243*a58d3d2aSXin Li   *                                           least \a max_data_bytes.
244*a58d3d2aSXin Li   * @param [in] max_data_bytes <tt>opus_int32</tt>: Size of the allocated
245*a58d3d2aSXin Li   *                                                 memory for the output
246*a58d3d2aSXin Li   *                                                 payload. This may be
247*a58d3d2aSXin Li   *                                                 used to impose an upper limit on
248*a58d3d2aSXin Li   *                                                 the instant bitrate, but should
249*a58d3d2aSXin Li   *                                                 not be used as the only bitrate
250*a58d3d2aSXin Li   *                                                 control. Use #OPUS_SET_BITRATE to
251*a58d3d2aSXin Li   *                                                 control the bitrate.
252*a58d3d2aSXin Li   * @returns The length of the encoded packet (in bytes) on success or a
253*a58d3d2aSXin Li   *          negative error code (see @ref opus_errorcodes) on failure.
254*a58d3d2aSXin Li   */
255*a58d3d2aSXin Li OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_projection_encode(
256*a58d3d2aSXin Li     OpusProjectionEncoder *st,
257*a58d3d2aSXin Li     const opus_int16 *pcm,
258*a58d3d2aSXin Li     int frame_size,
259*a58d3d2aSXin Li     unsigned char *data,
260*a58d3d2aSXin Li     opus_int32 max_data_bytes
261*a58d3d2aSXin Li ) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2) OPUS_ARG_NONNULL(4);
262*a58d3d2aSXin Li 
263*a58d3d2aSXin Li 
264*a58d3d2aSXin Li /** Encodes a projection Opus frame from floating point input.
265*a58d3d2aSXin Li   * @param st <tt>OpusProjectionEncoder*</tt>: Projection encoder state.
266*a58d3d2aSXin Li   * @param[in] pcm <tt>const float*</tt>: The input signal as interleaved
267*a58d3d2aSXin Li   *                                       samples with a normal range of
268*a58d3d2aSXin Li   *                                       +/-1.0.
269*a58d3d2aSXin Li   *                                       Samples with a range beyond +/-1.0
270*a58d3d2aSXin Li   *                                       are supported but will be clipped by
271*a58d3d2aSXin Li   *                                       decoders using the integer API and
272*a58d3d2aSXin Li   *                                       should only be used if it is known
273*a58d3d2aSXin Li   *                                       that the far end supports extended
274*a58d3d2aSXin Li   *                                       dynamic range.
275*a58d3d2aSXin Li   *                                       This must contain
276*a58d3d2aSXin Li   *                                       <code>frame_size*channels</code>
277*a58d3d2aSXin Li   *                                       samples.
278*a58d3d2aSXin Li   * @param frame_size <tt>int</tt>: Number of samples per channel in the input
279*a58d3d2aSXin Li   *                                 signal.
280*a58d3d2aSXin Li   *                                 This must be an Opus frame size for the
281*a58d3d2aSXin Li   *                                 encoder's sampling rate.
282*a58d3d2aSXin Li   *                                 For example, at 48 kHz the permitted values
283*a58d3d2aSXin Li   *                                 are 120, 240, 480, 960, 1920, and 2880.
284*a58d3d2aSXin Li   *                                 Passing in a duration of less than 10 ms
285*a58d3d2aSXin Li   *                                 (480 samples at 48 kHz) will prevent the
286*a58d3d2aSXin Li   *                                 encoder from using the LPC or hybrid modes.
287*a58d3d2aSXin Li   * @param[out] data <tt>unsigned char*</tt>: Output payload.
288*a58d3d2aSXin Li   *                                           This must contain storage for at
289*a58d3d2aSXin Li   *                                           least \a max_data_bytes.
290*a58d3d2aSXin Li   * @param [in] max_data_bytes <tt>opus_int32</tt>: Size of the allocated
291*a58d3d2aSXin Li   *                                                 memory for the output
292*a58d3d2aSXin Li   *                                                 payload. This may be
293*a58d3d2aSXin Li   *                                                 used to impose an upper limit on
294*a58d3d2aSXin Li   *                                                 the instant bitrate, but should
295*a58d3d2aSXin Li   *                                                 not be used as the only bitrate
296*a58d3d2aSXin Li   *                                                 control. Use #OPUS_SET_BITRATE to
297*a58d3d2aSXin Li   *                                                 control the bitrate.
298*a58d3d2aSXin Li   * @returns The length of the encoded packet (in bytes) on success or a
299*a58d3d2aSXin Li   *          negative error code (see @ref opus_errorcodes) on failure.
300*a58d3d2aSXin Li   */
301*a58d3d2aSXin Li OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_projection_encode_float(
302*a58d3d2aSXin Li     OpusProjectionEncoder *st,
303*a58d3d2aSXin Li     const float *pcm,
304*a58d3d2aSXin Li     int frame_size,
305*a58d3d2aSXin Li     unsigned char *data,
306*a58d3d2aSXin Li     opus_int32 max_data_bytes
307*a58d3d2aSXin Li ) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2) OPUS_ARG_NONNULL(4);
308*a58d3d2aSXin Li 
309*a58d3d2aSXin Li 
310*a58d3d2aSXin Li /** Frees an <code>OpusProjectionEncoder</code> allocated by
311*a58d3d2aSXin Li   * opus_projection_ambisonics_encoder_create().
312*a58d3d2aSXin Li   * @param st <tt>OpusProjectionEncoder*</tt>: Projection encoder state to be freed.
313*a58d3d2aSXin Li   */
314*a58d3d2aSXin Li OPUS_EXPORT void opus_projection_encoder_destroy(OpusProjectionEncoder *st);
315*a58d3d2aSXin Li 
316*a58d3d2aSXin Li 
317*a58d3d2aSXin Li /** Perform a CTL function on a projection Opus encoder.
318*a58d3d2aSXin Li   *
319*a58d3d2aSXin Li   * Generally the request and subsequent arguments are generated by a
320*a58d3d2aSXin Li   * convenience macro.
321*a58d3d2aSXin Li   * @param st <tt>OpusProjectionEncoder*</tt>: Projection encoder state.
322*a58d3d2aSXin Li   * @param request This and all remaining parameters should be replaced by one
323*a58d3d2aSXin Li   *                of the convenience macros in @ref opus_genericctls,
324*a58d3d2aSXin Li   *                @ref opus_encoderctls, @ref opus_multistream_ctls, or
325*a58d3d2aSXin Li   *                @ref opus_projection_ctls
326*a58d3d2aSXin Li   * @see opus_genericctls
327*a58d3d2aSXin Li   * @see opus_encoderctls
328*a58d3d2aSXin Li   * @see opus_multistream_ctls
329*a58d3d2aSXin Li   * @see opus_projection_ctls
330*a58d3d2aSXin Li   */
331*a58d3d2aSXin Li OPUS_EXPORT int opus_projection_encoder_ctl(OpusProjectionEncoder *st, int request, ...) OPUS_ARG_NONNULL(1);
332*a58d3d2aSXin Li 
333*a58d3d2aSXin Li 
334*a58d3d2aSXin Li /**@}*/
335*a58d3d2aSXin Li 
336*a58d3d2aSXin Li /**\name Projection decoder functions */
337*a58d3d2aSXin Li /**@{*/
338*a58d3d2aSXin Li 
339*a58d3d2aSXin Li /** Gets the size of an <code>OpusProjectionDecoder</code> structure.
340*a58d3d2aSXin Li   * @param channels <tt>int</tt>: The total number of output channels.
341*a58d3d2aSXin Li   *                               This must be no more than 255.
342*a58d3d2aSXin Li   * @param streams <tt>int</tt>: The total number of streams coded in the
343*a58d3d2aSXin Li   *                              input.
344*a58d3d2aSXin Li   *                              This must be no more than 255.
345*a58d3d2aSXin Li   * @param coupled_streams <tt>int</tt>: Number streams to decode as coupled
346*a58d3d2aSXin Li   *                                      (2 channel) streams.
347*a58d3d2aSXin Li   *                                      This must be no larger than the total
348*a58d3d2aSXin Li   *                                      number of streams.
349*a58d3d2aSXin Li   *                                      Additionally, The total number of
350*a58d3d2aSXin Li   *                                      coded channels (<code>streams +
351*a58d3d2aSXin Li   *                                      coupled_streams</code>) must be no
352*a58d3d2aSXin Li   *                                      more than 255.
353*a58d3d2aSXin Li   * @returns The size in bytes on success, or a negative error code
354*a58d3d2aSXin Li   *          (see @ref opus_errorcodes) on error.
355*a58d3d2aSXin Li   */
356*a58d3d2aSXin Li OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_projection_decoder_get_size(
357*a58d3d2aSXin Li     int channels,
358*a58d3d2aSXin Li     int streams,
359*a58d3d2aSXin Li     int coupled_streams
360*a58d3d2aSXin Li );
361*a58d3d2aSXin Li 
362*a58d3d2aSXin Li 
363*a58d3d2aSXin Li /** Allocates and initializes a projection decoder state.
364*a58d3d2aSXin Li   * Call opus_projection_decoder_destroy() to release
365*a58d3d2aSXin Li   * this object when finished.
366*a58d3d2aSXin Li   * @param Fs <tt>opus_int32</tt>: Sampling rate to decode at (in Hz).
367*a58d3d2aSXin Li   *                                This must be one of 8000, 12000, 16000,
368*a58d3d2aSXin Li   *                                24000, or 48000.
369*a58d3d2aSXin Li   * @param channels <tt>int</tt>: Number of channels to output.
370*a58d3d2aSXin Li   *                               This must be at most 255.
371*a58d3d2aSXin Li   *                               It may be different from the number of coded
372*a58d3d2aSXin Li   *                               channels (<code>streams +
373*a58d3d2aSXin Li   *                               coupled_streams</code>).
374*a58d3d2aSXin Li   * @param streams <tt>int</tt>: The total number of streams coded in the
375*a58d3d2aSXin Li   *                              input.
376*a58d3d2aSXin Li   *                              This must be no more than 255.
377*a58d3d2aSXin Li   * @param coupled_streams <tt>int</tt>: Number of streams to decode as coupled
378*a58d3d2aSXin Li   *                                      (2 channel) streams.
379*a58d3d2aSXin Li   *                                      This must be no larger than the total
380*a58d3d2aSXin Li   *                                      number of streams.
381*a58d3d2aSXin Li   *                                      Additionally, The total number of
382*a58d3d2aSXin Li   *                                      coded channels (<code>streams +
383*a58d3d2aSXin Li   *                                      coupled_streams</code>) must be no
384*a58d3d2aSXin Li   *                                      more than 255.
385*a58d3d2aSXin Li   * @param[in] demixing_matrix <tt>const unsigned char[demixing_matrix_size]</tt>: Demixing matrix
386*a58d3d2aSXin Li   *                         that mapping from coded channels to output channels,
387*a58d3d2aSXin Li   *                         as described in @ref opus_projection and
388*a58d3d2aSXin Li   *                         @ref opus_projection_ctls.
389*a58d3d2aSXin Li   * @param demixing_matrix_size <tt>opus_int32</tt>: The size in bytes of the
390*a58d3d2aSXin Li   *                                                  demixing matrix, as
391*a58d3d2aSXin Li   *                                                  described in @ref
392*a58d3d2aSXin Li   *                                                  opus_projection_ctls.
393*a58d3d2aSXin Li   * @param[out] error <tt>int *</tt>: Returns #OPUS_OK on success, or an error
394*a58d3d2aSXin Li   *                                   code (see @ref opus_errorcodes) on
395*a58d3d2aSXin Li   *                                   failure.
396*a58d3d2aSXin Li   */
397*a58d3d2aSXin Li OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusProjectionDecoder *opus_projection_decoder_create(
398*a58d3d2aSXin Li     opus_int32 Fs,
399*a58d3d2aSXin Li     int channels,
400*a58d3d2aSXin Li     int streams,
401*a58d3d2aSXin Li     int coupled_streams,
402*a58d3d2aSXin Li     unsigned char *demixing_matrix,
403*a58d3d2aSXin Li     opus_int32 demixing_matrix_size,
404*a58d3d2aSXin Li     int *error
405*a58d3d2aSXin Li ) OPUS_ARG_NONNULL(5);
406*a58d3d2aSXin Li 
407*a58d3d2aSXin Li 
408*a58d3d2aSXin Li /** Intialize a previously allocated projection decoder state object.
409*a58d3d2aSXin Li   * The memory pointed to by \a st must be at least the size returned by
410*a58d3d2aSXin Li   * opus_projection_decoder_get_size().
411*a58d3d2aSXin Li   * This is intended for applications which use their own allocator instead of
412*a58d3d2aSXin Li   * malloc.
413*a58d3d2aSXin Li   * To reset a previously initialized state, use the #OPUS_RESET_STATE CTL.
414*a58d3d2aSXin Li   * @see opus_projection_decoder_create
415*a58d3d2aSXin Li   * @see opus_projection_decoder_get_size
416*a58d3d2aSXin Li   * @param st <tt>OpusProjectionDecoder*</tt>: Projection encoder state to initialize.
417*a58d3d2aSXin Li   * @param Fs <tt>opus_int32</tt>: Sampling rate to decode at (in Hz).
418*a58d3d2aSXin Li   *                                This must be one of 8000, 12000, 16000,
419*a58d3d2aSXin Li   *                                24000, or 48000.
420*a58d3d2aSXin Li   * @param channels <tt>int</tt>: Number of channels to output.
421*a58d3d2aSXin Li   *                               This must be at most 255.
422*a58d3d2aSXin Li   *                               It may be different from the number of coded
423*a58d3d2aSXin Li   *                               channels (<code>streams +
424*a58d3d2aSXin Li   *                               coupled_streams</code>).
425*a58d3d2aSXin Li   * @param streams <tt>int</tt>: The total number of streams coded in the
426*a58d3d2aSXin Li   *                              input.
427*a58d3d2aSXin Li   *                              This must be no more than 255.
428*a58d3d2aSXin Li   * @param coupled_streams <tt>int</tt>: Number of streams to decode as coupled
429*a58d3d2aSXin Li   *                                      (2 channel) streams.
430*a58d3d2aSXin Li   *                                      This must be no larger than the total
431*a58d3d2aSXin Li   *                                      number of streams.
432*a58d3d2aSXin Li   *                                      Additionally, The total number of
433*a58d3d2aSXin Li   *                                      coded channels (<code>streams +
434*a58d3d2aSXin Li   *                                      coupled_streams</code>) must be no
435*a58d3d2aSXin Li   *                                      more than 255.
436*a58d3d2aSXin Li   * @param[in] demixing_matrix <tt>const unsigned char[demixing_matrix_size]</tt>: Demixing matrix
437*a58d3d2aSXin Li   *                         that mapping from coded channels to output channels,
438*a58d3d2aSXin Li   *                         as described in @ref opus_projection and
439*a58d3d2aSXin Li   *                         @ref opus_projection_ctls.
440*a58d3d2aSXin Li   * @param demixing_matrix_size <tt>opus_int32</tt>: The size in bytes of the
441*a58d3d2aSXin Li   *                                                  demixing matrix, as
442*a58d3d2aSXin Li   *                                                  described in @ref
443*a58d3d2aSXin Li   *                                                  opus_projection_ctls.
444*a58d3d2aSXin Li   * @returns #OPUS_OK on success, or an error code (see @ref opus_errorcodes)
445*a58d3d2aSXin Li   *          on failure.
446*a58d3d2aSXin Li   */
447*a58d3d2aSXin Li OPUS_EXPORT int opus_projection_decoder_init(
448*a58d3d2aSXin Li     OpusProjectionDecoder *st,
449*a58d3d2aSXin Li     opus_int32 Fs,
450*a58d3d2aSXin Li     int channels,
451*a58d3d2aSXin Li     int streams,
452*a58d3d2aSXin Li     int coupled_streams,
453*a58d3d2aSXin Li     unsigned char *demixing_matrix,
454*a58d3d2aSXin Li     opus_int32 demixing_matrix_size
455*a58d3d2aSXin Li ) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(6);
456*a58d3d2aSXin Li 
457*a58d3d2aSXin Li 
458*a58d3d2aSXin Li /** Decode a projection Opus packet.
459*a58d3d2aSXin Li   * @param st <tt>OpusProjectionDecoder*</tt>: Projection decoder state.
460*a58d3d2aSXin Li   * @param[in] data <tt>const unsigned char*</tt>: Input payload.
461*a58d3d2aSXin Li   *                                                Use a <code>NULL</code>
462*a58d3d2aSXin Li   *                                                pointer to indicate packet
463*a58d3d2aSXin Li   *                                                loss.
464*a58d3d2aSXin Li   * @param len <tt>opus_int32</tt>: Number of bytes in payload.
465*a58d3d2aSXin Li   * @param[out] pcm <tt>opus_int16*</tt>: Output signal, with interleaved
466*a58d3d2aSXin Li   *                                       samples.
467*a58d3d2aSXin Li   *                                       This must contain room for
468*a58d3d2aSXin Li   *                                       <code>frame_size*channels</code>
469*a58d3d2aSXin Li   *                                       samples.
470*a58d3d2aSXin Li   * @param frame_size <tt>int</tt>: The number of samples per channel of
471*a58d3d2aSXin Li   *                                 available space in \a pcm.
472*a58d3d2aSXin Li   *                                 If this is less than the maximum packet duration
473*a58d3d2aSXin Li   *                                 (120 ms; 5760 for 48kHz), this function will not be capable
474*a58d3d2aSXin Li   *                                 of decoding some packets. In the case of PLC (data==NULL)
475*a58d3d2aSXin Li   *                                 or FEC (decode_fec=1), then frame_size needs to be exactly
476*a58d3d2aSXin Li   *                                 the duration of audio that is missing, otherwise the
477*a58d3d2aSXin Li   *                                 decoder will not be in the optimal state to decode the
478*a58d3d2aSXin Li   *                                 next incoming packet. For the PLC and FEC cases, frame_size
479*a58d3d2aSXin Li   *                                 <b>must</b> be a multiple of 2.5 ms.
480*a58d3d2aSXin Li   * @param decode_fec <tt>int</tt>: Flag (0 or 1) to request that any in-band
481*a58d3d2aSXin Li   *                                 forward error correction data be decoded.
482*a58d3d2aSXin Li   *                                 If no such data is available, the frame is
483*a58d3d2aSXin Li   *                                 decoded as if it were lost.
484*a58d3d2aSXin Li   * @returns Number of samples decoded on success or a negative error code
485*a58d3d2aSXin Li   *          (see @ref opus_errorcodes) on failure.
486*a58d3d2aSXin Li   */
487*a58d3d2aSXin Li OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_projection_decode(
488*a58d3d2aSXin Li     OpusProjectionDecoder *st,
489*a58d3d2aSXin Li     const unsigned char *data,
490*a58d3d2aSXin Li     opus_int32 len,
491*a58d3d2aSXin Li     opus_int16 *pcm,
492*a58d3d2aSXin Li     int frame_size,
493*a58d3d2aSXin Li     int decode_fec
494*a58d3d2aSXin Li ) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4);
495*a58d3d2aSXin Li 
496*a58d3d2aSXin Li 
497*a58d3d2aSXin Li /** Decode a projection Opus packet with floating point output.
498*a58d3d2aSXin Li   * @param st <tt>OpusProjectionDecoder*</tt>: Projection decoder state.
499*a58d3d2aSXin Li   * @param[in] data <tt>const unsigned char*</tt>: Input payload.
500*a58d3d2aSXin Li   *                                                Use a <code>NULL</code>
501*a58d3d2aSXin Li   *                                                pointer to indicate packet
502*a58d3d2aSXin Li   *                                                loss.
503*a58d3d2aSXin Li   * @param len <tt>opus_int32</tt>: Number of bytes in payload.
504*a58d3d2aSXin Li   * @param[out] pcm <tt>opus_int16*</tt>: Output signal, with interleaved
505*a58d3d2aSXin Li   *                                       samples.
506*a58d3d2aSXin Li   *                                       This must contain room for
507*a58d3d2aSXin Li   *                                       <code>frame_size*channels</code>
508*a58d3d2aSXin Li   *                                       samples.
509*a58d3d2aSXin Li   * @param frame_size <tt>int</tt>: The number of samples per channel of
510*a58d3d2aSXin Li   *                                 available space in \a pcm.
511*a58d3d2aSXin Li   *                                 If this is less than the maximum packet duration
512*a58d3d2aSXin Li   *                                 (120 ms; 5760 for 48kHz), this function will not be capable
513*a58d3d2aSXin Li   *                                 of decoding some packets. In the case of PLC (data==NULL)
514*a58d3d2aSXin Li   *                                 or FEC (decode_fec=1), then frame_size needs to be exactly
515*a58d3d2aSXin Li   *                                 the duration of audio that is missing, otherwise the
516*a58d3d2aSXin Li   *                                 decoder will not be in the optimal state to decode the
517*a58d3d2aSXin Li   *                                 next incoming packet. For the PLC and FEC cases, frame_size
518*a58d3d2aSXin Li   *                                 <b>must</b> be a multiple of 2.5 ms.
519*a58d3d2aSXin Li   * @param decode_fec <tt>int</tt>: Flag (0 or 1) to request that any in-band
520*a58d3d2aSXin Li   *                                 forward error correction data be decoded.
521*a58d3d2aSXin Li   *                                 If no such data is available, the frame is
522*a58d3d2aSXin Li   *                                 decoded as if it were lost.
523*a58d3d2aSXin Li   * @returns Number of samples decoded on success or a negative error code
524*a58d3d2aSXin Li   *          (see @ref opus_errorcodes) on failure.
525*a58d3d2aSXin Li   */
526*a58d3d2aSXin Li OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_projection_decode_float(
527*a58d3d2aSXin Li     OpusProjectionDecoder *st,
528*a58d3d2aSXin Li     const unsigned char *data,
529*a58d3d2aSXin Li     opus_int32 len,
530*a58d3d2aSXin Li     float *pcm,
531*a58d3d2aSXin Li     int frame_size,
532*a58d3d2aSXin Li     int decode_fec
533*a58d3d2aSXin Li ) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4);
534*a58d3d2aSXin Li 
535*a58d3d2aSXin Li 
536*a58d3d2aSXin Li /** Perform a CTL function on a projection Opus decoder.
537*a58d3d2aSXin Li   *
538*a58d3d2aSXin Li   * Generally the request and subsequent arguments are generated by a
539*a58d3d2aSXin Li   * convenience macro.
540*a58d3d2aSXin Li   * @param st <tt>OpusProjectionDecoder*</tt>: Projection decoder state.
541*a58d3d2aSXin Li   * @param request This and all remaining parameters should be replaced by one
542*a58d3d2aSXin Li   *                of the convenience macros in @ref opus_genericctls,
543*a58d3d2aSXin Li   *                @ref opus_decoderctls, @ref opus_multistream_ctls, or
544*a58d3d2aSXin Li   *                @ref opus_projection_ctls.
545*a58d3d2aSXin Li   * @see opus_genericctls
546*a58d3d2aSXin Li   * @see opus_decoderctls
547*a58d3d2aSXin Li   * @see opus_multistream_ctls
548*a58d3d2aSXin Li   * @see opus_projection_ctls
549*a58d3d2aSXin Li   */
550*a58d3d2aSXin Li OPUS_EXPORT int opus_projection_decoder_ctl(OpusProjectionDecoder *st, int request, ...) OPUS_ARG_NONNULL(1);
551*a58d3d2aSXin Li 
552*a58d3d2aSXin Li 
553*a58d3d2aSXin Li /** Frees an <code>OpusProjectionDecoder</code> allocated by
554*a58d3d2aSXin Li   * opus_projection_decoder_create().
555*a58d3d2aSXin Li   * @param st <tt>OpusProjectionDecoder</tt>: Projection decoder state to be freed.
556*a58d3d2aSXin Li   */
557*a58d3d2aSXin Li OPUS_EXPORT void opus_projection_decoder_destroy(OpusProjectionDecoder *st);
558*a58d3d2aSXin Li 
559*a58d3d2aSXin Li 
560*a58d3d2aSXin Li /**@}*/
561*a58d3d2aSXin Li 
562*a58d3d2aSXin Li /**@}*/
563*a58d3d2aSXin Li 
564*a58d3d2aSXin Li #ifdef __cplusplus
565*a58d3d2aSXin Li }
566*a58d3d2aSXin Li #endif
567*a58d3d2aSXin Li 
568*a58d3d2aSXin Li #endif /* OPUS_PROJECTION_H */
569