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