1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
use crate::{sys, mem, ErrorCode, Application, Channels, SampleRate, Bandwidth, Bitrate, Signal, InbandFec, FrameDuration};
use mem::alloc::vec::Vec;
///OPUS encoder
pub struct Encoder {
inner: mem::Unique<sys::OpusEncoder>,
channels: Channels,
}
impl Encoder {
///Creates new encoder instance
pub fn new(channels: Channels, rate: SampleRate, app: Application) -> Result<Self, ErrorCode> {
let size = unsafe {
sys::opus_encoder_get_size(channels as _)
};
if size == 0 {
return Err(ErrorCode::Internal);
}
let mut encoder = match mem::Unique::new(size as _) {
Some(inner) => Encoder {
inner,
channels,
},
None => return Err(ErrorCode::AllocFail)
};
let result = unsafe {
sys::opus_encoder_init(encoder.inner.as_mut(), rate as _, channels as _, app as _)
};
map_sys_error!(result => encoder)
}
#[inline(always)]
///Returns channels number
///
///When encoding, it is used to determine frame size as `input.len() / channels`
pub fn channels(&self) -> Channels {
self.channels
}
///Encodes an Opus frame, returning number of bytes written.
///
///If more than 1 channel is configured, then input must be interleaved.
///
///Input size must correspond to sampling rate.
///For example, at 48 kHz allowed frame sizes are 120, 240, 480, 960, 1920, and 2880.
///Passing in a duration of less than 10 ms (480 samples at 48 kHz) will prevent the encoder from using the LPC or hybrid modes.
pub fn encode_to(&mut self, input: &[u16], output: &mut [mem::MaybeUninit<u8>]) -> Result<usize, ErrorCode> {
let result = unsafe {
sys::opus_encode(self.inner.as_mut(),
input.as_ptr() as _, (input.len() / (self.channels as usize)) as _,
output.as_mut_ptr() as _, output.len() as _)
};
map_sys_error!(result => result as _)
}
#[inline(always)]
///Encodes an Opus frame, returning number of bytes written.
///
///Refer to `encode_to` for details
pub fn encode_to_slice(&mut self, input: &[u16], output: &mut [u8]) -> Result<usize, ErrorCode> {
self.encode_to(input, unsafe { mem::transmute(output) })
}
#[inline(always)]
///Encodes an Opus frame, returning number of bytes written.
///
///Vector will be written into spare capacity, modifying its length on success.
///
///It is user responsibility to reserve correct amount of space
///
///Refer to `encode_to` for details
pub fn encode_to_vec(&mut self, input: &[u16], output: &mut Vec<u8>) -> Result<usize, ErrorCode> {
let initial_len = output.len();
let result = self.encode_to(input, output.spare_capacity_mut())?;
unsafe {
output.set_len(initial_len + result);
}
Ok(result)
}
///Encodes an Opus frame, returning number of bytes written.
///
///If more than 1 channel is configured, then input must be interleaved.
///
///Input size must correspond to sampling rate.
///For example, at 48 kHz allowed frame sizes are 120, 240, 480, 960, 1920, and 2880.
///Passing in a duration of less than 10 ms (480 samples at 48 kHz) will prevent the encoder from using the LPC or hybrid modes.
///
///## Note
///
///When using float API, input with a normal range of +/-1.0 should be preferred.
///Samples with a range beyond +/-1.0 are supported
///but will be clipped by decoders using the integer API and should only be used
///if it is known that the far end supports extended dynamic range
pub fn encode_float_to(&mut self, input: &[f32], output: &mut [mem::MaybeUninit<u8>]) -> Result<usize, ErrorCode> {
let result = unsafe {
sys::opus_encode_float(self.inner.as_mut(),
input.as_ptr(), (input.len() / (self.channels as usize)) as _,
output.as_mut_ptr() as _, output.len() as _)
};
map_sys_error!(result => result as _)
}
#[inline(always)]
///Encodes an Opus frame, returning number of bytes written.
///
///Refer to `encode_to` for details
pub fn encode_float_to_slice(&mut self, input: &[f32], output: &mut [u8]) -> Result<usize, ErrorCode> {
self.encode_float_to(input, unsafe { mem::transmute(output) })
}
#[inline(always)]
///Encodes an Opus frame, returning number of bytes written.
///
///Vector will be written into spare capacity, modifying its length on success.
///
///It is user responsibility to reserve correct amount of space
///
///Refer to `encode_to` for details
pub fn encode_float_to_vec(&mut self, input: &[f32], output: &mut Vec<u8>) -> Result<usize, ErrorCode> {
let initial_len = output.len();
let result = self.encode_float_to(input, output.spare_capacity_mut())?;
unsafe {
output.set_len(initial_len + result);
}
Ok(result)
}
#[inline]
///Resets state to initial state
pub fn reset(&mut self) -> Result<(), ErrorCode> {
let result = unsafe {
sys::opus_encoder_ctl(self.inner.as_mut(), sys::OPUS_RESET_STATE)
};
map_sys_error!(result => ())
}
#[inline]
///Gets the total samples of delay added by the entire codec.
///
///From the perspective of a decoding application the real data begins this many samples late.
pub fn get_look_ahead(&mut self) -> Result<u32, ErrorCode> {
let mut value: i32 = 0;
let result = unsafe {
sys::opus_encoder_ctl(self.inner.as_mut(), sys::OPUS_GET_LOOKAHEAD_REQUEST, &mut value)
};
map_sys_error!(result => match value.is_negative() {
false => value as _,
true => return Err(ErrorCode::unknown())
})
}
#[inline]
///Gets the encoder's bitrate configuration.
pub fn get_bitrate(&mut self) -> Result<Bitrate, ErrorCode> {
let mut value: i32 = 0;
let result = unsafe {
sys::opus_encoder_ctl(self.inner.as_mut(), sys::OPUS_GET_BITRATE_REQUEST, &mut value)
};
map_sys_error!(result => value.into())
}
#[inline]
///Configures the encoder's bitrate
pub fn set_bitrate(&mut self, value: Bitrate) -> Result<(), ErrorCode> {
let value: i32 = value.into();
let result = unsafe {
sys::opus_encoder_ctl(self.inner.as_mut(), sys::OPUS_SET_BITRATE_REQUEST, value)
};
map_sys_error!(result => ())
}
#[inline]
///Determine if variable bitrate (VBR) is enabled in the encoder.
pub fn get_vbr(&mut self) -> Result<bool, ErrorCode> {
let mut value: i32 = 0;
let result = unsafe {
sys::opus_encoder_ctl(self.inner.as_mut(), sys::OPUS_GET_VBR_REQUEST, &mut value)
};
map_sys_error!(result => value == 1)
}
#[inline]
///Enables or disables variable bitrate (VBR) in the encoder.
///
///The configured bitrate may not be met exactly because frames must be an integer number of bytes in length.
pub fn set_vbr(&mut self, value: bool) -> Result<(), ErrorCode> {
let value: i32 = match value {
true => 1,
false => 0
};
let result = unsafe {
sys::opus_encoder_ctl(self.inner.as_mut(), sys::OPUS_SET_VBR_REQUEST, value)
};
map_sys_error!(result => ())
}
#[inline]
///Determine if constrained VBR is enabled in the encoder.
pub fn get_vbr_constraint(&mut self) -> Result<bool, ErrorCode> {
let mut value: i32 = 0;
let result = unsafe {
sys::opus_encoder_ctl(self.inner.as_mut(), sys::OPUS_GET_VBR_CONSTRAINT_REQUEST, &mut value)
};
map_sys_error!(result => value == 1)
}
#[inline]
///Enables or disables constrained VBR in the encoder.
///
///This setting is ignored when the encoder is in CBR mode.
///
///## Note
///
///Only the MDCT mode of Opus currently heeds the constraint. Speech mode ignores it
///completely, hybrid mode may fail to obey it if the LPC layer uses more bitrate than the
///constraint would have permitted.
pub fn set_vbr_constraint(&mut self, value: bool) -> Result<(), ErrorCode> {
let value: i32 = match value {
true => 1,
false => 0
};
let result = unsafe {
sys::opus_encoder_ctl(self.inner.as_mut(), sys::OPUS_SET_VBR_CONSTRAINT_REQUEST, value)
};
map_sys_error!(result => ())
}
#[inline]
///Gets the encoder's forced channel configuration (if set).
pub fn get_force_channels(&mut self) -> Result<Option<Channels>, ErrorCode> {
let mut value: i32 = 0;
let result = unsafe {
sys::opus_encoder_ctl(self.inner.as_mut(), sys::OPUS_GET_FORCE_CHANNELS_REQUEST, &mut value)
};
map_sys_error!(result => match value {
1 => Some(Channels::Mono),
2 => Some(Channels::Stereo),
_ => None,
})
}
#[inline]
///Configures mono/stereo forcing in the encoder (or disables it by specifying None).
///
///This can force the encoder to produce packets encoded as either mono or stereo, regardless
///of the format of the input audio. This is useful when the caller knows that the input signal
///is currently a mono source embedded in a stereo stream.
pub fn set_force_channels(&mut self, value: Option<Channels>) -> Result<(), ErrorCode> {
let value = match value {
Some(value) => value as i32,
None => sys::OPUS_AUTO
};
let result = unsafe {
sys::opus_encoder_ctl(self.inner.as_mut(), sys::OPUS_SET_FORCE_CHANNELS_REQUEST, value)
};
map_sys_error!(result => ())
}
#[inline]
///Gets the encoder's complexity configuration.
pub fn get_complexity(&mut self) -> Result<u8, ErrorCode> {
let mut value: i32 = 0;
let result = unsafe {
sys::opus_encoder_ctl(self.inner.as_mut(), sys::OPUS_GET_COMPLEXITY_REQUEST, &mut value)
};
map_sys_error!(result => value as _)
}
#[inline]
///Configures the encoder's computational complexity.
///
///The supported range is 0-10 inclusive with 10 representing the highest complexity.
pub fn set_complexity(&mut self, value: u8) -> Result<(), ErrorCode> {
let result = unsafe {
sys::opus_encoder_ctl(self.inner.as_mut(), sys::OPUS_SET_COMPLEXITY_REQUEST, value as i32)
};
map_sys_error!(result => ())
}
#[inline]
///Gets the encoder's configured signal type.
pub fn get_signal(&mut self) -> Result<Signal, ErrorCode> {
let mut value: i32 = 0;
let result = unsafe {
sys::opus_encoder_ctl(self.inner.as_mut(), sys::OPUS_GET_SIGNAL_REQUEST, &mut value)
};
map_sys_error!(result => value.into())
}
#[inline]
///Configures the type of signal being encoded.
///
///This is a hint which helps the encoder's mode selection.
pub fn set_signal(&mut self, value: Signal) -> Result<(), ErrorCode> {
let result = unsafe {
sys::opus_encoder_ctl(self.inner.as_mut(), sys::OPUS_SET_SIGNAL_REQUEST, value as i32)
};
map_sys_error!(result => ())
}
#[inline]
///Gets the encoder's configured application.
pub fn get_application(&mut self) -> Result<Application, ErrorCode> {
let mut value: i32 = 0;
let result = unsafe {
sys::opus_encoder_ctl(self.inner.as_mut(), sys::OPUS_GET_APPLICATION_REQUEST, &mut value)
};
map_sys_error!(result => match Application::from_sys(value) {
Some(value) => value,
None => return Err(ErrorCode::unknown())
})
}
#[inline]
///Configures the encoder's intended application.
///
///The initial value is a mandatory argument to encoder constructor.
pub fn set_application(&mut self, value: Application) -> Result<(), ErrorCode> {
let result = unsafe {
sys::opus_encoder_ctl(self.inner.as_mut(), sys::OPUS_SET_APPLICATION_REQUEST, value as i32)
};
map_sys_error!(result => ())
}
#[inline]
///Gets the encoder's configured bandpass
pub fn get_bandwidth(&mut self) -> Result<Bandwidth, ErrorCode> {
let mut value: i32 = 0;
let result = unsafe {
sys::opus_encoder_ctl(self.inner.as_mut(), sys::OPUS_GET_BANDWIDTH_REQUEST, &mut value)
};
map_sys_error!(result => value.into())
}
#[inline]
///Sets the encoder's bandpass to a specific value.
///
///This prevents the encoder from automatically selecting the bandpass based on the available
///bitrate. If an application knows the bandpass of the input audio it is providing, it should
///normally use `set_max_bandwidth` instead, which still gives the encoder the freedom to
///reduce the bandpass when the bitrate becomes too low, for better overall quality.
pub fn set_bandwidth(&mut self, value: Bandwidth) -> Result<(), ErrorCode> {
let result = unsafe {
sys::opus_encoder_ctl(self.inner.as_mut(), sys::OPUS_SET_BANDWIDTH_REQUEST, value as i32)
};
map_sys_error!(result => ())
}
#[inline]
///Gets the encoder's configured maximum allowed bandpass.
pub fn get_max_bandwidth(&mut self) -> Result<Bandwidth, ErrorCode> {
let mut value: i32 = 0;
let result = unsafe {
sys::opus_encoder_ctl(self.inner.as_mut(), sys::OPUS_GET_MAX_BANDWIDTH_REQUEST, &mut value)
};
map_sys_error!(result => value.into())
}
#[inline]
///Configures the maximum bandpass that the encoder will select automatically.
///
///Applications should normally use this instead of `set_bandwidth` (leaving that set to the
///default, `Bandwidth::Auto`). This allows the application to set an upper bound based on the type of
///input it is providing, but still gives the encoder the freedom to reduce the bandpass when
///the bitrate becomes too low, for better overall quality.
pub fn set_max_bandwidth(&mut self, value: Bandwidth) -> Result<(), ErrorCode> {
let result = unsafe {
sys::opus_encoder_ctl(self.inner.as_mut(), sys::OPUS_SET_MAX_BANDWIDTH_REQUEST, value as i32)
};
map_sys_error!(result => ())
}
#[inline]
///Gets encoder's configured use of inband forward error correction.
pub fn get_inband_fec(&mut self) -> Result<InbandFec, ErrorCode> {
let mut value: i32 = 0;
let result = unsafe {
sys::opus_encoder_ctl(self.inner.as_mut(), sys::OPUS_GET_INBAND_FEC_REQUEST, &mut value)
};
map_sys_error!(result => match value {
0 => InbandFec::Off,
1 => InbandFec::Mode1,
2 => InbandFec::Mode2,
_ => return Err(ErrorCode::unknown()),
})
}
#[inline]
///Configures the encoder's use of inband forward error correction (FEC).
///
///## Note
///
///This is only applicable to the LPC layer
pub fn set_inband_fec(&mut self, value: InbandFec) -> Result<(), ErrorCode> {
let result = unsafe {
sys::opus_encoder_ctl(self.inner.as_mut(), sys::OPUS_SET_INBAND_FEC_REQUEST, value as i32)
};
map_sys_error!(result => ())
}
#[inline]
///Gets the encoder's configured packet loss percentage.
pub fn get_packet_loss(&mut self) -> Result<u8, ErrorCode> {
let mut value: i32 = 0;
let result = unsafe {
sys::opus_encoder_ctl(self.inner.as_mut(), sys::OPUS_GET_PACKET_LOSS_PERC_REQUEST, &mut value)
};
map_sys_error!(result => value as _)
}
#[inline]
///Configures the encoder's expected packet loss percentage (Allowed values are 0..=100).
///
///Higher values trigger progressively more loss resistant behavior in the encoder at the
///expense of quality at a given bitrate in the absence of packet loss, but greater quality
///under loss.
pub fn set_packet_loss(&mut self, value: u8) -> Result<(), ErrorCode> {
let result = unsafe {
sys::opus_encoder_ctl(self.inner.as_mut(), sys::OPUS_SET_PACKET_LOSS_PERC_REQUEST, value as i32)
};
map_sys_error!(result => ())
}
#[inline]
///Gets the encoder's configured prediction status.
pub fn get_prediction_disabled(&mut self) -> Result<bool, ErrorCode> {
let mut value: i32 = 0;
let result = unsafe {
sys::opus_encoder_ctl(self.inner.as_mut(), sys::OPUS_GET_PREDICTION_DISABLED_REQUEST, &mut value)
};
map_sys_error!(result => value == 1)
}
#[inline]
///If set to `true`, disables almost all use of prediction, making frames almost completely independent.
///
///This reduces quality.
pub fn set_prediction_disabled(&mut self, value: bool) -> Result<(), ErrorCode> {
let value: i32 = match value {
true => 1,
false => 0,
};
let result = unsafe {
sys::opus_encoder_ctl(self.inner.as_mut(), sys::OPUS_SET_PREDICTION_DISABLED_REQUEST, value)
};
map_sys_error!(result => ())
}
#[inline]
///Gets the encoder's configured signal depth.
pub fn get_lsb_depth(&mut self) -> Result<u8, ErrorCode> {
let mut value: i32 = 0;
let result = unsafe {
sys::opus_encoder_ctl(self.inner.as_mut(), sys::OPUS_GET_LSB_DEPTH_REQUEST, &mut value)
};
map_sys_error!(result => value as _)
}
#[inline]
///Configures the depth of signal being encoded (Defaults to 24) in range 8 to 24.
///
///This is a hint which helps the encoder identify silence and near-silence. It represents the
///number of significant bits of linear intensity below which the signal contains ignorable
///quantization or other noise.
///
///For example, 14 would be an appropriate setting for G.711 u-law input.
///16 would be appropriate for 16-bit linear pcm input with `encode_float`.
///
///When using `encode` instead of `encode_float`, or when libopus is compiled for
///fixed-point, the encoder uses the minimum of the value set here and the value 16.
pub fn set_lsb_depth(&mut self, value: u8) -> Result<(), ErrorCode> {
let result = unsafe {
sys::opus_encoder_ctl(self.inner.as_mut(), sys::OPUS_SET_LSB_DEPTH_REQUEST, value as i32)
};
map_sys_error!(result => ())
}
#[inline]
///Gets the encoder's configured use of variable duration frames.
pub fn get_frame_duration(&mut self) -> Result<FrameDuration, ErrorCode> {
let mut value: i32 = 0;
let result = unsafe {
sys::opus_encoder_ctl(self.inner.as_mut(), sys::OPUS_GET_EXPERT_FRAME_DURATION_REQUEST, &mut value)
};
map_sys_error!(result => match value {
sys::OPUS_FRAMESIZE_ARG => FrameDuration::SizeArg,
sys::OPUS_FRAMESIZE_2_5_MS => FrameDuration::Size2_5,
sys::OPUS_FRAMESIZE_5_MS => FrameDuration::Size5,
sys::OPUS_FRAMESIZE_10_MS => FrameDuration::Size10,
sys::OPUS_FRAMESIZE_20_MS => FrameDuration::Size20,
sys::OPUS_FRAMESIZE_40_MS => FrameDuration::Size40,
sys::OPUS_FRAMESIZE_60_MS => FrameDuration::Size60,
sys::OPUS_FRAMESIZE_80_MS => FrameDuration::Size80,
sys::OPUS_FRAMESIZE_100_MS => FrameDuration::Size100,
sys::OPUS_FRAMESIZE_120_MS => FrameDuration::Size120,
_ => return Err(ErrorCode::unknown()),
})
}
#[inline]
///Configures the encoder's use of variable duration frames.
///
///When variable duration is enabled, the encoder is free to use a shorter frame size than the
///one requested in the `encode` call. It is then the user's responsibility to verify how
///much audio was encoded by checking the ToC byte of the encoded packet. The part of the audio
///that was not encoded needs to be resent to the encoder for the next call. Do not use this
///option unless you really know what you are doing.
pub fn set_frame_duration(&mut self, value: FrameDuration) -> Result<(), ErrorCode> {
let result = unsafe {
sys::opus_encoder_ctl(self.inner.as_mut(), sys::OPUS_SET_EXPERT_FRAME_DURATION_REQUEST, value as i32)
};
map_sys_error!(result => ())
}
#[inline]
///Gets the encoder's configured Deep Redundancy (DRED) maximum number of frames.
pub fn get_dred_duration(&mut self) -> Result<u8, ErrorCode> {
let mut value: i32 = 0;
let result = unsafe {
sys::opus_encoder_ctl(self.inner.as_mut(), sys::OPUS_GET_DRED_DURATION_REQUEST, &mut value)
};
map_sys_error!(result => value as _)
}
#[inline]
///Configures value of Deep Redundancy (DRED) in range 0..=104
///
///If non-zero, enables DRED and use the specified maximum number of 10-ms redundant frames.
pub fn set_dred_duration(&mut self, value: u8) -> Result<(), ErrorCode> {
let result = unsafe {
sys::opus_encoder_ctl(self.inner.as_mut(), sys::OPUS_SET_DRED_DURATION_REQUEST, value as i32)
};
map_sys_error!(result => ())
}
#[inline]
///Gets configured sample rate of this instance
pub fn get_sample_rate(&mut self) -> Result<SampleRate, ErrorCode> {
let mut value: i32 = 0;
let result = unsafe {
sys::opus_encoder_ctl(self.inner.as_mut(), sys::OPUS_GET_SAMPLE_RATE_REQUEST, &mut value)
};
map_sys_error!(result => match value {
8000 => SampleRate::Hz8000,
12000 => SampleRate::Hz12000,
16000 => SampleRate::Hz16000,
24000 => SampleRate::Hz24000,
48000 => SampleRate::Hz48000,
_ => return Err(ErrorCode::unknown())
})
}
#[inline]
///Access encoder's DTX value
pub fn get_dtx(&mut self) -> Result<bool, ErrorCode> {
let mut value: i32 = 0;
let result = unsafe {
sys::opus_encoder_ctl(self.inner.as_mut(), sys::OPUS_GET_DTX_REQUEST, &mut value)
};
map_sys_error!(result => value == 1)
}
#[inline]
///Configures the encoder's use of discontinuous transmission (DTX).
///
///This is only applicable to the LPC layer
pub fn set_dtx(&mut self, value: bool) -> Result<(), ErrorCode> {
let value: i32 = match value {
true => 1,
false => 0,
};
let result = unsafe {
sys::opus_encoder_ctl(self.inner.as_mut(), sys::OPUS_SET_DTX_REQUEST, value)
};
map_sys_error!(result => ())
}
#[inline]
///Gets the encoder's configured phase inversion status.
pub fn get_phase_inversion_disabled(&mut self) -> Result<bool, ErrorCode> {
let mut value: i32 = 0;
let result = unsafe {
sys::opus_encoder_ctl(self.inner.as_mut(), sys::OPUS_GET_PHASE_INVERSION_DISABLED_REQUEST, &mut value)
};
map_sys_error!(result => value == 1)
}
#[inline]
///Configures phase inversion.
///
///If set to `true`, disables the use of phase inversion for intensity stereo, improving the quality
///of mono downmixes, but slightly reducing normal stereo quality.
pub fn set_phase_inversion_disabled(&mut self, value: bool) -> Result<(), ErrorCode> {
let value: i32 = match value {
true => 1,
false => 0,
};
let result = unsafe {
sys::opus_encoder_ctl(self.inner.as_mut(), sys::OPUS_SET_PHASE_INVERSION_DISABLED_REQUEST, value)
};
map_sys_error!(result => ())
}
}
unsafe impl Send for Encoder {}