shithub: sox

Download patch

ref: 98794ec760bef653e12081344167c8c5f1e10318
parent: 7c691371778b480154fb5c9f66c9541d3a62d807
author: rrt <rrt>
date: Wed Dec 27 17:59:57 EST 2006

Make speed work without ST_EFF_NULL; add st_effect_nothing_flow to
enable this.

--- a/src/misc.c
+++ b/src/misc.c
@@ -438,17 +438,33 @@
 int st_format_nothing_seek(ft_t ft UNUSED, st_size_t offset UNUSED) { st_fail_errno(ft, ST_ENOTSUP, "operation not supported"); return(ST_EOF); }
 
 /* dummy effect routine for do-nothing functions */
-int st_effect_nothing(eff_t effp UNUSED) { return(ST_SUCCESS); }
+int st_effect_nothing(eff_t effp UNUSED)
+{
+  return ST_SUCCESS;
+}
+
+int st_effect_nothing_flow(eff_t effp UNUSED, st_sample_t *ibuf UNUSED, st_sample_t *obuf UNUSED, st_size_t *isamp, st_size_t *osamp)
+{
+  /* Pass through samples verbatim */
+  *isamp = *osamp = min(*isamp, *osamp);
+  memcpy(obuf, ibuf, *isamp * sizeof(st_sample_t));
+  return ST_SUCCESS;
+}
+
 int st_effect_nothing_drain(eff_t effp UNUSED, st_sample_t *obuf UNUSED, st_size_t *osamp)
-  { /* Inform no more samples to drain */ *osamp = 0; return(ST_EOF); }
+{
+  /* Inform no more samples to drain */
+  *osamp = 0;
+  return ST_EOF;
+}
 
 int st_effect_nothing_getopts(eff_t effp, int n, char **argv UNUSED)
 {
-     if (n) {
-          st_fail(effp->h->usage);
-          return (ST_EOF);
-     }
-     return (ST_SUCCESS);
+  if (n) {
+    st_fail(effp->h->usage);
+    return (ST_EOF);
+  }
+  return (ST_SUCCESS);
 }
 
 
@@ -455,16 +471,16 @@
 /* here for linear interp.  might be useful for other things */
 st_sample_t st_gcd(st_sample_t a, st_sample_t b)
 {
-        if (b == 0)
-                return a;
-        else
-                return st_gcd(b, a % b);
+  if (b == 0)
+    return a;
+  else
+    return st_gcd(b, a % b);
 }
 
 st_sample_t st_lcm(st_sample_t a, st_sample_t b)
 {
-    /* parenthesize this way to avoid st_sample_t overflow in product term */
-    return a * (b / st_gcd(a, b));
+  /* parenthesize this way to avoid st_sample_t overflow in product term */
+  return a * (b / st_gcd(a, b));
 }
 
 #ifndef HAVE_STRCASECMP
--- a/src/speed.c
+++ b/src/speed.c
@@ -37,10 +37,17 @@
   return ST_EOF;
 }
 
-st_effect_t const * st_speed_effect_fn(void)
+st_effect_t const *st_speed_effect_fn(void)
 {
   static st_effect_t driver = {
-    "speed", "Usage: speed factor[c]", ST_EFF_NULL,
-    getopts, NULL, NULL, NULL, NULL, NULL};
+    "speed", "Usage: speed factor[c]",
+    ST_EFF_MCHAN,
+    getopts,
+    st_effect_nothing,
+    st_effect_nothing_flow,
+    st_effect_nothing_drain,
+    st_effect_nothing,
+    st_effect_nothing
+  };
   return &driver;
 }
--- a/src/st_i.h
+++ b/src/st_i.h
@@ -247,6 +247,7 @@
 st_size_t st_format_nothing_write_io(ft_t ft, const st_sample_t *buf, st_size_t len);
 int st_format_nothing_seek(ft_t ft, st_size_t offset);
 int st_effect_nothing(eff_t effp);
+int st_effect_nothing_flow(eff_t effp, st_sample_t *ibuf, st_sample_t *obuf, st_size_t *isamp, st_size_t *osamp);
 int st_effect_nothing_drain(eff_t effp, st_sample_t *obuf, st_size_t *osamp);
 int st_effect_nothing_getopts(eff_t effp, int n, char **argv UNUSED);