xref: /aosp_15_r20/external/libopus/dnn/osce_structs.h (revision a58d3d2adb790c104798cd88c8a3aff4fa8b82cc)
1 /* Copyright (c) 2023 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 OSCE_STRUCTS_H
29 #define OSCE_STRUCTS_H
30 
31 #include "opus_types.h"
32 #include "osce_config.h"
33 #ifndef DISABLE_LACE
34 #include "lace_data.h"
35 #endif
36 #ifndef DISABLE_NOLACE
37 #include "nolace_data.h"
38 #endif
39 #include "nndsp.h"
40 #include "nnet.h"
41 
42 /* feature calculation */
43 
44 typedef struct {
45     float               numbits_smooth;
46     int                 pitch_hangover_count;
47     int                 last_lag;
48     int                 last_type;
49     float               signal_history[OSCE_FEATURES_MAX_HISTORY];
50     int                 reset;
51 } OSCEFeatureState;
52 
53 
54 #ifndef DISABLE_LACE
55 /* LACE */
56 typedef struct {
57     float feature_net_conv2_state[LACE_FNET_CONV2_STATE_SIZE];
58     float feature_net_gru_state[LACE_COND_DIM];
59     AdaCombState cf1_state;
60     AdaCombState cf2_state;
61     AdaConvState af1_state;
62     float preemph_mem;
63     float deemph_mem;
64 } LACEState;
65 
66 typedef struct
67 {
68     LACELayers layers;
69     float window[LACE_OVERLAP_SIZE];
70 } LACE;
71 
72 #endif /* #ifndef DISABLE_LACE */
73 
74 
75 #ifndef DISABLE_NOLACE
76 /* NoLACE */
77 typedef struct {
78     float feature_net_conv2_state[NOLACE_FNET_CONV2_STATE_SIZE];
79     float feature_net_gru_state[NOLACE_COND_DIM];
80     float post_cf1_state[NOLACE_COND_DIM];
81     float post_cf2_state[NOLACE_COND_DIM];
82     float post_af1_state[NOLACE_COND_DIM];
83     float post_af2_state[NOLACE_COND_DIM];
84     float post_af3_state[NOLACE_COND_DIM];
85     AdaCombState cf1_state;
86     AdaCombState cf2_state;
87     AdaConvState af1_state;
88     AdaConvState af2_state;
89     AdaConvState af3_state;
90     AdaConvState af4_state;
91     AdaShapeState tdshape1_state;
92     AdaShapeState tdshape2_state;
93     AdaShapeState tdshape3_state;
94     float preemph_mem;
95     float deemph_mem;
96 } NoLACEState;
97 
98 typedef struct {
99     NOLACELayers layers;
100     float window[LACE_OVERLAP_SIZE];
101 } NoLACE;
102 
103 #endif /* #ifndef DISABLE_NOLACE */
104 
105 /* OSCEModel */
106 typedef struct {
107    int loaded;
108 #ifndef DISABLE_LACE
109     LACE lace;
110 #endif
111 #ifndef DISABLE_NOLACE
112     NoLACE nolace;
113 #endif
114 } OSCEModel;
115 
116 typedef union {
117 #ifndef DISABLE_LACE
118     LACEState lace;
119 #endif
120 #ifndef DISABLE_NOLACE
121     NoLACEState nolace;
122 #endif
123 } OSCEState;
124 
125 #endif
126