/* Code provided by Reality AI */
/* 
    Generated by Reality AI Tools
    Date            : 06/06/2025, 00:33:37
    Account         : RealityAIAdmin
    Project         : baby cry demo - ra8p1
    H2Go Version    : 1.8
    Hopper Version  : 1.572
    Target          : RA8xx (ARM Cortex-M85)
    Model Type      : RAI_SVM_CLASSIFIER
    User Data Type  : int16
    Window Length   : 4000
    Channel Count   : 1
    Class Map       : [no_results: 0, baby_cry: 1, noise: 2]
    ET Segmentation : None
    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 <stdio.h>
#include "baby_cry_10_sm_model.h"
#ifdef __linux__
#include <unistd.h>
#endif

int example_main(void);

#define APPLY_SOFTMAX  1
static float conf_scores[baby_cry_10_sm_NUM_CLASSES];  /* confidence scores */
static int16_t inputData[baby_cry_10_sm_SAMPLES_PER_CHANNEL * baby_cry_10_sm_NUM_CHANNELS];

int example_main(void)
{
    /* Init Your board and hardware here. */

    /* Example code loop
    *  Enter an infinite loop, generate a random vector of input data, execute predict function,
    *  and print the result. Replace this with your actual data read and windowing process.
    */

    while(1){
        /*
         * Fetch next data input window from your device.
         * Sensor data is simulated in this loop and formatted as a single dimensional array in WC
         * format (width W, channels C). Multi-channel windows are constructed for single-event prediction.
         *
         * Expected format of sensor data stream:
         * ch0[0],ch0[1],...,ch0[N-1], ch1[0],ch1[1],...,ch1[N-1], ... where N is SAMPLES_PER_CHANNEL (Window Length)
         * REPLACE THIS BLOCK WITH INPUT FROM YOUR DEVICE
        */
        for(size_t sample = 0; sample < baby_cry_10_sm_SAMPLES_PER_CHANNEL; sample++){
            for(size_t channel = 0; channel < baby_cry_10_sm_NUM_CHANNELS; channel++){
                int16_t x = (int16_t)((rand() % 64000) - 32000);
                inputData[channel*baby_cry_10_sm_SAMPLES_PER_CHANNEL+sample] = x;
            }
        }
    
        /* Model prediction */
        baby_cry_10_sm_AICLASS AIC = baby_cry_10_sm_predict(inputData);
        
        /* Convert class score to confidence score (CS) */
        RealityAI_get_class_scores(conf_scores, baby_cry_10_sm_NUM_CLASSES, APPLY_SOFTMAX, get_baby_cry_10_sm_model());

        /* Decode classification event using class names */
		switch(AIC){
		case(baby_cry_10_sm_no_results):
			printf("Predicted Class: no_results\n");
			break;
		case(baby_cry_10_sm_baby_cry):
			printf("Predicted Class: baby_cry [%.2f]\n", conf_scores[0]);
			break;
		case(baby_cry_10_sm_noise):
			printf("Predicted Class: noise [%.2f]\n", conf_scores[1]);
			break;
		};

        /* throttle execution speed */
    #ifdef __linux__
        sleep(1);
    #endif
  }
  return 0;
}
