-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathOpusDecoderExtensions.cs
More file actions
197 lines (183 loc) · 8.12 KB
/
OpusDecoderExtensions.cs
File metadata and controls
197 lines (183 loc) · 8.12 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
using System;
using OpusSharp.Core.Interfaces;
namespace OpusSharp.Core.Extensions
{
/// <summary>
/// Contains the <see cref="OpusDecoder"/> helper extensions.
/// </summary>
/// <remarks>OPUS_SET_COMPLEXITY and OPUS_GET_COMPLEXITY have not been added since they aren't documented yet in the opus documentation.</remarks>
public static class OpusDecoderExtensions
{
/// <summary>
/// Sets gain for an opus decoder.
/// </summary>
/// <param name="decoder">The decoder state.</param>
/// <param name="gain">The gain to set.</param>
/// <exception cref="OpusException" />
/// <exception cref="ObjectDisposedException" />
public static void SetGain(this IOpusDecoder decoder, short gain)
{
decoder.Ctl(DecoderCTL.OPUS_SET_GAIN, gain);
}
/// <summary>
/// Gets the gain for an opus decoder.
/// </summary>
/// <param name="decoder">The decoder state.</param>
/// <returns>The gain for the opus decoder.</returns>
/// <exception cref="OpusException" />
/// <exception cref="ObjectDisposedException" />
public static int GetGain(this IOpusDecoder decoder)
{
var gain = 0;
decoder.Ctl(DecoderCTL.OPUS_GET_GAIN, ref gain);
return gain;
}
/// <summary>
/// Gets the duration (in samples) of the last packet successfully decoded or concealed.
/// </summary>
/// <param name="decoder">The decoder state.</param>
/// <returns>The last packet duration (in samples).</returns>
/// <exception cref="OpusException" />
/// <exception cref="ObjectDisposedException" />
public static int GetLastPacketDuration(this IOpusDecoder decoder)
{
var lastPacketDuration = 0;
decoder.Ctl(DecoderCTL.OPUS_GET_LAST_PACKET_DURATION, ref lastPacketDuration);
return lastPacketDuration;
}
/// <summary>
/// Gets the pitch of the last decoded frame, if available.
/// </summary>
/// <param name="decoder">The decoder state.</param>
/// <returns>The pitch of the last decoded frame if available.</returns>
/// <exception cref="OpusException" />
/// <exception cref="ObjectDisposedException" />
public static int GetPitch(this IOpusDecoder decoder)
{
var pitch = 0;
decoder.Ctl(DecoderCTL.OPUS_GET_PITCH, ref pitch);
return pitch;
}
/// <summary>
/// Enables or disables the decoder's OSCE BWE module.
/// </summary>
/// <param name="decoder">The decoder state.</param>
/// <param name="enabled">Whether to enable or disable the OSCE BWE module.</param>
/// <exception cref="OpusException" />
/// <exception cref="ObjectDisposedException" />
public static void SetOsceBwe(this IOpusDecoder decoder, bool enabled)
{
decoder.Ctl(DecoderCTL.OPUS_SET_OSCE_BWE, enabled ? 1 : 0);
}
/// <summary>
/// Determines whether the decoder's OSCE BWE module is enabled or not.
/// </summary>
/// <param name="decoder">The decoder state.</param>
/// <returns>Whether the OSCE BWE module is enabled or not.</returns>
/// <exception cref="OpusException" />
/// <exception cref="ObjectDisposedException" />
public static bool GetOsceBwe(this IOpusDecoder decoder)
{
var value = 0;
decoder.Ctl(DecoderCTL.OPUS_GET_OSCE_BWE, ref value);
return value == 1;
}
/// <summary>
/// Sets whether the decoder should ignore extensions in the padding area.
/// </summary>
/// <param name="decoder">The decoder state.</param>
/// <param name="disabled">Whether to disable all found extensions in the padding area.</param>
/// <exception cref="OpusException" />
/// <exception cref="ObjectDisposedException" />
public static void SetIgnoreExtensions(this IOpusDecoder decoder, bool disabled)
{
decoder.Ctl(DecoderCTL.OPUS_SET_IGNORE_EXTENSIONS, disabled ? 1 : 0);
}
/// <summary>
/// Determines whether the decoder is ignoring extensions found in the padding area.
/// </summary>
/// <param name="decoder">The decoder state.</param>
/// <returns>Whether the decoder is ignoring extensions.</returns>
/// <exception cref="OpusException" />
/// <exception cref="ObjectDisposedException" />
public static bool GetIgnoreExtensions(this IOpusDecoder decoder)
{
var value = 0;
decoder.Ctl(DecoderCTL.OPUS_GET_IGNORE_EXTENSIONS, ref value);
return value == 1;
}
/// <summary>
/// Resets the codec state to be equivalent to a freshly initialized state.
/// </summary>
/// <param name="decoder">The decoder state.</param>
/// <exception cref="OpusException" />
/// <exception cref="ObjectDisposedException" />
public static void Reset(this IOpusDecoder decoder)
{
decoder.Ctl(GenericCTL.OPUS_RESET_STATE);
}
/// <summary>
/// Gets the final state of the codec's entropy coder.
/// </summary>
/// <param name="decoder">The decoder state.</param>
/// <returns>The final state of the codec's entropy coder.</returns>
/// <exception cref="OpusException" />
/// <exception cref="ObjectDisposedException" />
public static uint GetFinalRange(this IOpusDecoder decoder)
{
var finalRange = 0u;
decoder.Ctl(GenericCTL.OPUS_GET_FINAL_RANGE, ref finalRange);
return finalRange;
}
/// <summary>
/// Gets the decoder's last bandpass.
/// </summary>
/// <param name="decoder">The decoder state.</param>
/// <returns>The decoder's last bandpass.</returns>
/// <exception cref="OpusException" />
/// <exception cref="ObjectDisposedException" />
public static OpusPredefinedValues GetBandwidth(this IOpusDecoder decoder)
{
var bandPass = 0;
decoder.Ctl(GenericCTL.OPUS_GET_BANDWIDTH, ref bandPass);
return (OpusPredefinedValues)bandPass;
}
/// <summary>
/// Gets the sampling rate the decoder was initialized with.
/// </summary>
/// <param name="decoder">The decoder state.</param>
/// <returns>The decoder's configured sample rate.</returns>
/// <exception cref="OpusException" />
/// <exception cref="ObjectDisposedException" />
public static int GetSampleRate(this IOpusDecoder decoder)
{
var sampleRate = 0;
decoder.Ctl(GenericCTL.OPUS_GET_SAMPLE_RATE, ref sampleRate);
return sampleRate;
}
/// <summary>
/// If set to true, disables the use of phase inversion for intensity stereo, improving the quality of mono down-mixes, but slightly reducing normal stereo quality.
/// </summary>
/// <param name="decoder">The decoder state.</param>
/// <param name="disabled">Whether to disable or not.</param>
/// <exception cref="OpusException" />
/// <exception cref="ObjectDisposedException" />
public static void SetPhaseInversionDisabled(this IOpusDecoder decoder, bool disabled)
{
decoder.Ctl(GenericCTL.OPUS_SET_PHASE_INVERSION_DISABLED, disabled ? 1 : 0);
}
/// <summary>
/// Gets the decoder's configured phase inversion status.
/// </summary>
/// <param name="decoder">The decoder state.</param>
/// <returns>Whether the phase inversion is disabled or not.</returns>
/// <exception cref="OpusException" />
/// <exception cref="ObjectDisposedException" />
public static bool GetPhaseInversionDisabled(this IOpusDecoder decoder)
{
var disabled = 0;
decoder.Ctl(GenericCTL.OPUS_GET_PHASE_INVERSION_DISABLED, ref disabled);
return disabled == 1;
}
}
}