shithub: sox

Download patch

ref: c220e4dab9d4c50e141f6a2e23e9a6f9e6569475
parent: 3a8a9d45f12e4e9b22bc6ad9ca578916ddf1cac6
author: robs <robs>
date: Wed Mar 18 13:47:19 EDT 2009

parameterise sox_flow_effects callback

--- a/src/effects.c
+++ b/src/effects.c
@@ -312,7 +312,7 @@
 }
 
 /* Flow data through the effects chain until an effect or callback gives EOF */
-int sox_flow_effects(sox_effects_chain_t * chain, int (* callback)(sox_bool all_done))
+int sox_flow_effects(sox_effects_chain_t * chain, int (* callback)(sox_bool all_done, void * client_data), void * client_data)
 {
   int flow_status = SOX_SUCCESS;
   size_t e, source_e = 0;               /* effect indices */
@@ -355,7 +355,7 @@
     else if ((int)--e < (int)source_e)
       e = source_e;
 
-    if (callback && callback(source_e == chain->length) != SOX_SUCCESS) {
+    if (callback && callback(source_e == chain->length, client_data) != SOX_SUCCESS) {
       flow_status = SOX_EOF; /* Client has requested to stop the flow. */
       break;
     }
--- a/src/example0.c
+++ b/src/example0.c
@@ -80,7 +80,7 @@
   assert(sox_add_effect(chain, e, &in->signal, &in->signal) == SOX_SUCCESS);
 
   /* Flow samples through the effects processing chain until EOF is reached */
-  sox_flow_effects(chain, NULL);
+  sox_flow_effects(chain, NULL, NULL);
 
   /* All done; tidy up: */
   sox_delete_effects_chain(chain);
--- a/src/example1.c
+++ b/src/example1.c
@@ -150,7 +150,7 @@
   assert(sox_add_effect(chain, e, &in->signal, &in->signal) == SOX_SUCCESS);
 
   /* Flow samples through the effects processing chain until EOF is reached */
-  sox_flow_effects(chain, NULL);
+  sox_flow_effects(chain, NULL, NULL);
 
   /* All done; tidy up: */
   sox_delete_effects_chain(chain);
--- a/src/sox.c
+++ b/src/sox.c
@@ -1186,8 +1186,9 @@
 }
 #endif
 
-static int update_status(sox_bool all_done)
+static int update_status(sox_bool all_done, void * client_data)
 {
+  (void)client_data;
   if (interactive) while (kbhit()) {
     int ch = getchar();
 
@@ -1607,7 +1608,7 @@
 
   signal(SIGTERM, sigint); /* Stop gracefully, as soon as we possibly can. */
   signal(SIGINT , sigint); /* Either skip current input or behave as SIGTERM. */
-  flow_status = sox_flow_effects(effects_chain, update_status);
+  flow_status = sox_flow_effects(effects_chain, update_status, NULL);
 
   /* Don't return SOX_EOF if
    * 1) input reach EOF and there are more input files to process or
--- a/src/sox.h
+++ b/src/sox.h
@@ -514,7 +514,7 @@
     sox_encodinginfo_t const * in_enc, sox_encodinginfo_t const * out_enc);
 void sox_delete_effects_chain(sox_effects_chain_t *ecp);
 int sox_add_effect( sox_effects_chain_t * chain, sox_effect_t * effp, sox_signalinfo_t * in, sox_signalinfo_t const * out);
-int sox_flow_effects(sox_effects_chain_t *, int (* callback)(sox_bool all_done));
+int sox_flow_effects(sox_effects_chain_t *, int (* callback)(sox_bool all_done, void * client_data), void * client_data);
 size_t sox_effects_clips(sox_effects_chain_t *);
 size_t sox_stop_effect(sox_effect_t *effp);
 void sox_push_effect_last(sox_effects_chain_t *chain, sox_effect_t *effp);