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 ------------------------------------------------------------*/

View File

@ -22,7 +22,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Id: tone_generate_tests.c,v 1.22 2009/05/30 15:23:14 steveu Exp $
* $Id: tone_generate_tests.c,v 1.23 2010/05/22 13:20:18 steveu Exp $
*/
/*! \page tone_generate_tests_page Tone generation tests
@ -66,7 +66,7 @@ int main(int argc, char *argv[])
}
/* Try a tone pair */
make_tone_gen_descriptor(&tone_desc,
tone_gen_descriptor_init(&tone_desc,
440,
-10,
620,
@ -88,7 +88,7 @@ int main(int argc, char *argv[])
}
/* Try a different tone pair */
make_tone_gen_descriptor(&tone_desc,
tone_gen_descriptor_init(&tone_desc,
350,
-10,
440,
@ -110,7 +110,7 @@ int main(int argc, char *argv[])
}
/* Try a different tone pair */
make_tone_gen_descriptor(&tone_desc,
tone_gen_descriptor_init(&tone_desc,
400,
-10,
450,
@ -132,7 +132,7 @@ int main(int argc, char *argv[])
}
/* Try a single tone */
make_tone_gen_descriptor(&tone_desc,
tone_gen_descriptor_init(&tone_desc,
400,
-10,
0,
@ -154,7 +154,7 @@ int main(int argc, char *argv[])
}
/* Try a single non-repeating tone */
make_tone_gen_descriptor(&tone_desc,
tone_gen_descriptor_init(&tone_desc,
820,
-10,
0,
@ -176,7 +176,7 @@ int main(int argc, char *argv[])
}
/* Try a single non-repeating tone at 0dBm0 */
make_tone_gen_descriptor(&tone_desc,
tone_gen_descriptor_init(&tone_desc,
820,
0,
0,
@ -198,7 +198,7 @@ int main(int argc, char *argv[])
}
/* Try an AM modulated tone at a modest modulation level (25%) */
make_tone_gen_descriptor(&tone_desc,
tone_gen_descriptor_init(&tone_desc,
425,
-10,
-50,
@ -220,7 +220,7 @@ int main(int argc, char *argv[])
}
/* Try an AM modulated tone at maximum modulation level (100%) */
make_tone_gen_descriptor(&tone_desc,
tone_gen_descriptor_init(&tone_desc,
425,
-10,
-50,