Chris@70
|
1 /* Copyright (c) 2011 Xiph.Org Foundation
|
Chris@70
|
2 Written by Jean-Marc Valin */
|
Chris@70
|
3 /*
|
Chris@70
|
4 Redistribution and use in source and binary forms, with or without
|
Chris@70
|
5 modification, are permitted provided that the following conditions
|
Chris@70
|
6 are met:
|
Chris@70
|
7
|
Chris@70
|
8 - Redistributions of source code must retain the above copyright
|
Chris@70
|
9 notice, this list of conditions and the following disclaimer.
|
Chris@70
|
10
|
Chris@70
|
11 - Redistributions in binary form must reproduce the above copyright
|
Chris@70
|
12 notice, this list of conditions and the following disclaimer in the
|
Chris@70
|
13 documentation and/or other materials provided with the distribution.
|
Chris@70
|
14
|
Chris@70
|
15 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
Chris@70
|
16 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
Chris@70
|
17 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
Chris@70
|
18 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
|
Chris@70
|
19 OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
Chris@70
|
20 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
Chris@70
|
21 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
Chris@70
|
22 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
Chris@70
|
23 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
Chris@70
|
24 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
Chris@70
|
25 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
Chris@70
|
26 */
|
Chris@70
|
27
|
Chris@70
|
28 /**
|
Chris@70
|
29 * @file opus_multistream.h
|
Chris@70
|
30 * @brief Opus reference implementation multistream API
|
Chris@70
|
31 */
|
Chris@70
|
32
|
Chris@70
|
33 #ifndef OPUS_MULTISTREAM_H
|
Chris@70
|
34 #define OPUS_MULTISTREAM_H
|
Chris@70
|
35
|
Chris@70
|
36 #include "opus.h"
|
Chris@70
|
37
|
Chris@70
|
38 #ifdef __cplusplus
|
Chris@70
|
39 extern "C" {
|
Chris@70
|
40 #endif
|
Chris@70
|
41
|
Chris@70
|
42 /** @cond OPUS_INTERNAL_DOC */
|
Chris@70
|
43
|
Chris@70
|
44 /** Macros to trigger compilation errors when the wrong types are provided to a
|
Chris@70
|
45 * CTL. */
|
Chris@70
|
46 /**@{*/
|
Chris@70
|
47 #define __opus_check_encstate_ptr(ptr) ((ptr) + ((ptr) - (OpusEncoder**)(ptr)))
|
Chris@70
|
48 #define __opus_check_decstate_ptr(ptr) ((ptr) + ((ptr) - (OpusDecoder**)(ptr)))
|
Chris@70
|
49 /**@}*/
|
Chris@70
|
50
|
Chris@70
|
51 /** These are the actual encoder and decoder CTL ID numbers.
|
Chris@70
|
52 * They should not be used directly by applications.
|
Chris@70
|
53 * In general, SETs should be even and GETs should be odd.*/
|
Chris@70
|
54 /**@{*/
|
Chris@70
|
55 #define OPUS_MULTISTREAM_GET_ENCODER_STATE_REQUEST 5120
|
Chris@70
|
56 #define OPUS_MULTISTREAM_GET_DECODER_STATE_REQUEST 5122
|
Chris@70
|
57 /**@}*/
|
Chris@70
|
58
|
Chris@70
|
59 /** @endcond */
|
Chris@70
|
60
|
Chris@70
|
61 /** @defgroup opus_multistream_ctls Multistream specific encoder and decoder CTLs
|
Chris@70
|
62 *
|
Chris@70
|
63 * These are convenience macros that are specific to the
|
Chris@70
|
64 * opus_multistream_encoder_ctl() and opus_multistream_decoder_ctl()
|
Chris@70
|
65 * interface.
|
Chris@70
|
66 * The CTLs from @ref opus_genericctls, @ref opus_encoderctls, and
|
Chris@70
|
67 * @ref opus_decoderctls may be applied to a multistream encoder or decoder as
|
Chris@70
|
68 * well.
|
Chris@70
|
69 * In addition, you may retrieve the encoder or decoder state for an specific
|
Chris@70
|
70 * stream via #OPUS_MULTISTREAM_GET_ENCODER_STATE or
|
Chris@70
|
71 * #OPUS_MULTISTREAM_GET_DECODER_STATE and apply CTLs to it individually.
|
Chris@70
|
72 */
|
Chris@70
|
73 /**@{*/
|
Chris@70
|
74
|
Chris@70
|
75 /** Gets the encoder state for an individual stream of a multistream encoder.
|
Chris@70
|
76 * @param[in] x <tt>opus_int32</tt>: The index of the stream whose encoder you
|
Chris@70
|
77 * wish to retrieve.
|
Chris@70
|
78 * This must be non-negative and less than
|
Chris@70
|
79 * the <code>streams</code> parameter used
|
Chris@70
|
80 * to initialize the encoder.
|
Chris@70
|
81 * @param[out] y <tt>OpusEncoder**</tt>: Returns a pointer to the given
|
Chris@70
|
82 * encoder state.
|
Chris@70
|
83 * @retval OPUS_BAD_ARG The index of the requested stream was out of range.
|
Chris@70
|
84 * @hideinitializer
|
Chris@70
|
85 */
|
Chris@70
|
86 #define OPUS_MULTISTREAM_GET_ENCODER_STATE(x,y) OPUS_MULTISTREAM_GET_ENCODER_STATE_REQUEST, __opus_check_int(x), __opus_check_encstate_ptr(y)
|
Chris@70
|
87
|
Chris@70
|
88 /** Gets the decoder state for an individual stream of a multistream decoder.
|
Chris@70
|
89 * @param[in] x <tt>opus_int32</tt>: The index of the stream whose decoder you
|
Chris@70
|
90 * wish to retrieve.
|
Chris@70
|
91 * This must be non-negative and less than
|
Chris@70
|
92 * the <code>streams</code> parameter used
|
Chris@70
|
93 * to initialize the decoder.
|
Chris@70
|
94 * @param[out] y <tt>OpusDecoder**</tt>: Returns a pointer to the given
|
Chris@70
|
95 * decoder state.
|
Chris@70
|
96 * @retval OPUS_BAD_ARG The index of the requested stream was out of range.
|
Chris@70
|
97 * @hideinitializer
|
Chris@70
|
98 */
|
Chris@70
|
99 #define OPUS_MULTISTREAM_GET_DECODER_STATE(x,y) OPUS_MULTISTREAM_GET_DECODER_STATE_REQUEST, __opus_check_int(x), __opus_check_decstate_ptr(y)
|
Chris@70
|
100
|
Chris@70
|
101 /**@}*/
|
Chris@70
|
102
|
Chris@70
|
103 /** @defgroup opus_multistream Opus Multistream API
|
Chris@70
|
104 * @{
|
Chris@70
|
105 *
|
Chris@70
|
106 * The multistream API allows individual Opus streams to be combined into a
|
Chris@70
|
107 * single packet, enabling support for up to 255 channels. Unlike an
|
Chris@70
|
108 * elementary Opus stream, the encoder and decoder must negotiate the channel
|
Chris@70
|
109 * configuration before the decoder can successfully interpret the data in the
|
Chris@70
|
110 * packets produced by the encoder. Some basic information, such as packet
|
Chris@70
|
111 * duration, can be computed without any special negotiation.
|
Chris@70
|
112 *
|
Chris@70
|
113 * The format for multistream Opus packets is defined in
|
Chris@70
|
114 * <a href="https://tools.ietf.org/html/rfc7845">RFC 7845</a>
|
Chris@70
|
115 * and is based on the self-delimited Opus framing described in Appendix B of
|
Chris@70
|
116 * <a href="https://tools.ietf.org/html/rfc6716">RFC 6716</a>.
|
Chris@70
|
117 * Normal Opus packets are just a degenerate case of multistream Opus packets,
|
Chris@70
|
118 * and can be encoded or decoded with the multistream API by setting
|
Chris@70
|
119 * <code>streams</code> to <code>1</code> when initializing the encoder or
|
Chris@70
|
120 * decoder.
|
Chris@70
|
121 *
|
Chris@70
|
122 * Multistream Opus streams can contain up to 255 elementary Opus streams.
|
Chris@70
|
123 * These may be either "uncoupled" or "coupled", indicating that the decoder
|
Chris@70
|
124 * is configured to decode them to either 1 or 2 channels, respectively.
|
Chris@70
|
125 * The streams are ordered so that all coupled streams appear at the
|
Chris@70
|
126 * beginning.
|
Chris@70
|
127 *
|
Chris@70
|
128 * A <code>mapping</code> table defines which decoded channel <code>i</code>
|
Chris@70
|
129 * should be used for each input/output (I/O) channel <code>j</code>. This table is
|
Chris@70
|
130 * typically provided as an unsigned char array.
|
Chris@70
|
131 * Let <code>i = mapping[j]</code> be the index for I/O channel <code>j</code>.
|
Chris@70
|
132 * If <code>i < 2*coupled_streams</code>, then I/O channel <code>j</code> is
|
Chris@70
|
133 * encoded as the left channel of stream <code>(i/2)</code> if <code>i</code>
|
Chris@70
|
134 * is even, or as the right channel of stream <code>(i/2)</code> if
|
Chris@70
|
135 * <code>i</code> is odd. Otherwise, I/O channel <code>j</code> is encoded as
|
Chris@70
|
136 * mono in stream <code>(i - coupled_streams)</code>, unless it has the special
|
Chris@70
|
137 * value 255, in which case it is omitted from the encoding entirely (the
|
Chris@70
|
138 * decoder will reproduce it as silence). Each value <code>i</code> must either
|
Chris@70
|
139 * be the special value 255 or be less than <code>streams + coupled_streams</code>.
|
Chris@70
|
140 *
|
Chris@70
|
141 * The output channels specified by the encoder
|
Chris@70
|
142 * should use the
|
Chris@70
|
143 * <a href="https://www.xiph.org/vorbis/doc/Vorbis_I_spec.html#x1-810004.3.9">Vorbis
|
Chris@70
|
144 * channel ordering</a>. A decoder may wish to apply an additional permutation
|
Chris@70
|
145 * to the mapping the encoder used to achieve a different output channel
|
Chris@70
|
146 * order (e.g. for outputing in WAV order).
|
Chris@70
|
147 *
|
Chris@70
|
148 * Each multistream packet contains an Opus packet for each stream, and all of
|
Chris@70
|
149 * the Opus packets in a single multistream packet must have the same
|
Chris@70
|
150 * duration. Therefore the duration of a multistream packet can be extracted
|
Chris@70
|
151 * from the TOC sequence of the first stream, which is located at the
|
Chris@70
|
152 * beginning of the packet, just like an elementary Opus stream:
|
Chris@70
|
153 *
|
Chris@70
|
154 * @code
|
Chris@70
|
155 * int nb_samples;
|
Chris@70
|
156 * int nb_frames;
|
Chris@70
|
157 * nb_frames = opus_packet_get_nb_frames(data, len);
|
Chris@70
|
158 * if (nb_frames < 1)
|
Chris@70
|
159 * return nb_frames;
|
Chris@70
|
160 * nb_samples = opus_packet_get_samples_per_frame(data, 48000) * nb_frames;
|
Chris@70
|
161 * @endcode
|
Chris@70
|
162 *
|
Chris@70
|
163 * The general encoding and decoding process proceeds exactly the same as in
|
Chris@70
|
164 * the normal @ref opus_encoder and @ref opus_decoder APIs.
|
Chris@70
|
165 * See their documentation for an overview of how to use the corresponding
|
Chris@70
|
166 * multistream functions.
|
Chris@70
|
167 */
|
Chris@70
|
168
|
Chris@70
|
169 /** Opus multistream encoder state.
|
Chris@70
|
170 * This contains the complete state of a multistream Opus encoder.
|
Chris@70
|
171 * It is position independent and can be freely copied.
|
Chris@70
|
172 * @see opus_multistream_encoder_create
|
Chris@70
|
173 * @see opus_multistream_encoder_init
|
Chris@70
|
174 */
|
Chris@70
|
175 typedef struct OpusMSEncoder OpusMSEncoder;
|
Chris@70
|
176
|
Chris@70
|
177 /** Opus multistream decoder state.
|
Chris@70
|
178 * This contains the complete state of a multistream Opus decoder.
|
Chris@70
|
179 * It is position independent and can be freely copied.
|
Chris@70
|
180 * @see opus_multistream_decoder_create
|
Chris@70
|
181 * @see opus_multistream_decoder_init
|
Chris@70
|
182 */
|
Chris@70
|
183 typedef struct OpusMSDecoder OpusMSDecoder;
|
Chris@70
|
184
|
Chris@70
|
185 /**\name Multistream encoder functions */
|
Chris@70
|
186 /**@{*/
|
Chris@70
|
187
|
Chris@70
|
188 /** Gets the size of an OpusMSEncoder structure.
|
Chris@70
|
189 * @param streams <tt>int</tt>: The total number of streams to encode from the
|
Chris@70
|
190 * input.
|
Chris@70
|
191 * This must be no more than 255.
|
Chris@70
|
192 * @param coupled_streams <tt>int</tt>: Number of coupled (2 channel) streams
|
Chris@70
|
193 * to encode.
|
Chris@70
|
194 * This must be no larger than the total
|
Chris@70
|
195 * number of streams.
|
Chris@70
|
196 * Additionally, The total number of
|
Chris@70
|
197 * encoded channels (<code>streams +
|
Chris@70
|
198 * coupled_streams</code>) must be no
|
Chris@70
|
199 * more than 255.
|
Chris@70
|
200 * @returns The size in bytes on success, or a negative error code
|
Chris@70
|
201 * (see @ref opus_errorcodes) on error.
|
Chris@70
|
202 */
|
Chris@70
|
203 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_multistream_encoder_get_size(
|
Chris@70
|
204 int streams,
|
Chris@70
|
205 int coupled_streams
|
Chris@70
|
206 );
|
Chris@70
|
207
|
Chris@70
|
208 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_multistream_surround_encoder_get_size(
|
Chris@70
|
209 int channels,
|
Chris@70
|
210 int mapping_family
|
Chris@70
|
211 );
|
Chris@70
|
212
|
Chris@70
|
213
|
Chris@70
|
214 /** Allocates and initializes a multistream encoder state.
|
Chris@70
|
215 * Call opus_multistream_encoder_destroy() to release
|
Chris@70
|
216 * this object when finished.
|
Chris@70
|
217 * @param Fs <tt>opus_int32</tt>: Sampling rate of the input signal (in Hz).
|
Chris@70
|
218 * This must be one of 8000, 12000, 16000,
|
Chris@70
|
219 * 24000, or 48000.
|
Chris@70
|
220 * @param channels <tt>int</tt>: Number of channels in the input signal.
|
Chris@70
|
221 * This must be at most 255.
|
Chris@70
|
222 * It may be greater than the number of
|
Chris@70
|
223 * coded channels (<code>streams +
|
Chris@70
|
224 * coupled_streams</code>).
|
Chris@70
|
225 * @param streams <tt>int</tt>: The total number of streams to encode from the
|
Chris@70
|
226 * input.
|
Chris@70
|
227 * This must be no more than the number of channels.
|
Chris@70
|
228 * @param coupled_streams <tt>int</tt>: Number of coupled (2 channel) streams
|
Chris@70
|
229 * to encode.
|
Chris@70
|
230 * This must be no larger than the total
|
Chris@70
|
231 * number of streams.
|
Chris@70
|
232 * Additionally, The total number of
|
Chris@70
|
233 * encoded channels (<code>streams +
|
Chris@70
|
234 * coupled_streams</code>) must be no
|
Chris@70
|
235 * more than the number of input channels.
|
Chris@70
|
236 * @param[in] mapping <code>const unsigned char[channels]</code>: Mapping from
|
Chris@70
|
237 * encoded channels to input channels, as described in
|
Chris@70
|
238 * @ref opus_multistream. As an extra constraint, the
|
Chris@70
|
239 * multistream encoder does not allow encoding coupled
|
Chris@70
|
240 * streams for which one channel is unused since this
|
Chris@70
|
241 * is never a good idea.
|
Chris@70
|
242 * @param application <tt>int</tt>: The target encoder application.
|
Chris@70
|
243 * This must be one of the following:
|
Chris@70
|
244 * <dl>
|
Chris@70
|
245 * <dt>#OPUS_APPLICATION_VOIP</dt>
|
Chris@70
|
246 * <dd>Process signal for improved speech intelligibility.</dd>
|
Chris@70
|
247 * <dt>#OPUS_APPLICATION_AUDIO</dt>
|
Chris@70
|
248 * <dd>Favor faithfulness to the original input.</dd>
|
Chris@70
|
249 * <dt>#OPUS_APPLICATION_RESTRICTED_LOWDELAY</dt>
|
Chris@70
|
250 * <dd>Configure the minimum possible coding delay by disabling certain modes
|
Chris@70
|
251 * of operation.</dd>
|
Chris@70
|
252 * </dl>
|
Chris@70
|
253 * @param[out] error <tt>int *</tt>: Returns #OPUS_OK on success, or an error
|
Chris@70
|
254 * code (see @ref opus_errorcodes) on
|
Chris@70
|
255 * failure.
|
Chris@70
|
256 */
|
Chris@70
|
257 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusMSEncoder *opus_multistream_encoder_create(
|
Chris@70
|
258 opus_int32 Fs,
|
Chris@70
|
259 int channels,
|
Chris@70
|
260 int streams,
|
Chris@70
|
261 int coupled_streams,
|
Chris@70
|
262 const unsigned char *mapping,
|
Chris@70
|
263 int application,
|
Chris@70
|
264 int *error
|
Chris@70
|
265 ) OPUS_ARG_NONNULL(5);
|
Chris@70
|
266
|
Chris@70
|
267 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusMSEncoder *opus_multistream_surround_encoder_create(
|
Chris@70
|
268 opus_int32 Fs,
|
Chris@70
|
269 int channels,
|
Chris@70
|
270 int mapping_family,
|
Chris@70
|
271 int *streams,
|
Chris@70
|
272 int *coupled_streams,
|
Chris@70
|
273 unsigned char *mapping,
|
Chris@70
|
274 int application,
|
Chris@70
|
275 int *error
|
Chris@70
|
276 ) OPUS_ARG_NONNULL(4) OPUS_ARG_NONNULL(5) OPUS_ARG_NONNULL(6);
|
Chris@70
|
277
|
Chris@70
|
278 /** Initialize a previously allocated multistream encoder state.
|
Chris@70
|
279 * The memory pointed to by \a st must be at least the size returned by
|
Chris@70
|
280 * opus_multistream_encoder_get_size().
|
Chris@70
|
281 * This is intended for applications which use their own allocator instead of
|
Chris@70
|
282 * malloc.
|
Chris@70
|
283 * To reset a previously initialized state, use the #OPUS_RESET_STATE CTL.
|
Chris@70
|
284 * @see opus_multistream_encoder_create
|
Chris@70
|
285 * @see opus_multistream_encoder_get_size
|
Chris@70
|
286 * @param st <tt>OpusMSEncoder*</tt>: Multistream encoder state to initialize.
|
Chris@70
|
287 * @param Fs <tt>opus_int32</tt>: Sampling rate of the input signal (in Hz).
|
Chris@70
|
288 * This must be one of 8000, 12000, 16000,
|
Chris@70
|
289 * 24000, or 48000.
|
Chris@70
|
290 * @param channels <tt>int</tt>: Number of channels in the input signal.
|
Chris@70
|
291 * This must be at most 255.
|
Chris@70
|
292 * It may be greater than the number of
|
Chris@70
|
293 * coded channels (<code>streams +
|
Chris@70
|
294 * coupled_streams</code>).
|
Chris@70
|
295 * @param streams <tt>int</tt>: The total number of streams to encode from the
|
Chris@70
|
296 * input.
|
Chris@70
|
297 * This must be no more than the number of channels.
|
Chris@70
|
298 * @param coupled_streams <tt>int</tt>: Number of coupled (2 channel) streams
|
Chris@70
|
299 * to encode.
|
Chris@70
|
300 * This must be no larger than the total
|
Chris@70
|
301 * number of streams.
|
Chris@70
|
302 * Additionally, The total number of
|
Chris@70
|
303 * encoded channels (<code>streams +
|
Chris@70
|
304 * coupled_streams</code>) must be no
|
Chris@70
|
305 * more than the number of input channels.
|
Chris@70
|
306 * @param[in] mapping <code>const unsigned char[channels]</code>: Mapping from
|
Chris@70
|
307 * encoded channels to input channels, as described in
|
Chris@70
|
308 * @ref opus_multistream. As an extra constraint, the
|
Chris@70
|
309 * multistream encoder does not allow encoding coupled
|
Chris@70
|
310 * streams for which one channel is unused since this
|
Chris@70
|
311 * is never a good idea.
|
Chris@70
|
312 * @param application <tt>int</tt>: The target encoder application.
|
Chris@70
|
313 * This must be one of the following:
|
Chris@70
|
314 * <dl>
|
Chris@70
|
315 * <dt>#OPUS_APPLICATION_VOIP</dt>
|
Chris@70
|
316 * <dd>Process signal for improved speech intelligibility.</dd>
|
Chris@70
|
317 * <dt>#OPUS_APPLICATION_AUDIO</dt>
|
Chris@70
|
318 * <dd>Favor faithfulness to the original input.</dd>
|
Chris@70
|
319 * <dt>#OPUS_APPLICATION_RESTRICTED_LOWDELAY</dt>
|
Chris@70
|
320 * <dd>Configure the minimum possible coding delay by disabling certain modes
|
Chris@70
|
321 * of operation.</dd>
|
Chris@70
|
322 * </dl>
|
Chris@70
|
323 * @returns #OPUS_OK on success, or an error code (see @ref opus_errorcodes)
|
Chris@70
|
324 * on failure.
|
Chris@70
|
325 */
|
Chris@70
|
326 OPUS_EXPORT int opus_multistream_encoder_init(
|
Chris@70
|
327 OpusMSEncoder *st,
|
Chris@70
|
328 opus_int32 Fs,
|
Chris@70
|
329 int channels,
|
Chris@70
|
330 int streams,
|
Chris@70
|
331 int coupled_streams,
|
Chris@70
|
332 const unsigned char *mapping,
|
Chris@70
|
333 int application
|
Chris@70
|
334 ) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(6);
|
Chris@70
|
335
|
Chris@70
|
336 OPUS_EXPORT int opus_multistream_surround_encoder_init(
|
Chris@70
|
337 OpusMSEncoder *st,
|
Chris@70
|
338 opus_int32 Fs,
|
Chris@70
|
339 int channels,
|
Chris@70
|
340 int mapping_family,
|
Chris@70
|
341 int *streams,
|
Chris@70
|
342 int *coupled_streams,
|
Chris@70
|
343 unsigned char *mapping,
|
Chris@70
|
344 int application
|
Chris@70
|
345 ) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(5) OPUS_ARG_NONNULL(6) OPUS_ARG_NONNULL(7);
|
Chris@70
|
346
|
Chris@70
|
347 /** Encodes a multistream Opus frame.
|
Chris@70
|
348 * @param st <tt>OpusMSEncoder*</tt>: Multistream encoder state.
|
Chris@70
|
349 * @param[in] pcm <tt>const opus_int16*</tt>: The input signal as interleaved
|
Chris@70
|
350 * samples.
|
Chris@70
|
351 * This must contain
|
Chris@70
|
352 * <code>frame_size*channels</code>
|
Chris@70
|
353 * samples.
|
Chris@70
|
354 * @param frame_size <tt>int</tt>: Number of samples per channel in the input
|
Chris@70
|
355 * signal.
|
Chris@70
|
356 * This must be an Opus frame size for the
|
Chris@70
|
357 * encoder's sampling rate.
|
Chris@70
|
358 * For example, at 48 kHz the permitted values
|
Chris@70
|
359 * are 120, 240, 480, 960, 1920, and 2880.
|
Chris@70
|
360 * Passing in a duration of less than 10 ms
|
Chris@70
|
361 * (480 samples at 48 kHz) will prevent the
|
Chris@70
|
362 * encoder from using the LPC or hybrid modes.
|
Chris@70
|
363 * @param[out] data <tt>unsigned char*</tt>: Output payload.
|
Chris@70
|
364 * This must contain storage for at
|
Chris@70
|
365 * least \a max_data_bytes.
|
Chris@70
|
366 * @param [in] max_data_bytes <tt>opus_int32</tt>: Size of the allocated
|
Chris@70
|
367 * memory for the output
|
Chris@70
|
368 * payload. This may be
|
Chris@70
|
369 * used to impose an upper limit on
|
Chris@70
|
370 * the instant bitrate, but should
|
Chris@70
|
371 * not be used as the only bitrate
|
Chris@70
|
372 * control. Use #OPUS_SET_BITRATE to
|
Chris@70
|
373 * control the bitrate.
|
Chris@70
|
374 * @returns The length of the encoded packet (in bytes) on success or a
|
Chris@70
|
375 * negative error code (see @ref opus_errorcodes) on failure.
|
Chris@70
|
376 */
|
Chris@70
|
377 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_multistream_encode(
|
Chris@70
|
378 OpusMSEncoder *st,
|
Chris@70
|
379 const opus_int16 *pcm,
|
Chris@70
|
380 int frame_size,
|
Chris@70
|
381 unsigned char *data,
|
Chris@70
|
382 opus_int32 max_data_bytes
|
Chris@70
|
383 ) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2) OPUS_ARG_NONNULL(4);
|
Chris@70
|
384
|
Chris@70
|
385 /** Encodes a multistream Opus frame from floating point input.
|
Chris@70
|
386 * @param st <tt>OpusMSEncoder*</tt>: Multistream encoder state.
|
Chris@70
|
387 * @param[in] pcm <tt>const float*</tt>: The input signal as interleaved
|
Chris@70
|
388 * samples with a normal range of
|
Chris@70
|
389 * +/-1.0.
|
Chris@70
|
390 * Samples with a range beyond +/-1.0
|
Chris@70
|
391 * are supported but will be clipped by
|
Chris@70
|
392 * decoders using the integer API and
|
Chris@70
|
393 * should only be used if it is known
|
Chris@70
|
394 * that the far end supports extended
|
Chris@70
|
395 * dynamic range.
|
Chris@70
|
396 * This must contain
|
Chris@70
|
397 * <code>frame_size*channels</code>
|
Chris@70
|
398 * samples.
|
Chris@70
|
399 * @param frame_size <tt>int</tt>: Number of samples per channel in the input
|
Chris@70
|
400 * signal.
|
Chris@70
|
401 * This must be an Opus frame size for the
|
Chris@70
|
402 * encoder's sampling rate.
|
Chris@70
|
403 * For example, at 48 kHz the permitted values
|
Chris@70
|
404 * are 120, 240, 480, 960, 1920, and 2880.
|
Chris@70
|
405 * Passing in a duration of less than 10 ms
|
Chris@70
|
406 * (480 samples at 48 kHz) will prevent the
|
Chris@70
|
407 * encoder from using the LPC or hybrid modes.
|
Chris@70
|
408 * @param[out] data <tt>unsigned char*</tt>: Output payload.
|
Chris@70
|
409 * This must contain storage for at
|
Chris@70
|
410 * least \a max_data_bytes.
|
Chris@70
|
411 * @param [in] max_data_bytes <tt>opus_int32</tt>: Size of the allocated
|
Chris@70
|
412 * memory for the output
|
Chris@70
|
413 * payload. This may be
|
Chris@70
|
414 * used to impose an upper limit on
|
Chris@70
|
415 * the instant bitrate, but should
|
Chris@70
|
416 * not be used as the only bitrate
|
Chris@70
|
417 * control. Use #OPUS_SET_BITRATE to
|
Chris@70
|
418 * control the bitrate.
|
Chris@70
|
419 * @returns The length of the encoded packet (in bytes) on success or a
|
Chris@70
|
420 * negative error code (see @ref opus_errorcodes) on failure.
|
Chris@70
|
421 */
|
Chris@70
|
422 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_multistream_encode_float(
|
Chris@70
|
423 OpusMSEncoder *st,
|
Chris@70
|
424 const float *pcm,
|
Chris@70
|
425 int frame_size,
|
Chris@70
|
426 unsigned char *data,
|
Chris@70
|
427 opus_int32 max_data_bytes
|
Chris@70
|
428 ) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2) OPUS_ARG_NONNULL(4);
|
Chris@70
|
429
|
Chris@70
|
430 /** Frees an <code>OpusMSEncoder</code> allocated by
|
Chris@70
|
431 * opus_multistream_encoder_create().
|
Chris@70
|
432 * @param st <tt>OpusMSEncoder*</tt>: Multistream encoder state to be freed.
|
Chris@70
|
433 */
|
Chris@70
|
434 OPUS_EXPORT void opus_multistream_encoder_destroy(OpusMSEncoder *st);
|
Chris@70
|
435
|
Chris@70
|
436 /** Perform a CTL function on a multistream Opus encoder.
|
Chris@70
|
437 *
|
Chris@70
|
438 * Generally the request and subsequent arguments are generated by a
|
Chris@70
|
439 * convenience macro.
|
Chris@70
|
440 * @param st <tt>OpusMSEncoder*</tt>: Multistream encoder state.
|
Chris@70
|
441 * @param request This and all remaining parameters should be replaced by one
|
Chris@70
|
442 * of the convenience macros in @ref opus_genericctls,
|
Chris@70
|
443 * @ref opus_encoderctls, or @ref opus_multistream_ctls.
|
Chris@70
|
444 * @see opus_genericctls
|
Chris@70
|
445 * @see opus_encoderctls
|
Chris@70
|
446 * @see opus_multistream_ctls
|
Chris@70
|
447 */
|
Chris@70
|
448 OPUS_EXPORT int opus_multistream_encoder_ctl(OpusMSEncoder *st, int request, ...) OPUS_ARG_NONNULL(1);
|
Chris@70
|
449
|
Chris@70
|
450 /**@}*/
|
Chris@70
|
451
|
Chris@70
|
452 /**\name Multistream decoder functions */
|
Chris@70
|
453 /**@{*/
|
Chris@70
|
454
|
Chris@70
|
455 /** Gets the size of an <code>OpusMSDecoder</code> structure.
|
Chris@70
|
456 * @param streams <tt>int</tt>: The total number of streams coded in the
|
Chris@70
|
457 * input.
|
Chris@70
|
458 * This must be no more than 255.
|
Chris@70
|
459 * @param coupled_streams <tt>int</tt>: Number streams to decode as coupled
|
Chris@70
|
460 * (2 channel) streams.
|
Chris@70
|
461 * This must be no larger than the total
|
Chris@70
|
462 * number of streams.
|
Chris@70
|
463 * Additionally, The total number of
|
Chris@70
|
464 * coded channels (<code>streams +
|
Chris@70
|
465 * coupled_streams</code>) must be no
|
Chris@70
|
466 * more than 255.
|
Chris@70
|
467 * @returns The size in bytes on success, or a negative error code
|
Chris@70
|
468 * (see @ref opus_errorcodes) on error.
|
Chris@70
|
469 */
|
Chris@70
|
470 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_multistream_decoder_get_size(
|
Chris@70
|
471 int streams,
|
Chris@70
|
472 int coupled_streams
|
Chris@70
|
473 );
|
Chris@70
|
474
|
Chris@70
|
475 /** Allocates and initializes a multistream decoder state.
|
Chris@70
|
476 * Call opus_multistream_decoder_destroy() to release
|
Chris@70
|
477 * this object when finished.
|
Chris@70
|
478 * @param Fs <tt>opus_int32</tt>: Sampling rate to decode at (in Hz).
|
Chris@70
|
479 * This must be one of 8000, 12000, 16000,
|
Chris@70
|
480 * 24000, or 48000.
|
Chris@70
|
481 * @param channels <tt>int</tt>: Number of channels to output.
|
Chris@70
|
482 * This must be at most 255.
|
Chris@70
|
483 * It may be different from the number of coded
|
Chris@70
|
484 * channels (<code>streams +
|
Chris@70
|
485 * coupled_streams</code>).
|
Chris@70
|
486 * @param streams <tt>int</tt>: The total number of streams coded in the
|
Chris@70
|
487 * input.
|
Chris@70
|
488 * This must be no more than 255.
|
Chris@70
|
489 * @param coupled_streams <tt>int</tt>: Number of streams to decode as coupled
|
Chris@70
|
490 * (2 channel) streams.
|
Chris@70
|
491 * This must be no larger than the total
|
Chris@70
|
492 * number of streams.
|
Chris@70
|
493 * Additionally, The total number of
|
Chris@70
|
494 * coded channels (<code>streams +
|
Chris@70
|
495 * coupled_streams</code>) must be no
|
Chris@70
|
496 * more than 255.
|
Chris@70
|
497 * @param[in] mapping <code>const unsigned char[channels]</code>: Mapping from
|
Chris@70
|
498 * coded channels to output channels, as described in
|
Chris@70
|
499 * @ref opus_multistream.
|
Chris@70
|
500 * @param[out] error <tt>int *</tt>: Returns #OPUS_OK on success, or an error
|
Chris@70
|
501 * code (see @ref opus_errorcodes) on
|
Chris@70
|
502 * failure.
|
Chris@70
|
503 */
|
Chris@70
|
504 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusMSDecoder *opus_multistream_decoder_create(
|
Chris@70
|
505 opus_int32 Fs,
|
Chris@70
|
506 int channels,
|
Chris@70
|
507 int streams,
|
Chris@70
|
508 int coupled_streams,
|
Chris@70
|
509 const unsigned char *mapping,
|
Chris@70
|
510 int *error
|
Chris@70
|
511 ) OPUS_ARG_NONNULL(5);
|
Chris@70
|
512
|
Chris@70
|
513 /** Intialize a previously allocated decoder state object.
|
Chris@70
|
514 * The memory pointed to by \a st must be at least the size returned by
|
Chris@70
|
515 * opus_multistream_encoder_get_size().
|
Chris@70
|
516 * This is intended for applications which use their own allocator instead of
|
Chris@70
|
517 * malloc.
|
Chris@70
|
518 * To reset a previously initialized state, use the #OPUS_RESET_STATE CTL.
|
Chris@70
|
519 * @see opus_multistream_decoder_create
|
Chris@70
|
520 * @see opus_multistream_deocder_get_size
|
Chris@70
|
521 * @param st <tt>OpusMSEncoder*</tt>: Multistream encoder state to initialize.
|
Chris@70
|
522 * @param Fs <tt>opus_int32</tt>: Sampling rate to decode at (in Hz).
|
Chris@70
|
523 * This must be one of 8000, 12000, 16000,
|
Chris@70
|
524 * 24000, or 48000.
|
Chris@70
|
525 * @param channels <tt>int</tt>: Number of channels to output.
|
Chris@70
|
526 * This must be at most 255.
|
Chris@70
|
527 * It may be different from the number of coded
|
Chris@70
|
528 * channels (<code>streams +
|
Chris@70
|
529 * coupled_streams</code>).
|
Chris@70
|
530 * @param streams <tt>int</tt>: The total number of streams coded in the
|
Chris@70
|
531 * input.
|
Chris@70
|
532 * This must be no more than 255.
|
Chris@70
|
533 * @param coupled_streams <tt>int</tt>: Number of streams to decode as coupled
|
Chris@70
|
534 * (2 channel) streams.
|
Chris@70
|
535 * This must be no larger than the total
|
Chris@70
|
536 * number of streams.
|
Chris@70
|
537 * Additionally, The total number of
|
Chris@70
|
538 * coded channels (<code>streams +
|
Chris@70
|
539 * coupled_streams</code>) must be no
|
Chris@70
|
540 * more than 255.
|
Chris@70
|
541 * @param[in] mapping <code>const unsigned char[channels]</code>: Mapping from
|
Chris@70
|
542 * coded channels to output channels, as described in
|
Chris@70
|
543 * @ref opus_multistream.
|
Chris@70
|
544 * @returns #OPUS_OK on success, or an error code (see @ref opus_errorcodes)
|
Chris@70
|
545 * on failure.
|
Chris@70
|
546 */
|
Chris@70
|
547 OPUS_EXPORT int opus_multistream_decoder_init(
|
Chris@70
|
548 OpusMSDecoder *st,
|
Chris@70
|
549 opus_int32 Fs,
|
Chris@70
|
550 int channels,
|
Chris@70
|
551 int streams,
|
Chris@70
|
552 int coupled_streams,
|
Chris@70
|
553 const unsigned char *mapping
|
Chris@70
|
554 ) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(6);
|
Chris@70
|
555
|
Chris@70
|
556 /** Decode a multistream Opus packet.
|
Chris@70
|
557 * @param st <tt>OpusMSDecoder*</tt>: Multistream decoder state.
|
Chris@70
|
558 * @param[in] data <tt>const unsigned char*</tt>: Input payload.
|
Chris@70
|
559 * Use a <code>NULL</code>
|
Chris@70
|
560 * pointer to indicate packet
|
Chris@70
|
561 * loss.
|
Chris@70
|
562 * @param len <tt>opus_int32</tt>: Number of bytes in payload.
|
Chris@70
|
563 * @param[out] pcm <tt>opus_int16*</tt>: Output signal, with interleaved
|
Chris@70
|
564 * samples.
|
Chris@70
|
565 * This must contain room for
|
Chris@70
|
566 * <code>frame_size*channels</code>
|
Chris@70
|
567 * samples.
|
Chris@70
|
568 * @param frame_size <tt>int</tt>: The number of samples per channel of
|
Chris@70
|
569 * available space in \a pcm.
|
Chris@70
|
570 * If this is less than the maximum packet duration
|
Chris@70
|
571 * (120 ms; 5760 for 48kHz), this function will not be capable
|
Chris@70
|
572 * of decoding some packets. In the case of PLC (data==NULL)
|
Chris@70
|
573 * or FEC (decode_fec=1), then frame_size needs to be exactly
|
Chris@70
|
574 * the duration of audio that is missing, otherwise the
|
Chris@70
|
575 * decoder will not be in the optimal state to decode the
|
Chris@70
|
576 * next incoming packet. For the PLC and FEC cases, frame_size
|
Chris@70
|
577 * <b>must</b> be a multiple of 2.5 ms.
|
Chris@70
|
578 * @param decode_fec <tt>int</tt>: Flag (0 or 1) to request that any in-band
|
Chris@70
|
579 * forward error correction data be decoded.
|
Chris@70
|
580 * If no such data is available, the frame is
|
Chris@70
|
581 * decoded as if it were lost.
|
Chris@70
|
582 * @returns Number of samples decoded on success or a negative error code
|
Chris@70
|
583 * (see @ref opus_errorcodes) on failure.
|
Chris@70
|
584 */
|
Chris@70
|
585 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_multistream_decode(
|
Chris@70
|
586 OpusMSDecoder *st,
|
Chris@70
|
587 const unsigned char *data,
|
Chris@70
|
588 opus_int32 len,
|
Chris@70
|
589 opus_int16 *pcm,
|
Chris@70
|
590 int frame_size,
|
Chris@70
|
591 int decode_fec
|
Chris@70
|
592 ) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4);
|
Chris@70
|
593
|
Chris@70
|
594 /** Decode a multistream Opus packet with floating point output.
|
Chris@70
|
595 * @param st <tt>OpusMSDecoder*</tt>: Multistream decoder state.
|
Chris@70
|
596 * @param[in] data <tt>const unsigned char*</tt>: Input payload.
|
Chris@70
|
597 * Use a <code>NULL</code>
|
Chris@70
|
598 * pointer to indicate packet
|
Chris@70
|
599 * loss.
|
Chris@70
|
600 * @param len <tt>opus_int32</tt>: Number of bytes in payload.
|
Chris@70
|
601 * @param[out] pcm <tt>opus_int16*</tt>: Output signal, with interleaved
|
Chris@70
|
602 * samples.
|
Chris@70
|
603 * This must contain room for
|
Chris@70
|
604 * <code>frame_size*channels</code>
|
Chris@70
|
605 * samples.
|
Chris@70
|
606 * @param frame_size <tt>int</tt>: The number of samples per channel of
|
Chris@70
|
607 * available space in \a pcm.
|
Chris@70
|
608 * If this is less than the maximum packet duration
|
Chris@70
|
609 * (120 ms; 5760 for 48kHz), this function will not be capable
|
Chris@70
|
610 * of decoding some packets. In the case of PLC (data==NULL)
|
Chris@70
|
611 * or FEC (decode_fec=1), then frame_size needs to be exactly
|
Chris@70
|
612 * the duration of audio that is missing, otherwise the
|
Chris@70
|
613 * decoder will not be in the optimal state to decode the
|
Chris@70
|
614 * next incoming packet. For the PLC and FEC cases, frame_size
|
Chris@70
|
615 * <b>must</b> be a multiple of 2.5 ms.
|
Chris@70
|
616 * @param decode_fec <tt>int</tt>: Flag (0 or 1) to request that any in-band
|
Chris@70
|
617 * forward error correction data be decoded.
|
Chris@70
|
618 * If no such data is available, the frame is
|
Chris@70
|
619 * decoded as if it were lost.
|
Chris@70
|
620 * @returns Number of samples decoded on success or a negative error code
|
Chris@70
|
621 * (see @ref opus_errorcodes) on failure.
|
Chris@70
|
622 */
|
Chris@70
|
623 OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_multistream_decode_float(
|
Chris@70
|
624 OpusMSDecoder *st,
|
Chris@70
|
625 const unsigned char *data,
|
Chris@70
|
626 opus_int32 len,
|
Chris@70
|
627 float *pcm,
|
Chris@70
|
628 int frame_size,
|
Chris@70
|
629 int decode_fec
|
Chris@70
|
630 ) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4);
|
Chris@70
|
631
|
Chris@70
|
632 /** Perform a CTL function on a multistream Opus decoder.
|
Chris@70
|
633 *
|
Chris@70
|
634 * Generally the request and subsequent arguments are generated by a
|
Chris@70
|
635 * convenience macro.
|
Chris@70
|
636 * @param st <tt>OpusMSDecoder*</tt>: Multistream decoder state.
|
Chris@70
|
637 * @param request This and all remaining parameters should be replaced by one
|
Chris@70
|
638 * of the convenience macros in @ref opus_genericctls,
|
Chris@70
|
639 * @ref opus_decoderctls, or @ref opus_multistream_ctls.
|
Chris@70
|
640 * @see opus_genericctls
|
Chris@70
|
641 * @see opus_decoderctls
|
Chris@70
|
642 * @see opus_multistream_ctls
|
Chris@70
|
643 */
|
Chris@70
|
644 OPUS_EXPORT int opus_multistream_decoder_ctl(OpusMSDecoder *st, int request, ...) OPUS_ARG_NONNULL(1);
|
Chris@70
|
645
|
Chris@70
|
646 /** Frees an <code>OpusMSDecoder</code> allocated by
|
Chris@70
|
647 * opus_multistream_decoder_create().
|
Chris@70
|
648 * @param st <tt>OpusMSDecoder</tt>: Multistream decoder state to be freed.
|
Chris@70
|
649 */
|
Chris@70
|
650 OPUS_EXPORT void opus_multistream_decoder_destroy(OpusMSDecoder *st);
|
Chris@70
|
651
|
Chris@70
|
652 /**@}*/
|
Chris@70
|
653
|
Chris@70
|
654 /**@}*/
|
Chris@70
|
655
|
Chris@70
|
656 #ifdef __cplusplus
|
Chris@70
|
657 }
|
Chris@70
|
658 #endif
|
Chris@70
|
659
|
Chris@70
|
660 #endif /* OPUS_MULTISTREAM_H */
|