From 0a77c3e56e7189302814b0a60ae9cb527dc65d4a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E2=AD=90=EF=B8=8FNINIKA=E2=AD=90=EF=B8=8F?=
 <dcnick3@users.noreply.github.com>
Date: Fri, 28 Jun 2024 21:29:49 +0300
Subject: [PATCH] refactor: replace pointers to OpusDecoder with mutable
 references

---
 src/celt/bands.rs                        |   2 +-
 src/celt/celt_decoder.rs                 |   8 +-
 src/celt/celt_encoder.rs                 |  10 +-
 src/celt/quant_bands.rs                  |   2 +-
 src/lib.rs                               |   8 +-
 src/silk/CNG.rs                          |  10 +-
 src/silk/decode_indices.rs               |  11 +-
 src/silk/enc_API.rs                      |   4 +-
 src/silk/encode_indices.rs               |  14 +-
 src/silk/float/encode_frame_FLP.rs       |   8 +-
 src/src/opus_decoder.rs                  | 300 +++++++++++------------
 src/src/opus_multistream_decoder.rs      |  18 +-
 tests/opus_api.rs                        |  69 ++++--
 tests/opus_decode.rs                     |  98 ++++----
 tests/opus_encode/main.rs                |  33 +--
 tests/opus_padding.rs                    |   3 +-
 unsafe-libopus-tools/src/demo/backend.rs |   4 +-
 17 files changed, 309 insertions(+), 293 deletions(-)

diff --git a/src/celt/bands.rs b/src/celt/bands.rs
index 2b32b9d..b37085e 100644
--- a/src/celt/bands.rs
+++ b/src/celt/bands.rs
@@ -1976,7 +1976,7 @@ pub unsafe fn quant_all_bands(
                         );
                     }
                     nstart_bytes = ec_save.offs as i32;
-                    nend_bytes = (*ec).storage as i32;
+                    nend_bytes = ec.storage as i32;
                     bytes_buf = ec.buf.as_ptr().offset(nstart_bytes as isize);
                     save_bytes = nend_bytes - nstart_bytes;
                     memcpy(
diff --git a/src/celt/celt_decoder.rs b/src/celt/celt_decoder.rs
index 87bade1..20ef006 100644
--- a/src/celt/celt_decoder.rs
+++ b/src/celt/celt_decoder.rs
@@ -1032,7 +1032,7 @@ pub unsafe fn celt_decode_with_ec(
     }
     if silence != 0 {
         tell = len * 8;
-        (*dec).nbits_total += tell - ec_tell(dec);
+        dec.nbits_total += tell - ec_tell(dec);
     }
     postfilter_gain = 0 as opus_val16;
     postfilter_pitch = 0;
@@ -1411,7 +1411,7 @@ pub unsafe fn celt_decode_with_ec(
             break;
         }
     }
-    (*st).rng = (*dec).rng;
+    (*st).rng = dec.rng;
     deemphasis(
         out_syn.as_mut_ptr(),
         pcm,
@@ -1441,7 +1441,7 @@ pub unsafe fn opus_custom_decoder_ctl_impl(
     match request {
         CELT_SET_START_BAND_REQUEST => {
             let value: i32 = ap.arg::<i32>();
-            if value < 0 || value >= (*(*st).mode).nbEBands as i32 {
+            if value < 0 || value >= (*st).mode.nbEBands as i32 {
                 current_block = 7990025728955927862;
             } else {
                 (*st).start = value;
@@ -1450,7 +1450,7 @@ pub unsafe fn opus_custom_decoder_ctl_impl(
         }
         CELT_SET_END_BAND_REQUEST => {
             let value_0: i32 = ap.arg::<i32>();
-            if value_0 < 1 || value_0 > (*(*st).mode).nbEBands as i32 {
+            if value_0 < 1 || value_0 > (*st).mode.nbEBands as i32 {
                 current_block = 7990025728955927862;
             } else {
                 (*st).end = value_0;
diff --git a/src/celt/celt_encoder.rs b/src/celt/celt_encoder.rs
index 6a166de..a8f9b49 100644
--- a/src/celt/celt_encoder.rs
+++ b/src/celt/celt_encoder.rs
@@ -839,7 +839,7 @@ unsafe fn tf_encode(
     let mut logp: i32 = 0;
     let mut budget: u32 = 0;
     let mut tell: u32 = 0;
-    budget = ((*enc).storage).wrapping_mul(8);
+    budget = enc.storage.wrapping_mul(8);
     tell = ec_tell(enc) as u32;
     logp = if isTransient != 0 { 2 } else { 4 };
     tf_select_rsv = (LM > 0 && tell.wrapping_add(logp as u32).wrapping_add(1) <= budget) as i32;
@@ -2045,8 +2045,8 @@ pub unsafe fn celt_encode_with_ec(
     oldLogE2 = oldLogE.offset((CC * nbEBands) as isize);
     energyError = oldLogE2.offset((CC * nbEBands) as isize);
     if let Some(enc) = enc.as_mut() {
-        tell0_frac = ec_tell_frac(*enc) as i32;
-        tell = ec_tell(*enc);
+        tell0_frac = ec_tell_frac(enc) as i32;
+        tell = ec_tell(enc);
         nbFilledBytes = tell + 4 >> 3;
     } else {
         tell = 1;
@@ -2187,7 +2187,7 @@ pub unsafe fn celt_encode_with_ec(
             ec_enc_shrink(enc, nbCompressedBytes as u32);
         }
         tell = nbCompressedBytes * 8;
-        (*enc).nbits_total += tell - ec_tell(enc);
+        enc.nbits_total += tell - ec_tell(enc);
     }
     c = 0;
     loop {
@@ -3293,7 +3293,7 @@ pub unsafe fn celt_encode_with_ec(
     } else {
         (*st).consec_transient = 0;
     }
-    (*st).rng = (*enc).rng;
+    (*st).rng = enc.rng;
     ec_enc_done(enc);
     if ec_get_error(enc) != 0 {
         return OPUS_INTERNAL_ERROR;
diff --git a/src/celt/quant_bands.rs b/src/celt/quant_bands.rs
index 90741a9..aa033d7 100644
--- a/src/celt/quant_bands.rs
+++ b/src/celt/quant_bands.rs
@@ -563,7 +563,7 @@ pub unsafe fn unquant_coarse_energy(
         beta = beta_coef[LM as usize];
         coef = pred_coef[LM as usize];
     }
-    budget = ((*dec).storage).wrapping_mul(8) as i32;
+    budget = dec.storage.wrapping_mul(8) as i32;
     i = start;
     while i < end {
         c = 0;
diff --git a/src/lib.rs b/src/lib.rs
index 659caf5..594cec9 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -188,9 +188,13 @@ pub use crate::src::opus_encoder::{
     opus_encoder_destroy, opus_encoder_get_size, opus_encoder_init, OpusEncoder,
 };
 // opus_decoder
+#[allow(deprecated)]
 pub use crate::src::opus_decoder::{
-    opus_decode, opus_decode_float, opus_decoder_create, opus_decoder_ctl_impl,
-    opus_decoder_destroy, opus_decoder_get_nb_samples, opus_decoder_get_size, opus_decoder_init,
+    opus_decoder_create, opus_decoder_destroy, opus_decoder_get_size, opus_decoder_init,
+};
+
+pub use crate::src::opus_decoder::{
+    opus_decode, opus_decode_float, opus_decoder_ctl_impl, opus_decoder_get_nb_samples,
     opus_packet_get_bandwidth, opus_packet_get_nb_channels, opus_packet_get_nb_frames,
     opus_packet_get_nb_samples, OpusDecoder,
 };
diff --git a/src/silk/CNG.rs b/src/silk/CNG.rs
index eacae4a..25de04a 100644
--- a/src/silk/CNG.rs
+++ b/src/silk/CNG.rs
@@ -34,16 +34,16 @@ pub fn silk_CNG_Reset(psDec: &mut silk_decoder_state) {
     let mut i: i32 = 0;
     let mut NLSF_step_Q15: i32 = 0;
     let mut NLSF_acc_Q15: i32 = 0;
-    NLSF_step_Q15 = 0x7fff / ((*psDec).LPC_order + 1);
+    NLSF_step_Q15 = 0x7fff / (psDec.LPC_order + 1);
     NLSF_acc_Q15 = 0;
     i = 0;
-    while i < (*psDec).LPC_order {
+    while i < psDec.LPC_order {
         NLSF_acc_Q15 += NLSF_step_Q15;
-        (*psDec).sCNG.CNG_smth_NLSF_Q15[i as usize] = NLSF_acc_Q15 as i16;
+        psDec.sCNG.CNG_smth_NLSF_Q15[i as usize] = NLSF_acc_Q15 as i16;
         i += 1;
     }
-    (*psDec).sCNG.CNG_smth_Gain_Q16 = 0;
-    (*psDec).sCNG.rand_seed = 3176576;
+    psDec.sCNG.CNG_smth_Gain_Q16 = 0;
+    psDec.sCNG.rand_seed = 3176576;
 }
 pub unsafe fn silk_CNG(
     psDec: *mut silk_decoder_state,
diff --git a/src/silk/decode_indices.rs b/src/silk/decode_indices.rs
index 269e1b8..8889e90 100644
--- a/src/silk/decode_indices.rs
+++ b/src/silk/decode_indices.rs
@@ -56,9 +56,8 @@ pub unsafe fn silk_decode_indices(
     }
     (*psDec).indices.NLSFIndices[0 as usize] = ec_dec_icdf(
         psRangeDec,
-        &(*(*psDec).psNLSF_CB).CB1_iCDF[(((*psDec).indices.signalType as i32 >> 1)
-            * (*(*psDec).psNLSF_CB).nVectors as i32)
-            as usize..],
+        &(*psDec).psNLSF_CB.CB1_iCDF[(((*psDec).indices.signalType as i32 >> 1)
+            * (*psDec).psNLSF_CB.nVectors as i32) as usize..],
         8,
     ) as i8;
     silk_NLSF_unpack(
@@ -67,12 +66,12 @@ pub unsafe fn silk_decode_indices(
         (*psDec).psNLSF_CB,
         (*psDec).indices.NLSFIndices[0 as usize] as i32,
     );
-    assert!((*(*psDec).psNLSF_CB).order as i32 == (*psDec).LPC_order);
+    assert!((*psDec).psNLSF_CB.order as i32 == (*psDec).LPC_order);
     i = 0;
-    while i < (*(*psDec).psNLSF_CB).order as i32 {
+    while i < (*psDec).psNLSF_CB.order as i32 {
         Ix = ec_dec_icdf(
             psRangeDec,
-            &(*(*psDec).psNLSF_CB).ec_iCDF[*ec_ix.as_mut_ptr().offset(i as isize) as usize..],
+            &(*psDec).psNLSF_CB.ec_iCDF[*ec_ix.as_mut_ptr().offset(i as isize) as usize..],
             8,
         );
         if Ix == 0 {
diff --git a/src/silk/enc_API.rs b/src/silk/enc_API.rs
index f76f82f..8a78db3 100644
--- a/src/silk/enc_API.rs
+++ b/src/silk/enc_API.rs
@@ -565,7 +565,7 @@ pub unsafe fn silk_Encode(
         }
         TargetRate_bps -= (*psEnc).nBitsExceeded * 1000 / 500;
         if prefillFlag == 0 && (*psEnc).state_Fxx[0 as usize].sCmn.nFramesEncoded > 0 {
-            let bitsBalance: i32 = ec_tell(&mut **psRangeEnc.as_mut().unwrap())
+            let bitsBalance: i32 = ec_tell(psRangeEnc.as_mut().unwrap())
                 - (*psEnc).nBitsUsedLBRR
                 - nBits * (*psEnc).state_Fxx[0 as usize].sCmn.nFramesEncoded;
             TargetRate_bps -= bitsBalance * 1000 / 500;
@@ -791,7 +791,7 @@ pub unsafe fn silk_Encode(
             }
             if prefillFlag == 0 {
                 ec_enc_patch_initial_bits(
-                    &mut **psRangeEnc.as_mut().unwrap(),
+                    psRangeEnc.as_mut().unwrap(),
                     flags as u32,
                     (((*psEnc).state_Fxx[0 as usize].sCmn.nFramesPerPacket + 1)
                         * (*encControl).nChannelsInternal) as u32,
diff --git a/src/silk/encode_indices.rs b/src/silk/encode_indices.rs
index 4361682..e227da3 100644
--- a/src/silk/encode_indices.rs
+++ b/src/silk/encode_indices.rs
@@ -77,8 +77,8 @@ pub unsafe fn silk_encode_indices(
     ec_enc_icdf(
         psRangeEnc,
         (*psIndices).NLSFIndices[0 as usize] as i32,
-        &(*(*psEncC).psNLSF_CB).CB1_iCDF[(((*psIndices).signalType as i32 >> 1)
-            * (*(*psEncC).psNLSF_CB).nVectors as i32)
+        &(*psEncC).psNLSF_CB.CB1_iCDF[(((*psIndices).signalType as i32 >> 1)
+            * (*psEncC).psNLSF_CB.nVectors as i32)
             as usize..],
         8,
     );
@@ -88,14 +88,14 @@ pub unsafe fn silk_encode_indices(
         (*psEncC).psNLSF_CB,
         (*psIndices).NLSFIndices[0 as usize] as i32,
     );
-    assert!((*(*psEncC).psNLSF_CB).order as i32 == (*psEncC).predictLPCOrder);
+    assert!((*psEncC).psNLSF_CB.order as i32 == (*psEncC).predictLPCOrder);
     i = 0;
-    while i < (*(*psEncC).psNLSF_CB).order as i32 {
+    while i < (*psEncC).psNLSF_CB.order as i32 {
         if (*psIndices).NLSFIndices[(i + 1) as usize] as i32 >= NLSF_QUANT_MAX_AMPLITUDE {
             ec_enc_icdf(
                 psRangeEnc,
                 2 * NLSF_QUANT_MAX_AMPLITUDE,
-                &(*(*psEncC).psNLSF_CB).ec_iCDF[*ec_ix.as_mut_ptr().offset(i as isize) as usize..],
+                &(*psEncC).psNLSF_CB.ec_iCDF[*ec_ix.as_mut_ptr().offset(i as isize) as usize..],
                 8,
             );
             ec_enc_icdf(
@@ -108,7 +108,7 @@ pub unsafe fn silk_encode_indices(
             ec_enc_icdf(
                 psRangeEnc,
                 0,
-                &(*(*psEncC).psNLSF_CB).ec_iCDF[*ec_ix.as_mut_ptr().offset(i as isize) as usize..],
+                &(*psEncC).psNLSF_CB.ec_iCDF[*ec_ix.as_mut_ptr().offset(i as isize) as usize..],
                 8,
             );
             ec_enc_icdf(
@@ -121,7 +121,7 @@ pub unsafe fn silk_encode_indices(
             ec_enc_icdf(
                 psRangeEnc,
                 (*psIndices).NLSFIndices[(i + 1) as usize] as i32 + NLSF_QUANT_MAX_AMPLITUDE,
-                &(*(*psEncC).psNLSF_CB).ec_iCDF[*ec_ix.as_mut_ptr().offset(i as isize) as usize..],
+                &(*psEncC).psNLSF_CB.ec_iCDF[*ec_ix.as_mut_ptr().offset(i as isize) as usize..],
                 8,
             );
         }
diff --git a/src/silk/float/encode_frame_FLP.rs b/src/silk/float/encode_frame_FLP.rs
index 35e9684..de9a4d3 100644
--- a/src/silk/float/encode_frame_FLP.rs
+++ b/src/silk/float/encode_frame_FLP.rs
@@ -295,7 +295,7 @@ pub unsafe fn silk_encode_frame_FLP(
                     psRangeEnc.restore(sRangeEnc_copy2);
                     assert!(sRangeEnc_copy2.offs <= 1275);
                     memcpy(
-                        (*psRangeEnc).buf.as_mut_ptr() as *mut core::ffi::c_void,
+                        psRangeEnc.buf.as_mut_ptr() as *mut core::ffi::c_void,
                         ec_buf_copy.as_mut_ptr() as *const core::ffi::c_void,
                         sRangeEnc_copy2.offs as u64,
                     );
@@ -334,11 +334,11 @@ pub unsafe fn silk_encode_frame_FLP(
                     if gainsID != gainsID_lower {
                         gainsID_lower = gainsID;
                         sRangeEnc_copy2 = psRangeEnc.save();
-                        assert!((*psRangeEnc).offs <= 1275);
+                        assert!(psRangeEnc.offs <= 1275);
                         memcpy(
                             ec_buf_copy.as_mut_ptr() as *mut core::ffi::c_void,
-                            (*psRangeEnc).buf.as_mut_ptr() as *const core::ffi::c_void,
-                            (*psRangeEnc).offs as u64,
+                            psRangeEnc.buf.as_mut_ptr() as *const core::ffi::c_void,
+                            psRangeEnc.offs as u64,
                         );
                         memcpy(
                             &mut sNSQ_copy2 as *mut silk_nsq_state as *mut core::ffi::c_void,
diff --git a/src/src/opus_decoder.rs b/src/src/opus_decoder.rs
index f55d085..83916c0 100644
--- a/src/src/opus_decoder.rs
+++ b/src/src/opus_decoder.rs
@@ -26,7 +26,6 @@ use crate::celt::entdec::{ec_dec_bit_logp, ec_dec_init, ec_dec_uint};
 use crate::celt::float_cast::FLOAT2INT16;
 use crate::celt::mathops::celt_exp2;
 use crate::celt::modes::OpusCustomMode;
-use crate::externs::memset;
 use crate::silk::dec_API::{silk_DecControlStruct, silk_decoder};
 use crate::silk::dec_API::{silk_Decode, silk_InitDecoder};
 use crate::src::opus::opus_packet_parse_impl;
@@ -103,35 +102,29 @@ impl OpusDecoder {
 }
 
 unsafe fn validate_opus_decoder(st: &OpusDecoder) {
-    assert!((*st).channels == 1 || (*st).channels == 2);
+    assert!(st.channels == 1 || st.channels == 2);
+    assert!(st.Fs == 48000 || st.Fs == 24000 || st.Fs == 16000 || st.Fs == 12000 || st.Fs == 8000);
+    assert!(st.DecControl.API_sampleRate == st.Fs);
     assert!(
-        (*st).Fs == 48000
-            || (*st).Fs == 24000
-            || (*st).Fs == 16000
-            || (*st).Fs == 12000
-            || (*st).Fs == 8000
+        st.DecControl.internalSampleRate == 0
+            || st.DecControl.internalSampleRate == 16000
+            || st.DecControl.internalSampleRate == 12000
+            || st.DecControl.internalSampleRate == 8000
     );
-    assert!((*st).DecControl.API_sampleRate == (*st).Fs);
+    assert!(st.DecControl.nChannelsAPI == st.channels);
     assert!(
-        (*st).DecControl.internalSampleRate == 0
-            || (*st).DecControl.internalSampleRate == 16000
-            || (*st).DecControl.internalSampleRate == 12000
-            || (*st).DecControl.internalSampleRate == 8000
+        st.DecControl.nChannelsInternal == 0
+            || st.DecControl.nChannelsInternal == 1
+            || st.DecControl.nChannelsInternal == 2
     );
-    assert!((*st).DecControl.nChannelsAPI == (*st).channels);
     assert!(
-        (*st).DecControl.nChannelsInternal == 0
-            || (*st).DecControl.nChannelsInternal == 1
-            || (*st).DecControl.nChannelsInternal == 2
+        st.DecControl.payloadSize_ms == 0
+            || st.DecControl.payloadSize_ms == 10
+            || st.DecControl.payloadSize_ms == 20
+            || st.DecControl.payloadSize_ms == 40
+            || st.DecControl.payloadSize_ms == 60
     );
-    assert!(
-        (*st).DecControl.payloadSize_ms == 0
-            || (*st).DecControl.payloadSize_ms == 10
-            || (*st).DecControl.payloadSize_ms == 20
-            || (*st).DecControl.payloadSize_ms == 40
-            || (*st).DecControl.payloadSize_ms == 60
-    );
-    assert!((*st).stream_channels == 1 || (*st).stream_channels == 2);
+    assert!(st.stream_channels == 1 || st.stream_channels == 2);
 }
 #[deprecated]
 pub fn opus_decoder_get_size(channels: i32) -> i32 {
@@ -153,6 +146,7 @@ pub unsafe fn opus_decoder_init(st: *mut OpusDecoder, Fs: i32, channels: i32) ->
     }
 }
 #[deprecated]
+#[allow(deprecated)]
 pub unsafe fn opus_decoder_create(Fs: i32, channels: i32, error: *mut i32) -> *mut OpusDecoder {
     let mut st: *mut OpusDecoder = 0 as *mut OpusDecoder;
     if Fs != 48000 && Fs != 24000 && Fs != 16000 && Fs != 12000 && Fs != 8000
@@ -217,7 +211,7 @@ unsafe fn opus_packet_get_mode(data: *const u8) -> i32 {
     return mode;
 }
 unsafe fn opus_decode_frame(
-    st: *mut OpusDecoder,
+    st: &mut OpusDecoder,
     mut data: *const u8,
     mut len: i32,
     mut pcm: *mut opus_val16,
@@ -263,42 +257,41 @@ unsafe fn opus_decode_frame(
     let mut window: *const opus_val16 = 0 as *const opus_val16;
     let mut redundant_rng: u32 = 0;
     let mut celt_accum: i32 = 0;
-    let celt_dec = &mut (*st).celt_dec;
-    F20 = (*st).Fs / 50;
+    F20 = st.Fs / 50;
     F10 = F20 >> 1;
     F5 = F10 >> 1;
     F2_5 = F5 >> 1;
     if frame_size < F2_5 {
         return OPUS_BUFFER_TOO_SMALL;
     }
-    frame_size = if frame_size < (*st).Fs / 25 * 3 {
+    frame_size = if frame_size < st.Fs / 25 * 3 {
         frame_size
     } else {
-        (*st).Fs / 25 * 3
+        st.Fs / 25 * 3
     };
     if len <= 1 {
         data = NULL as *const u8;
-        frame_size = if frame_size < (*st).frame_size {
+        frame_size = if frame_size < st.frame_size {
             frame_size
         } else {
-            (*st).frame_size
+            st.frame_size
         };
     }
     if !data.is_null() {
-        audiosize = (*st).frame_size;
-        mode = (*st).mode;
-        bandwidth = (*st).bandwidth;
+        audiosize = st.frame_size;
+        mode = st.mode;
+        bandwidth = st.bandwidth;
         dec = ec_dec_init(std::slice::from_raw_parts_mut(
             data as *mut u8,
             len as usize,
         ));
     } else {
         audiosize = frame_size;
-        mode = (*st).prev_mode;
+        mode = st.prev_mode;
         bandwidth = 0;
         if mode == 0 {
             i = 0;
-            while i < audiosize * (*st).channels {
+            while i < audiosize * st.channels {
                 *pcm.offset(i as isize) = 0 as opus_val16;
                 i += 1;
             }
@@ -317,7 +310,7 @@ unsafe fn opus_decode_frame(
                 if ret < 0 {
                     return ret;
                 }
-                pcm = pcm.offset((ret * (*st).channels) as isize);
+                pcm = pcm.offset((ret * st.channels) as isize);
                 audiosize -= ret;
                 if !(audiosize > 0) {
                     break;
@@ -338,17 +331,15 @@ unsafe fn opus_decode_frame(
     pcm_transition_silk_size = ALLOC_NONE;
     pcm_transition_celt_size = ALLOC_NONE;
     if !data.is_null()
-        && (*st).prev_mode > 0
-        && (mode == MODE_CELT_ONLY
-            && (*st).prev_mode != MODE_CELT_ONLY
-            && (*st).prev_redundancy == 0
-            || mode != MODE_CELT_ONLY && (*st).prev_mode == MODE_CELT_ONLY)
+        && st.prev_mode > 0
+        && (mode == MODE_CELT_ONLY && st.prev_mode != MODE_CELT_ONLY && st.prev_redundancy == 0
+            || mode != MODE_CELT_ONLY && st.prev_mode == MODE_CELT_ONLY)
     {
         transition = 1;
         if mode == MODE_CELT_ONLY {
-            pcm_transition_celt_size = F5 * (*st).channels;
+            pcm_transition_celt_size = F5 * st.channels;
         } else {
-            pcm_transition_silk_size = F5 * (*st).channels;
+            pcm_transition_silk_size = F5 * st.channels;
         }
     }
     let vla = pcm_transition_celt_size as usize;
@@ -370,7 +361,7 @@ unsafe fn opus_decode_frame(
         frame_size = audiosize;
     }
     pcm_silk_size = if mode != MODE_CELT_ONLY && celt_accum == 0 {
-        (if F10 > frame_size { F10 } else { frame_size }) * (*st).channels
+        (if F10 > frame_size { F10 } else { frame_size }) * st.channels
     } else {
         ALLOC_NONE
     };
@@ -381,29 +372,29 @@ unsafe fn opus_decode_frame(
         let mut decoded_samples: i32 = 0;
         let mut pcm_ptr: *mut i16 = 0 as *mut i16;
         pcm_ptr = pcm_silk.as_mut_ptr();
-        if (*st).prev_mode == MODE_CELT_ONLY {
-            (*st).silk_dec = silk_InitDecoder();
+        if st.prev_mode == MODE_CELT_ONLY {
+            st.silk_dec = silk_InitDecoder();
         }
-        (*st).DecControl.payloadSize_ms = if 10 > 1000 * audiosize / (*st).Fs {
+        st.DecControl.payloadSize_ms = if 10 > 1000 * audiosize / st.Fs {
             10
         } else {
-            1000 * audiosize / (*st).Fs
+            1000 * audiosize / st.Fs
         };
         if !data.is_null() {
-            (*st).DecControl.nChannelsInternal = (*st).stream_channels;
+            st.DecControl.nChannelsInternal = st.stream_channels;
             if mode == MODE_SILK_ONLY {
                 if bandwidth == OPUS_BANDWIDTH_NARROWBAND {
-                    (*st).DecControl.internalSampleRate = 8000;
+                    st.DecControl.internalSampleRate = 8000;
                 } else if bandwidth == OPUS_BANDWIDTH_MEDIUMBAND {
-                    (*st).DecControl.internalSampleRate = 12000;
+                    st.DecControl.internalSampleRate = 12000;
                 } else if bandwidth == OPUS_BANDWIDTH_WIDEBAND {
-                    (*st).DecControl.internalSampleRate = 16000;
+                    st.DecControl.internalSampleRate = 16000;
                 } else {
-                    (*st).DecControl.internalSampleRate = 16000;
+                    st.DecControl.internalSampleRate = 16000;
                     panic!("libopus: assert(0) called");
                 }
             } else {
-                (*st).DecControl.internalSampleRate = 16000;
+                st.DecControl.internalSampleRate = 16000;
             }
         }
         lost_flag = if data.is_null() { 1 } else { 2 * decode_fec };
@@ -411,8 +402,8 @@ unsafe fn opus_decode_frame(
         loop {
             let first_frame: i32 = (decoded_samples == 0) as i32;
             silk_ret = silk_Decode(
-                &mut (*st).silk_dec,
-                &mut (*st).DecControl,
+                &mut st.silk_dec,
+                &mut st.DecControl,
                 lost_flag,
                 first_frame,
                 &mut dec,
@@ -424,7 +415,7 @@ unsafe fn opus_decode_frame(
                 if lost_flag != 0 {
                     silk_frame_size = frame_size;
                     i = 0;
-                    while i < frame_size * (*st).channels {
+                    while i < frame_size * st.channels {
                         *pcm_ptr.offset(i as isize) = 0;
                         i += 1;
                     }
@@ -432,7 +423,7 @@ unsafe fn opus_decode_frame(
                     return OPUS_INTERNAL_ERROR;
                 }
             }
-            pcm_ptr = pcm_ptr.offset((silk_frame_size * (*st).channels) as isize);
+            pcm_ptr = pcm_ptr.offset((silk_frame_size * st.channels) as isize);
             decoded_samples += silk_frame_size;
             if !(decoded_samples < frame_size) {
                 break;
@@ -443,7 +434,7 @@ unsafe fn opus_decode_frame(
     if decode_fec == 0
         && mode != MODE_CELT_ONLY
         && !data.is_null()
-        && ec_tell(&mut dec) + 17 + 20 * ((*st).mode == MODE_HYBRID) as i32 <= 8 * len
+        && ec_tell(&mut dec) + 17 + 20 * (st.mode == MODE_HYBRID) as i32 <= 8 * len
     {
         if mode == MODE_HYBRID {
             redundancy = ec_dec_bit_logp(&mut dec, 12);
@@ -486,6 +477,9 @@ unsafe fn opus_decode_frame(
             0,
         );
     }
+
+    let celt_dec = &mut st.celt_dec;
+
     if bandwidth != 0 {
         let mut endband: i32 = 21;
         match bandwidth {
@@ -507,9 +501,9 @@ unsafe fn opus_decode_frame(
         }
         assert!(opus_custom_decoder_ctl!(celt_dec, 10012, endband) == 0);
     }
-    assert!(opus_custom_decoder_ctl!(celt_dec, 10008, (*st).stream_channels) == 0);
+    assert!(opus_custom_decoder_ctl!(celt_dec, 10008, st.stream_channels) == 0);
     redundant_audio_size = if redundancy != 0 {
-        F5 * (*st).channels
+        F5 * st.channels
     } else {
         ALLOC_NONE
     };
@@ -531,7 +525,7 @@ unsafe fn opus_decode_frame(
     assert!(opus_custom_decoder_ctl!(celt_dec, 10010, start_band) == 0);
     if mode != MODE_SILK_ONLY {
         let celt_frame_size: i32 = if F20 < frame_size { F20 } else { frame_size };
-        if mode != (*st).prev_mode && (*st).prev_mode > 0 && (*st).prev_redundancy == 0 {
+        if mode != st.prev_mode && st.prev_mode > 0 && st.prev_redundancy == 0 {
             assert!(opus_custom_decoder_ctl!(celt_dec, 4028) == 0);
         }
         celt_ret = celt_decode_with_ec(
@@ -551,13 +545,13 @@ unsafe fn opus_decode_frame(
         let mut silence: [u8; 2] = [0xff, 0xff];
         if celt_accum == 0 {
             i = 0;
-            while i < frame_size * (*st).channels {
+            while i < frame_size * st.channels {
                 *pcm.offset(i as isize) = 0 as opus_val16;
                 i += 1;
             }
         }
-        if (*st).prev_mode == MODE_HYBRID
-            && !(redundancy != 0 && celt_to_silk != 0 && (*st).prev_redundancy != 0)
+        if st.prev_mode == MODE_HYBRID
+            && !(redundancy != 0 && celt_to_silk != 0 && st.prev_redundancy != 0)
         {
             assert!(opus_custom_decoder_ctl!(celt_dec, 10010, 0) == 0);
             celt_decode_with_ec(
@@ -573,7 +567,7 @@ unsafe fn opus_decode_frame(
     }
     if mode != MODE_CELT_ONLY && celt_accum == 0 {
         i = 0;
-        while i < frame_size * (*st).channels {
+        while i < frame_size * st.channels {
             *pcm.offset(i as isize) = *pcm.offset(i as isize)
                 + 1.0f32 / 32768.0f32 * *pcm_silk.as_mut_ptr().offset(i as isize) as i32 as f32;
             i += 1;
@@ -596,25 +590,25 @@ unsafe fn opus_decode_frame(
         );
         assert!(opus_custom_decoder_ctl!(celt_dec, 4031, &mut redundant_rng) == 0);
         smooth_fade(
-            pcm.offset(((*st).channels * (frame_size - F2_5)) as isize),
+            pcm.offset((st.channels * (frame_size - F2_5)) as isize),
             redundant_audio
                 .as_mut_ptr()
-                .offset(((*st).channels * F2_5) as isize),
-            pcm.offset(((*st).channels * (frame_size - F2_5)) as isize),
+                .offset((st.channels * F2_5) as isize),
+            pcm.offset((st.channels * (frame_size - F2_5)) as isize),
             F2_5,
-            (*st).channels,
+            st.channels,
             window,
-            (*st).Fs,
+            st.Fs,
         );
     }
     if redundancy != 0 && celt_to_silk != 0 {
         c = 0;
-        while c < (*st).channels {
+        while c < st.channels {
             i = 0;
             while i < F2_5 {
-                *pcm.offset(((*st).channels * i + c) as isize) = *redundant_audio
+                *pcm.offset((st.channels * i + c) as isize) = *redundant_audio
                     .as_mut_ptr()
-                    .offset(((*st).channels * i + c) as isize);
+                    .offset((st.channels * i + c) as isize);
                 i += 1;
             }
             c += 1;
@@ -622,48 +616,40 @@ unsafe fn opus_decode_frame(
         smooth_fade(
             redundant_audio
                 .as_mut_ptr()
-                .offset(((*st).channels * F2_5) as isize),
-            pcm.offset(((*st).channels * F2_5) as isize),
-            pcm.offset(((*st).channels * F2_5) as isize),
+                .offset((st.channels * F2_5) as isize),
+            pcm.offset((st.channels * F2_5) as isize),
+            pcm.offset((st.channels * F2_5) as isize),
             F2_5,
-            (*st).channels,
+            st.channels,
             window,
-            (*st).Fs,
+            st.Fs,
         );
     }
     if transition != 0 {
         if audiosize >= F5 {
             i = 0;
-            while i < (*st).channels * F2_5 {
+            while i < st.channels * F2_5 {
                 *pcm.offset(i as isize) = *pcm_transition.offset(i as isize);
                 i += 1;
             }
             smooth_fade(
-                pcm_transition.offset(((*st).channels * F2_5) as isize),
-                pcm.offset(((*st).channels * F2_5) as isize),
-                pcm.offset(((*st).channels * F2_5) as isize),
+                pcm_transition.offset((st.channels * F2_5) as isize),
+                pcm.offset((st.channels * F2_5) as isize),
+                pcm.offset((st.channels * F2_5) as isize),
                 F2_5,
-                (*st).channels,
+                st.channels,
                 window,
-                (*st).Fs,
+                st.Fs,
             );
         } else {
-            smooth_fade(
-                pcm_transition,
-                pcm,
-                pcm,
-                F2_5,
-                (*st).channels,
-                window,
-                (*st).Fs,
-            );
+            smooth_fade(pcm_transition, pcm, pcm, F2_5, st.channels, window, st.Fs);
         }
     }
-    if (*st).decode_gain != 0 {
+    if st.decode_gain != 0 {
         let mut gain: opus_val32 = 0.;
-        gain = celt_exp2(6.48814081e-4f32 * (*st).decode_gain as f32);
+        gain = celt_exp2(6.48814081e-4f32 * st.decode_gain as f32);
         i = 0;
-        while i < frame_size * (*st).channels {
+        while i < frame_size * st.channels {
             let mut x: opus_val32 = 0.;
             x = *pcm.offset(i as isize) * gain;
             *pcm.offset(i as isize) = x;
@@ -671,19 +657,19 @@ unsafe fn opus_decode_frame(
         }
     }
     if len <= 1 {
-        (*st).rangeFinal = 0;
+        st.rangeFinal = 0;
     } else {
-        (*st).rangeFinal = dec.rng ^ redundant_rng;
+        st.rangeFinal = dec.rng ^ redundant_rng;
     }
-    (*st).prev_mode = mode;
-    (*st).prev_redundancy = (redundancy != 0 && celt_to_silk == 0) as i32;
+    st.prev_mode = mode;
+    st.prev_redundancy = (redundancy != 0 && celt_to_silk == 0) as i32;
     if celt_ret >= 0 {
         let _ = _opus_false() != 0;
     }
     return if celt_ret < 0 { celt_ret } else { audiosize };
 }
 pub unsafe fn opus_decode_native(
-    st: *mut OpusDecoder,
+    st: &mut OpusDecoder,
     mut data: *const u8,
     len: i32,
     pcm: *mut opus_val16,
@@ -707,7 +693,7 @@ pub unsafe fn opus_decode_native(
     if decode_fec < 0 || decode_fec > 1 {
         return OPUS_BAD_ARG;
     }
-    if (decode_fec != 0 || len == 0 || data.is_null()) && frame_size % ((*st).Fs / 400) != 0 {
+    if (decode_fec != 0 || len == 0 || data.is_null()) && frame_size % (st.Fs / 400) != 0 {
         return OPUS_BAD_ARG;
     }
     if len == 0 || data.is_null() {
@@ -718,7 +704,7 @@ pub unsafe fn opus_decode_native(
                 st,
                 NULL as *const u8,
                 0,
-                pcm.offset((pcm_count * (*st).channels) as isize),
+                pcm.offset((pcm_count * st.channels) as isize),
                 frame_size - pcm_count,
                 0,
             );
@@ -732,7 +718,7 @@ pub unsafe fn opus_decode_native(
         }
         assert!(pcm_count == frame_size);
         let _ = _opus_false() != 0;
-        (*st).last_packet_duration = pcm_count;
+        st.last_packet_duration = pcm_count;
         return pcm_count;
     } else {
         if len < 0 {
@@ -741,7 +727,7 @@ pub unsafe fn opus_decode_native(
     }
     packet_mode = opus_packet_get_mode(data);
     packet_bandwidth = opus_packet_get_bandwidth(data);
-    packet_frame_size = opus_packet_get_samples_per_frame(data, (*st).Fs);
+    packet_frame_size = opus_packet_get_samples_per_frame(data, st.Fs);
     packet_stream_channels = opus_packet_get_nb_channels(data);
     count = opus_packet_parse_impl(
         data,
@@ -762,7 +748,7 @@ pub unsafe fn opus_decode_native(
         let mut ret_0: i32 = 0;
         if frame_size < packet_frame_size
             || packet_mode == MODE_CELT_ONLY
-            || (*st).mode == MODE_CELT_ONLY
+            || st.mode == MODE_CELT_ONLY
         {
             return opus_decode_native(
                 st,
@@ -776,7 +762,7 @@ pub unsafe fn opus_decode_native(
                 soft_clip,
             );
         }
-        duration_copy = (*st).last_packet_duration;
+        duration_copy = st.last_packet_duration;
         if frame_size - packet_frame_size != 0 {
             ret_0 = opus_decode_native(
                 st,
@@ -790,20 +776,20 @@ pub unsafe fn opus_decode_native(
                 soft_clip,
             );
             if ret_0 < 0 {
-                (*st).last_packet_duration = duration_copy;
+                st.last_packet_duration = duration_copy;
                 return ret_0;
             }
             assert!(ret_0 == frame_size - packet_frame_size);
         }
-        (*st).mode = packet_mode;
-        (*st).bandwidth = packet_bandwidth;
-        (*st).frame_size = packet_frame_size;
-        (*st).stream_channels = packet_stream_channels;
+        st.mode = packet_mode;
+        st.bandwidth = packet_bandwidth;
+        st.frame_size = packet_frame_size;
+        st.stream_channels = packet_stream_channels;
         ret_0 = opus_decode_frame(
             st,
             data,
             size[0 as usize] as i32,
-            pcm.offset(((*st).channels * (frame_size - packet_frame_size)) as isize),
+            pcm.offset((st.channels * (frame_size - packet_frame_size)) as isize),
             packet_frame_size,
             1,
         );
@@ -811,17 +797,17 @@ pub unsafe fn opus_decode_native(
             return ret_0;
         } else {
             let _ = _opus_false() != 0;
-            (*st).last_packet_duration = frame_size;
+            st.last_packet_duration = frame_size;
             return frame_size;
         }
     }
     if count * packet_frame_size > frame_size {
         return OPUS_BUFFER_TOO_SMALL;
     }
-    (*st).mode = packet_mode;
-    (*st).bandwidth = packet_bandwidth;
-    (*st).frame_size = packet_frame_size;
-    (*st).stream_channels = packet_stream_channels;
+    st.mode = packet_mode;
+    st.bandwidth = packet_bandwidth;
+    st.frame_size = packet_frame_size;
+    st.stream_channels = packet_stream_channels;
     nb_samples = 0;
     i = 0;
     while i < count {
@@ -830,7 +816,7 @@ pub unsafe fn opus_decode_native(
             st,
             data,
             size[i as usize] as i32,
-            pcm.offset((nb_samples * (*st).channels) as isize),
+            pcm.offset((nb_samples * st.channels) as isize),
             frame_size - nb_samples,
             0,
         );
@@ -842,23 +828,18 @@ pub unsafe fn opus_decode_native(
         nb_samples += ret_1;
         i += 1;
     }
-    (*st).last_packet_duration = nb_samples;
+    st.last_packet_duration = nb_samples;
     let _ = _opus_false() != 0;
     if soft_clip != 0 {
-        opus_pcm_soft_clip(
-            pcm,
-            nb_samples,
-            (*st).channels,
-            ((*st).softclip_mem).as_mut_ptr(),
-        );
+        opus_pcm_soft_clip(pcm, nb_samples, st.channels, st.softclip_mem.as_mut_ptr());
     } else {
-        (*st).softclip_mem[1 as usize] = 0 as opus_val16;
-        (*st).softclip_mem[0 as usize] = (*st).softclip_mem[1 as usize];
+        st.softclip_mem[1 as usize] = 0 as opus_val16;
+        st.softclip_mem[0 as usize] = st.softclip_mem[1 as usize];
     }
     return nb_samples;
 }
 pub unsafe fn opus_decode(
-    st: *mut OpusDecoder,
+    st: &mut OpusDecoder,
     data: *const u8,
     len: i32,
     pcm: *mut i16,
@@ -883,8 +864,8 @@ pub unsafe fn opus_decode(
             return OPUS_INVALID_PACKET;
         }
     }
-    assert!((*st).channels == 1 || (*st).channels == 2);
-    let vla = (frame_size * (*st).channels) as usize;
+    assert!(st.channels == 1 || st.channels == 2);
+    let vla = (frame_size * st.channels) as usize;
     let mut out: Vec<f32> = ::std::vec::from_elem(0., vla);
     ret = opus_decode_native(
         st,
@@ -899,7 +880,7 @@ pub unsafe fn opus_decode(
     );
     if ret > 0 {
         i = 0;
-        while i < ret * (*st).channels {
+        while i < ret * st.channels {
             *pcm.offset(i as isize) = FLOAT2INT16(*out.as_mut_ptr().offset(i as isize));
             i += 1;
         }
@@ -907,7 +888,7 @@ pub unsafe fn opus_decode(
     return ret;
 }
 pub unsafe fn opus_decode_float(
-    st: *mut OpusDecoder,
+    st: &mut OpusDecoder,
     data: *const u8,
     len: i32,
     pcm: *mut opus_val16,
@@ -929,57 +910,52 @@ pub unsafe fn opus_decode_float(
         0,
     );
 }
-pub unsafe fn opus_decoder_ctl_impl(st: *mut OpusDecoder, request: i32, args: VarArgs) -> i32 {
-    let silk_dec = &mut (*st).silk_dec;
-    let celt_dec = &mut (*st).celt_dec;
+pub unsafe fn opus_decoder_ctl_impl(st: &mut OpusDecoder, request: i32, args: VarArgs) -> i32 {
+    let celt_dec = &mut st.celt_dec;
 
     let mut ap = args;
 
     match request {
         OPUS_GET_BANDWIDTH_REQUEST => {
             let value = ap.arg::<&mut i32>();
-            *value = (*st).bandwidth;
+            *value = st.bandwidth;
             OPUS_OK
         }
         OPUS_GET_FINAL_RANGE_REQUEST => {
             let value_0 = ap.arg::<&mut u32>();
-            *value_0 = (*st).rangeFinal;
+            *value_0 = st.rangeFinal;
             OPUS_OK
         }
         OPUS_RESET_STATE => {
-            memset(
-                &mut (*st).stream_channels as *mut i32 as *mut i8 as *mut core::ffi::c_void,
-                0,
-                (::core::mem::size_of::<OpusDecoder>() as u64)
-                    .wrapping_sub(
-                        (&mut (*st).stream_channels as *mut i32 as *mut i8)
-                            .offset_from(st as *mut i8) as i64 as u64,
-                    )
-                    .wrapping_mul(::core::mem::size_of::<i8>() as u64),
-            );
-            opus_custom_decoder_ctl!(celt_dec, OPUS_RESET_STATE);
-            *silk_dec = silk_InitDecoder();
-            (*st).stream_channels = (*st).channels;
-            (*st).frame_size = (*st).Fs / 400;
+            st.stream_channels = st.channels;
+            st.bandwidth = 0;
+            st.mode = 0;
+            st.prev_mode = 0;
+            st.frame_size = st.Fs / 400;
+            st.prev_redundancy = 0;
+            st.last_packet_duration = 0;
+            st.softclip_mem = [0.0; 2];
+            st.rangeFinal = 0;
+
             OPUS_OK
         }
         OPUS_GET_SAMPLE_RATE_REQUEST => {
             let value_1 = ap.arg::<&mut i32>();
-            *value_1 = (*st).Fs;
+            *value_1 = st.Fs;
             OPUS_OK
         }
         OPUS_GET_PITCH_REQUEST => {
             let value_2 = ap.arg::<&mut i32>();
-            if (*st).prev_mode == MODE_CELT_ONLY {
+            if st.prev_mode == MODE_CELT_ONLY {
                 opus_custom_decoder_ctl!(celt_dec, OPUS_GET_PITCH_REQUEST, value_2,)
             } else {
-                *value_2 = (*st).DecControl.prevPitchLag;
+                *value_2 = st.DecControl.prevPitchLag;
                 OPUS_OK
             }
         }
         OPUS_GET_GAIN_REQUEST => {
             let value_3 = ap.arg::<&mut i32>();
-            *value_3 = (*st).decode_gain;
+            *value_3 = st.decode_gain;
             OPUS_OK
         }
         OPUS_SET_GAIN_REQUEST => {
@@ -987,13 +963,13 @@ pub unsafe fn opus_decoder_ctl_impl(st: *mut OpusDecoder, request: i32, args: Va
             if value_4 < -(32768) || value_4 > 32767 {
                 OPUS_BAD_ARG
             } else {
-                (*st).decode_gain = value_4;
+                st.decode_gain = value_4;
                 OPUS_OK
             }
         }
         OPUS_GET_LAST_PACKET_DURATION_REQUEST => {
             let value_5 = ap.arg::<&mut i32>();
-            *value_5 = (*st).last_packet_duration;
+            *value_5 = st.last_packet_duration;
             OPUS_OK
         }
         OPUS_SET_PHASE_INVERSION_DISABLED_REQUEST => {
@@ -1090,9 +1066,9 @@ pub unsafe fn opus_packet_get_nb_samples(packet: *const u8, len: i32, Fs: i32) -
     };
 }
 pub unsafe fn opus_decoder_get_nb_samples(
-    dec: *const OpusDecoder,
+    dec: &mut OpusDecoder,
     packet: *const u8,
     len: i32,
 ) -> i32 {
-    return opus_packet_get_nb_samples(packet, len, (*dec).Fs);
+    return opus_packet_get_nb_samples(packet, len, dec.Fs);
 }
diff --git a/src/src/opus_multistream_decoder.rs b/src/src/opus_multistream_decoder.rs
index ca1880c..6a17dcb 100644
--- a/src/src/opus_multistream_decoder.rs
+++ b/src/src/opus_multistream_decoder.rs
@@ -1,3 +1,7 @@
+// we mark unidiomatic functions that have better analogues as deprecated
+// but multistream decoder still uses it
+#![allow(deprecated)]
+
 use crate::externs::{free, malloc};
 
 #[derive(Copy, Clone)]
@@ -56,8 +60,8 @@ pub unsafe fn opus_multistream_decoder_get_size(nb_streams: i32, nb_coupled_stre
     if nb_streams < 1 || nb_coupled_streams > nb_streams || nb_coupled_streams < 0 {
         return 0;
     }
-    let coupled_size = opus_decoder_get_size(2);
-    let mono_size = opus_decoder_get_size(1);
+    let coupled_size = crate::opus_decoder_get_size(2);
+    let mono_size = crate::opus_decoder_get_size(1);
     return align(::core::mem::size_of::<OpusMSDecoder>() as u64 as i32)
         + nb_coupled_streams * align(coupled_size as _)
         + (nb_streams - nb_coupled_streams) * align(mono_size as _);
@@ -276,7 +280,7 @@ pub unsafe fn opus_multistream_decode_native(
         }
         packet_offset = 0;
         ret_0 = opus_decode_native(
-            dec,
+            &mut *dec,
             data,
             len,
             buf.as_mut_ptr(),
@@ -510,7 +514,7 @@ pub unsafe fn opus_multistream_decoder_ctl_va_list(
             let mut dec: *mut OpusDecoder = 0 as *mut OpusDecoder;
             let value: &mut i32 = ap.arg::<&mut i32>();
             dec = ptr as *mut OpusDecoder;
-            ret = opus_decoder_ctl!(dec, request, value);
+            ret = opus_decoder_ctl!(&mut *dec, request, value);
             current_block = 7343950298149844727;
         }
         OPUS_GET_FINAL_RANGE_REQUEST => {
@@ -527,7 +531,7 @@ pub unsafe fn opus_multistream_decoder_ctl_va_list(
                 } else {
                     ptr = ptr.offset(align(mono_size as _) as isize);
                 }
-                ret = opus_decoder_ctl!(dec_0, request, &mut tmp);
+                ret = opus_decoder_ctl!(&mut *dec_0, request, &mut tmp);
                 if ret != OPUS_OK {
                     break;
                 }
@@ -547,7 +551,7 @@ pub unsafe fn opus_multistream_decoder_ctl_va_list(
                 } else {
                     ptr = ptr.offset(align(mono_size as _) as isize);
                 }
-                ret = opus_decoder_ctl!(dec_1, OPUS_RESET_STATE);
+                ret = opus_decoder_ctl!(&mut *dec_1, OPUS_RESET_STATE);
                 if ret != OPUS_OK {
                     break;
                 }
@@ -589,7 +593,7 @@ pub unsafe fn opus_multistream_decoder_ctl_va_list(
                 } else {
                     ptr = ptr.offset(align(mono_size as _) as isize);
                 }
-                ret = opus_decoder_ctl!(dec_2, request, value_2);
+                ret = opus_decoder_ctl!(&mut *dec_2, request, value_2);
                 if ret != OPUS_OK {
                     break;
                 }
diff --git a/tests/opus_api.rs b/tests/opus_api.rs
index 898256d..edfca6c 100644
--- a/tests/opus_api.rs
+++ b/tests/opus_api.rs
@@ -3,6 +3,7 @@
 #![allow(non_upper_case_globals)]
 #![allow(unused_assignments)]
 #![allow(unused_mut)]
+#![allow(deprecated)]
 
 pub mod test_opus_common_h {
     pub unsafe fn _test_failed(mut file: *const i8, mut line: i32) -> ! {
@@ -134,31 +135,31 @@ pub unsafe fn test_dec_api() -> i32 {
     cfgs += 1;
     println!("    opus_decoder_create() ........................ OK.");
     println!("    opus_decoder_init() .......................... OK.");
-    err = opus_decoder_ctl!(dec, 4031, &mut dec_final_range);
+    err = opus_decoder_ctl!(&mut *dec, 4031, &mut dec_final_range);
     if err != 0 {
         _test_failed(b"tests/test_opus_api.c\0" as *const u8 as *const i8, 155);
     }
     println!("    OPUS_GET_FINAL_RANGE ......................... OK.");
     cfgs += 1;
-    err = opus_decoder_ctl!(dec, -(5));
+    err = opus_decoder_ctl!(&mut *dec, -(5));
     if err != -(5) {
         _test_failed(b"tests/test_opus_api.c\0" as *const u8 as *const i8, 161);
     }
     println!("    OPUS_UNIMPLEMENTED ........................... OK.");
     cfgs += 1;
-    err = opus_decoder_ctl!(dec, 4009, &mut i);
+    err = opus_decoder_ctl!(&mut *dec, 4009, &mut i);
     if err != 0 || i != 0 {
         _test_failed(b"tests/test_opus_api.c\0" as *const u8 as *const i8, 169);
     }
     println!("    OPUS_GET_BANDWIDTH ........................... OK.");
     cfgs += 1;
-    err = opus_decoder_ctl!(dec, 4029, &mut i);
+    err = opus_decoder_ctl!(&mut *dec, 4029, &mut i);
     if err != 0 || i != 48000 {
         _test_failed(b"tests/test_opus_api.c\0" as *const u8 as *const i8, 177);
     }
     println!("    OPUS_GET_SAMPLE_RATE ......................... OK.");
     cfgs += 1;
-    err = opus_decoder_ctl!(dec, 4033, &mut i);
+    err = opus_decoder_ctl!(&mut *dec, 4033, &mut i);
     if err != 0 || i > 0 || i < -1 {
         _test_failed(b"tests/test_opus_api.c\0" as *const u8 as *const i8, 187);
     }
@@ -166,53 +167,53 @@ pub unsafe fn test_dec_api() -> i32 {
     packet[0 as usize] = ((63) << 2) as u8;
     packet[2 as usize] = 0;
     packet[1 as usize] = packet[2 as usize];
-    if opus_decode(dec, packet.as_mut_ptr(), 3, sbuf.as_mut_ptr(), 960, 0) != 960 {
+    if opus_decode(&mut *dec, packet.as_mut_ptr(), 3, sbuf.as_mut_ptr(), 960, 0) != 960 {
         _test_failed(b"tests/test_opus_api.c\0" as *const u8 as *const i8, 191);
     }
     cfgs += 1;
-    err = opus_decoder_ctl!(dec, 4033, &mut i);
+    err = opus_decoder_ctl!(&mut *dec, 4033, &mut i);
     if err != 0 || i > 0 || i < -1 {
         _test_failed(b"tests/test_opus_api.c\0" as *const u8 as *const i8, 195);
     }
     cfgs += 1;
     packet[0 as usize] = 1;
-    if opus_decode(dec, packet.as_mut_ptr(), 1, sbuf.as_mut_ptr(), 960, 0) != 960 {
+    if opus_decode(&mut *dec, packet.as_mut_ptr(), 1, sbuf.as_mut_ptr(), 960, 0) != 960 {
         _test_failed(b"tests/test_opus_api.c\0" as *const u8 as *const i8, 198);
     }
     cfgs += 1;
-    err = opus_decoder_ctl!(dec, 4033, &mut i);
+    err = opus_decoder_ctl!(&mut *dec, 4033, &mut i);
     if err != 0 || i > 0 || i < -1 {
         _test_failed(b"tests/test_opus_api.c\0" as *const u8 as *const i8, 202);
     }
     cfgs += 1;
     println!("    OPUS_GET_PITCH ............................... OK.");
-    err = opus_decoder_ctl!(dec, 4039, &mut i);
+    err = opus_decoder_ctl!(&mut *dec, 4039, &mut i);
     if err != 0 || i != 960 {
         _test_failed(b"tests/test_opus_api.c\0" as *const u8 as *const i8, 210);
     }
     cfgs += 1;
     println!("    OPUS_GET_LAST_PACKET_DURATION ................ OK.");
-    err = opus_decoder_ctl!(dec, 4045, &mut i);
+    err = opus_decoder_ctl!(&mut *dec, 4045, &mut i);
     if err != 0 || i != 0 {
         _test_failed(b"tests/test_opus_api.c\0" as *const u8 as *const i8, 217);
     }
     cfgs += 1;
-    err = opus_decoder_ctl!(dec, 4034, -(32769));
+    err = opus_decoder_ctl!(&mut *dec, 4034, -(32769));
     if err != -1 {
         _test_failed(b"tests/test_opus_api.c\0" as *const u8 as *const i8, 223);
     }
     cfgs += 1;
-    err = opus_decoder_ctl!(dec, 4034, 32768);
+    err = opus_decoder_ctl!(&mut *dec, 4034, 32768);
     if err != -1 {
         _test_failed(b"tests/test_opus_api.c\0" as *const u8 as *const i8, 226);
     }
     cfgs += 1;
-    err = opus_decoder_ctl!(dec, 4034, -(15));
+    err = opus_decoder_ctl!(&mut *dec, 4034, -(15));
     if err != 0 {
         _test_failed(b"tests/test_opus_api.c\0" as *const u8 as *const i8, 229);
     }
     cfgs += 1;
-    err = opus_decoder_ctl!(dec, 4045, &mut i);
+    err = opus_decoder_ctl!(&mut *dec, 4045, &mut i);
     if err != 0 || i != -(15) {
         _test_failed(b"tests/test_opus_api.c\0" as *const u8 as *const i8, 234);
     }
@@ -225,7 +226,7 @@ pub unsafe fn test_dec_api() -> i32 {
         dec as *const core::ffi::c_void,
         opus_decoder_get_size(2) as u64,
     );
-    if opus_decoder_ctl!(dec, 4028) != 0 {
+    if opus_decoder_ctl!(&mut *dec, 4028) != 0 {
         _test_failed(b"tests/test_opus_api.c\0" as *const u8 as *const i8, 242);
     }
     if memcmp(
@@ -240,7 +241,7 @@ pub unsafe fn test_dec_api() -> i32 {
     println!("    OPUS_RESET_STATE ............................. OK.");
     cfgs += 1;
     packet[0 as usize] = 0;
-    if opus_decoder_get_nb_samples(dec, packet.as_mut_ptr() as *const u8, 1) != 480 {
+    if opus_decoder_get_nb_samples(&mut *dec, packet.as_mut_ptr() as *const u8, 1) != 480 {
         _test_failed(b"tests/test_opus_api.c\0" as *const u8 as *const i8, 250);
     }
     if opus_packet_get_nb_samples(packet.as_mut_ptr() as *const u8, 1, 48000) != 480 {
@@ -267,7 +268,7 @@ pub unsafe fn test_dec_api() -> i32 {
     if opus_packet_get_nb_samples(packet.as_mut_ptr() as *const u8, 2, 48000) != -(4) {
         _test_failed(b"tests/test_opus_api.c\0" as *const u8 as *const i8, 260);
     }
-    if opus_decoder_get_nb_samples(dec, packet.as_mut_ptr() as *const u8, 2) != -(4) {
+    if opus_decoder_get_nb_samples(&mut *dec, packet.as_mut_ptr() as *const u8, 2) != -(4) {
         _test_failed(b"tests/test_opus_api.c\0" as *const u8 as *const i8, 261);
     }
     println!("    opus_{{packet,decoder}}_get_nb_samples() ....... OK.");
@@ -344,31 +345,47 @@ pub unsafe fn test_dec_api() -> i32 {
         packet[j as usize] = 0;
         j += 1;
     }
-    if opus_decode(dec, packet.as_mut_ptr(), 51, sbuf.as_mut_ptr(), 960, 0) != -(4) {
+    if opus_decode(
+        &mut *dec,
+        packet.as_mut_ptr(),
+        51,
+        sbuf.as_mut_ptr(),
+        960,
+        0,
+    ) != -(4)
+    {
         _test_failed(b"tests/test_opus_api.c\0" as *const u8 as *const i8, 305);
     }
     cfgs += 1;
     packet[0 as usize] = ((63) << 2) as u8;
     packet[2 as usize] = 0;
     packet[1 as usize] = packet[2 as usize];
-    if opus_decode(dec, packet.as_mut_ptr(), -1, sbuf.as_mut_ptr(), 960, 0) != -1 {
+    if opus_decode(
+        &mut *dec,
+        packet.as_mut_ptr(),
+        -1,
+        sbuf.as_mut_ptr(),
+        960,
+        0,
+    ) != -1
+    {
         _test_failed(b"tests/test_opus_api.c\0" as *const u8 as *const i8, 309);
     }
     cfgs += 1;
-    if opus_decode(dec, packet.as_mut_ptr(), 3, sbuf.as_mut_ptr(), 60, 0) != -(2) {
+    if opus_decode(&mut *dec, packet.as_mut_ptr(), 3, sbuf.as_mut_ptr(), 60, 0) != -(2) {
         _test_failed(b"tests/test_opus_api.c\0" as *const u8 as *const i8, 311);
     }
     cfgs += 1;
-    if opus_decode(dec, packet.as_mut_ptr(), 3, sbuf.as_mut_ptr(), 480, 0) != -(2) {
+    if opus_decode(&mut *dec, packet.as_mut_ptr(), 3, sbuf.as_mut_ptr(), 480, 0) != -(2) {
         _test_failed(b"tests/test_opus_api.c\0" as *const u8 as *const i8, 313);
     }
     cfgs += 1;
-    if opus_decode(dec, packet.as_mut_ptr(), 3, sbuf.as_mut_ptr(), 960, 0) != 960 {
+    if opus_decode(&mut *dec, packet.as_mut_ptr(), 3, sbuf.as_mut_ptr(), 960, 0) != 960 {
         _test_failed(b"tests/test_opus_api.c\0" as *const u8 as *const i8, 315);
     }
     cfgs += 1;
     println!("    opus_decode() ................................ OK.");
-    if opus_decode_float(dec, packet.as_mut_ptr(), 3, fbuf.as_mut_ptr(), 960, 0) != 960 {
+    if opus_decode_float(&mut *dec, packet.as_mut_ptr(), 3, fbuf.as_mut_ptr(), 960, 0) != 960 {
         _test_failed(b"tests/test_opus_api.c\0" as *const u8 as *const i8, 320);
     }
     cfgs += 1;
@@ -664,7 +681,7 @@ pub unsafe fn test_msdec_api() -> i32 {
         if err != 0 {
             _test_failed(b"tests/test_opus_api.c\0" as *const u8 as *const i8, 572);
         }
-        err = opus_decoder_ctl!(od, 4045, &mut i);
+        err = opus_decoder_ctl!(&mut *od, 4045, &mut i);
         if err != 0 || i != 0 {
             _test_failed(b"tests/test_opus_api.c\0" as *const u8 as *const i8, 576);
         }
@@ -683,7 +700,7 @@ pub unsafe fn test_msdec_api() -> i32 {
         if err != 0 {
             _test_failed(b"tests/test_opus_api.c\0" as *const u8 as *const i8, 586);
         }
-        err = opus_decoder_ctl!(od_0, 4045, &mut i);
+        err = opus_decoder_ctl!(&mut *od_0, 4045, &mut i);
         if err != 0 || i != 15 {
             _test_failed(b"tests/test_opus_api.c\0" as *const u8 as *const i8, 590);
         }
diff --git a/tests/opus_decode.rs b/tests/opus_decode.rs
index 0d83450..f3b7b77 100644
--- a/tests/opus_decode.rs
+++ b/tests/opus_decode.rs
@@ -3,6 +3,7 @@
 #![allow(non_upper_case_globals)]
 #![allow(unused_assignments)]
 #![allow(unused_mut)]
+#![allow(deprecated)]
 
 use libc::{getpid, rand, time};
 
@@ -175,7 +176,7 @@ pub unsafe fn test_decoder_code0(no_fuzz: bool) -> i32 {
         while fec < 2 {
             let mut dur: i32 = 0;
             out_samples = opus_decode(
-                dec[t as usize],
+                &mut *dec[t as usize],
                 std::ptr::null::<u8>(),
                 0,
                 outbuf,
@@ -185,14 +186,14 @@ pub unsafe fn test_decoder_code0(no_fuzz: bool) -> i32 {
             if out_samples != 120 / factor {
                 _test_failed(b"tests/test_opus_decode.c\0" as *const u8 as *const i8, 110);
             }
-            if opus_decoder_ctl!(dec[t as usize], 4039, &mut dur) != 0 {
+            if opus_decoder_ctl!(&mut *dec[t as usize], 4039, &mut dur) != 0 {
                 _test_failed(b"tests/test_opus_decode.c\0" as *const u8 as *const i8, 111);
             }
             if dur != 120 / factor {
                 _test_failed(b"tests/test_opus_decode.c\0" as *const u8 as *const i8, 112);
             }
             out_samples = opus_decode(
-                dec[t as usize],
+                &mut *dec[t as usize],
                 std::ptr::null::<u8>(),
                 0,
                 outbuf,
@@ -203,7 +204,7 @@ pub unsafe fn test_decoder_code0(no_fuzz: bool) -> i32 {
                 _test_failed(b"tests/test_opus_decode.c\0" as *const u8 as *const i8, 116);
             }
             out_samples = opus_decode(
-                dec[t as usize],
+                &mut *dec[t as usize],
                 std::ptr::null::<u8>(),
                 -1,
                 outbuf,
@@ -214,7 +215,7 @@ pub unsafe fn test_decoder_code0(no_fuzz: bool) -> i32 {
                 _test_failed(b"tests/test_opus_decode.c\0" as *const u8 as *const i8, 120);
             }
             out_samples = opus_decode(
-                dec[t as usize],
+                &mut *dec[t as usize],
                 std::ptr::null::<u8>(),
                 1,
                 outbuf,
@@ -225,7 +226,7 @@ pub unsafe fn test_decoder_code0(no_fuzz: bool) -> i32 {
                 _test_failed(b"tests/test_opus_decode.c\0" as *const u8 as *const i8, 122);
             }
             out_samples = opus_decode(
-                dec[t as usize],
+                &mut *dec[t as usize],
                 std::ptr::null::<u8>(),
                 10,
                 outbuf,
@@ -236,7 +237,7 @@ pub unsafe fn test_decoder_code0(no_fuzz: bool) -> i32 {
                 _test_failed(b"tests/test_opus_decode.c\0" as *const u8 as *const i8, 124);
             }
             out_samples = opus_decode(
-                dec[t as usize],
+                &mut *dec[t as usize],
                 std::ptr::null::<u8>(),
                 fast_rand() as i32,
                 outbuf,
@@ -246,23 +247,23 @@ pub unsafe fn test_decoder_code0(no_fuzz: bool) -> i32 {
             if out_samples != 120 / factor {
                 _test_failed(b"tests/test_opus_decode.c\0" as *const u8 as *const i8, 126);
             }
-            if opus_decoder_ctl!(dec[t as usize], 4039, &mut dur) != 0 {
+            if opus_decoder_ctl!(&mut *dec[t as usize], 4039, &mut dur) != 0 {
                 _test_failed(b"tests/test_opus_decode.c\0" as *const u8 as *const i8, 127);
             }
             if dur != 120 / factor {
                 _test_failed(b"tests/test_opus_decode.c\0" as *const u8 as *const i8, 128);
             }
-            out_samples = opus_decode(dec[t as usize], packet, 0, outbuf, 120 / factor, fec);
+            out_samples = opus_decode(&mut *dec[t as usize], packet, 0, outbuf, 120 / factor, fec);
             if out_samples != 120 / factor {
                 _test_failed(b"tests/test_opus_decode.c\0" as *const u8 as *const i8, 132);
             }
             *outbuf.offset(0 as isize) = 32749 as libc::c_short;
-            out_samples = opus_decode(dec[t as usize], packet, 0, outbuf, 0, fec);
+            out_samples = opus_decode(&mut *dec[t as usize], packet, 0, outbuf, 0, fec);
             if out_samples > 0 {
                 _test_failed(b"tests/test_opus_decode.c\0" as *const u8 as *const i8, 137);
             }
             out_samples = opus_decode(
-                dec[t as usize],
+                &mut *dec[t as usize],
                 packet,
                 0,
                 std::ptr::null_mut::<i16>(),
@@ -275,12 +276,12 @@ pub unsafe fn test_decoder_code0(no_fuzz: bool) -> i32 {
             if *outbuf.offset(0 as isize) as i32 != 32749 {
                 _test_failed(b"tests/test_opus_decode.c\0" as *const u8 as *const i8, 147);
             }
-            out_samples = opus_decode(dec[t as usize], packet, -1, outbuf, 5760, fec);
+            out_samples = opus_decode(&mut *dec[t as usize], packet, -1, outbuf, 5760, fec);
             if out_samples >= 0 {
                 _test_failed(b"tests/test_opus_decode.c\0" as *const u8 as *const i8, 151);
             }
             out_samples = opus_decode(
-                dec[t as usize],
+                &mut *dec[t as usize],
                 packet,
                 -(2147483647) - 1,
                 outbuf,
@@ -290,12 +291,12 @@ pub unsafe fn test_decoder_code0(no_fuzz: bool) -> i32 {
             if out_samples >= 0 {
                 _test_failed(b"tests/test_opus_decode.c\0" as *const u8 as *const i8, 153);
             }
-            out_samples = opus_decode(dec[t as usize], packet, -1, outbuf, -1, fec);
+            out_samples = opus_decode(&mut *dec[t as usize], packet, -1, outbuf, -1, fec);
             if out_samples >= 0 {
                 _test_failed(b"tests/test_opus_decode.c\0" as *const u8 as *const i8, 155);
             }
             out_samples = opus_decode(
-                dec[t as usize],
+                &mut *dec[t as usize],
                 packet,
                 1,
                 outbuf,
@@ -305,7 +306,7 @@ pub unsafe fn test_decoder_code0(no_fuzz: bool) -> i32 {
             if out_samples >= 0 {
                 _test_failed(b"tests/test_opus_decode.c\0" as *const u8 as *const i8, 159);
             }
-            if opus_decoder_ctl!(dec[t as usize], 4028) != 0 {
+            if opus_decoder_ctl!(&mut *dec[t as usize], 4028) != 0 {
                 _test_failed(b"tests/test_opus_decode.c\0" as *const u8 as *const i8, 162);
             }
             fec += 1;
@@ -328,7 +329,7 @@ pub unsafe fn test_decoder_code0(no_fuzz: bool) -> i32 {
         t = 0;
         while t < 5 * 2 {
             expected[t as usize] =
-                opus_decoder_get_nb_samples(dec[t as usize], packet as *const u8, 1);
+                opus_decoder_get_nb_samples(&mut *dec[t as usize], packet as *const u8, 1);
             if expected[t as usize] > 2880 {
                 _test_failed(b"tests/test_opus_decode.c\0" as *const u8 as *const i8, 180);
             }
@@ -339,17 +340,17 @@ pub unsafe fn test_decoder_code0(no_fuzz: bool) -> i32 {
             *packet.offset(1 as isize) = j as u8;
             t = 0;
             while t < 5 * 2 {
-                out_samples = opus_decode(dec[t as usize], packet, 3, outbuf, 5760, 0);
+                out_samples = opus_decode(&mut *dec[t as usize], packet, 3, outbuf, 5760, 0);
                 if out_samples != expected[t as usize] {
                     _test_failed(b"tests/test_opus_decode.c\0" as *const u8 as *const i8, 189);
                 }
-                if opus_decoder_ctl!(dec[t as usize], 4039, &mut dur_0) != 0 {
+                if opus_decoder_ctl!(&mut *dec[t as usize], 4039, &mut dur_0) != 0 {
                     _test_failed(b"tests/test_opus_decode.c\0" as *const u8 as *const i8, 190);
                 }
                 if dur_0 != out_samples {
                     _test_failed(b"tests/test_opus_decode.c\0" as *const u8 as *const i8, 191);
                 }
-                opus_decoder_ctl!(dec[t as usize], 4031, &mut dec_final_range1);
+                opus_decoder_ctl!(&mut *dec[t as usize], 4031, &mut dec_final_range1);
                 if t == 0 {
                     dec_final_range2 = dec_final_range1;
                 } else if dec_final_range1 != dec_final_range2 {
@@ -365,7 +366,7 @@ pub unsafe fn test_decoder_code0(no_fuzz: bool) -> i32 {
             j = 0;
             while j < 6 {
                 out_samples = opus_decode(
-                    dec[t as usize],
+                    &mut *dec[t as usize],
                     std::ptr::null::<u8>(),
                     0,
                     outbuf,
@@ -375,7 +376,7 @@ pub unsafe fn test_decoder_code0(no_fuzz: bool) -> i32 {
                 if out_samples != expected[t as usize] {
                     _test_failed(b"tests/test_opus_decode.c\0" as *const u8 as *const i8, 204);
                 }
-                if opus_decoder_ctl!(dec[t as usize], 4039, &mut dur_0) != 0 {
+                if opus_decoder_ctl!(&mut *dec[t as usize], 4039, &mut dur_0) != 0 {
                     _test_failed(b"tests/test_opus_decode.c\0" as *const u8 as *const i8, 205);
                 }
                 if dur_0 != out_samples {
@@ -385,7 +386,7 @@ pub unsafe fn test_decoder_code0(no_fuzz: bool) -> i32 {
             }
             if expected[t as usize] != 120 / factor_0 {
                 out_samples = opus_decode(
-                    dec[t as usize],
+                    &mut *dec[t as usize],
                     std::ptr::null::<u8>(),
                     0,
                     outbuf,
@@ -395,7 +396,7 @@ pub unsafe fn test_decoder_code0(no_fuzz: bool) -> i32 {
                 if out_samples != 120 / factor_0 {
                     _test_failed(b"tests/test_opus_decode.c\0" as *const u8 as *const i8, 213);
                 }
-                if opus_decoder_ctl!(dec[t as usize], 4039, &mut dur_0) != 0 {
+                if opus_decoder_ctl!(&mut *dec[t as usize], 4039, &mut dur_0) != 0 {
                     _test_failed(b"tests/test_opus_decode.c\0" as *const u8 as *const i8, 214);
                 }
                 if dur_0 != out_samples {
@@ -403,7 +404,7 @@ pub unsafe fn test_decoder_code0(no_fuzz: bool) -> i32 {
                 }
             }
             out_samples = opus_decode(
-                dec[t as usize],
+                &mut *dec[t as usize],
                 packet,
                 2,
                 outbuf,
@@ -464,11 +465,11 @@ pub unsafe fn test_decoder_code0(no_fuzz: bool) -> i32 {
         *packet.offset(1 as isize) = (i >> 8) as u8;
         *packet.offset(2 as isize) = (i & 255) as u8;
         *packet.offset(3 as isize) = 255;
-        out_samples = opus_decode(dec[t as usize], packet, 4, outbuf, 5760, 0);
+        out_samples = opus_decode(&mut *dec[t as usize], packet, 4, outbuf, 5760, 0);
         if out_samples != 120 / factor_1 {
             _test_failed(b"tests/test_opus_decode.c\0" as *const u8 as *const i8, 260);
         }
-        opus_decoder_ctl!(dec[t as usize], 4031, &mut dec_final_range1);
+        opus_decoder_ctl!(&mut *dec[t as usize], 4031, &mut dec_final_range1);
         dec_final_acc = (dec_final_acc as u32).wrapping_add(dec_final_range1) as u32 as u32;
         i += 1;
     }
@@ -489,11 +490,11 @@ pub unsafe fn test_decoder_code0(no_fuzz: bool) -> i32 {
         *packet.offset(1 as isize) = (i >> 8) as u8;
         *packet.offset(2 as isize) = (i & 255) as u8;
         *packet.offset(3 as isize) = 255;
-        out_samples = opus_decode(dec[t as usize], packet, 4, outbuf, 5760, 0);
+        out_samples = opus_decode(&mut *dec[t as usize], packet, 4, outbuf, 5760, 0);
         if out_samples != 480 / factor_2 {
             _test_failed(b"tests/test_opus_decode.c\0" as *const u8 as *const i8, 278);
         }
-        opus_decoder_ctl!(dec[t as usize], 4031, &mut dec_final_range1);
+        opus_decoder_ctl!(&mut *dec[t as usize], 4031, &mut dec_final_range1);
         dec_final_acc = (dec_final_acc as u32).wrapping_add(dec_final_range1) as u32 as u32;
         i += 1;
     }
@@ -513,7 +514,7 @@ pub unsafe fn test_decoder_code0(no_fuzz: bool) -> i32 {
         t = 0;
         while t < 5 * 2 {
             expected_0[t as usize] =
-                opus_decoder_get_nb_samples(dec[t as usize], packet as *const u8, 1);
+                opus_decoder_get_nb_samples(&mut *dec[t as usize], packet as *const u8, 1);
             t += 1;
         }
         j_0 = 2 + skip;
@@ -526,11 +527,11 @@ pub unsafe fn test_decoder_code0(no_fuzz: bool) -> i32 {
             }
             t = 0;
             while t < 5 * 2 {
-                out_samples = opus_decode(dec[t as usize], packet, j_0 + 1, outbuf, 5760, 0);
+                out_samples = opus_decode(&mut *dec[t as usize], packet, j_0 + 1, outbuf, 5760, 0);
                 if out_samples != expected_0[t as usize] {
                     _test_failed(b"tests/test_opus_decode.c\0" as *const u8 as *const i8, 299);
                 }
-                opus_decoder_ctl!(dec[t as usize], 4031, &mut dec_final_range1);
+                opus_decoder_ctl!(&mut *dec[t as usize], 4031, &mut dec_final_range1);
                 if t == 0 {
                     dec_final_range2 = dec_final_range1;
                 } else if dec_final_range1 != dec_final_range2 {
@@ -561,7 +562,7 @@ pub unsafe fn test_decoder_code0(no_fuzz: bool) -> i32 {
         t = 0;
         while t < 5 * 2 {
             expected_1[t as usize] =
-                opus_decoder_get_nb_samples(dec[t as usize], packet as *const u8, plen);
+                opus_decoder_get_nb_samples(&mut *dec[t as usize], packet as *const u8, plen);
             t += 1;
         }
         j_1 = 0;
@@ -574,8 +575,14 @@ pub unsafe fn test_decoder_code0(no_fuzz: bool) -> i32 {
             dec[0 as usize] as *const core::ffi::c_void,
             decsize as u64,
         );
-        if opus_decode(decbak, packet, plen + 1, outbuf, expected_1[0 as usize], 1)
-            != expected_1[0 as usize]
+        if opus_decode(
+            &mut *decbak,
+            packet,
+            plen + 1,
+            outbuf,
+            expected_1[0 as usize],
+            1,
+        ) != expected_1[0 as usize]
         {
             _test_failed(b"tests/test_opus_decode.c\0" as *const u8 as *const i8, 317);
         }
@@ -584,7 +591,7 @@ pub unsafe fn test_decoder_code0(no_fuzz: bool) -> i32 {
             dec[0 as usize] as *const core::ffi::c_void,
             decsize as u64,
         );
-        if opus_decode(decbak, std::ptr::null::<u8>(), 0, outbuf, 5760, 1) < 20 {
+        if opus_decode(&mut *decbak, std::ptr::null::<u8>(), 0, outbuf, 5760, 1) < 20 {
             _test_failed(b"tests/test_opus_decode.c\0" as *const u8 as *const i8, 319);
         }
         memcpy(
@@ -592,13 +599,13 @@ pub unsafe fn test_decoder_code0(no_fuzz: bool) -> i32 {
             dec[0 as usize] as *const core::ffi::c_void,
             decsize as u64,
         );
-        if opus_decode(decbak, std::ptr::null::<u8>(), 0, outbuf, 5760, 0) < 20 {
+        if opus_decode(&mut *decbak, std::ptr::null::<u8>(), 0, outbuf, 5760, 0) < 20 {
             _test_failed(b"tests/test_opus_decode.c\0" as *const u8 as *const i8, 321);
         }
         t = 0;
         while t < 5 * 2 {
             let mut dur_1: i32 = 0;
-            out_samples = opus_decode(dec[t as usize], packet, plen + 1, outbuf, 5760, 0);
+            out_samples = opus_decode(&mut *dec[t as usize], packet, plen + 1, outbuf, 5760, 0);
             if out_samples != expected_1[t as usize] {
                 _test_failed(b"tests/test_opus_decode.c\0" as *const u8 as *const i8, 326);
             }
@@ -607,7 +614,7 @@ pub unsafe fn test_decoder_code0(no_fuzz: bool) -> i32 {
             } else if dec_final_range1 != dec_final_range2 {
                 _test_failed(b"tests/test_opus_decode.c\0" as *const u8 as *const i8, 328);
             }
-            if opus_decoder_ctl!(dec[t as usize], 4039, &mut dur_1) != 0 {
+            if opus_decoder_ctl!(&mut *dec[t as usize], 4039, &mut dur_1) != 0 {
                 _test_failed(b"tests/test_opus_decode.c\0" as *const u8 as *const i8, 329);
             }
             if dur_1 != out_samples {
@@ -634,7 +641,7 @@ pub unsafe fn test_decoder_code0(no_fuzz: bool) -> i32 {
         let mut j_2: i32 = 0;
         let mut expected_2: i32 = 0;
         *packet.offset(0 as isize) = ((modes[i as usize] as i32) << 2) as u8;
-        expected_2 = opus_decoder_get_nb_samples(dec[t as usize], packet as *const u8, plen);
+        expected_2 = opus_decoder_get_nb_samples(&mut *dec[t as usize], packet as *const u8, plen);
         count = 0;
         while count < 10 {
             j_2 = 0;
@@ -642,7 +649,7 @@ pub unsafe fn test_decoder_code0(no_fuzz: bool) -> i32 {
                 *packet.offset((j_2 + 1) as isize) = ((fast_rand() | fast_rand()) & 255) as u8;
                 j_2 += 1;
             }
-            out_samples = opus_decode(dec[t as usize], packet, plen + 1, outbuf, 5760, 0);
+            out_samples = opus_decode(&mut *dec[t as usize], packet, plen + 1, outbuf, 5760, 0);
             if out_samples != expected_2 {
                 _test_failed(b"tests/test_opus_decode.c\0" as *const u8 as *const i8, 346);
             }
@@ -671,7 +678,14 @@ pub unsafe fn test_decoder_code0(no_fuzz: bool) -> i32 {
             *packet.offset(j_3 as isize) = (fast_rand() & 255) as u8;
             j_3 += 1;
         }
-        out_samples = opus_decode(dec[t as usize], packet, tlen[i as usize], outbuf, 5760, 0);
+        out_samples = opus_decode(
+            &mut *dec[t as usize],
+            packet,
+            tlen[i as usize],
+            outbuf,
+            5760,
+            0,
+        );
         if out_samples != tret[i as usize] {
             _test_failed(b"tests/test_opus_decode.c\0" as *const u8 as *const i8, 364);
         }
diff --git a/tests/opus_encode/main.rs b/tests/opus_encode/main.rs
index 5b7edab..a6ae630 100644
--- a/tests/opus_encode/main.rs
+++ b/tests/opus_encode/main.rs
@@ -3,6 +3,7 @@
 #![allow(non_upper_case_globals)]
 #![allow(unused_assignments)]
 #![allow(unused_mut)]
+#![allow(deprecated)]
 
 use libc::{getpid, time};
 
@@ -232,7 +233,7 @@ pub unsafe fn test_encode(
             ret = -1;
             break;
         } else {
-            out_samples = opus_decode(dec, packet.as_mut_ptr(), len, outbuf, 5760, 0);
+            out_samples = opus_decode(&mut *dec, packet.as_mut_ptr(), len, outbuf, 5760, 0);
             if out_samples != frame_size {
                 eprintln!("opus_decode() returned {}", out_samples);
                 ret = -1;
@@ -664,17 +665,17 @@ pub unsafe fn run_test1(no_fuzz: bool) -> i32 {
                     if opus_encoder_ctl!(enc, 4028) != 0 {
                         _test_failed(b"tests/test_opus_encode.c\0" as *const u8 as *const i8, 410);
                     }
-                    if opus_decoder_ctl!(dec, 4028) != 0 {
+                    if opus_decoder_ctl!(&mut *dec, 4028) != 0 {
                         _test_failed(b"tests/test_opus_encode.c\0" as *const u8 as *const i8, 411);
                     }
                     if fast_rand() & 1 != 0
-                        && opus_decoder_ctl!(dec_err[(fast_rand() & 1) as usize], 4028,) != 0
+                        && opus_decoder_ctl!(&mut *dec_err[(fast_rand() & 1) as usize], 4028,) != 0
                     {
                         _test_failed(b"tests/test_opus_encode.c\0" as *const u8 as *const i8, 414);
                     }
                 }
                 if fast_rand() & 127 == 0
-                    && opus_decoder_ctl!(dec_err[(fast_rand() & 1) as usize], 4028,) != 0
+                    && opus_decoder_ctl!(&mut *dec_err[(fast_rand() & 1) as usize], 4028,) != 0
                 {
                     _test_failed(b"tests/test_opus_encode.c\0" as *const u8 as *const i8, 419);
                 }
@@ -685,7 +686,7 @@ pub unsafe fn run_test1(no_fuzz: bool) -> i32 {
                     }
                 }
                 if (fast_rand()).wrapping_rem(50) == 0 {
-                    opus_decoder_ctl!(dec, 4028);
+                    opus_decoder_ctl!(&mut *dec, 4028);
                 }
                 if opus_encoder_ctl!(enc, 4012, (rc == 0) as i32,) != 0 {
                     _test_failed(b"tests/test_opus_encode.c\0" as *const u8 as *const i8, 426);
@@ -766,7 +767,7 @@ pub unsafe fn run_test1(no_fuzz: bool) -> i32 {
                     }
                 }
                 out_samples = opus_decode(
-                    dec,
+                    &mut *dec,
                     packet.as_mut_ptr(),
                     len,
                     &mut *outbuf.offset((i << 1) as isize),
@@ -776,14 +777,14 @@ pub unsafe fn run_test1(no_fuzz: bool) -> i32 {
                 if out_samples != frame_size {
                     _test_failed(b"tests/test_opus_encode.c\0" as *const u8 as *const i8, 457);
                 }
-                if opus_decoder_ctl!(dec, 4031, &mut dec_final_range) != 0 {
+                if opus_decoder_ctl!(&mut *dec, 4031, &mut dec_final_range) != 0 {
                     _test_failed(b"tests/test_opus_encode.c\0" as *const u8 as *const i8, 458);
                 }
                 if enc_final_range != dec_final_range {
                     _test_failed(b"tests/test_opus_encode.c\0" as *const u8 as *const i8, 459);
                 }
                 out_samples = opus_decode(
-                    dec_err[0 as usize],
+                    &mut *dec_err[0 as usize],
                     packet.as_mut_ptr(),
                     len,
                     out2buf,
@@ -794,7 +795,7 @@ pub unsafe fn run_test1(no_fuzz: bool) -> i32 {
                     _test_failed(b"tests/test_opus_encode.c\0" as *const u8 as *const i8, 462);
                 }
                 out_samples = opus_decode(
-                    dec_err[1 as usize],
+                    &mut *dec_err[1 as usize],
                     packet.as_mut_ptr(),
                     if fast_rand() & 3 == 0 { 0 } else { len },
                     out2buf,
@@ -1055,7 +1056,7 @@ pub unsafe fn run_test1(no_fuzz: bool) -> i32 {
         count += 1;
         opus_encoder_ctl!(enc, 4031, &mut enc_final_range);
         out_samples_1 = opus_decode(
-            dec,
+            &mut *dec,
             packet.as_mut_ptr(),
             len_1,
             &mut *outbuf.offset((offset << 1) as isize),
@@ -1065,7 +1066,7 @@ pub unsafe fn run_test1(no_fuzz: bool) -> i32 {
         if out_samples_1 != frame_size_1 {
             _test_failed(b"tests/test_opus_encode.c\0" as *const u8 as *const i8, 575);
         }
-        opus_decoder_ctl!(dec, 4031, &mut dec_final_range);
+        opus_decoder_ctl!(&mut *dec, 4031, &mut dec_final_range);
         if dec_final_range != enc_final_range {
             _test_failed(b"tests/test_opus_encode.c\0" as *const u8 as *const i8, 580);
         }
@@ -1095,7 +1096,7 @@ pub unsafe fn run_test1(no_fuzz: bool) -> i32 {
             j += 1;
         }
         out_samples_1 = opus_decode(
-            dec_err[0 as usize],
+            &mut *dec_err[0 as usize],
             if len_1 > 0 {
                 packet.as_mut_ptr()
             } else {
@@ -1112,10 +1113,10 @@ pub unsafe fn run_test1(no_fuzz: bool) -> i32 {
         if len_1 > 0 && out_samples_1 != frame_size_1 {
             _test_failed(b"tests/test_opus_encode.c\0" as *const u8 as *const i8, 590);
         }
-        opus_decoder_ctl!(dec_err[0 as usize], 4031, &mut dec_final_range);
+        opus_decoder_ctl!(&mut *dec_err[0 as usize], 4031, &mut dec_final_range);
         dec2 = (fast_rand()).wrapping_rem(9).wrapping_add(1) as i32;
         out_samples_1 = opus_decode(
-            dec_err[dec2 as usize],
+            &mut *dec_err[dec2 as usize],
             if len_1 > 0 {
                 packet.as_mut_ptr()
             } else {
@@ -1129,7 +1130,7 @@ pub unsafe fn run_test1(no_fuzz: bool) -> i32 {
         if out_samples_1 < 0 || out_samples_1 > 5760 {
             _test_failed(b"tests/test_opus_encode.c\0" as *const u8 as *const i8, 597);
         }
-        opus_decoder_ctl!(dec_err[dec2 as usize], 4031, &mut dec_final_range2);
+        opus_decoder_ctl!(&mut *dec_err[dec2 as usize], 4031, &mut dec_final_range2);
         if len_1 > 0 && dec_final_range != dec_final_range2 {
             _test_failed(b"tests/test_opus_encode.c\0" as *const u8 as *const i8, 600);
         }
@@ -1170,7 +1171,7 @@ pub unsafe fn run_test1(no_fuzz: bool) -> i32 {
         _test_failed(b"tests/test_opus_encode.c\0" as *const u8 as *const i8, 618);
     }
     opus_multistream_encoder_destroy(MSenc);
-    if opus_decoder_ctl!(dec, 4028) != 0 {
+    if opus_decoder_ctl!(&mut *dec, 4028) != 0 {
         _test_failed(b"tests/test_opus_encode.c\0" as *const u8 as *const i8, 620);
     }
     opus_decoder_destroy(dec);
diff --git a/tests/opus_padding.rs b/tests/opus_padding.rs
index 5c41a78..4a8b6b4 100644
--- a/tests/opus_padding.rs
+++ b/tests/opus_padding.rs
@@ -3,6 +3,7 @@
 #![allow(non_upper_case_globals)]
 #![allow(unused_assignments)]
 #![allow(unused_mut)]
+#![allow(deprecated)]
 
 pub mod test_opus_common_h {
     pub static mut iseed: u32 = 0;
@@ -49,7 +50,7 @@ pub unsafe fn test_overflow() -> i32 {
     );
     *in_0.offset((16909318 - 1) as isize) = 0xb;
     decoder = opus_decoder_create(48000, 2, &mut error);
-    result = opus_decode(decoder, in_0, 16909318, out, 5760, 0);
+    result = opus_decode(&mut *decoder, in_0, 16909318, out, 5760, 0);
     opus_decoder_destroy(decoder);
     free(in_0 as *mut core::ffi::c_void);
     free(out as *mut core::ffi::c_void);
diff --git a/unsafe-libopus-tools/src/demo/backend.rs b/unsafe-libopus-tools/src/demo/backend.rs
index ad8fbf2..1acf9a0 100644
--- a/unsafe-libopus-tools/src/demo/backend.rs
+++ b/unsafe-libopus-tools/src/demo/backend.rs
@@ -97,7 +97,7 @@ mod unsafe_libopus {
             frame_size: i32,
             decode_fec: i32,
         ) -> i32 {
-            opus_decode(st.as_mut(), data, len, pcm, frame_size, decode_fec)
+            opus_decode(st, data, len, pcm, frame_size, decode_fec)
         }
 
         unsafe fn opus_decoder_ctl_impl(
@@ -105,7 +105,7 @@ mod unsafe_libopus {
             request: i32,
             args: VarArgs,
         ) -> i32 {
-            opus_decoder_ctl_impl(st.as_mut(), request, args)
+            opus_decoder_ctl_impl(st, request, args)
         }
 
         unsafe fn opus_decoder_destroy(st: Box<OpusDecoder>) {