shithub: sox

Download patch

ref: ed218d25d6e01167f8c3485d44b9d33e98a129c8
parent: aa3dc68a1719f6115ccacfaab145eca19da38ece
author: Ulrich Klauer <ulrich@chirlu.de>
date: Fri Jan 20 20:49:49 EST 2012

Remove crop effect

Remove the experimental crop effect, as its functionality is now
included in trim.

--- a/FEATURES.in
+++ b/FEATURES.in
@@ -89,7 +89,6 @@
 ** vol: Adjust audio volume
 
 * Editing effects
-** crop+: Like `trim', but can crop end without specifying length (W.I.P.)
 ** pad: Pad (usually) the ends of the audio with silence
 ** silence: Remove portions of silence from the audio
 ** splice: Perform the equivalent of a cross-faded tape splice
--- a/msvc10/LibSoX.vcxproj
+++ b/msvc10/LibSoX.vcxproj
@@ -200,7 +200,6 @@
     <ClCompile Include="..\src\compand.c" />
     <ClCompile Include="..\src\compandt.c" />
     <ClCompile Include="..\src\contrast.c" />
-    <ClCompile Include="..\src\crop.c" />
     <ClCompile Include="..\src\dcshift.c" />
     <ClCompile Include="..\src\delay.c" />
     <ClCompile Include="..\src\dft_filter.c" />
--- a/msvc10/LibSoX.vcxproj.filters
+++ b/msvc10/LibSoX.vcxproj.filters
@@ -201,9 +201,6 @@
     <ClCompile Include="..\src\contrast.c">
       <Filter>Effect Sources</Filter>
     </ClCompile>
-    <ClCompile Include="..\src\crop.c">
-      <Filter>Effect Sources</Filter>
-    </ClCompile>
     <ClCompile Include="..\src\dcshift.c">
       <Filter>Effect Sources</Filter>
     </ClCompile>
--- a/msvc9/LibSoX.vcproj
+++ b/msvc9/LibSoX.vcproj
@@ -656,10 +656,6 @@
 				>
 			</File>
 			<File
-				RelativePath="..\src\crop.c"
-				>
-			</File>
-			<File
 				RelativePath="..\src\dcshift.c"
 				>
 			</File>
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -29,7 +29,7 @@
   compand         echo            mcompand        reverb          synth
   compandt        echos           mixer           reverse         tempo
   contrast        fade            noiseprof       silence         tremolo
-  crop            fft4g           noisered        sinc            trim
+                  fft4g           noisered        sinc            trim
   dcshift         fir             output          skeleff         upsample
   delay           firfit          overdrive       speed           vad
   dft_filter      flanger         pad             splice          vol
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -66,7 +66,7 @@
 
 # Effects source
 libsox_la_SOURCES += \
-	band.h bend.c biquad.c biquad.h biquads.c chorus.c compand.c crop.c \
+	band.h bend.c biquad.c biquad.h biquads.c chorus.c compand.c \
 	compandt.c compandt.h contrast.c dcshift.c delay.c dft_filter.c \
 	dft_filter.h dither.c dither.h divide.c downsample.c earwax.c \
 	echo.c echos.c effects.c effects.h effects_i.c effects_i_dsp.c \
--- a/src/crop.c
+++ /dev/null
@@ -1,176 +1,0 @@
-/* libSoX effect: Crop ends of audio   (c) 2009 robs@users.sourceforge.net
- *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 2.1 of the License, or (at
- * your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser
- * General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this library; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- */
-
-/* This is W.I.P. hence marked SOX_EFF_ALPHA for now.
- * Need to change size_t/INT32_MAX to uint64_t/INT64_MAX (for LFS) and do
- * proper length change tracking through the effects chain.
- */
-
-#include "sox_i.h"
-#include <string.h>
-
-typedef struct {
-  int argc;
-  struct {int flag; char * str; uint64_t at;} pos[2];
-} priv_t;
-
-static int parse(sox_effect_t * effp, char * * argv, sox_rate_t rate)
-{
-  priv_t * p = (priv_t *)effp->priv;
-  char const * s, * q;
-  uint64_t samples;
-  int i;
-
-  for (i = p->argc - 1; i == 0 || i == 1; --i) {
-    if (argv) /* 1st parse only */
-      p->pos[i].str = lsx_strdup(argv[i]);
-    s = p->pos[i].str;
-    if (strchr("+-" + 1 - i, *s))
-      p->pos[i].flag = *s++;
-
-    q = lsx_parsesamples(rate, s, &samples, 't');
-    p->pos[i].at = samples;
-    if (!q || *q)
-      break;
-  }
-  return i >= 0 ? lsx_usage(effp) : SOX_SUCCESS;
-}
-
-static int create(sox_effect_t * effp, int argc, char * * argv)
-{
-  priv_t * p = (priv_t *)effp->priv;
-  --argc, ++argv;
-  p->argc = argc;
-  return parse(effp, argv, 1e5); /* No rate yet; parse with dummy */
-}
-
-static int start(sox_effect_t * effp)
-{
-  priv_t * p = (priv_t *)effp->priv;
-  int i;
-
-  p->pos[1].at = ((uint64_t)(-1)) / 2 / effp->in_signal.channels;
-  parse(effp, 0, effp->in_signal.rate); /* Re-parse now rate is known */
-  for (i = 0; i < 2; ++i) {
-    p->pos[i].at *= effp->in_signal.channels;
-    if (p->pos[i].flag == '-') {
-      if (effp->in_signal.length == SOX_UNSPEC) {
-        lsx_fail("cannot crop from end: audio length is not known");
-        return SOX_EOF;
-      }
-      if (p->pos[i].at > effp->in_signal.length) {
-        lsx_fail("cannot crop that much from end: audio is too short");
-        return SOX_EOF;
-      }
-      p->pos[i].at = effp->in_signal.length - p->pos[i].at;
-    }
-  }
-  if (p->pos[1].flag != '+') {
-    if (p->pos[0].at > p->pos[1].at) {
-      lsx_fail("start position must be less than stop position");
-      return SOX_EOF;
-    }
-    if (!(p->pos[1].at -= p->pos[0].at))
-      p->pos[0].at = 0;
-  }
-  if (effp->in_signal.length) {
-    if (!p->pos[0].at && p->pos[1].at == effp->in_signal.length)
-      return SOX_EFF_NULL;
-    if (p->pos[0].at > effp->in_signal.length ||
-        (p->argc > 1 && p->pos[0].at + p->pos[1].at > effp->in_signal.length)) {
-      lsx_fail("audio is too short");
-      return SOX_EOF;
-    }
-    effp->out_signal.length = p->argc == 2 ?
-      p->pos[1].at : effp->in_signal.length - p->pos[0].at;
-  }
-  return SOX_SUCCESS;
-}
-
-static int flow(sox_effect_t * effp, sox_sample_t const * ibuf,
-    sox_sample_t * obuf, size_t * isamp, size_t * osamp)
-{
-  priv_t * p = (priv_t *)effp->priv;
-  uint64_t skipped;
-
-  p->pos[0].at -= skipped = min(p->pos[0].at, *isamp);
-  *osamp = !p->pos[0].at * min(p->pos[1].at, min(*isamp - skipped, *osamp));
-  memcpy(obuf, ibuf + skipped, *osamp * sizeof(*obuf));
-  *isamp = skipped + *osamp;
-  return (p->pos[1].at -= *osamp) ? SOX_SUCCESS : SOX_EOF;
-}
-
-static int stop(sox_effect_t * effp)
-{
-  priv_t * p = (priv_t *)effp->priv;
-  if (p->pos[0].at || (p->pos[1].at && p->argc == 2))
-    lsx_warn("input audio was too short to crop as requested");
-  return SOX_SUCCESS;
-}
-
-static int lsx_kill(sox_effect_t * effp)
-{
-  priv_t * p = (priv_t *)effp->priv;
-  free(p->pos[0].str);
-  free(p->pos[1].str);
-  return SOX_SUCCESS;
-}
-
-sox_effect_handler_t const * lsx_crop_effect_fn(void)
-{
-  static sox_effect_handler_t handler = {
-    "crop", "[-]before [[+|-]from]\n"
-      "  n\tposition relative to start\n"
-      "  -n\tposition relative to end\n"
-      "  +n\tposition relative to previous",
-    SOX_EFF_MCHAN | /* SOX_EFF_LENGTH | */ SOX_EFF_MODIFY | SOX_EFF_ALPHA,
-
-    create, start, flow, NULL, stop, lsx_kill, sizeof(priv_t)
-  };
-  return &handler;
-}
-
-sox_uint64_t sox_crop_get_start(sox_effect_t * effp)
-{
-  return ((priv_t *)effp->priv)->pos[0].at;
-}
-
-void sox_crop_clear_start(sox_effect_t * effp)
-{
-  ((priv_t *)effp->priv)->pos[0].at = 0;
-}
-
-#if 0
-/*---------------------- emulation of the `trim' effect ----------------------*/
-
-static int trim_getopts(sox_effect_t * effp, int argc, char * * argv)
-{
-  priv_t * p = (priv_t *)effp->priv;
-  p->pos[1].flag = '+';
-  return lsx_crop_effect_fn()->getopts(effp, argc, argv);
-}
-
-sox_effect_handler_t const * lsx_trim_effect_fn(void)
-{
-  static sox_effect_handler_t handler;
-  handler = *lsx_crop_effect_fn();
-  handler.name = "trim";
-  handler.usage = "start [length]";
-  handler.getopts = trim_getopts;
-  return &handler;
-}
-#endif
--- a/src/effects.h
+++ b/src/effects.h
@@ -26,7 +26,6 @@
   EFFECT(channels)
   EFFECT(compand)
   EFFECT(contrast)
-  EFFECT(crop)
   EFFECT(dcshift)
   EFFECT(deemph)
   EFFECT(delay)
--- a/src/sox.c
+++ b/src/sox.c
@@ -1403,19 +1403,6 @@
       }
     }
   }
-  else if (input_count == 1 && effects_chain->length > 1 && strcmp(effects_chain->effects[1][0].handler.name, "crop") == 0) {
-    if (files[0]->ft->handler.seek && files[0]->ft->seekable){
-      uint64_t offset = sox_crop_get_start(&effects_chain->effects[1][0]);
-      if (offset && sox_seek(files[0]->ft, offset, SOX_SEEK_SET) == SOX_SUCCESS) {
-        read_wide_samples = offset / files[0]->ft->signal.channels;
-        /* Assuming a failed seek stayed where it was.  If the seek worked then
-         * reset the start location of crop so that it thinks user didn't
-         * request a skip.  */
-        sox_crop_clear_start(&effects_chain->effects[1][0]);
-        lsx_debug("optimize_crop successful");
-      }
-    }
-  }
 }
 
 static sox_bool overwrite_permitted(char const * filename)
--- a/src/sox.h
+++ b/src/sox.h
@@ -2225,29 +2225,6 @@
 
 /**
 Client API:
-Gets the sample offset of the start of the crop, useful for efficiently
-skipping the part that will be trimmed anyway (get crop start, seek, then
-clear crop start).
-@returns the sample offset of the start of the crop.
-*/
-sox_uint64_t
-LSX_API
-sox_crop_get_start(
-    LSX_PARAM_IN sox_effect_t * effp /**< Crop effect. */
-    );
-
-/**
-Client API:
-Clears the start of the trim to 0.
-*/
-void
-LSX_API
-sox_crop_clear_start(
-    LSX_PARAM_INOUT sox_effect_t * effp /**< Crop effect. */
-    );
-
-/**
-Client API:
 Returns true if the specified file is a known playlist file type.
 @returns true if the specified file is a known playlist file type.
 */