Tone generate modified to export the descriptor creation and deletion.

This commit is contained in:
Steve Underwood
2010-06-07 00:33:46 +08:00
parent bc13e944c6
commit f87bf812e7
3 changed files with 87 additions and 62 deletions

View File

@@ -22,7 +22,7 @@
* License along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Id: tone_generate.h,v 1.39 2009/06/02 16:03:56 steveu Exp $
* $Id: tone_generate.h,v 1.40 2010/05/22 13:20:18 steveu Exp $
*/
/*! \file */
@@ -77,16 +77,18 @@ extern "C"
\param d3 x
\param d4 x
\param repeat x */
SPAN_DECLARE(void) make_tone_gen_descriptor(tone_gen_descriptor_t *s,
int f1,
int l1,
int f2,
int l2,
int d1,
int d2,
int d3,
int d4,
int repeat);
SPAN_DECLARE(tone_gen_descriptor_t *) tone_gen_descriptor_init(tone_gen_descriptor_t *s,
int f1,
int l1,
int f2,
int l2,
int d1,
int d2,
int d3,
int d4,
int repeat);
SPAN_DECLARE(void) tone_gen_descriptor_free(tone_gen_descriptor_t *s);
SPAN_DECLARE_NONSTD(int) tone_gen(tone_gen_state_t *s, int16_t amp[], int max_samples);

View File

@@ -22,7 +22,7 @@
* License along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Id: tone_generate.c,v 1.53.4.1 2009/12/23 14:23:49 steveu Exp $
* $Id: tone_generate.c,v 1.56 2010/05/23 14:02:21 steveu Exp $
*/
/*! \file */
@@ -59,18 +59,26 @@
#define M_PI 3.14159265358979323846264338327
#endif
SPAN_DECLARE(void) make_tone_gen_descriptor(tone_gen_descriptor_t *s,
int f1,
int l1,
int f2,
int l2,
int d1,
int d2,
int d3,
int d4,
int repeat)
SPAN_DECLARE(tone_gen_descriptor_t *) tone_gen_descriptor_init(tone_gen_descriptor_t *s,
int f1,
int l1,
int f2,
int l2,
int d1,
int d2,
int d3,
int d4,
int repeat)
{
if (s == NULL)
{
if ((s = (tone_gen_descriptor_t *) malloc(sizeof(*s))) == NULL)
{
return NULL;
}
}
memset(s, 0, sizeof(*s));
if (f1)
{
#if defined(SPANDSP_USE_FIXED_POINT)
@@ -102,42 +110,14 @@ SPAN_DECLARE(void) make_tone_gen_descriptor(tone_gen_descriptor_t *s,
s->duration[3] = d4*SAMPLE_RATE/1000;
s->repeat = repeat;
}
/*- End of function --------------------------------------------------------*/
SPAN_DECLARE(tone_gen_state_t *) tone_gen_init(tone_gen_state_t *s, tone_gen_descriptor_t *t)
{
int i;
if (s == NULL)
return NULL;
for (i = 0; i < 4; i++)
{
s->tone[i] = t->tone[i];
s->phase[i] = 0;
}
for (i = 0; i < 4; i++)
s->duration[i] = t->duration[i];
s->repeat = t->repeat;
s->current_section = 0;
s->current_position = 0;
return s;
}
/*- End of function --------------------------------------------------------*/
SPAN_DECLARE(int) tone_gen_release(tone_gen_state_t *s)
SPAN_DECLARE(void) tone_gen_descriptor_free(tone_gen_descriptor_t *s)
{
return 0;
}
/*- End of function --------------------------------------------------------*/
SPAN_DECLARE(int) tone_gen_free(tone_gen_state_t *s)
{
if (s)
free(s);
return 0;
free(s);
}
/*- End of function --------------------------------------------------------*/
@@ -236,4 +216,47 @@ SPAN_DECLARE_NONSTD(int) tone_gen(tone_gen_state_t *s, int16_t amp[], int max_sa
return samples;
}
/*- End of function --------------------------------------------------------*/
SPAN_DECLARE(tone_gen_state_t *) tone_gen_init(tone_gen_state_t *s, tone_gen_descriptor_t *t)
{
int i;
if (s == NULL)
{
if ((s = (tone_gen_state_t *) malloc(sizeof(*s))) == NULL)
{
return NULL;
}
}
memset(s, 0, sizeof(*s));
for (i = 0; i < 4; i++)
{
s->tone[i] = t->tone[i];
s->phase[i] = 0;
}
for (i = 0; i < 4; i++)
s->duration[i] = t->duration[i];
s->repeat = t->repeat;
s->current_section = 0;
s->current_position = 0;
return s;
}
/*- End of function --------------------------------------------------------*/
SPAN_DECLARE(int) tone_gen_release(tone_gen_state_t *s)
{
return 0;
}
/*- End of function --------------------------------------------------------*/
SPAN_DECLARE(int) tone_gen_free(tone_gen_state_t *s)
{
if (s)
free(s);
return 0;
}
/*- End of function --------------------------------------------------------*/
/*- End of file ------------------------------------------------------------*/