@@ -54,7 +54,15 @@ public Celt(int sampleRate, int bufferSize, int channels, bool decoderOnly)
5454 /// </summary>
5555 public void Dispose ( )
5656 {
57- xnCeltDestroy ( ) ;
57+ if ( encoder != null )
58+ opus_custom_encoder_destroy ( encoder ) ;
59+ encoder = null ;
60+ if ( decoder != null )
61+ opus_custom_decoder_destroy ( decoder ) ;
62+ decoder = null ;
63+ if ( mode != null )
64+ opus_custom_mode_destroy ( mode ) ;
65+ mode = null ;
5866 }
5967
6068 /// <summary>
@@ -70,7 +78,7 @@ public unsafe int Decode(byte[] inputBuffer, int inputBufferSize, short[] output
7078 fixed ( short * samplesPtr = outputSamples )
7179 fixed ( byte * bufferPtr = inputBuffer )
7280 {
73- return xnCeltDecodeShort ( decoder , bufferPtr , inputBufferSize , samplesPtr , outputSamples . Length / Channels ) ;
81+ return opus_custom_decode ( decoder , bufferPtr , inputBufferSize , samplesPtr , outputSamples . Length / Channels ) ;
7482 }
7583 }
7684
@@ -86,7 +94,7 @@ public unsafe int Decode(byte[] inputBuffer, int inputBufferSize, short* outputS
8694 Debug . Assert ( ( uint ) inputBufferSize <= ( uint ) inputBuffer . Length ) ;
8795 fixed ( byte * bufferPtr = inputBuffer )
8896 {
89- return xnCeltDecodeShort ( decoder , bufferPtr , inputBufferSize , outputSamples , BufferSize ) ;
97+ return opus_custom_decode ( decoder , bufferPtr , inputBufferSize , outputSamples , BufferSize ) ;
9098 }
9199 }
92100
@@ -95,7 +103,7 @@ public unsafe int Decode(byte[] inputBuffer, int inputBufferSize, short* outputS
95103 /// </summary>
96104 public void ResetDecoder ( )
97105 {
98- xnCeltResetDecoder ( decoder ) ;
106+ opus_custom_decoder_ctl ( decoder , ( int ) OpusRequest . ResetState ) ;
99107 }
100108
101109 /// <summary>
@@ -121,7 +129,7 @@ public unsafe int Encode(short[] audioSamples, byte[] outputBuffer)
121129 fixed ( short * samplesPtr = audioSamples )
122130 fixed ( byte * bufferPtr = outputBuffer )
123131 {
124- return xnCeltEncodeShort ( encoder , samplesPtr , audioSamples . Length / Channels , bufferPtr , outputBuffer . Length ) ;
132+ return opus_custom_encode ( encoder , samplesPtr , audioSamples . Length / Channels , bufferPtr , outputBuffer . Length ) ;
125133 }
126134 }
127135
@@ -137,7 +145,7 @@ public unsafe int Decode(byte[] inputBuffer, int inputBufferSize, float[] output
137145 fixed ( float * samplesPtr = outputSamples )
138146 fixed ( byte * bufferPtr = inputBuffer )
139147 {
140- return xnCeltDecodeFloat ( decoder , bufferPtr , inputBufferSize , samplesPtr , outputSamples . Length / Channels ) ;
148+ return opus_custom_decode_float ( decoder , bufferPtr , inputBufferSize , samplesPtr , outputSamples . Length / Channels ) ;
141149 }
142150 }
143151
@@ -152,7 +160,7 @@ public unsafe int Encode(float[] audioSamples, byte[] outputBuffer)
152160 fixed ( float * samplesPtr = audioSamples )
153161 fixed ( byte * bufferPtr = outputBuffer )
154162 {
155- return xnCeltEncodeFloat ( encoder , samplesPtr , audioSamples . Length / Channels , bufferPtr , outputBuffer . Length ) ;
163+ return opus_custom_encode_float ( encoder , samplesPtr , audioSamples . Length / Channels , bufferPtr , outputBuffer . Length ) ;
156164 }
157165 }
158166
@@ -205,48 +213,10 @@ private bool xnCeltCreate(int sampleRate, int bufferSize, int channels, bool dec
205213 [ DllImport ( "opus" , CallingConvention = CallingConvention . Cdecl ) ]
206214 private static extern int opus_custom_decode ( OpusCustomDecoder * decoder , byte * inputBuffer , int inputBufferSize , short * outputBuffer , int numberOfOutputSamples ) ;
207215
208- private void xnCeltDestroy ( )
209- {
210- if ( encoder != null )
211- opus_custom_encoder_destroy ( encoder ) ;
212- encoder = null ;
213- if ( decoder != null )
214- opus_custom_decoder_destroy ( decoder ) ;
215- decoder = null ;
216- if ( mode != null )
217- opus_custom_mode_destroy ( mode ) ;
218- mode = null ;
219- }
220-
221- private static int xnCeltResetDecoder ( OpusCustomDecoder * decoder )
222- {
223- return opus_custom_decoder_ctl ( decoder , ( int ) OpusRequest . ResetState ) ;
224- }
225-
226216 private static int xnCeltGetDecoderSampleDelay ( OpusCustomDecoder * decoder , ref int delay )
227217 {
228218 return opus_custom_decoder_ctl ( decoder , ( int ) OpusRequest . LookAhead , delay ) ;
229219 }
230-
231- private static unsafe int xnCeltEncodeFloat ( OpusCustomEncoder * encoder , float * inputSamples , int numberOfInputSamples , byte * outputBuffer , int maxOutputSize )
232- {
233- return opus_custom_encode_float ( encoder , inputSamples , numberOfInputSamples , outputBuffer , maxOutputSize ) ;
234- }
235-
236- private static unsafe int xnCeltDecodeFloat ( OpusCustomDecoder * decoder , byte * inputBuffer , int inputBufferSize , float * outputBuffer , int numberOfOutputSamples )
237- {
238- return opus_custom_decode_float ( decoder , inputBuffer , inputBufferSize , outputBuffer , numberOfOutputSamples ) ;
239- }
240-
241- private static unsafe int xnCeltEncodeShort ( OpusCustomEncoder * encoder , short * inputSamples , int numberOfInputSamples , byte * outputBuffer , int maxOutputSize )
242- {
243- return opus_custom_encode ( encoder , inputSamples , numberOfInputSamples , outputBuffer , maxOutputSize ) ;
244- }
245-
246- private static unsafe int xnCeltDecodeShort ( OpusCustomDecoder * decoder , byte * inputBuffer , int inputBufferSize , short * outputBuffer , int numberOfOutputSamples )
247- {
248- return opus_custom_decode ( decoder , inputBuffer , inputBufferSize , outputBuffer , numberOfOutputSamples ) ;
249- }
250220 }
251221
252222 internal enum OpusRequest
0 commit comments