/*
 * rec_float.c
 *
 *  Created on: 04-01-2017
 *      Author: KJ
 */


#include "tdefs.h"
#include "misc.h"

#include "rec_float.h"
#include "helper.h"

int rec_float_initlog(void *arguments, void *logic)
{
	struct rec_float_args *args = (struct rec_float_args *)arguments;
	struct rec_float_logic *log = (struct rec_float_logic *)logic;

	if(set_float_ptr(args->io.sample_float_in,&log->sample))
		return -1;

	log->sample_new=0;
	log->in_ptr = &log->sample_new;

	log->mul=((double)32768.0/args->params.wart_absmax);

	return 0;
}

void rec_float(void *arguments, void *logic)
{
	struct rec_float_logic *log = (struct rec_float_logic *)logic;
	float tmp;

	if(*log->sample==32768.0f)
		log->sample_new=32768;
	else
	{
		tmp = (*log->sample*log->mul);
		log->sample_new=tmp>32767.0f?32767:(tmp<-32767.0f?-32767:(u16)tmp);
	}
}
