1*1295d682SXin Li /* Copyright (c) 2017 Jean-Marc Valin */ 2*1295d682SXin Li /* 3*1295d682SXin Li Redistribution and use in source and binary forms, with or without 4*1295d682SXin Li modification, are permitted provided that the following conditions 5*1295d682SXin Li are met: 6*1295d682SXin Li 7*1295d682SXin Li - Redistributions of source code must retain the above copyright 8*1295d682SXin Li notice, this list of conditions and the following disclaimer. 9*1295d682SXin Li 10*1295d682SXin Li - Redistributions in binary form must reproduce the above copyright 11*1295d682SXin Li notice, this list of conditions and the following disclaimer in the 12*1295d682SXin Li documentation and/or other materials provided with the distribution. 13*1295d682SXin Li 14*1295d682SXin Li THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 15*1295d682SXin Li ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 16*1295d682SXin Li LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 17*1295d682SXin Li A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR 18*1295d682SXin Li CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 19*1295d682SXin Li EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 20*1295d682SXin Li PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 21*1295d682SXin Li PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 22*1295d682SXin Li LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 23*1295d682SXin Li NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24*1295d682SXin Li SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25*1295d682SXin Li */ 26*1295d682SXin Li 27*1295d682SXin Li #ifndef RNN_H_ 28*1295d682SXin Li #define RNN_H_ 29*1295d682SXin Li 30*1295d682SXin Li #include "rnnoise.h" 31*1295d682SXin Li 32*1295d682SXin Li #include "opus_types.h" 33*1295d682SXin Li 34*1295d682SXin Li #define WEIGHTS_SCALE (1.f/256) 35*1295d682SXin Li 36*1295d682SXin Li #define MAX_NEURONS 128 37*1295d682SXin Li 38*1295d682SXin Li #define ACTIVATION_TANH 0 39*1295d682SXin Li #define ACTIVATION_SIGMOID 1 40*1295d682SXin Li #define ACTIVATION_RELU 2 41*1295d682SXin Li 42*1295d682SXin Li typedef signed char rnn_weight; 43*1295d682SXin Li 44*1295d682SXin Li typedef struct { 45*1295d682SXin Li const rnn_weight *bias; 46*1295d682SXin Li const rnn_weight *input_weights; 47*1295d682SXin Li int nb_inputs; 48*1295d682SXin Li int nb_neurons; 49*1295d682SXin Li int activation; 50*1295d682SXin Li } DenseLayer; 51*1295d682SXin Li 52*1295d682SXin Li typedef struct { 53*1295d682SXin Li const rnn_weight *bias; 54*1295d682SXin Li const rnn_weight *input_weights; 55*1295d682SXin Li const rnn_weight *recurrent_weights; 56*1295d682SXin Li int nb_inputs; 57*1295d682SXin Li int nb_neurons; 58*1295d682SXin Li int activation; 59*1295d682SXin Li } GRULayer; 60*1295d682SXin Li 61*1295d682SXin Li typedef struct RNNState RNNState; 62*1295d682SXin Li 63*1295d682SXin Li void compute_dense(const DenseLayer *layer, float *output, const float *input); 64*1295d682SXin Li 65*1295d682SXin Li void compute_gru(const GRULayer *gru, float *state, const float *input); 66*1295d682SXin Li 67*1295d682SXin Li void compute_rnn(RNNState *rnn, float *gains, float *vad, const float *input); 68*1295d682SXin Li 69*1295d682SXin Li #endif /* RNN_H_ */ 70