]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
Tone generate modified to export the descriptor creation and deletion.
authorSteve Underwood <steveu@coppice.org>
Sun, 6 Jun 2010 16:33:46 +0000 (00:33 +0800)
committerSteve Underwood <steveu@coppice.org>
Sun, 6 Jun 2010 16:33:46 +0000 (00:33 +0800)
libs/spandsp/src/spandsp/tone_generate.h
libs/spandsp/src/tone_generate.c
libs/spandsp/tests/tone_generate_tests.c

index 2a15914efa471223d39e327d24fb70cb9d16a452..4cd7ff93a0a0ca09c0d0d2f4eb8a2a3c92a37f1b 100644 (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);
 
index 6ea3077186e1648b2a0ee199924073734742e1e7..4b65610289c3b4854546dabed3938d1914ece3d0 100644 (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 */
 #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 ------------------------------------------------------------*/
index d16c61d80a8afda441f971a7e3e8904e41f758cb..1e5035510ff46a35adae670073b0e2d8177f4441 100644 (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,