* 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 */
\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);
* 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 */
#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)
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 --------------------------------------------------------*/
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 ------------------------------------------------------------*/
* 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
}
/* Try a tone pair */
- make_tone_gen_descriptor(&tone_desc,
+ tone_gen_descriptor_init(&tone_desc,
440,
-10,
620,
}
/* Try a different tone pair */
- make_tone_gen_descriptor(&tone_desc,
+ tone_gen_descriptor_init(&tone_desc,
350,
-10,
440,
}
/* Try a different tone pair */
- make_tone_gen_descriptor(&tone_desc,
+ tone_gen_descriptor_init(&tone_desc,
400,
-10,
450,
}
/* Try a single tone */
- make_tone_gen_descriptor(&tone_desc,
+ tone_gen_descriptor_init(&tone_desc,
400,
-10,
0,
}
/* Try a single non-repeating tone */
- make_tone_gen_descriptor(&tone_desc,
+ tone_gen_descriptor_init(&tone_desc,
820,
-10,
0,
}
/* Try a single non-repeating tone at 0dBm0 */
- make_tone_gen_descriptor(&tone_desc,
+ tone_gen_descriptor_init(&tone_desc,
820,
0,
0,
}
/* 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,
}
/* 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,