blob: 603011887410b5ea8383a9f6c8822211ffd159a7
1 | /* Copyright (c) 2010-2011 Xiph.Org Foundation, Skype Limited |
2 | Written by Jean-Marc Valin and Koen Vos */ |
3 | /* |
4 | Redistribution and use in source and binary forms, with or without |
5 | modification, are permitted provided that the following conditions |
6 | are met: |
7 | |
8 | - Redistributions of source code must retain the above copyright |
9 | notice, this list of conditions and the following disclaimer. |
10 | |
11 | - Redistributions in binary form must reproduce the above copyright |
12 | notice, this list of conditions and the following disclaimer in the |
13 | documentation and/or other materials provided with the distribution. |
14 | |
15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
16 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
17 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
18 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER |
19 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
20 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
21 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
22 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
23 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
24 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ |
27 | |
28 | /** |
29 | * @file opus_defines.h |
30 | * @brief Opus reference implementation constants |
31 | */ |
32 | |
33 | #ifndef OPUS_DEFINES_H |
34 | #define OPUS_DEFINES_H |
35 | |
36 | #include "opus_types.h" |
37 | |
38 | #ifdef __cplusplus |
39 | extern "C" { |
40 | #endif |
41 | |
42 | /** @defgroup opus_errorcodes Error codes |
43 | * @ingroup opus |
44 | * @{ |
45 | */ |
46 | /** No error @hideinitializer*/ |
47 | #define OPUS_OK 0 |
48 | /** One or more invalid/out of range arguments @hideinitializer*/ |
49 | #define OPUS_BAD_ARG -1 |
50 | /** Not enough bytes allocated in the buffer @hideinitializer*/ |
51 | #define OPUS_BUFFER_TOO_SMALL -2 |
52 | /** An internal error was detected @hideinitializer*/ |
53 | #define OPUS_INTERNAL_ERROR -3 |
54 | /** The compressed data passed is corrupted @hideinitializer*/ |
55 | #define OPUS_INVALID_PACKET -4 |
56 | /** Invalid/unsupported request number @hideinitializer*/ |
57 | #define OPUS_UNIMPLEMENTED -5 |
58 | /** An encoder or decoder structure is invalid or already freed @hideinitializer*/ |
59 | #define OPUS_INVALID_STATE -6 |
60 | /** Memory allocation has failed @hideinitializer*/ |
61 | #define OPUS_ALLOC_FAIL -7 |
62 | /**@}*/ |
63 | |
64 | /** @cond OPUS_INTERNAL_DOC */ |
65 | /**Export control for opus functions */ |
66 | |
67 | #ifndef OPUS_EXPORT |
68 | # if defined(WIN32) |
69 | # if defined(OPUS_BUILD) && defined(DLL_EXPORT) |
70 | # define OPUS_EXPORT __declspec(dllexport) |
71 | # else |
72 | # define OPUS_EXPORT |
73 | # endif |
74 | # elif defined(__GNUC__) && defined(OPUS_BUILD) |
75 | # define OPUS_EXPORT __attribute__ ((visibility ("default"))) |
76 | # else |
77 | # define OPUS_EXPORT |
78 | # endif |
79 | #endif |
80 | |
81 | # if !defined(OPUS_GNUC_PREREQ) |
82 | # if defined(__GNUC__)&&defined(__GNUC_MINOR__) |
83 | # define OPUS_GNUC_PREREQ(_maj,_min) \ |
84 | ((__GNUC__<<16)+__GNUC_MINOR__>=((_maj)<<16)+(_min)) |
85 | # else |
86 | # define OPUS_GNUC_PREREQ(_maj,_min) 0 |
87 | # endif |
88 | # endif |
89 | |
90 | #if (!defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L) ) |
91 | # if OPUS_GNUC_PREREQ(3,0) |
92 | # define OPUS_RESTRICT __restrict__ |
93 | # elif (defined(_MSC_VER) && _MSC_VER >= 1400) |
94 | # define OPUS_RESTRICT __restrict |
95 | # else |
96 | # define OPUS_RESTRICT |
97 | # endif |
98 | #else |
99 | # define OPUS_RESTRICT restrict |
100 | #endif |
101 | |
102 | #if (!defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L) ) |
103 | # if OPUS_GNUC_PREREQ(2,7) |
104 | # define OPUS_INLINE __inline__ |
105 | # elif (defined(_MSC_VER)) |
106 | # define OPUS_INLINE __inline |
107 | # else |
108 | # define OPUS_INLINE |
109 | # endif |
110 | #else |
111 | # define OPUS_INLINE inline |
112 | #endif |
113 | |
114 | /**Warning attributes for opus functions |
115 | * NONNULL is not used in OPUS_BUILD to avoid the compiler optimizing out |
116 | * some paranoid null checks. */ |
117 | #if defined(__GNUC__) && OPUS_GNUC_PREREQ(3, 4) |
118 | # define OPUS_WARN_UNUSED_RESULT __attribute__ ((__warn_unused_result__)) |
119 | #else |
120 | # define OPUS_WARN_UNUSED_RESULT |
121 | #endif |
122 | #if !defined(OPUS_BUILD) && defined(__GNUC__) && OPUS_GNUC_PREREQ(3, 4) |
123 | # define OPUS_ARG_NONNULL(_x) __attribute__ ((__nonnull__(_x))) |
124 | #else |
125 | # define OPUS_ARG_NONNULL(_x) |
126 | #endif |
127 | |
128 | /** These are the actual Encoder CTL ID numbers. |
129 | * They should not be used directly by applications. |
130 | * In general, SETs should be even and GETs should be odd.*/ |
131 | #define OPUS_SET_APPLICATION_REQUEST 4000 |
132 | #define OPUS_GET_APPLICATION_REQUEST 4001 |
133 | #define OPUS_SET_BITRATE_REQUEST 4002 |
134 | #define OPUS_GET_BITRATE_REQUEST 4003 |
135 | #define OPUS_SET_MAX_BANDWIDTH_REQUEST 4004 |
136 | #define OPUS_GET_MAX_BANDWIDTH_REQUEST 4005 |
137 | #define OPUS_SET_VBR_REQUEST 4006 |
138 | #define OPUS_GET_VBR_REQUEST 4007 |
139 | #define OPUS_SET_BANDWIDTH_REQUEST 4008 |
140 | #define OPUS_GET_BANDWIDTH_REQUEST 4009 |
141 | #define OPUS_SET_COMPLEXITY_REQUEST 4010 |
142 | #define OPUS_GET_COMPLEXITY_REQUEST 4011 |
143 | #define OPUS_SET_INBAND_FEC_REQUEST 4012 |
144 | #define OPUS_GET_INBAND_FEC_REQUEST 4013 |
145 | #define OPUS_SET_PACKET_LOSS_PERC_REQUEST 4014 |
146 | #define OPUS_GET_PACKET_LOSS_PERC_REQUEST 4015 |
147 | #define OPUS_SET_DTX_REQUEST 4016 |
148 | #define OPUS_GET_DTX_REQUEST 4017 |
149 | #define OPUS_SET_VBR_CONSTRAINT_REQUEST 4020 |
150 | #define OPUS_GET_VBR_CONSTRAINT_REQUEST 4021 |
151 | #define OPUS_SET_FORCE_CHANNELS_REQUEST 4022 |
152 | #define OPUS_GET_FORCE_CHANNELS_REQUEST 4023 |
153 | #define OPUS_SET_SIGNAL_REQUEST 4024 |
154 | #define OPUS_GET_SIGNAL_REQUEST 4025 |
155 | #define OPUS_GET_LOOKAHEAD_REQUEST 4027 |
156 | /* #define OPUS_RESET_STATE 4028 */ |
157 | #define OPUS_GET_SAMPLE_RATE_REQUEST 4029 |
158 | #define OPUS_GET_FINAL_RANGE_REQUEST 4031 |
159 | #define OPUS_GET_PITCH_REQUEST 4033 |
160 | #define OPUS_SET_GAIN_REQUEST 4034 |
161 | #define OPUS_GET_GAIN_REQUEST 4045 /* Should have been 4035 */ |
162 | #define OPUS_SET_LSB_DEPTH_REQUEST 4036 |
163 | #define OPUS_GET_LSB_DEPTH_REQUEST 4037 |
164 | #define OPUS_GET_LAST_PACKET_DURATION_REQUEST 4039 |
165 | #define OPUS_SET_EXPERT_FRAME_DURATION_REQUEST 4040 |
166 | #define OPUS_GET_EXPERT_FRAME_DURATION_REQUEST 4041 |
167 | #define OPUS_SET_PREDICTION_DISABLED_REQUEST 4042 |
168 | #define OPUS_GET_PREDICTION_DISABLED_REQUEST 4043 |
169 | |
170 | /* Don't use 4045, it's already taken by OPUS_GET_GAIN_REQUEST */ |
171 | |
172 | /* Macros to trigger compilation errors when the wrong types are provided to a CTL */ |
173 | #ifdef __GNUC__ |
174 | #define __opus_check_int(x) (((void)((x) == (opus_int32)0)), (opus_int32)(x)) |
175 | #define __opus_check_int_ptr(ptr) ((ptr) + ((ptr) - (opus_int32*)(ptr))) |
176 | #define __opus_check_uint_ptr(ptr) ((ptr) + ((ptr) - (opus_uint32*)(ptr))) |
177 | #define __opus_check_val16_ptr(ptr) ((ptr) + ((ptr) - (opus_val16*)(ptr))) |
178 | #else |
179 | #define __opus_check_int(x) ((opus_int32)(x)) |
180 | #define __opus_check_int_ptr(ptr) ((opus_int32*)(ptr)) |
181 | #define __opus_check_uint_ptr(ptr) ((opus_uint32*)(ptr)) |
182 | #define __opus_check_val16_ptr(ptr) ((opus_val16*)(ptr)) |
183 | #endif |
184 | /** @endcond */ |
185 | |
186 | /** @defgroup opus_ctlvalues Pre-defined values for CTL interface |
187 | * @ingroup opus |
188 | * @see opus_genericctls, opus_encoderctls |
189 | * @{ |
190 | */ |
191 | /* Values for the various encoder CTLs */ |
192 | #define OPUS_AUTO -1000 /**<Auto/default setting @hideinitializer*/ |
193 | #define OPUS_BITRATE_MAX -1 /**<Maximum bitrate @hideinitializer*/ |
194 | |
195 | /** Best for most VoIP/videoconference applications where listening quality and intelligibility matter most |
196 | * @hideinitializer */ |
197 | #define OPUS_APPLICATION_VOIP 2048 |
198 | /** Best for broadcast/high-fidelity application where the decoded audio should be as close as possible to the input |
199 | * @hideinitializer */ |
200 | #define OPUS_APPLICATION_AUDIO 2049 |
201 | /** Only use when lowest-achievable latency is what matters most. Voice-optimized modes cannot be used. |
202 | * @hideinitializer */ |
203 | #define OPUS_APPLICATION_RESTRICTED_LOWDELAY 2051 |
204 | |
205 | #define OPUS_SIGNAL_VOICE 3001 /**< Signal being encoded is voice */ |
206 | #define OPUS_SIGNAL_MUSIC 3002 /**< Signal being encoded is music */ |
207 | #define OPUS_BANDWIDTH_NARROWBAND 1101 /**< 4 kHz bandpass @hideinitializer*/ |
208 | #define OPUS_BANDWIDTH_MEDIUMBAND 1102 /**< 6 kHz bandpass @hideinitializer*/ |
209 | #define OPUS_BANDWIDTH_WIDEBAND 1103 /**< 8 kHz bandpass @hideinitializer*/ |
210 | #define OPUS_BANDWIDTH_SUPERWIDEBAND 1104 /**<12 kHz bandpass @hideinitializer*/ |
211 | #define OPUS_BANDWIDTH_FULLBAND 1105 /**<20 kHz bandpass @hideinitializer*/ |
212 | |
213 | #define OPUS_FRAMESIZE_ARG 5000 /**< Select frame size from the argument (default) */ |
214 | #define OPUS_FRAMESIZE_2_5_MS 5001 /**< Use 2.5 ms frames */ |
215 | #define OPUS_FRAMESIZE_5_MS 5002 /**< Use 5 ms frames */ |
216 | #define OPUS_FRAMESIZE_10_MS 5003 /**< Use 10 ms frames */ |
217 | #define OPUS_FRAMESIZE_20_MS 5004 /**< Use 20 ms frames */ |
218 | #define OPUS_FRAMESIZE_40_MS 5005 /**< Use 40 ms frames */ |
219 | #define OPUS_FRAMESIZE_60_MS 5006 /**< Use 60 ms frames */ |
220 | |
221 | /**@}*/ |
222 | |
223 | |
224 | /** @defgroup opus_encoderctls Encoder related CTLs |
225 | * @ingroup opus |
226 | * |
227 | * These are convenience macros for use with the \c opus_encode_ctl |
228 | * interface. They are used to generate the appropriate series of |
229 | * arguments for that call, passing the correct type, size and so |
230 | * on as expected for each particular request. |
231 | * |
232 | * Some usage examples: |
233 | * |
234 | * @code |
235 | * int ret; |
236 | * ret = opus_encoder_ctl(enc_ctx, OPUS_SET_BANDWIDTH(OPUS_AUTO)); |
237 | * if (ret != OPUS_OK) return ret; |
238 | * |
239 | * opus_int32 rate; |
240 | * opus_encoder_ctl(enc_ctx, OPUS_GET_BANDWIDTH(&rate)); |
241 | * |
242 | * opus_encoder_ctl(enc_ctx, OPUS_RESET_STATE); |
243 | * @endcode |
244 | * |
245 | * @see opus_genericctls, opus_encoder |
246 | * @{ |
247 | */ |
248 | |
249 | /** Configures the encoder's computational complexity. |
250 | * The supported range is 0-10 inclusive with 10 representing the highest complexity. |
251 | * @see OPUS_GET_COMPLEXITY |
252 | * @param[in] x <tt>opus_int32</tt>: Allowed values: 0-10, inclusive. |
253 | * |
254 | * @hideinitializer */ |
255 | #define OPUS_SET_COMPLEXITY(x) OPUS_SET_COMPLEXITY_REQUEST, __opus_check_int(x) |
256 | /** Gets the encoder's complexity configuration. |
257 | * @see OPUS_SET_COMPLEXITY |
258 | * @param[out] x <tt>opus_int32 *</tt>: Returns a value in the range 0-10, |
259 | * inclusive. |
260 | * @hideinitializer */ |
261 | #define OPUS_GET_COMPLEXITY(x) OPUS_GET_COMPLEXITY_REQUEST, __opus_check_int_ptr(x) |
262 | |
263 | /** Configures the bitrate in the encoder. |
264 | * Rates from 500 to 512000 bits per second are meaningful, as well as the |
265 | * special values #OPUS_AUTO and #OPUS_BITRATE_MAX. |
266 | * The value #OPUS_BITRATE_MAX can be used to cause the codec to use as much |
267 | * rate as it can, which is useful for controlling the rate by adjusting the |
268 | * output buffer size. |
269 | * @see OPUS_GET_BITRATE |
270 | * @param[in] x <tt>opus_int32</tt>: Bitrate in bits per second. The default |
271 | * is determined based on the number of |
272 | * channels and the input sampling rate. |
273 | * @hideinitializer */ |
274 | #define OPUS_SET_BITRATE(x) OPUS_SET_BITRATE_REQUEST, __opus_check_int(x) |
275 | /** Gets the encoder's bitrate configuration. |
276 | * @see OPUS_SET_BITRATE |
277 | * @param[out] x <tt>opus_int32 *</tt>: Returns the bitrate in bits per second. |
278 | * The default is determined based on the |
279 | * number of channels and the input |
280 | * sampling rate. |
281 | * @hideinitializer */ |
282 | #define OPUS_GET_BITRATE(x) OPUS_GET_BITRATE_REQUEST, __opus_check_int_ptr(x) |
283 | |
284 | /** Enables or disables variable bitrate (VBR) in the encoder. |
285 | * The configured bitrate may not be met exactly because frames must |
286 | * be an integer number of bytes in length. |
287 | * @see OPUS_GET_VBR |
288 | * @see OPUS_SET_VBR_CONSTRAINT |
289 | * @param[in] x <tt>opus_int32</tt>: Allowed values: |
290 | * <dl> |
291 | * <dt>0</dt><dd>Hard CBR. For LPC/hybrid modes at very low bit-rate, this can |
292 | * cause noticeable quality degradation.</dd> |
293 | * <dt>1</dt><dd>VBR (default). The exact type of VBR is controlled by |
294 | * #OPUS_SET_VBR_CONSTRAINT.</dd> |
295 | * </dl> |
296 | * @hideinitializer */ |
297 | #define OPUS_SET_VBR(x) OPUS_SET_VBR_REQUEST, __opus_check_int(x) |
298 | /** Determine if variable bitrate (VBR) is enabled in the encoder. |
299 | * @see OPUS_SET_VBR |
300 | * @see OPUS_GET_VBR_CONSTRAINT |
301 | * @param[out] x <tt>opus_int32 *</tt>: Returns one of the following values: |
302 | * <dl> |
303 | * <dt>0</dt><dd>Hard CBR.</dd> |
304 | * <dt>1</dt><dd>VBR (default). The exact type of VBR may be retrieved via |
305 | * #OPUS_GET_VBR_CONSTRAINT.</dd> |
306 | * </dl> |
307 | * @hideinitializer */ |
308 | #define OPUS_GET_VBR(x) OPUS_GET_VBR_REQUEST, __opus_check_int_ptr(x) |
309 | |
310 | /** Enables or disables constrained VBR in the encoder. |
311 | * This setting is ignored when the encoder is in CBR mode. |
312 | * @warning Only the MDCT mode of Opus currently heeds the constraint. |
313 | * Speech mode ignores it completely, hybrid mode may fail to obey it |
314 | * if the LPC layer uses more bitrate than the constraint would have |
315 | * permitted. |
316 | * @see OPUS_GET_VBR_CONSTRAINT |
317 | * @see OPUS_SET_VBR |
318 | * @param[in] x <tt>opus_int32</tt>: Allowed values: |
319 | * <dl> |
320 | * <dt>0</dt><dd>Unconstrained VBR.</dd> |
321 | * <dt>1</dt><dd>Constrained VBR (default). This creates a maximum of one |
322 | * frame of buffering delay assuming a transport with a |
323 | * serialization speed of the nominal bitrate.</dd> |
324 | * </dl> |
325 | * @hideinitializer */ |
326 | #define OPUS_SET_VBR_CONSTRAINT(x) OPUS_SET_VBR_CONSTRAINT_REQUEST, __opus_check_int(x) |
327 | /** Determine if constrained VBR is enabled in the encoder. |
328 | * @see OPUS_SET_VBR_CONSTRAINT |
329 | * @see OPUS_GET_VBR |
330 | * @param[out] x <tt>opus_int32 *</tt>: Returns one of the following values: |
331 | * <dl> |
332 | * <dt>0</dt><dd>Unconstrained VBR.</dd> |
333 | * <dt>1</dt><dd>Constrained VBR (default).</dd> |
334 | * </dl> |
335 | * @hideinitializer */ |
336 | #define OPUS_GET_VBR_CONSTRAINT(x) OPUS_GET_VBR_CONSTRAINT_REQUEST, __opus_check_int_ptr(x) |
337 | |
338 | /** Configures mono/stereo forcing in the encoder. |
339 | * This can force the encoder to produce packets encoded as either mono or |
340 | * stereo, regardless of the format of the input audio. This is useful when |
341 | * the caller knows that the input signal is currently a mono source embedded |
342 | * in a stereo stream. |
343 | * @see OPUS_GET_FORCE_CHANNELS |
344 | * @param[in] x <tt>opus_int32</tt>: Allowed values: |
345 | * <dl> |
346 | * <dt>#OPUS_AUTO</dt><dd>Not forced (default)</dd> |
347 | * <dt>1</dt> <dd>Forced mono</dd> |
348 | * <dt>2</dt> <dd>Forced stereo</dd> |
349 | * </dl> |
350 | * @hideinitializer */ |
351 | #define OPUS_SET_FORCE_CHANNELS(x) OPUS_SET_FORCE_CHANNELS_REQUEST, __opus_check_int(x) |
352 | /** Gets the encoder's forced channel configuration. |
353 | * @see OPUS_SET_FORCE_CHANNELS |
354 | * @param[out] x <tt>opus_int32 *</tt>: |
355 | * <dl> |
356 | * <dt>#OPUS_AUTO</dt><dd>Not forced (default)</dd> |
357 | * <dt>1</dt> <dd>Forced mono</dd> |
358 | * <dt>2</dt> <dd>Forced stereo</dd> |
359 | * </dl> |
360 | * @hideinitializer */ |
361 | #define OPUS_GET_FORCE_CHANNELS(x) OPUS_GET_FORCE_CHANNELS_REQUEST, __opus_check_int_ptr(x) |
362 | |
363 | /** Configures the maximum bandpass that the encoder will select automatically. |
364 | * Applications should normally use this instead of #OPUS_SET_BANDWIDTH |
365 | * (leaving that set to the default, #OPUS_AUTO). This allows the |
366 | * application to set an upper bound based on the type of input it is |
367 | * providing, but still gives the encoder the freedom to reduce the bandpass |
368 | * when the bitrate becomes too low, for better overall quality. |
369 | * @see OPUS_GET_MAX_BANDWIDTH |
370 | * @param[in] x <tt>opus_int32</tt>: Allowed values: |
371 | * <dl> |
372 | * <dt>OPUS_BANDWIDTH_NARROWBAND</dt> <dd>4 kHz passband</dd> |
373 | * <dt>OPUS_BANDWIDTH_MEDIUMBAND</dt> <dd>6 kHz passband</dd> |
374 | * <dt>OPUS_BANDWIDTH_WIDEBAND</dt> <dd>8 kHz passband</dd> |
375 | * <dt>OPUS_BANDWIDTH_SUPERWIDEBAND</dt><dd>12 kHz passband</dd> |
376 | * <dt>OPUS_BANDWIDTH_FULLBAND</dt> <dd>20 kHz passband (default)</dd> |
377 | * </dl> |
378 | * @hideinitializer */ |
379 | #define OPUS_SET_MAX_BANDWIDTH(x) OPUS_SET_MAX_BANDWIDTH_REQUEST, __opus_check_int(x) |
380 | |
381 | /** Gets the encoder's configured maximum allowed bandpass. |
382 | * @see OPUS_SET_MAX_BANDWIDTH |
383 | * @param[out] x <tt>opus_int32 *</tt>: Allowed values: |
384 | * <dl> |
385 | * <dt>#OPUS_BANDWIDTH_NARROWBAND</dt> <dd>4 kHz passband</dd> |
386 | * <dt>#OPUS_BANDWIDTH_MEDIUMBAND</dt> <dd>6 kHz passband</dd> |
387 | * <dt>#OPUS_BANDWIDTH_WIDEBAND</dt> <dd>8 kHz passband</dd> |
388 | * <dt>#OPUS_BANDWIDTH_SUPERWIDEBAND</dt><dd>12 kHz passband</dd> |
389 | * <dt>#OPUS_BANDWIDTH_FULLBAND</dt> <dd>20 kHz passband (default)</dd> |
390 | * </dl> |
391 | * @hideinitializer */ |
392 | #define OPUS_GET_MAX_BANDWIDTH(x) OPUS_GET_MAX_BANDWIDTH_REQUEST, __opus_check_int_ptr(x) |
393 | |
394 | /** Sets the encoder's bandpass to a specific value. |
395 | * This prevents the encoder from automatically selecting the bandpass based |
396 | * on the available bitrate. If an application knows the bandpass of the input |
397 | * audio it is providing, it should normally use #OPUS_SET_MAX_BANDWIDTH |
398 | * instead, which still gives the encoder the freedom to reduce the bandpass |
399 | * when the bitrate becomes too low, for better overall quality. |
400 | * @see OPUS_GET_BANDWIDTH |
401 | * @param[in] x <tt>opus_int32</tt>: Allowed values: |
402 | * <dl> |
403 | * <dt>#OPUS_AUTO</dt> <dd>(default)</dd> |
404 | * <dt>#OPUS_BANDWIDTH_NARROWBAND</dt> <dd>4 kHz passband</dd> |
405 | * <dt>#OPUS_BANDWIDTH_MEDIUMBAND</dt> <dd>6 kHz passband</dd> |
406 | * <dt>#OPUS_BANDWIDTH_WIDEBAND</dt> <dd>8 kHz passband</dd> |
407 | * <dt>#OPUS_BANDWIDTH_SUPERWIDEBAND</dt><dd>12 kHz passband</dd> |
408 | * <dt>#OPUS_BANDWIDTH_FULLBAND</dt> <dd>20 kHz passband</dd> |
409 | * </dl> |
410 | * @hideinitializer */ |
411 | #define OPUS_SET_BANDWIDTH(x) OPUS_SET_BANDWIDTH_REQUEST, __opus_check_int(x) |
412 | |
413 | /** Configures the type of signal being encoded. |
414 | * This is a hint which helps the encoder's mode selection. |
415 | * @see OPUS_GET_SIGNAL |
416 | * @param[in] x <tt>opus_int32</tt>: Allowed values: |
417 | * <dl> |
418 | * <dt>#OPUS_AUTO</dt> <dd>(default)</dd> |
419 | * <dt>#OPUS_SIGNAL_VOICE</dt><dd>Bias thresholds towards choosing LPC or Hybrid modes.</dd> |
420 | * <dt>#OPUS_SIGNAL_MUSIC</dt><dd>Bias thresholds towards choosing MDCT modes.</dd> |
421 | * </dl> |
422 | * @hideinitializer */ |
423 | #define OPUS_SET_SIGNAL(x) OPUS_SET_SIGNAL_REQUEST, __opus_check_int(x) |
424 | /** Gets the encoder's configured signal type. |
425 | * @see OPUS_SET_SIGNAL |
426 | * @param[out] x <tt>opus_int32 *</tt>: Returns one of the following values: |
427 | * <dl> |
428 | * <dt>#OPUS_AUTO</dt> <dd>(default)</dd> |
429 | * <dt>#OPUS_SIGNAL_VOICE</dt><dd>Bias thresholds towards choosing LPC or Hybrid modes.</dd> |
430 | * <dt>#OPUS_SIGNAL_MUSIC</dt><dd>Bias thresholds towards choosing MDCT modes.</dd> |
431 | * </dl> |
432 | * @hideinitializer */ |
433 | #define OPUS_GET_SIGNAL(x) OPUS_GET_SIGNAL_REQUEST, __opus_check_int_ptr(x) |
434 | |
435 | |
436 | /** Configures the encoder's intended application. |
437 | * The initial value is a mandatory argument to the encoder_create function. |
438 | * @see OPUS_GET_APPLICATION |
439 | * @param[in] x <tt>opus_int32</tt>: Returns one of the following values: |
440 | * <dl> |
441 | * <dt>#OPUS_APPLICATION_VOIP</dt> |
442 | * <dd>Process signal for improved speech intelligibility.</dd> |
443 | * <dt>#OPUS_APPLICATION_AUDIO</dt> |
444 | * <dd>Favor faithfulness to the original input.</dd> |
445 | * <dt>#OPUS_APPLICATION_RESTRICTED_LOWDELAY</dt> |
446 | * <dd>Configure the minimum possible coding delay by disabling certain modes |
447 | * of operation.</dd> |
448 | * </dl> |
449 | * @hideinitializer */ |
450 | #define OPUS_SET_APPLICATION(x) OPUS_SET_APPLICATION_REQUEST, __opus_check_int(x) |
451 | /** Gets the encoder's configured application. |
452 | * @see OPUS_SET_APPLICATION |
453 | * @param[out] x <tt>opus_int32 *</tt>: Returns one of the following values: |
454 | * <dl> |
455 | * <dt>#OPUS_APPLICATION_VOIP</dt> |
456 | * <dd>Process signal for improved speech intelligibility.</dd> |
457 | * <dt>#OPUS_APPLICATION_AUDIO</dt> |
458 | * <dd>Favor faithfulness to the original input.</dd> |
459 | * <dt>#OPUS_APPLICATION_RESTRICTED_LOWDELAY</dt> |
460 | * <dd>Configure the minimum possible coding delay by disabling certain modes |
461 | * of operation.</dd> |
462 | * </dl> |
463 | * @hideinitializer */ |
464 | #define OPUS_GET_APPLICATION(x) OPUS_GET_APPLICATION_REQUEST, __opus_check_int_ptr(x) |
465 | |
466 | /** Gets the total samples of delay added by the entire codec. |
467 | * This can be queried by the encoder and then the provided number of samples can be |
468 | * skipped on from the start of the decoder's output to provide time aligned input |
469 | * and output. From the perspective of a decoding application the real data begins this many |
470 | * samples late. |
471 | * |
472 | * The decoder contribution to this delay is identical for all decoders, but the |
473 | * encoder portion of the delay may vary from implementation to implementation, |
474 | * version to version, or even depend on the encoder's initial configuration. |
475 | * Applications needing delay compensation should call this CTL rather than |
476 | * hard-coding a value. |
477 | * @param[out] x <tt>opus_int32 *</tt>: Number of lookahead samples |
478 | * @hideinitializer */ |
479 | #define OPUS_GET_LOOKAHEAD(x) OPUS_GET_LOOKAHEAD_REQUEST, __opus_check_int_ptr(x) |
480 | |
481 | /** Configures the encoder's use of inband forward error correction (FEC). |
482 | * @note This is only applicable to the LPC layer |
483 | * @see OPUS_GET_INBAND_FEC |
484 | * @param[in] x <tt>opus_int32</tt>: Allowed values: |
485 | * <dl> |
486 | * <dt>0</dt><dd>Disable inband FEC (default).</dd> |
487 | * <dt>1</dt><dd>Enable inband FEC.</dd> |
488 | * </dl> |
489 | * @hideinitializer */ |
490 | #define OPUS_SET_INBAND_FEC(x) OPUS_SET_INBAND_FEC_REQUEST, __opus_check_int(x) |
491 | /** Gets encoder's configured use of inband forward error correction. |
492 | * @see OPUS_SET_INBAND_FEC |
493 | * @param[out] x <tt>opus_int32 *</tt>: Returns one of the following values: |
494 | * <dl> |
495 | * <dt>0</dt><dd>Inband FEC disabled (default).</dd> |
496 | * <dt>1</dt><dd>Inband FEC enabled.</dd> |
497 | * </dl> |
498 | * @hideinitializer */ |
499 | #define OPUS_GET_INBAND_FEC(x) OPUS_GET_INBAND_FEC_REQUEST, __opus_check_int_ptr(x) |
500 | |
501 | /** Configures the encoder's expected packet loss percentage. |
502 | * Higher values trigger progressively more loss resistant behavior in the encoder |
503 | * at the expense of quality at a given bitrate in the absence of packet loss, but |
504 | * greater quality under loss. |
505 | * @see OPUS_GET_PACKET_LOSS_PERC |
506 | * @param[in] x <tt>opus_int32</tt>: Loss percentage in the range 0-100, inclusive (default: 0). |
507 | * @hideinitializer */ |
508 | #define OPUS_SET_PACKET_LOSS_PERC(x) OPUS_SET_PACKET_LOSS_PERC_REQUEST, __opus_check_int(x) |
509 | /** Gets the encoder's configured packet loss percentage. |
510 | * @see OPUS_SET_PACKET_LOSS_PERC |
511 | * @param[out] x <tt>opus_int32 *</tt>: Returns the configured loss percentage |
512 | * in the range 0-100, inclusive (default: 0). |
513 | * @hideinitializer */ |
514 | #define OPUS_GET_PACKET_LOSS_PERC(x) OPUS_GET_PACKET_LOSS_PERC_REQUEST, __opus_check_int_ptr(x) |
515 | |
516 | /** Configures the encoder's use of discontinuous transmission (DTX). |
517 | * @note This is only applicable to the LPC layer |
518 | * @see OPUS_GET_DTX |
519 | * @param[in] x <tt>opus_int32</tt>: Allowed values: |
520 | * <dl> |
521 | * <dt>0</dt><dd>Disable DTX (default).</dd> |
522 | * <dt>1</dt><dd>Enabled DTX.</dd> |
523 | * </dl> |
524 | * @hideinitializer */ |
525 | #define OPUS_SET_DTX(x) OPUS_SET_DTX_REQUEST, __opus_check_int(x) |
526 | /** Gets encoder's configured use of discontinuous transmission. |
527 | * @see OPUS_SET_DTX |
528 | * @param[out] x <tt>opus_int32 *</tt>: Returns one of the following values: |
529 | * <dl> |
530 | * <dt>0</dt><dd>DTX disabled (default).</dd> |
531 | * <dt>1</dt><dd>DTX enabled.</dd> |
532 | * </dl> |
533 | * @hideinitializer */ |
534 | #define OPUS_GET_DTX(x) OPUS_GET_DTX_REQUEST, __opus_check_int_ptr(x) |
535 | /** Configures the depth of signal being encoded. |
536 | * |
537 | * This is a hint which helps the encoder identify silence and near-silence. |
538 | * It represents the number of significant bits of linear intensity below |
539 | * which the signal contains ignorable quantization or other noise. |
540 | * |
541 | * For example, OPUS_SET_LSB_DEPTH(14) would be an appropriate setting |
542 | * for G.711 u-law input. OPUS_SET_LSB_DEPTH(16) would be appropriate |
543 | * for 16-bit linear pcm input with opus_encode_float(). |
544 | * |
545 | * When using opus_encode() instead of opus_encode_float(), or when libopus |
546 | * is compiled for fixed-point, the encoder uses the minimum of the value |
547 | * set here and the value 16. |
548 | * |
549 | * @see OPUS_GET_LSB_DEPTH |
550 | * @param[in] x <tt>opus_int32</tt>: Input precision in bits, between 8 and 24 |
551 | * (default: 24). |
552 | * @hideinitializer */ |
553 | #define OPUS_SET_LSB_DEPTH(x) OPUS_SET_LSB_DEPTH_REQUEST, __opus_check_int(x) |
554 | /** Gets the encoder's configured signal depth. |
555 | * @see OPUS_SET_LSB_DEPTH |
556 | * @param[out] x <tt>opus_int32 *</tt>: Input precision in bits, between 8 and |
557 | * 24 (default: 24). |
558 | * @hideinitializer */ |
559 | #define OPUS_GET_LSB_DEPTH(x) OPUS_GET_LSB_DEPTH_REQUEST, __opus_check_int_ptr(x) |
560 | |
561 | /** Configures the encoder's use of variable duration frames. |
562 | * When variable duration is enabled, the encoder is free to use a shorter frame |
563 | * size than the one requested in the opus_encode*() call. |
564 | * It is then the user's responsibility |
565 | * to verify how much audio was encoded by checking the ToC byte of the encoded |
566 | * packet. The part of the audio that was not encoded needs to be resent to the |
567 | * encoder for the next call. Do not use this option unless you <b>really</b> |
568 | * know what you are doing. |
569 | * @see OPUS_GET_EXPERT_FRAME_DURATION |
570 | * @param[in] x <tt>opus_int32</tt>: Allowed values: |
571 | * <dl> |
572 | * <dt>OPUS_FRAMESIZE_ARG</dt><dd>Select frame size from the argument (default).</dd> |
573 | * <dt>OPUS_FRAMESIZE_2_5_MS</dt><dd>Use 2.5 ms frames.</dd> |
574 | * <dt>OPUS_FRAMESIZE_5_MS</dt><dd>Use 5 ms frames.</dd> |
575 | * <dt>OPUS_FRAMESIZE_10_MS</dt><dd>Use 10 ms frames.</dd> |
576 | * <dt>OPUS_FRAMESIZE_20_MS</dt><dd>Use 20 ms frames.</dd> |
577 | * <dt>OPUS_FRAMESIZE_40_MS</dt><dd>Use 40 ms frames.</dd> |
578 | * <dt>OPUS_FRAMESIZE_60_MS</dt><dd>Use 60 ms frames.</dd> |
579 | * <dt>OPUS_FRAMESIZE_VARIABLE</dt><dd>Optimize the frame size dynamically.</dd> |
580 | * </dl> |
581 | * @hideinitializer */ |
582 | #define OPUS_SET_EXPERT_FRAME_DURATION(x) OPUS_SET_EXPERT_FRAME_DURATION_REQUEST, __opus_check_int(x) |
583 | /** Gets the encoder's configured use of variable duration frames. |
584 | * @see OPUS_SET_EXPERT_FRAME_DURATION |
585 | * @param[out] x <tt>opus_int32 *</tt>: Returns one of the following values: |
586 | * <dl> |
587 | * <dt>OPUS_FRAMESIZE_ARG</dt><dd>Select frame size from the argument (default).</dd> |
588 | * <dt>OPUS_FRAMESIZE_2_5_MS</dt><dd>Use 2.5 ms frames.</dd> |
589 | * <dt>OPUS_FRAMESIZE_5_MS</dt><dd>Use 5 ms frames.</dd> |
590 | * <dt>OPUS_FRAMESIZE_10_MS</dt><dd>Use 10 ms frames.</dd> |
591 | * <dt>OPUS_FRAMESIZE_20_MS</dt><dd>Use 20 ms frames.</dd> |
592 | * <dt>OPUS_FRAMESIZE_40_MS</dt><dd>Use 40 ms frames.</dd> |
593 | * <dt>OPUS_FRAMESIZE_60_MS</dt><dd>Use 60 ms frames.</dd> |
594 | * <dt>OPUS_FRAMESIZE_VARIABLE</dt><dd>Optimize the frame size dynamically.</dd> |
595 | * </dl> |
596 | * @hideinitializer */ |
597 | #define OPUS_GET_EXPERT_FRAME_DURATION(x) OPUS_GET_EXPERT_FRAME_DURATION_REQUEST, __opus_check_int_ptr(x) |
598 | |
599 | /** If set to 1, disables almost all use of prediction, making frames almost |
600 | * completely independent. This reduces quality. |
601 | * @see OPUS_GET_PREDICTION_DISABLED |
602 | * @param[in] x <tt>opus_int32</tt>: Allowed values: |
603 | * <dl> |
604 | * <dt>0</dt><dd>Enable prediction (default).</dd> |
605 | * <dt>1</dt><dd>Disable prediction.</dd> |
606 | * </dl> |
607 | * @hideinitializer */ |
608 | #define OPUS_SET_PREDICTION_DISABLED(x) OPUS_SET_PREDICTION_DISABLED_REQUEST, __opus_check_int(x) |
609 | /** Gets the encoder's configured prediction status. |
610 | * @see OPUS_SET_PREDICTION_DISABLED |
611 | * @param[out] x <tt>opus_int32 *</tt>: Returns one of the following values: |
612 | * <dl> |
613 | * <dt>0</dt><dd>Prediction enabled (default).</dd> |
614 | * <dt>1</dt><dd>Prediction disabled.</dd> |
615 | * </dl> |
616 | * @hideinitializer */ |
617 | #define OPUS_GET_PREDICTION_DISABLED(x) OPUS_GET_PREDICTION_DISABLED_REQUEST, __opus_check_int_ptr(x) |
618 | |
619 | /**@}*/ |
620 | |
621 | /** @defgroup opus_genericctls Generic CTLs |
622 | * @ingroup opus |
623 | * |
624 | * These macros are used with the \c opus_decoder_ctl and |
625 | * \c opus_encoder_ctl calls to generate a particular |
626 | * request. |
627 | * |
628 | * When called on an \c OpusDecoder they apply to that |
629 | * particular decoder instance. When called on an |
630 | * \c OpusEncoder they apply to the corresponding setting |
631 | * on that encoder instance, if present. |
632 | * |
633 | * Some usage examples: |
634 | * |
635 | * @code |
636 | * int ret; |
637 | * opus_int32 pitch; |
638 | * ret = opus_decoder_ctl(dec_ctx, OPUS_GET_PITCH(&pitch)); |
639 | * if (ret == OPUS_OK) return ret; |
640 | * |
641 | * opus_encoder_ctl(enc_ctx, OPUS_RESET_STATE); |
642 | * opus_decoder_ctl(dec_ctx, OPUS_RESET_STATE); |
643 | * |
644 | * opus_int32 enc_bw, dec_bw; |
645 | * opus_encoder_ctl(enc_ctx, OPUS_GET_BANDWIDTH(&enc_bw)); |
646 | * opus_decoder_ctl(dec_ctx, OPUS_GET_BANDWIDTH(&dec_bw)); |
647 | * if (enc_bw != dec_bw) { |
648 | * printf("packet bandwidth mismatch!\n"); |
649 | * } |
650 | * @endcode |
651 | * |
652 | * @see opus_encoder, opus_decoder_ctl, opus_encoder_ctl, opus_decoderctls, opus_encoderctls |
653 | * @{ |
654 | */ |
655 | |
656 | /** Resets the codec state to be equivalent to a freshly initialized state. |
657 | * This should be called when switching streams in order to prevent |
658 | * the back to back decoding from giving different results from |
659 | * one at a time decoding. |
660 | * @hideinitializer */ |
661 | #define OPUS_RESET_STATE 4028 |
662 | |
663 | /** Gets the final state of the codec's entropy coder. |
664 | * This is used for testing purposes, |
665 | * The encoder and decoder state should be identical after coding a payload |
666 | * (assuming no data corruption or software bugs) |
667 | * |
668 | * @param[out] x <tt>opus_uint32 *</tt>: Entropy coder state |
669 | * |
670 | * @hideinitializer */ |
671 | #define OPUS_GET_FINAL_RANGE(x) OPUS_GET_FINAL_RANGE_REQUEST, __opus_check_uint_ptr(x) |
672 | |
673 | /** Gets the encoder's configured bandpass or the decoder's last bandpass. |
674 | * @see OPUS_SET_BANDWIDTH |
675 | * @param[out] x <tt>opus_int32 *</tt>: Returns one of the following values: |
676 | * <dl> |
677 | * <dt>#OPUS_AUTO</dt> <dd>(default)</dd> |
678 | * <dt>#OPUS_BANDWIDTH_NARROWBAND</dt> <dd>4 kHz passband</dd> |
679 | * <dt>#OPUS_BANDWIDTH_MEDIUMBAND</dt> <dd>6 kHz passband</dd> |
680 | * <dt>#OPUS_BANDWIDTH_WIDEBAND</dt> <dd>8 kHz passband</dd> |
681 | * <dt>#OPUS_BANDWIDTH_SUPERWIDEBAND</dt><dd>12 kHz passband</dd> |
682 | * <dt>#OPUS_BANDWIDTH_FULLBAND</dt> <dd>20 kHz passband</dd> |
683 | * </dl> |
684 | * @hideinitializer */ |
685 | #define OPUS_GET_BANDWIDTH(x) OPUS_GET_BANDWIDTH_REQUEST, __opus_check_int_ptr(x) |
686 | |
687 | /** Gets the sampling rate the encoder or decoder was initialized with. |
688 | * This simply returns the <code>Fs</code> value passed to opus_encoder_init() |
689 | * or opus_decoder_init(). |
690 | * @param[out] x <tt>opus_int32 *</tt>: Sampling rate of encoder or decoder. |
691 | * @hideinitializer |
692 | */ |
693 | #define OPUS_GET_SAMPLE_RATE(x) OPUS_GET_SAMPLE_RATE_REQUEST, __opus_check_int_ptr(x) |
694 | |
695 | /**@}*/ |
696 | |
697 | /** @defgroup opus_decoderctls Decoder related CTLs |
698 | * @ingroup opus |
699 | * @see opus_genericctls, opus_encoderctls, opus_decoder |
700 | * @{ |
701 | */ |
702 | |
703 | /** Configures decoder gain adjustment. |
704 | * Scales the decoded output by a factor specified in Q8 dB units. |
705 | * This has a maximum range of -32768 to 32767 inclusive, and returns |
706 | * OPUS_BAD_ARG otherwise. The default is zero indicating no adjustment. |
707 | * This setting survives decoder reset. |
708 | * |
709 | * gain = pow(10, x/(20.0*256)) |
710 | * |
711 | * @param[in] x <tt>opus_int32</tt>: Amount to scale PCM signal by in Q8 dB units. |
712 | * @hideinitializer */ |
713 | #define OPUS_SET_GAIN(x) OPUS_SET_GAIN_REQUEST, __opus_check_int(x) |
714 | /** Gets the decoder's configured gain adjustment. @see OPUS_SET_GAIN |
715 | * |
716 | * @param[out] x <tt>opus_int32 *</tt>: Amount to scale PCM signal by in Q8 dB units. |
717 | * @hideinitializer */ |
718 | #define OPUS_GET_GAIN(x) OPUS_GET_GAIN_REQUEST, __opus_check_int_ptr(x) |
719 | |
720 | /** Gets the duration (in samples) of the last packet successfully decoded or concealed. |
721 | * @param[out] x <tt>opus_int32 *</tt>: Number of samples (at current sampling rate). |
722 | * @hideinitializer */ |
723 | #define OPUS_GET_LAST_PACKET_DURATION(x) OPUS_GET_LAST_PACKET_DURATION_REQUEST, __opus_check_int_ptr(x) |
724 | |
725 | /** Gets the pitch of the last decoded frame, if available. |
726 | * This can be used for any post-processing algorithm requiring the use of pitch, |
727 | * e.g. time stretching/shortening. If the last frame was not voiced, or if the |
728 | * pitch was not coded in the frame, then zero is returned. |
729 | * |
730 | * This CTL is only implemented for decoder instances. |
731 | * |
732 | * @param[out] x <tt>opus_int32 *</tt>: pitch period at 48 kHz (or 0 if not available) |
733 | * |
734 | * @hideinitializer */ |
735 | #define OPUS_GET_PITCH(x) OPUS_GET_PITCH_REQUEST, __opus_check_int_ptr(x) |
736 | |
737 | /**@}*/ |
738 | |
739 | /** @defgroup opus_libinfo Opus library information functions |
740 | * @ingroup opus |
741 | * @{ |
742 | */ |
743 | |
744 | /** Converts an opus error code into a human readable string. |
745 | * |
746 | * @param[in] error <tt>int</tt>: Error number |
747 | * @returns Error string |
748 | */ |
749 | OPUS_EXPORT const char *opus_strerror(int error); |
750 | |
751 | /** Gets the libopus version string. |
752 | * |
753 | * Applications may look for the substring "-fixed" in the version string to |
754 | * determine whether they have a fixed-point or floating-point build at |
755 | * runtime. |
756 | * |
757 | * @returns Version string |
758 | */ |
759 | OPUS_EXPORT const char *opus_get_version_string(void); |
760 | /**@}*/ |
761 | |
762 | #ifdef __cplusplus |
763 | } |
764 | #endif |
765 | |
766 | #endif /* OPUS_DEFINES_H */ |
767 |