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