1*a58d3d2aSXin Li /* Copyright (c) 2022 Amazon 2*a58d3d2aSXin Li Written by Jan Buethe */ 3*a58d3d2aSXin Li /* 4*a58d3d2aSXin Li Redistribution and use in source and binary forms, with or without 5*a58d3d2aSXin Li modification, are permitted provided that the following conditions 6*a58d3d2aSXin Li are met: 7*a58d3d2aSXin Li 8*a58d3d2aSXin Li - Redistributions of source code must retain the above copyright 9*a58d3d2aSXin Li notice, this list of conditions and the following disclaimer. 10*a58d3d2aSXin Li 11*a58d3d2aSXin Li - Redistributions in binary form must reproduce the above copyright 12*a58d3d2aSXin Li notice, this list of conditions and the following disclaimer in the 13*a58d3d2aSXin Li documentation and/or other materials provided with the distribution. 14*a58d3d2aSXin Li 15*a58d3d2aSXin Li THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16*a58d3d2aSXin Li ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17*a58d3d2aSXin Li LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18*a58d3d2aSXin Li A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 19*a58d3d2aSXin Li OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20*a58d3d2aSXin Li EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21*a58d3d2aSXin Li PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 22*a58d3d2aSXin Li PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 23*a58d3d2aSXin Li LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 24*a58d3d2aSXin Li NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25*a58d3d2aSXin Li SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26*a58d3d2aSXin Li */ 27*a58d3d2aSXin Li 28*a58d3d2aSXin Li #ifndef DRED_ENCODER_H 29*a58d3d2aSXin Li #define DRED_ENCODER_H 30*a58d3d2aSXin Li 31*a58d3d2aSXin Li #include "lpcnet.h" 32*a58d3d2aSXin Li #include "dred_config.h" 33*a58d3d2aSXin Li #include "dred_rdovae.h" 34*a58d3d2aSXin Li #include "entcode.h" 35*a58d3d2aSXin Li #include "lpcnet_private.h" 36*a58d3d2aSXin Li #include "dred_rdovae_enc.h" 37*a58d3d2aSXin Li #include "dred_rdovae_enc_data.h" 38*a58d3d2aSXin Li 39*a58d3d2aSXin Li #define RESAMPLING_ORDER 8 40*a58d3d2aSXin Li 41*a58d3d2aSXin Li typedef struct { 42*a58d3d2aSXin Li RDOVAEEnc model; 43*a58d3d2aSXin Li LPCNetEncState lpcnet_enc_state; 44*a58d3d2aSXin Li RDOVAEEncState rdovae_enc; 45*a58d3d2aSXin Li int loaded; 46*a58d3d2aSXin Li opus_int32 Fs; 47*a58d3d2aSXin Li int channels; 48*a58d3d2aSXin Li 49*a58d3d2aSXin Li #define DREDENC_RESET_START input_buffer 50*a58d3d2aSXin Li float input_buffer[2*DRED_DFRAME_SIZE]; 51*a58d3d2aSXin Li int input_buffer_fill; 52*a58d3d2aSXin Li int dred_offset; 53*a58d3d2aSXin Li int latent_offset; 54*a58d3d2aSXin Li int last_extra_dred_offset; 55*a58d3d2aSXin Li float latents_buffer[DRED_MAX_FRAMES * DRED_LATENT_DIM]; 56*a58d3d2aSXin Li int latents_buffer_fill; 57*a58d3d2aSXin Li float state_buffer[DRED_MAX_FRAMES * DRED_STATE_DIM]; 58*a58d3d2aSXin Li float resample_mem[RESAMPLING_ORDER + 1]; 59*a58d3d2aSXin Li } DREDEnc; 60*a58d3d2aSXin Li 61*a58d3d2aSXin Li int dred_encoder_load_model(DREDEnc* enc, const void *data, int len); 62*a58d3d2aSXin Li void dred_encoder_init(DREDEnc* enc, opus_int32 Fs, int channels); 63*a58d3d2aSXin Li void dred_encoder_reset(DREDEnc* enc); 64*a58d3d2aSXin Li 65*a58d3d2aSXin Li void dred_deinit_encoder(DREDEnc *enc); 66*a58d3d2aSXin Li 67*a58d3d2aSXin Li void dred_compute_latents(DREDEnc *enc, const float *pcm, int frame_size, int extra_delay, int arch); 68*a58d3d2aSXin Li 69*a58d3d2aSXin Li int dred_encode_silk_frame(DREDEnc *enc, unsigned char *buf, int max_chunks, int max_bytes, int q0, int dQ, int qmax, unsigned char *activity_mem, int arch); 70*a58d3d2aSXin Li 71*a58d3d2aSXin Li #endif 72