-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathStaticNativeOpus.cs
More file actions
1332 lines (1245 loc) · 86.2 KB
/
StaticNativeOpus.cs
File metadata and controls
1332 lines (1245 loc) · 86.2 KB
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
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using OpusSharp.Core.SafeHandlers;
using System.Runtime.InteropServices;
//This is for rider purposes ONLY!
// ReSharper disable All
#pragma warning disable CA1401
namespace OpusSharp.Core
{
/// <summary>
/// Native opus handler that directly calls the exported opus functions. Requires a dynamically loaded library.
/// </summary>
public static partial class StaticNativeOpus
{
#if COMPILE_STATIC
private const string DllName = "__Internal";
#else
private const string DllName = "opus";
#endif
//Encoder
/// <summary>
/// Gets the size of an <see cref="OpusEncoderSafeHandle"/> structure.
/// </summary>
/// <param name="channels">Number of channels. This must be 1 or 2.</param>
/// <returns>The size in bytes.</returns>
#if NET8_0_OR_GREATER
[LibraryImport(DllName)]
public static partial int opus_encoder_get_size(int channels);
#else
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern int opus_encoder_get_size(int channels);
#endif
/// <summary>
/// Allocates and initializes an encoder state (statically linked).
/// </summary>
/// <param name="Fs">Sampling rate of input signal (Hz) This must be one of 8000, 12000, 16000, 24000, or 48000.</param>
/// <param name="channels">Number of channels (1 or 2) in input signal.</param>
/// <param name="application">Coding mode (one of <see cref="OpusPredefinedValues.OPUS_APPLICATION_VOIP"/>, <see cref="OpusPredefinedValues.OPUS_APPLICATION_AUDIO"/> or <see cref="OpusPredefinedValues.OPUS_APPLICATION_RESTRICTED_LOWDELAY"/>)</param>
/// <param name="error"><see cref="OpusErrorCodes.OPUS_OK"/> Success or <see cref="OpusErrorCodes"/>.</param>
/// <returns><see cref="StaticOpusEncoderSafeHandle"/></returns>
#if NET8_0_OR_GREATER
[LibraryImport(DllName)]
public static unsafe partial StaticOpusEncoderSafeHandle opus_encoder_create(int Fs, int channels, int application, int* error);
#else
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern unsafe StaticOpusEncoderSafeHandle opus_encoder_create(int Fs, int channels, int application, int* error);
#endif
/// <summary>
/// Initializes a previously allocated <see cref="OpusEncoderSafeHandle"/> state. The memory pointed to by st must be at least the size returned by <see cref="opus_encoder_get_size(int)"/>.
/// </summary>
/// <param name="st">Encoder state.</param>
/// <param name="Fs">Sampling rate of input signal (Hz) This must be one of 8000, 12000, 16000, 24000, or 48000.</param>
/// <param name="channels">Number of channels (1 or 2) in input signal.</param>
/// <param name="application">>Coding mode (one of <see cref="OpusPredefinedValues.OPUS_APPLICATION_VOIP"/>, <see cref="OpusPredefinedValues.OPUS_APPLICATION_AUDIO"/> or <see cref="OpusPredefinedValues.OPUS_APPLICATION_RESTRICTED_LOWDELAY"/>)</param>
/// <returns><see cref="OpusErrorCodes"/></returns>
#if NET8_0_OR_GREATER
[LibraryImport(DllName)]
public static partial int opus_encoder_init(OpusEncoderSafeHandle st, int Fs, int channels, int application);
#else
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern int opus_encoder_init(OpusEncoderSafeHandle st, int Fs, int channels, int application);
#endif
/// <summary>
/// Encodes an Opus frame.
/// </summary>
/// <param name="st">Encoder state.</param>
/// <param name="pcm">Input signal (interleaved if 2 channels). length is frame_size*channels*sizeof(short)</param>
/// <param name="frame_size">Number of samples per channel in the input signal. This must be an Opus frame size for the encoder's sampling rate. For example, at 48 kHz the permitted values 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.</param>
/// <param name="data">Output payload. This must contain storage for at least max_data_bytes.</param>
/// <param name="max_data_bytes">Size of the allocated memory for the output payload. This may be used to impose an upper limit on the instant bitrate, but should not be used as the only bitrate control. Use <see cref="EncoderCTL.OPUS_SET_BITRATE"/> to control the bitrate.</param>
/// <returns>The length of the encoded packet (in bytes) on success or a negative error code (see <see cref="OpusErrorCodes"/>) on failure.</returns>
#if NET8_0_OR_GREATER
[LibraryImport(DllName)]
public static unsafe partial int opus_encode(OpusEncoderSafeHandle st, short* pcm, int frame_size, byte* data, int max_data_bytes);
#else
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern unsafe int opus_encode(OpusEncoderSafeHandle st, short* pcm, int frame_size, byte* data, int max_data_bytes);
#endif
/// <summary>
/// Encodes an Opus frame.
/// </summary>
/// <param name="st">Encoder state.</param>
/// <param name="pcm">Input signal (interleaved if 2 channels) representing (or slightly exceeding) 24-bit values. length is frame_size*channels*sizeof(int)</param>
/// <param name="frame_size">Number of samples per channel in the input signal. This must be an Opus frame size for the encoder's sampling rate. For example, at 48 kHz the permitted values 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.</param>
/// <param name="data">Output payload. This must contain storage for at least max_data_bytes.</param>
/// <param name="max_data_bytes">Size of the allocated memory for the output payload. This may be used to impose an upper limit on the instant bitrate, but should not be used as the only bitrate control. Use <see cref="EncoderCTL.OPUS_SET_BITRATE"/> to control the bitrate.</param>
/// <returns>The length of the encoded packet (in bytes) on success or a negative error code (see <see cref="OpusErrorCodes"/>) on failure.</returns>
#if NET8_0_OR_GREATER
[LibraryImport(DllName)]
public static unsafe partial int opus_encode24(OpusEncoderSafeHandle st, int* pcm, int frame_size, byte* data, int max_data_bytes);
#else
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern unsafe int opus_encode24(OpusEncoderSafeHandle st, int* pcm, int frame_size, byte* data, int max_data_bytes);
#endif
/// <summary>
/// Encodes an Opus frame from floating point input.
/// </summary>
/// <param name="st">Encoder state.</param>
/// <param name="pcm">Input in float format (interleaved if 2 channels), with a normal range of +/-1.0. 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. length is frame_size*channels*sizeof(float)</param>
/// <param name="frame_size">Number of samples per channel in the input signal. This must be an Opus frame size for the encoder's sampling rate. For example, at 48 kHz the permitted values 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.</param>
/// <param name="data">Output payload. This must contain storage for at least max_data_bytes.</param>
/// <param name="max_data_bytes">Size of the allocated memory for the output payload. This may be used to impose an upper limit on the instant bitrate, but should not be used as the only bitrate control. Use <see cref="EncoderCTL.OPUS_SET_BITRATE"/> to control the bitrate.</param>
/// <returns>The length of the encoded packet (in bytes) on success or a negative error code (see <see cref="OpusErrorCodes"/>) on failure.</returns>
#if NET8_0_OR_GREATER
[LibraryImport(DllName)]
public static unsafe partial int opus_encode_float(OpusEncoderSafeHandle st, float* pcm, int frame_size, byte* data, int max_data_bytes);
#else
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern unsafe int opus_encode_float(OpusEncoderSafeHandle st, float* pcm, int frame_size, byte* data, int max_data_bytes);
#endif
/// <summary>
/// Frees an <see cref="OpusEncoderSafeHandle"/> allocated by <see cref="opus_encoder_create(int, int, int, int*)"/>.
/// </summary>
/// <param name="st">State to be freed.</param>
#if NET8_0_OR_GREATER
[LibraryImport(DllName)]
public static partial void opus_encoder_destroy(IntPtr st);
#else
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern void opus_encoder_destroy(IntPtr st);
#endif
/// <summary>
/// Perform a CTL function on an <see cref="OpusEncoderSafeHandle"/>.
/// </summary>
/// <param name="st">Encoder state.</param>
/// <param name="request">This and all remaining parameters should be replaced by one of the convenience macros in <see cref="GenericCTL"/> or <see cref="EncoderCTL"/>.</param>
/// <returns><see cref="OpusErrorCodes"/></returns>
#if NET8_0_OR_GREATER
[LibraryImport(DllName)]
public static partial int opus_encoder_ctl(OpusEncoderSafeHandle st, int request); //Apparently GenericCTL.OPUS_RESET_STATE exists.
#else
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern int opus_encoder_ctl(OpusEncoderSafeHandle st, int request); //Apparently GenericCTL.OPUS_RESET_STATE exists.
#endif
/// <summary>
/// Perform a CTL function on an <see cref="OpusEncoderSafeHandle"/>.
/// </summary>
/// <param name="st">Encoder state.</param>
/// <param name="request">This and all remaining parameters should be replaced by one of the convenience macros in <see cref="GenericCTL"/> or <see cref="EncoderCTL"/>.</param>
/// <param name="data">The data to input.</param>
/// <returns><see cref="OpusErrorCodes"/></returns>
#if NET8_0_OR_GREATER
[LibraryImport(DllName)]
public static unsafe partial int opus_encoder_ctl(OpusEncoderSafeHandle st, int request, int data);
#else
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern unsafe int opus_encoder_ctl(OpusEncoderSafeHandle st, int request, int data);
#endif
/// <summary>
/// Perform a CTL function on an <see cref="OpusEncoderSafeHandle"/>.
/// </summary>
/// <param name="st">Encoder state.</param>
/// <param name="request">This and all remaining parameters should be replaced by one of the convenience macros in <see cref="GenericCTL"/> or <see cref="EncoderCTL"/>.</param>
/// <param name="data">The data to input/output.</param>
/// <returns><see cref="OpusErrorCodes"/></returns>
#if NET8_0_OR_GREATER
[LibraryImport(DllName)]
public static unsafe partial int opus_encoder_ctl(OpusEncoderSafeHandle st, int request, void* data);
#else
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern unsafe int opus_encoder_ctl(OpusEncoderSafeHandle st, int request, void* data);
#endif
/// <summary>
/// Perform a CTL function on an Opus encoder.
/// </summary>
/// <param name="st">Encoder state.</param>
/// <param name="request">This and all remaining parameters should be replaced by one of the convenience macros in <see cref="GenericCTL"/> or <see cref="EncoderCTL"/>.</param>
/// <param name="data">The data to input/output.</param>
/// <param name="data2">The second data to input.</param>
/// <returns><see cref="OpusErrorCodes"/></returns>
#if NET8_0_OR_GREATER
[LibraryImport(DllName)]
public static unsafe partial int opus_encoder_ctl(OpusEncoderSafeHandle st, int request, void* data, int data2);
#else
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern unsafe int opus_encoder_ctl(OpusEncoderSafeHandle st, int request, void* data, int data2);
#endif
/// <summary>
/// Perform a CTL function on an Opus encoder.
/// </summary>
/// <param name="st">Encoder state.</param>
/// <param name="request">This and all remaining parameters should be replaced by one of the convenience macros in <see cref="GenericCTL"/> or <see cref="EncoderCTL"/>.</param>
/// <param name="data">The data to input.</param>
/// <param name="data2">The second data to input/output.</param>
/// <returns><see cref="OpusErrorCodes"/></returns>
#if NET8_0_OR_GREATER
[LibraryImport(DllName)]
public static unsafe partial int opus_encoder_ctl(OpusEncoderSafeHandle st, int request, int data, void* data2);
#else
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern unsafe int opus_encoder_ctl(OpusEncoderSafeHandle st, int request, int data, void* data2);
#endif
/// <summary>
/// Perform a CTL function on an Opus encoder.
/// </summary>
/// <param name="st">Encoder state.</param>
/// <param name="request">This and all remaining parameters should be replaced by one of the convenience macros in <see cref="GenericCTL"/> or <see cref="EncoderCTL"/>.</param>
/// <param name="data">The data to input/output.</param>
/// <param name="data2">The second data to input/output.</param>
/// <returns><see cref="OpusErrorCodes"/></returns>
#if NET8_0_OR_GREATER
[LibraryImport(DllName)]
public static unsafe partial int opus_encoder_ctl(OpusEncoderSafeHandle st, int request, void* data, void* data2);
#else
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern unsafe int opus_encoder_ctl(OpusEncoderSafeHandle st, int request, void* data, void* data2);
#endif
//Decoder
/// <summary>
/// Gets the size of an <see cref="OpusDecoderSafeHandle"/> structure.
/// </summary>
/// <param name="channels">Number of channels. This must be 1 or 2.</param>
/// <returns>The size in bytes.</returns>
#if NET8_0_OR_GREATER
[LibraryImport(DllName)]
public static partial int opus_decoder_get_size(int channels);
#else
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern int opus_decoder_get_size(int channels);
#endif
/// <summary>
/// Allocates and initializes a <see cref="StaticOpusDecoderSafeHandle"/> state.
/// </summary>
/// <param name="Fs">Sample rate to decode at (Hz). This must be one of 8000, 12000, 16000, 24000, or 48000.</param>
/// <param name="channels">Number of channels (1 or 2) to decode.</param>
/// <param name="error"><see cref="OpusErrorCodes.OPUS_OK"/> Success or <see cref="OpusErrorCodes"/>.</param>
/// <returns><see cref="StaticOpusDecoderSafeHandle"/></returns>
#if NET8_0_OR_GREATER
[LibraryImport(DllName)]
public static unsafe partial StaticOpusDecoderSafeHandle opus_decoder_create(int Fs, int channels, int* error);
#else
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern unsafe StaticOpusDecoderSafeHandle opus_decoder_create(int Fs, int channels, int* error);
#endif
/// <summary>
/// Initializes a previously allocated <see cref="OpusDecoderSafeHandle"/> state.
/// </summary>
/// <param name="st">Decoder state.</param>
/// <param name="Fs">Sampling rate to decode to (Hz). This must be one of 8000, 12000, 16000, 24000, or 48000.</param>
/// <param name="channels">Number of channels (1 or 2) to decode.</param>
/// <returns><see cref="OpusErrorCodes.OPUS_OK"/> Success or <see cref="OpusErrorCodes"/>.</returns>
#if NET8_0_OR_GREATER
[LibraryImport(DllName)]
public static partial int opus_decoder_init(OpusDecoderSafeHandle st, int Fs, int channels);
#else
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern int opus_decoder_init(OpusDecoderSafeHandle st, int Fs, int channels);
#endif
/// <summary>
/// Decode an Opus packet.
/// </summary>
/// <param name="st">Decoder state.</param>
/// <param name="data">Input payload. Use a NULL pointer to indicate packet loss.</param>
/// <param name="len">Number of bytes in payload.</param>
/// <param name="pcm">Output signal (interleaved if 2 channels). length is frame_size*channels*sizeof(short).</param>
/// <param name="frame_size">Number of samples per channel of available space in pcm. If this is less than the maximum packet duration (120ms; 5760 for 48kHz), this function will not be capable of decoding some packets. In the case of PLC (data==NULL) or FEC (decode_fec=1), then frame_size needs to be exactly the duration of audio that is missing, otherwise the decoder will not be in the optimal state to decode the next incoming packet. For the PLC and FEC cases, frame_size must be a multiple of 2.5 ms.</param>
/// <param name="decode_fec">Flag (0 or 1) to request that any in-band forward error correction data be decoded. If no such data is available, the frame is decoded as if it were lost.</param>
/// <returns>Number of decoded samples or <see cref="OpusErrorCodes"/>.</returns>
#if NET8_0_OR_GREATER
[LibraryImport(DllName)]
public static unsafe partial int opus_decode(OpusDecoderSafeHandle st, byte* data, int len, short* pcm, int frame_size, int decode_fec);
#else
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern unsafe int opus_decode(OpusDecoderSafeHandle st, byte* data, int len, short* pcm, int frame_size, int decode_fec);
#endif
/// <summary>
/// Decode an Opus packet.
/// </summary>
/// <param name="st">Decoder state.</param>
/// <param name="data">Input payload. Use a NULL pointer to indicate packet loss.</param>
/// <param name="len">Number of bytes in payload.</param>
/// <param name="pcm">Output signal (interleaved if 2 channels). length is frame_size*channels*sizeof(int).</param>
/// <param name="frame_size">Number of samples per channel of available space in pcm. If this is less than the maximum packet duration (120ms; 5760 for 48kHz), this function will not be capable of decoding some packets. In the case of PLC (data==NULL) or FEC (decode_fec=1), then frame_size needs to be exactly the duration of audio that is missing, otherwise the decoder will not be in the optimal state to decode the next incoming packet. For the PLC and FEC cases, frame_size must be a multiple of 2.5 ms.</param>
/// <param name="decode_fec">Flag (0 or 1) to request that any in-band forward error correction data be decoded. If no such data is available, the frame is decoded as if it were lost.</param>
/// <returns>Number of decoded samples or <see cref="OpusErrorCodes"/>.</returns>
#if NET8_0_OR_GREATER
[LibraryImport(DllName)]
public static unsafe partial int opus_decode24(OpusDecoderSafeHandle st, byte* data, int len, int* pcm, int frame_size, int decode_fec);
#else
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern unsafe int opus_decode24(OpusDecoderSafeHandle st, byte* data, int len, int* pcm, int frame_size, int decode_fec);
#endif
/// <summary>
/// Decode an Opus packet with floating point output.
/// </summary>
/// <param name="st">Decoder state.</param>
/// <param name="data">Input payload. Use a NULL pointer to indicate packet loss.</param>
/// <param name="len">Number of bytes in payload.</param>
/// <param name="pcm">Output signal (interleaved if 2 channels). length is frame_size*channels*sizeof(float).</param>
/// <param name="frame_size">Number of samples per channel of available space in pcm. If this is less than the maximum packet duration (120ms; 5760 for 48kHz), this function will not be capable of decoding some packets. In the case of PLC (data==NULL) or FEC (decode_fec=1), then frame_size needs to be exactly the duration of audio that is missing, otherwise the decoder will not be in the optimal state to decode the next incoming packet. For the PLC and FEC cases, frame_size must be a multiple of 2.5 ms.</param>
/// <param name="decode_fec">Flag (0 or 1) to request that any in-band forward error correction data be decoded. If no such data is available the frame is decoded as if it were lost.</param>
/// <returns>Number of decoded samples or <see cref="OpusErrorCodes"/></returns>
#if NET8_0_OR_GREATER
[LibraryImport(DllName)]
public static unsafe partial int opus_decode_float(OpusDecoderSafeHandle st, byte* data, int len, float* pcm, int frame_size, int decode_fec);
#else
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern unsafe int opus_decode_float(OpusDecoderSafeHandle st, byte* data, int len, float* pcm, int frame_size, int decode_fec);
#endif
/// <summary>
/// Perform a CTL function on an <see cref="OpusDecoderSafeHandle"/>.
/// </summary>
/// <param name="st">Decoder state.</param>
/// <param name="request">This and all remaining parameters should be replaced by one of the convenience macros in <see cref="GenericCTL"/> or <see cref="DecoderCTL"/>.</param>
/// <returns><see cref="OpusErrorCodes"/></returns>
#if NET8_0_OR_GREATER
[LibraryImport(DllName)]
public static partial int opus_decoder_ctl(OpusDecoderSafeHandle st, int request); //Apparently GenericCTL.OPUS_RESET_STATE exists.
#else
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern int opus_decoder_ctl(OpusDecoderSafeHandle st, int request); //Apparently GenericCTL.OPUS_RESET_STATE exists.
#endif
/// <summary>
/// Perform a CTL function on an <see cref="OpusDecoderSafeHandle"/>.
/// </summary>
/// <param name="st">Decoder state.</param>
/// <param name="request">This and all remaining parameters should be replaced by one of the convenience macros in <see cref="GenericCTL"/> or <see cref="DecoderCTL"/>.</param>
/// <param name="data">The data to input.</param>
/// <returns><see cref="OpusErrorCodes"/></returns>
#if NET8_0_OR_GREATER
[LibraryImport(DllName)]
public static unsafe partial int opus_decoder_ctl(OpusDecoderSafeHandle st, int request, int data);
#else
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern unsafe int opus_decoder_ctl(OpusDecoderSafeHandle st, int request, int data);
#endif
/// <summary>
/// Perform a CTL function on an <see cref="OpusDecoderSafeHandle"/>.
/// </summary>
/// <param name="st">Decoder state.</param>
/// <param name="request">This and all remaining parameters should be replaced by one of the convenience macros in <see cref="GenericCTL"/> or <see cref="DecoderCTL"/>.</param>
/// <param name="data">The data to input or output.</param>
/// <returns><see cref="OpusErrorCodes"/></returns>
#if NET8_0_OR_GREATER
[LibraryImport(DllName)]
public static unsafe partial int opus_decoder_ctl(OpusDecoderSafeHandle st, int request, void* data);
#else
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern unsafe int opus_decoder_ctl(OpusDecoderSafeHandle st, int request, void* data);
#endif
/// <summary>
/// Frees an <see cref="OpusDecoderSafeHandle"/> allocated by <see cref="opus_decoder_create(int, int, int*)"/>.
/// </summary>
/// <param name="st">State to be freed.</param>
#if NET8_0_OR_GREATER
[LibraryImport(DllName)]
public static partial void opus_decoder_destroy(IntPtr st);
#else
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern void opus_decoder_destroy(IntPtr st);
#endif
//Dred Decoder
/// <summary>
/// Gets the size of an <see cref="OpusDREDDecoderSafeHandle"/> structure.
/// </summary>
/// <returns>The size in bytes.</returns>
#if NET8_0_OR_GREATER
[LibraryImport(DllName)]
public static partial int opus_dred_decoder_get_size();
#else
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern int opus_dred_decoder_get_size();
#endif
/// <summary>
/// Allocates and initializes an <see cref="StaticOpusDREDDecoderSafeHandle"/> state.
/// </summary>
/// <param name="error"><see cref="OpusErrorCodes.OPUS_OK"/> Success or <see cref="OpusErrorCodes"/>.</param>
/// <returns><see cref="StaticOpusDREDDecoderSafeHandle"/></returns>
#if NET8_0_OR_GREATER
[LibraryImport(DllName)]
public static unsafe partial StaticOpusDREDDecoderSafeHandle opus_dred_decoder_create(int* error);
#else
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern unsafe StaticOpusDREDDecoderSafeHandle opus_dred_decoder_create(int* error);
#endif
/// <summary>
/// Initializes an <see cref="OpusDREDDecoderSafeHandle"/> state.
/// </summary>
/// <param name="dec">State to be initialized.</param>
/// <returns><see cref="OpusErrorCodes"/></returns>
#if NET8_0_OR_GREATER
[LibraryImport(DllName)]
public static partial int opus_dred_decoder_init(OpusDREDDecoderSafeHandle dec);
#else
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern int opus_dred_decoder_init(OpusDREDDecoderSafeHandle dec);
#endif
/// <summary>
/// Frees an <see cref="OpusDREDDecoderSafeHandle"/> allocated by <see cref="opus_dred_decoder_create(int*)"/>.
/// </summary>
/// <param name="dec">State to be freed.</param>
#if NET8_0_OR_GREATER
[LibraryImport(DllName)]
public static partial void opus_dred_decoder_destroy(IntPtr dec);
#else
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern void opus_dred_decoder_destroy(IntPtr dec);
#endif
/// <summary>
/// Perform a CTL function on an <see cref="OpusDREDDecoderSafeHandle"/>.
/// </summary>
/// <param name="dred_dec">DRED Decoder state.</param>
/// <param name="request">This and all remaining parameters should be replaced by one of the convenience macros in <see cref="GenericCTL"/> or <see cref="DecoderCTL"/>.</param>
/// <returns><see cref="OpusErrorCodes"/></returns>
#if NET8_0_OR_GREATER
[LibraryImport(DllName)]
public static partial int opus_dred_decoder_ctl(OpusDREDDecoderSafeHandle dred_dec, int request); //Apparently GenericCTL.OPUS_RESET_STATE exists.
#else
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern int opus_dred_decoder_ctl(OpusDREDDecoderSafeHandle dred_dec, int request); //Apparently GenericCTL.OPUS_RESET_STATE exists.
#endif
/// <summary>
/// Perform a CTL function on an <see cref="OpusDREDDecoderSafeHandle"/>.
/// </summary>
/// <param name="dred_dec">DRED Decoder state.</param>
/// <param name="request">This and all remaining parameters should be replaced by one of the convenience macros in <see cref="GenericCTL"/> or <see cref="DecoderCTL"/>.</param>
/// <param name="data">The data to input or output.</param>
/// <returns><see cref="OpusErrorCodes"/></returns>
#if NET8_0_OR_GREATER
[LibraryImport(DllName)]
public static unsafe partial int opus_dred_decoder_ctl(OpusDREDDecoderSafeHandle dred_dec, int request, void* data);
#else
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern unsafe int opus_dred_decoder_ctl(OpusDREDDecoderSafeHandle dred_dec, int request, void* data);
#endif
//Dred Packet?
/// <summary>
/// Gets the size of an <see cref="OpusDREDSafeHandle"/> structure.
/// </summary>
/// <returns>The size in bytes.</returns>
#if NET8_0_OR_GREATER
[LibraryImport(DllName)]
public static partial int opus_dred_get_size();
#else
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern int opus_dred_get_size();
#endif
/// <summary>
/// Allocates and initializes a <see cref="StaticOpusDREDSafeHandle"/> state.
/// </summary>
/// <param name="error"><see cref="OpusErrorCodes.OPUS_OK"/> Success or <see cref="OpusErrorCodes"/>.</param>
/// <returns><see cref="StaticOpusDREDSafeHandle"/></returns>
#if NET8_0_OR_GREATER
[LibraryImport(DllName)]
public static unsafe partial StaticOpusDREDSafeHandle opus_dred_alloc(int* error);
#else
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern unsafe StaticOpusDREDSafeHandle opus_dred_alloc(int* error);
#endif
/// <summary>
/// Frees an <see cref="OpusDREDSafeHandle"/> allocated by <see cref="opus_dred_alloc(int*)"/>.
/// </summary>
/// <param name="dec">State to be freed.</param>
#if NET8_0_OR_GREATER
[LibraryImport(DllName)]
public static partial void opus_dred_free(IntPtr dec); //I'M JUST FOLLOWING THE DOCS!
#else
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern void opus_dred_free(IntPtr dec); //I'M JUST FOLLOWING THE DOCS!
#endif
/// <summary>
/// Decode an Opus DRED packet.
/// </summary>
/// <param name="dred_dec">DRED Decoder state.</param>
/// <param name="dred">DRED state.</param>
/// <param name="data">Input payload.</param>
/// <param name="len">Number of bytes in payload.</param>
/// <param name="max_dred_samples">Maximum number of DRED samples that may be needed (if available in the packet).</param>
/// <param name="sampling_rate">Sampling rate used for max_dred_samples argument. Needs not match the actual sampling rate of the decoder.</param>
/// <param name="dred_end">Number of non-encoded (silence) samples between the DRED timestamp and the last DRED sample.</param>
/// <param name="defer_processing">Flag (0 or 1). If set to one, the CPU-intensive part of the DRED decoding is deferred until <see cref="opus_dred_process(OpusDREDDecoderSafeHandle, OpusDREDSafeHandle, OpusDREDSafeHandle)"/> is called.</param>
/// <returns>Offset (positive) of the first decoded DRED samples, zero if no DRED is present, or <see cref="OpusErrorCodes"/></returns>
#if NET8_0_OR_GREATER
[LibraryImport(DllName)]
public static unsafe partial int opus_dred_parse(OpusDREDDecoderSafeHandle dred_dec, OpusDREDSafeHandle dred, byte* data, int len, int max_dred_samples, int sampling_rate, int* dred_end, int defer_processing);
#else
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern unsafe int opus_dred_parse(OpusDREDDecoderSafeHandle dred_dec, OpusDREDSafeHandle dred, byte* data, int len, int max_dred_samples, int sampling_rate, int* dred_end, int defer_processing);
#endif
/// <summary>
/// Finish decoding an <see cref="OpusDREDSafeHandle"/> packet.
/// </summary>
/// <param name="dred_dec">DRED Decoder state.</param>
/// <param name="src">Source DRED state to start the processing from.</param>
/// <param name="dst">Destination DRED state to store the updated state after processing.</param>
/// <returns><see cref="OpusErrorCodes"/></returns>
#if NET8_0_OR_GREATER
[LibraryImport(DllName)]
public static partial int opus_dred_process(OpusDREDDecoderSafeHandle dred_dec, OpusDREDSafeHandle src, OpusDREDSafeHandle dst);
#else
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern int opus_dred_process(OpusDREDDecoderSafeHandle dred_dec, OpusDREDSafeHandle src, OpusDREDSafeHandle dst);
#endif
/// <summary>
/// Decode audio from an <see cref="OpusDREDSafeHandle"/> packet with floating point output.
/// </summary>
/// <param name="st">Decoder state.</param>
/// <param name="dred">DRED state.</param>
/// <param name="dred_offset">position of the redundancy to decode (in samples before the beginning of the real audio data in the packet).</param>
/// <param name="pcm">Output signal (interleaved if 2 channels). length is frame_size*channels*sizeof(short)</param>
/// <param name="frame_size">Number of samples per channel to decode in pcm. frame_size must be a multiple of 2.5 ms.</param>
/// <returns>Number of decoded samples or <see cref="OpusErrorCodes"/>.</returns>
#if NET8_0_OR_GREATER
[LibraryImport(DllName)]
public static unsafe partial int opus_decoder_dred_decode(OpusDecoderSafeHandle st, OpusDREDSafeHandle dred, int dred_offset, short* pcm, int frame_size);
#else
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern unsafe int opus_decoder_dred_decode(OpusDecoderSafeHandle st, OpusDREDSafeHandle dred, int dred_offset, short* pcm, int frame_size);
#endif
/// <summary>
/// Decode audio from an <see cref="OpusDREDSafeHandle"/> packet with floating point output.
/// </summary>
/// <param name="st">Decoder state.</param>
/// <param name="dred">DRED state.</param>
/// <param name="dred_offset">position of the redundancy to decode (in samples before the beginning of the real audio data in the packet).</param>
/// <param name="pcm">Output signal (interleaved if 2 channels). length is frame_size*channels*sizeof(int)</param>
/// <param name="frame_size">Number of samples per channel to decode in pcm. frame_size must be a multiple of 2.5 ms.</param>
/// <returns>Number of decoded samples or <see cref="OpusErrorCodes"/>.</returns>
#if NET8_0_OR_GREATER
[LibraryImport(DllName)]
public static unsafe partial int opus_decoder_dred_decode24(OpusDecoderSafeHandle st, OpusDREDSafeHandle dred, int dred_offset, int* pcm, int frame_size);
#else
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern unsafe int opus_decoder_dred_decode24(OpusDecoderSafeHandle st, OpusDREDSafeHandle dred, int dred_offset, int* pcm, int frame_size);
#endif
/// <summary>
/// Decode audio from an <see cref="OpusDREDSafeHandle"/> packet with floating point output.
/// </summary>
/// <param name="st">Decoder state.</param>
/// <param name="dred">DRED state.</param>
/// <param name="dred_offset">position of the redundancy to decode (in samples before the beginning of the real audio data in the packet).</param>
/// <param name="pcm">Output signal (interleaved if 2 channels). length is frame_size*channels*sizeof(float).</param>
/// <param name="frame_size">Number of samples per channel to decode in pcm. frame_size must be a multiple of 2.5 ms.</param>
/// <returns>Number of decoded samples or <see cref="OpusErrorCodes"/>.</returns>
#if NET8_0_OR_GREATER
[LibraryImport(DllName)]
public static unsafe partial int opus_decoder_dred_decode_float(OpusDecoderSafeHandle st, OpusDREDSafeHandle dred, int dred_offset, float* pcm, int frame_size);
#else
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern unsafe int opus_decoder_dred_decode_float(OpusDecoderSafeHandle st, OpusDREDSafeHandle dred, int dred_offset, float* pcm, int frame_size);
#endif
//Opus Packet Parsers
/// <summary>
/// Parse an opus packet into one or more frames.
/// </summary>
/// <param name="data">Opus packet to be parsed.</param>
/// <param name="len">size of data.</param>
/// <param name="out_toc">TOC pointer.</param>
/// <param name="frames">encapsulated frames.</param>
/// <param name="size">sizes of the encapsulated frames.</param>
/// <param name="payload_offset">returns the position of the payload within the packet (in bytes).</param>
/// <returns>number of frames.</returns>
#if NET8_0_OR_GREATER
[LibraryImport(DllName)]
public static unsafe partial int opus_packet_parse(byte* data, int len, byte* out_toc, byte*[] frames, short[] size, int* payload_offset);
#else
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern unsafe int opus_packet_parse(byte* data, int len, byte* out_toc, byte*[] frames, short[] size, int* payload_offset);
#endif
/// <summary>
/// Gets the bandwidth of an Opus packet.
/// </summary>
/// <param name="data">Opus packet.</param>
/// <returns><see cref="OpusPredefinedValues"/> or <see cref="OpusErrorCodes"/></returns>
#if NET8_0_OR_GREATER
[LibraryImport(DllName)]
public static unsafe partial int opus_packet_get_bandwidth(byte* data);
#else
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern unsafe int opus_packet_get_bandwidth(byte* data);
#endif
/// <summary>
/// Gets the number of samples per frame from an Opus packet.
/// </summary>
/// <param name="data">Opus packet. This must contain at least one byte of data.</param>
/// <param name="Fs">Sampling rate in Hz. This must be a multiple of 400, or inaccurate results will be returned.</param>
/// <returns>Number of samples per frame.</returns>
#if NET8_0_OR_GREATER
[LibraryImport(DllName)]
public static unsafe partial int opus_packet_get_samples_per_frame(byte* data, int Fs);
#else
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern unsafe int opus_packet_get_samples_per_frame(byte* data, int Fs);
#endif
/// <summary>
/// Gets the number of channels from an Opus packet.
/// </summary>
/// <param name="data">Opus packet.</param>
/// <returns>Number of channels or <see cref="OpusErrorCodes"/>.</returns>
#if NET8_0_OR_GREATER
[LibraryImport(DllName)]
public static unsafe partial int opus_packet_get_nb_channels(byte* data);
#else
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern unsafe int opus_packet_get_nb_channels(byte* data);
#endif
/// <summary>
/// Gets the number of frames in an Opus packet.
/// </summary>
/// <param name="packet">Opus packet.</param>
/// <param name="len">Length of packet.</param>
/// <returns>Number of frames or <see cref="OpusErrorCodes"/>.</returns>
#if NET8_0_OR_GREATER
[LibraryImport(DllName)]
public static unsafe partial int opus_packet_get_nb_frames(byte* packet, int len);
#else
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern unsafe int opus_packet_get_nb_frames(byte* packet, int len);
#endif
/// <summary>
/// Gets the number of samples of an Opus packet.
/// </summary>
/// <param name="packet">Opus packet.</param>
/// <param name="len">Length of packet.</param>
/// <param name="Fs">Sampling rate in Hz. This must be a multiple of 400, or inaccurate results will be returned.</param>
/// <returns>Number of samples or <see cref="OpusErrorCodes"/>.</returns>
#if NET8_0_OR_GREATER
[LibraryImport(DllName)]
public static unsafe partial int opus_packet_get_nb_samples(byte* packet, int len, int Fs);
#else
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern unsafe int opus_packet_get_nb_samples(byte* packet, int len, int Fs);
#endif
/// <summary>
/// Checks whether an Opus packet has LBRR.
/// </summary>
/// <param name="packet">Opus packet.</param>
/// <param name="len">Length of packet.</param>
/// <returns>1 is LBRR is present, 0 otherwise or <see cref="OpusErrorCodes"/></returns>
#if NET8_0_OR_GREATER
[LibraryImport(DllName)]
public static unsafe partial int opus_packet_has_lbrr(byte* packet, int len);
#else
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern unsafe int opus_packet_has_lbrr(byte* packet, int len);
#endif
/// <summary>
/// Gets the number of samples of an Opus packet.
/// </summary>
/// <param name="dec">Decoder state.</param>
/// <param name="packet">Opus packet.</param>
/// <param name="len">Length of packet.</param>
/// <returns>Number of samples or <see cref="OpusErrorCodes"/>.</returns>
#if NET8_0_OR_GREATER
[LibraryImport(DllName)]
public static unsafe partial int opus_decoder_get_nb_samples(OpusDecoderSafeHandle dec, byte* packet, int len);
#else
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern unsafe int opus_decoder_get_nb_samples(OpusDecoderSafeHandle dec, byte* packet, int len);
#endif
/// <summary>
/// Applies soft-clipping to bring a float signal within the [-1,1] range.
/// </summary>
/// <param name="pcm">Input PCM and modified PCM.</param>
/// <param name="frame_size">Number of samples per channel to process.</param>
/// <param name="channels">Number of channels.</param>
/// <param name="softclip_mem">State memory for the soft clipping process (one float per channel, initialized to zero).</param>
#if NET8_0_OR_GREATER
[LibraryImport(DllName)]
public static unsafe partial void opus_pcm_soft_clip(float* pcm, int frame_size, int channels, float* softclip_mem);
#else
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern unsafe void opus_pcm_soft_clip(float* pcm, int frame_size, int channels, float* softclip_mem);
#endif
//Repacketizer
/// <summary>
/// Gets the size of an <see cref="OpusRepacketizerSafeHandle"/> structure.
/// </summary>
/// <returns>The size in bytes.</returns>
#if NET8_0_OR_GREATER
[LibraryImport(DllName)]
public static partial int opus_repacketizer_get_size();
#else
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern int opus_repacketizer_get_size();
#endif
/// <summary>
/// (Re)initializes a previously allocated <see cref="OpusRepacketizerSafeHandle"/> state.
/// </summary>
/// <param name="rp">The <see cref="OpusRepacketizerSafeHandle"/> state to (re)initialize.</param>
/// <returns><see cref="StaticOpusRepacketizerSafeHandle"/></returns>
#if NET8_0_OR_GREATER
[LibraryImport(DllName)]
public static partial StaticOpusRepacketizerSafeHandle opus_repacketizer_init(OpusRepacketizerSafeHandle rp);
#else
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern StaticOpusRepacketizerSafeHandle opus_repacketizer_init(OpusRepacketizerSafeHandle rp);
#endif
/// <summary>
/// Allocates memory and initializes the new <see cref="StaticOpusRepacketizerSafeHandle"/> with <see cref="opus_repacketizer_init(OpusRepacketizerSafeHandle)"/>.
/// </summary>
/// <returns><see cref="StaticOpusRepacketizerSafeHandle"/></returns>
#if NET8_0_OR_GREATER
[LibraryImport(DllName)]
public static partial StaticOpusRepacketizerSafeHandle opus_repacketizer_create();
#else
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern StaticOpusRepacketizerSafeHandle opus_repacketizer_create();
#endif
/// <summary>
/// Frees an <see cref="OpusRepacketizerSafeHandle"/> allocated by <see cref="opus_repacketizer_create"/>.
/// </summary>
/// <param name="rp">State to be freed.</param>
#if NET8_0_OR_GREATER
[LibraryImport(DllName)]
public static partial void opus_repacketizer_destroy(IntPtr rp);
#else
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern void opus_repacketizer_destroy(IntPtr rp);
#endif
/// <summary>
/// Add a packet to the current <see cref="OpusRepacketizerSafeHandle"/> state.
/// </summary>
/// <param name="rp">The repacketizer state to which to add the packet.</param>
/// <param name="data">The packet data. The application must ensure this pointer remains valid until the next call to <see cref="opus_repacketizer_init(OpusRepacketizerSafeHandle)"/> or <see cref="opus_repacketizer_destroy(IntPtr)"/>.</param>
/// <param name="len">The number of bytes in the packet data.</param>
/// <returns><see cref="OpusErrorCodes"/></returns>
#if NET8_0_OR_GREATER
[LibraryImport(DllName)]
public static unsafe partial int opus_repacketizer_cat(OpusRepacketizerSafeHandle rp, byte* data, int len);
#else
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern unsafe int opus_repacketizer_cat(OpusRepacketizerSafeHandle rp, byte* data, int len);
#endif
/// <summary>
/// Construct a new packet from data previously submitted to the <see cref="OpusRepacketizerSafeHandle"/> state via <see cref="opus_repacketizer_cat(OpusRepacketizerSafeHandle, byte*, int)"/>.
/// </summary>
/// <param name="rp">The repacketizer state from which to construct the new packet.</param>
/// <param name="begin">The index of the first frame in the current repacketizer state to include in the output.</param>
/// <param name="end">One past the index of the last frame in the current repacketizer state to include in the output.</param>
/// <param name="data">The buffer in which to store the output packet.</param>
/// <param name="maxlen">The maximum number of bytes to store in the output buffer. In order to guarantee success, this should be at least 1276 for a single frame, or for multiple frames, 1277*(end-begin). However, 1*(end-begin) plus the size of all packet data submitted to the repacketizer since the last call to <see cref="opus_repacketizer_init(OpusRepacketizerSafeHandle)"/> or <see cref="opus_repacketizer_create"/> is also sufficient, and possibly much smaller.</param>
/// <returns>The total size of the output packet on success, or an <see cref="OpusErrorCodes"/> on failure.</returns>
#if NET8_0_OR_GREATER
[LibraryImport(DllName)]
public static unsafe partial int opus_repacketizer_out_range(OpusRepacketizerSafeHandle rp, int begin, int end, byte* data, int maxlen);
#else
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern unsafe int opus_repacketizer_out_range(OpusRepacketizerSafeHandle rp, int begin, int end, byte* data, int maxlen);
#endif
/// <summary>
/// Return the total number of frames contained in packet data submitted to the <see cref="OpusRepacketizerSafeHandle"/> state so far via <see cref="opus_repacketizer_cat(OpusRepacketizerSafeHandle, byte*, int)"/> since the last call to <see cref="opus_repacketizer_init(OpusRepacketizerSafeHandle)"/> or <see cref="opus_repacketizer_create"/>.
/// </summary>
/// <param name="rp">The repacketizer state containing the frames.</param>
/// <returns>The total number of frames contained in the packet data submitted to the repacketizer state.</returns>
#if NET8_0_OR_GREATER
[LibraryImport(DllName)]
public static partial int opus_repacketizer_get_nb_frames(OpusRepacketizerSafeHandle rp);
#else
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern int opus_repacketizer_get_nb_frames(OpusRepacketizerSafeHandle rp);
#endif
/// <summary>
/// Construct a new packet from data previously submitted to the <see cref="OpusRepacketizerSafeHandle"/> state via <see cref="opus_repacketizer_cat(OpusRepacketizerSafeHandle, byte*, int)"/>.
/// </summary>
/// <param name="rp">The repacketizer state from which to construct the new packet.</param>
/// <param name="data">The buffer in which to store the output packet.</param>
/// <param name="maxlen">The maximum number of bytes to store in the output buffer. In order to guarantee success, this should be at least 1277*opus_repacketizer_get_nb_frames(rp). However, 1*opus_repacketizer_get_nb_frames(rp) plus the size of all packet data submitted to the repacketizer since the last call to opus_repacketizer_init() or opus_repacketizer_create() is also sufficient, and possibly much smaller.</param>
/// <returns>The total size of the output packet on success, or an <see cref="OpusErrorCodes"/> on failure.</returns>
#if NET8_0_OR_GREATER
[LibraryImport(DllName)]
public static unsafe partial int opus_repacketizer_out(OpusRepacketizerSafeHandle rp, byte* data, int maxlen);
#else
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern unsafe int opus_repacketizer_out(OpusRepacketizerSafeHandle rp, byte* data, int maxlen);
#endif
/// <summary>
/// Pads a given Opus packet to a larger size (possibly changing the TOC sequence).
/// </summary>
/// <param name="data">The buffer containing the packet to pad.</param>
/// <param name="len">The size of the packet. This must be at least 1.</param>
/// <param name="new_len">The desired size of the packet after padding. This must be at least as large as len.</param>
/// <returns><see cref="OpusErrorCodes"/></returns>
#if NET8_0_OR_GREATER
[LibraryImport(DllName)]
public static unsafe partial int opus_packet_pad(byte* data, int len, int new_len);
#else
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern unsafe int opus_packet_pad(byte* data, int len, int new_len);
#endif
/// <summary>
/// Remove all padding from a given Opus packet and rewrite the TOC sequence to minimize space usage.
/// </summary>
/// <param name="data">The buffer containing the packet to strip.</param>
/// <param name="len">The size of the packet. This must be at least 1.</param>
/// <returns>The new size of the output packet on success, or an <see cref="OpusErrorCodes"/> on failure.</returns>
#if NET8_0_OR_GREATER
[LibraryImport(DllName)]
public static unsafe partial int opus_packet_unpad(byte* data, int len);
#else
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern unsafe int opus_packet_unpad(byte* data, int len);
#endif
/// <summary>
/// Pads a given Opus multi-stream packet to a larger size (possibly changing the TOC sequence).
/// </summary>
/// <param name="data">The buffer containing the packet to pad.</param>
/// <param name="len">The size of the packet. This must be at least 1.</param>
/// <param name="new_len">The desired size of the packet after padding. This must be at least 1.</param>
/// <param name="nb_streams">The number of streams (not channels) in the packet. This must be at least as large as len.</param>
/// <returns><see cref="OpusErrorCodes"/></returns>
#if NET8_0_OR_GREATER
[LibraryImport(DllName)]
public static unsafe partial int opus_multistream_packet_pad(byte* data, int len, int new_len, int nb_streams);
#else
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern unsafe int opus_multistream_packet_pad(byte* data, int len, int new_len, int nb_streams);
#endif
/// <summary>
/// Remove all padding from a given Opus multi-stream packet and rewrite the TOC sequence to minimize space usage.
/// </summary>
/// <param name="data">The buffer containing the packet to strip.</param>
/// <param name="len">The size of the packet. This must be at least 1.</param>
/// <param name="nb_streams">The number of streams (not channels) in the packet. This must be at least 1.</param>
/// <returns>The new size of the output packet on success, or an <see cref="OpusErrorCodes"/> on failure.</returns>
#if NET8_0_OR_GREATER
[LibraryImport(DllName)]
public static unsafe partial int opus_multistream_packet_unpad(byte* data, int len, int nb_streams);
#else
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern unsafe int opus_multistream_packet_unpad(byte* data, int len, int nb_streams);
#endif
//Multistream Encoder
/// <summary>
/// Gets the size of an <see cref="OpusMSEncoderSafeHandle"/> structure.
/// </summary>
/// <param name="streams">The total number of streams to encode from the input. This must be no more than 255.</param>
/// <param name="coupled_streams">Number of coupled (2 channel) streams to encode. This must be no larger than the total number of streams. Additionally, The total number of encoded channels (streams + coupled_streams) must be no more than 255.</param>
/// <returns>The size in bytes on success, or a negative error code (see <see cref="OpusErrorCodes"/>) on error.</returns>
#if NET8_0_OR_GREATER
[LibraryImport(DllName)]
public static partial int opus_multistream_encoder_get_size(int streams, int coupled_streams);
#else
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern int opus_multistream_encoder_get_size(int streams, int coupled_streams);
#endif
/// <summary>
/// N.A.
/// </summary>
/// <param name="channels"></param>
/// <param name="mapping_family"></param>
/// <returns></returns>
#if NET8_0_OR_GREATER
[LibraryImport(DllName)]
public static partial int opus_multistream_surround_encoder_get_size(int channels, int mapping_family);
#else
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern int opus_multistream_surround_encoder_get_size(int channels, int mapping_family);
#endif
/// <summary>
/// Allocates and initializes a <see cref="StaticOpusMSEncoderSafeHandle"/> state.
/// </summary>
/// <param name="Fs">Sampling rate of the input signal (in Hz). This must be one of 8000, 12000, 16000, 24000, or 48000.</param>
/// <param name="channels">Number of channels in the input signal. This must be at most 255. It may be greater than the number of coded channels (streams + coupled_streams).</param>
/// <param name="streams">The total number of streams to encode from the input. This must be no more than the number of channels.</param>
/// <param name="coupled_streams">Number of coupled (2 channel) streams to encode. This must be no larger than the total number of streams. Additionally, The total number of encoded channels (streams + coupled_streams) must be no more than the number of input channels.</param>
/// <param name="mapping">Mapping from encoded channels to input channels, as described in Opus Multistream API. As an extra constraint, the multistream encoder does not allow encoding coupled streams for which one channel is unused since this is never a good idea.</param>
/// <param name="application">The target encoder application. This must be one of the following: <see cref="OpusPredefinedValues.OPUS_APPLICATION_VOIP"/>, <see cref="OpusPredefinedValues.OPUS_APPLICATION_AUDIO"/> or <see cref="OpusPredefinedValues.OPUS_APPLICATION_RESTRICTED_LOWDELAY"/>.</param>
/// <param name="error">Returns <see cref="OpusErrorCodes.OPUS_OK"/> on success, or an error code (see <see cref="OpusErrorCodes"/>) on failure.</param>
/// <returns><see cref="StaticOpusMSEncoderSafeHandle"/></returns>
#if NET8_0_OR_GREATER
[LibraryImport(DllName)]
public static unsafe partial StaticOpusMSEncoderSafeHandle opus_multistream_encoder_create(int Fs, int channels, int streams, int coupled_streams, byte* mapping, int application, int* error);
#else
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern unsafe StaticOpusMSEncoderSafeHandle opus_multistream_encoder_create(int Fs, int channels, int streams, int coupled_streams, byte* mapping, int application, int* error);
#endif
/// <summary>
/// N.A.
/// </summary>
/// <param name="Fs"></param>
/// <param name="channels"></param>
/// <param name="mapping_family"></param>
/// <param name="streams"></param>
/// <param name="coupled_streams"></param>
/// <param name="mapping"></param>
/// <param name="application"></param>
/// <param name="error"></param>
/// <returns></returns>
#if NET8_0_OR_GREATER
[LibraryImport(DllName)]
public static unsafe partial StaticOpusMSEncoderSafeHandle opus_multistream_surround_encoder_create(int Fs, int channels, int mapping_family, int* streams, int* coupled_streams, byte* mapping, int application, int* error);
#else
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern unsafe StaticOpusMSEncoderSafeHandle opus_multistream_surround_encoder_create(int Fs, int channels, int mapping_family, int* streams, int* coupled_streams, byte* mapping, int application, int* error);
#endif
/// <summary>
/// Initialize a previously allocated <see cref="OpusMSEncoderSafeHandle"/> state.
/// </summary>
/// <param name="st">Multistream encoder state to initialize.</param>
/// <param name="Fs">Sampling rate of the input signal (in Hz). This must be one of 8000, 12000, 16000, 24000, or 48000.</param>
/// <param name="channels">Number of channels in the input signal. This must be at most 255. It may be greater than the number of coded channels (streams + coupled_streams).</param>
/// <param name="streams">The total number of streams to encode from the input. This must be no more than the number of channels.</param>
/// <param name="coupled_streams">Number of coupled (2 channel) streams to encode. This must be no larger than the total number of streams. Additionally, The total number of encoded channels (streams + coupled_streams) must be no more than the number of input channels.</param>
/// <param name="mapping">Mapping from encoded channels to input channels, as described in Opus Multistream API. As an extra constraint, the multistream encoder does not allow encoding coupled streams for which one channel is unused since this is never a good idea.</param>
/// <param name="application">The target encoder application. This must be one of the following: <see cref="OpusPredefinedValues.OPUS_APPLICATION_VOIP"/>, <see cref="OpusPredefinedValues.OPUS_APPLICATION_AUDIO"/> or <see cref="OpusPredefinedValues.OPUS_APPLICATION_RESTRICTED_LOWDELAY"/>.</param>
/// <returns><see cref="OpusErrorCodes.OPUS_OK"/> on success, or an error code (see <see cref="OpusErrorCodes"/>) on failure.</returns>
#if NET8_0_OR_GREATER
[LibraryImport(DllName)]
public static unsafe partial int opus_multistream_encoder_init(OpusMSEncoderSafeHandle st, int Fs, int channels, int streams, int coupled_streams, byte* mapping, int application);
#else
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern unsafe int opus_multistream_encoder_init(OpusMSEncoderSafeHandle st, int Fs, int channels, int streams, int coupled_streams, byte* mapping, int application);
#endif
/// <summary>
/// N.A.
/// </summary>
/// <param name="st"></param>
/// <param name="Fs"></param>
/// <param name="channels"></param>
/// <param name="mapping_family"></param>
/// <param name="streams"></param>
/// <param name="coupled_streams"></param>
/// <param name="mapping"></param>
/// <param name="application"></param>
/// <returns></returns>
#if NET8_0_OR_GREATER
[LibraryImport(DllName)]
public static unsafe partial int opus_multistream_surround_encoder_init(OpusMSEncoderSafeHandle st, int Fs, int channels, int mapping_family, int* streams, int* coupled_streams, byte* mapping, int application);
#else
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern unsafe int opus_multistream_surround_encoder_init(OpusMSEncoderSafeHandle st, int Fs, int channels, int mapping_family, int* streams, int* coupled_streams, byte* mapping, int application);
#endif
/// <summary>
/// Encodes a multistream Opus frame.
/// </summary>
/// <param name="st">Multistream encoder state.</param>
/// <param name="pcm">The input signal as interleaved samples. This must contain frame_size*channels samples.</param>
/// <param name="frame_size">Number of samples per channel in the input signal. This must be an Opus frame size for the encoder's sampling rate. For example, at 48 kHz the permitted values 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.</param>
/// <param name="data">Output payload. This must contain storage for at least max_data_bytes.</param>
/// <param name="max_data_bytes">Size of the allocated memory for the output payload. This may be used to impose an upper limit on the instant bitrate, but should not be used as the only bitrate control. Use <see cref="EncoderCTL.OPUS_SET_BITRATE"/> to control the bitrate.</param>
/// <returns>The length of the encoded packet (in bytes) on success or a negative error code (see <see cref="OpusErrorCodes"/>) on failure.</returns>
#if NET8_0_OR_GREATER
[LibraryImport(DllName)]
public static unsafe partial int opus_multistream_encode(OpusMSEncoderSafeHandle st, short* pcm, int frame_size, byte* data, int max_data_bytes);