2013-10-13 20:05:38 +00:00
|
|
|
/*
|
|
|
|
* fosphor.c
|
|
|
|
*
|
|
|
|
* Main fosphor entry point
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013 Sylvain Munaut
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*! \addtogroup fosphor
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*! \file fosphor.c
|
|
|
|
* \brief Main fosphor entry point
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "cl.h"
|
|
|
|
#include "gl.h"
|
|
|
|
#include "fosphor.h"
|
2013-11-07 22:46:29 +00:00
|
|
|
#include "private.h"
|
2013-10-13 20:05:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
struct fosphor *
|
|
|
|
fosphor_init(void)
|
|
|
|
{
|
|
|
|
struct fosphor *self;
|
2013-11-07 22:46:29 +00:00
|
|
|
int rv;
|
2013-10-13 20:05:38 +00:00
|
|
|
|
|
|
|
/* Allocate structure */
|
|
|
|
self = malloc(sizeof(struct fosphor));
|
|
|
|
if (!self)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
memset(self, 0, sizeof(struct fosphor));
|
|
|
|
|
|
|
|
/* Init GL/CL sub-states */
|
2013-11-07 22:46:29 +00:00
|
|
|
rv = fosphor_gl_init(self);
|
|
|
|
if (rv)
|
2013-10-13 20:05:38 +00:00
|
|
|
goto error;
|
|
|
|
|
2013-11-07 22:46:29 +00:00
|
|
|
rv = fosphor_cl_init(self);
|
|
|
|
if (rv)
|
2013-10-13 20:05:38 +00:00
|
|
|
goto error;
|
|
|
|
|
|
|
|
/* Initial state */
|
2013-11-08 10:28:34 +00:00
|
|
|
fosphor_set_power_range(self, 0, 10);
|
2013-10-13 20:05:38 +00:00
|
|
|
|
|
|
|
return self;
|
|
|
|
|
|
|
|
/* Error path */
|
|
|
|
error:
|
|
|
|
fosphor_release(self);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
fosphor_release(struct fosphor *self)
|
|
|
|
{
|
|
|
|
if (!self)
|
|
|
|
return;
|
|
|
|
|
2013-11-07 22:46:29 +00:00
|
|
|
fosphor_cl_release(self);
|
|
|
|
fosphor_gl_release(self);
|
2013-10-13 20:05:38 +00:00
|
|
|
|
|
|
|
free(self);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fosphor_process(struct fosphor *self, void *samples, int len)
|
|
|
|
{
|
2013-11-07 22:46:29 +00:00
|
|
|
return fosphor_cl_process(self, samples, len);
|
2013-10-13 20:05:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
fosphor_draw(struct fosphor *self, int w, int h)
|
|
|
|
{
|
2013-11-07 22:46:29 +00:00
|
|
|
int wf_pos = fosphor_cl_get_waterfall_position(self);
|
|
|
|
fosphor_gl_draw(self, w, h, wf_pos);
|
2013-10-13 20:05:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2013-11-08 10:28:34 +00:00
|
|
|
fosphor_set_power_range(struct fosphor *self, int db_ref, int db_per_div)
|
2013-10-13 20:05:38 +00:00
|
|
|
{
|
|
|
|
int db0, db1;
|
|
|
|
float k;
|
|
|
|
float scale, offset;
|
|
|
|
|
|
|
|
db0 = db_ref - 10*db_per_div;
|
|
|
|
db1 = db_ref;
|
|
|
|
|
|
|
|
k = log10f((float)FOSPHOR_FFT_LEN);
|
|
|
|
|
|
|
|
offset = - ( k + ((float)db0 / 20.0f) );
|
|
|
|
scale = 20.0f / (float)(db1 - db0);
|
|
|
|
|
2013-11-08 10:28:34 +00:00
|
|
|
self->power.db_ref = db_ref;
|
|
|
|
self->power.db_per_div = db_per_div;
|
|
|
|
self->power.scale = scale;
|
|
|
|
self->power.offset = offset;
|
|
|
|
|
2013-11-07 22:46:29 +00:00
|
|
|
fosphor_cl_set_histogram_range(self, scale, offset);
|
2013-10-13 20:05:38 +00:00
|
|
|
}
|
|
|
|
|
2013-11-09 10:11:38 +00:00
|
|
|
void
|
|
|
|
fosphor_set_frequency_range(struct fosphor *self, double center, double span)
|
|
|
|
{
|
|
|
|
self->frequency.center = center;
|
|
|
|
self->frequency.span = span;
|
|
|
|
}
|
|
|
|
|
2013-10-13 20:05:38 +00:00
|
|
|
/*! @} */
|