/* Code provided by Reality AI */
/* 
    Generated by Reality AI Tools
    Date            : 11/12/2024, 05:41:02
    Account         : NA
    Project         : NA
    H2Go Version    : 1.6
    Hopper Version  : 1.570
    Target Proc     : VOICE-RA6E1
    Model Type      : RAI_SVM_CLASSIFIER
    User Data Type  : float32
    Window Length   : 4096
    Channel Count   : 1
    Class Map       : [no_results: 0, baby_cry: 1, everything_else: 2]
    Smoothing       : None

    Copyright (c) Renesas of America, Inc.  All rights reserved.
    Use and distribution are subject to applicable contract restrictions.
*/

/*
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#include "baby_cry_alp_v1_model.h"

/*********************** --- MODEL INFORMATION --- ***********************/

#define baby_cry_alp_v1_MODEL_NAME               "baby_cry_alp_v1"
#define baby_cry_alp_v1_WINDOW_SIZE               64
#define baby_cry_alp_v1_SUBWINDOW_SIZE            0
#define baby_cry_alp_v1_WINDOWS_PER_CHANNEL       127
#define baby_cry_alp_v1_STEP_SIZE                 32
#define baby_cry_alp_v1_SUBSET_FEATURE_LENGTH     32
#define baby_cry_alp_v1_FLAGS                     0x0
#define baby_cry_alp_v1_DTYPE_MATCH               1

extern void  edsp_convert_from_float32(const void*, rai_data_t*,int,struct conversion_struct*);
extern void  group_e4c2_feature(rai_data_t*,rai_data_t*,struct feature_extraction_struct*);

float baby_cry_alp_v1_LEARNER_SCORES[baby_cry_alp_v1_NUM_LEARNERS];
float baby_cry_alp_v1_CLASS_SCORES[baby_cry_alp_v1_NUM_CLASSES];

RAI_ATTR_ALIGN(8) const float baby_cry_alp_v1_MU[baby_cry_alp_v1_NUM_LEARNERS*baby_cry_alp_v1_FEATURE_LENGTH]={
	11.296653340292551f,8.979812949061831f,7.380323082447580f,6.758053683965673f,6.452017107601192f,6.016449539799144f,5.975149705750320f,5.965481059364193f,5.736589668658866f,5.403153909234661f,5.180165799637783f,5.011868420778696f,4.857176488776636f,5.148563657478992f,5.273193164773224f,5.523580592354451f,5.409313139465374f,5.282951928491851f,4.986426148206788f,4.890975198789003f,4.798610770422631f,4.641347818581393f,4.731980314313229f,4.826624824471689f,4.727927229686983f,4.839615889352920f,4.910505383417620f,4.894114567116032f,5.003388790055528f,5.092786494235955f,4.983097893723459f,4.951898747906187f,
};
RAI_ATTR_ALIGN(8) const float baby_cry_alp_v1_SIGMA[baby_cry_alp_v1_NUM_LEARNERS*baby_cry_alp_v1_FEATURE_LENGTH]={
	1.559212877678740f,5.714332458946375f,3.398897636538552f,1.716903991814031f,1.066474457511491f,1.265903096393054f,0.955046823900447f,0.814154375475799f,0.920443890213547f,1.229939049919472f,1.346379418175023f,1.550820749133317f,1.637384388261288f,1.284606358173157f,1.053101358754674f,0.935163773313376f,0.874090543152346f,0.949153871678310f,0.982149200333095f,0.968237027016551f,0.927819195145972f,0.932001178582325f,0.884985390347616f,0.873986169101607f,0.811181643009241f,0.768816434964791f,0.746478300446523f,0.678403335064417f,0.661699387463004f,0.686038112964687f,0.643131866415925f,0.623632833294689f,
};
RAI_ATTR_ALIGN(8) const float baby_cry_alp_v1_BETA[baby_cry_alp_v1_NUM_LEARNERS*baby_cry_alp_v1_FEATURE_LENGTH]={
	0.088163464673723f,-0.932145349442369f,-0.373018675959042f,1.644739756762712f,2.576072238641139f,0.736024197714617f,-0.161818476276525f,-0.147206346437360f,-0.777248522069291f,-0.247422783320362f,1.930387803171461f,-0.367301761132743f,-1.040576596603946f,1.149905739710964f,-1.322303109694191f,-0.802433578790603f,0.649325332502704f,0.350009668593191f,0.429176059017651f,-0.352118568941354f,0.118200652157915f,-0.948106080400027f,-0.769066288920284f,1.226553356051546f,-0.176158502724758f,-0.566146940747129f,0.436035978350494f,0.236342191101109f,0.534105356499561f,1.352537444529412f,0.086242350862175f,-1.395332111880146f,
};
RAI_ATTR_ALIGN(8) const float baby_cry_alp_v1_BIAS[baby_cry_alp_v1_NUM_LEARNERS]={
	1.069692035444141f,
};
const int8_t baby_cry_alp_v1_CODMAT[baby_cry_alp_v1_NUM_CLASSES*baby_cry_alp_v1_NUM_LEARNERS]={
	-1,1,
};

const uint32_t baby_cry_alp_v1_CONV_DATA[4] = {
	8,0,1,0,
};
struct conversion_struct baby_cry_alp_v1_conv = {baby_cry_alp_v1_CONV_DATA, &edsp_convert_from_float32};
struct feature_extraction_struct baby_cry_alp_v1_fe = {baby_cry_alp_v1_NUM_CHANNELS,baby_cry_alp_v1_SAMPLES_PER_CHANNEL,baby_cry_alp_v1_WINDOW_SIZE,baby_cry_alp_v1_SUBWINDOW_SIZE,baby_cry_alp_v1_WINDOWS_PER_CHANNEL,baby_cry_alp_v1_STEP_SIZE,baby_cry_alp_v1_FEATURE_LENGTH,&group_e4c2_feature};


struct svm_network_struct baby_cry_alp_v1_net = {
  .Beta                    = baby_cry_alp_v1_BETA,
  .Bias                    = baby_cry_alp_v1_BIAS,
  .Mu                      = baby_cry_alp_v1_MU,
  .Sigma                   = baby_cry_alp_v1_SIGMA,
  .coding_matrix           = baby_cry_alp_v1_CODMAT,
  .learner_scores          = baby_cry_alp_v1_LEARNER_SCORES
};

struct rai_model_struct baby_cry_alp_v1_model = {
  .Conv                    = &baby_cry_alp_v1_conv,
  .Fe                      = &baby_cry_alp_v1_fe,
  .Smo                     = 0,
  .Cal                     = 0,
  .class_index             = 1,
  .flags                   = baby_cry_alp_v1_FLAGS,
  .Class_scores            = baby_cry_alp_v1_CLASS_SCORES,
  .num_classes             = baby_cry_alp_v1_NUM_CLASSES,
  .num_learners            = baby_cry_alp_v1_NUM_LEARNERS,
  .subset_feature_length   = baby_cry_alp_v1_SUBSET_FEATURE_LENGTH,
  .network                 = &baby_cry_alp_v1_net
};

struct rai_model_struct* get_baby_cry_alp_v1_model(void){
    return &baby_cry_alp_v1_model;
}

baby_cry_alp_v1_AICLASS baby_cry_alp_v1_predict(float* inputData){
    float* ret = baby_cry_alp_v1_model.results;
#if baby_cry_alp_v1_DTYPE_MATCH
    ret[0] = RealityAI_predict(inputData, &baby_cry_alp_v1_model);
#else
    rai_data_t convertedInput[baby_cry_alp_v1_SAMPLES_PER_FRAME];
    RealityAI_convert((void*)inputData, convertedInput, baby_cry_alp_v1_SAMPLES_PER_FRAME, &baby_cry_alp_v1_model);
    ret[0] = RealityAI_predict(convertedInput, &baby_cry_alp_v1_model);
#endif
    ret[1] = RealityAI_smooth(ret[0], &baby_cry_alp_v1_model);
    return (baby_cry_alp_v1_AICLASS)ret[1];
}
