Update of /cvsroot/sox/sox/src In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv26769/src Modified Files: CMakeLists.txt Makefile.am effects.c sox.c sox.h speed.c tempo.c Removed Files: pitch.c Log Message: Improved handling of speed changes in the effects chain. Fixes e.g. 'play -n synth speed 100' not working properly. Index: effects.c =================================================================== RCS file: /cvsroot/sox/sox/src/effects.c,v retrieving revision 1.37 retrieving revision 1.38 diff -u -d -r1.37 -r1.38 --- effects.c 24 Oct 2008 02:15:25 -0000 1.37 +++ effects.c 26 Oct 2008 09:34:06 -0000 1.38 @@ -33,7 +33,7 @@ /* FIXME: Not thread safe using globals */ sox_effects_globals_t sox_effects_globals = - {sox_plot_off, 1, &sox_globals}; + {sox_plot_off, &sox_globals}; /* Default effect handler functions for do-nothing situations: */ @@ -137,10 +137,6 @@ unsigned f; sox_effect_t eff0; /* Copy of effect for flow 0 before calling start */ - if (effp->handler.flags & SOX_EFF_NULL) { - lsx_report("has no effect (is a proxy effect)"); - return SOX_SUCCESS; - } effp->global_info = &chain->global_info; effp->in_signal = *in; effp->out_signal = *out; Index: sox.c =================================================================== RCS file: /cvsroot/sox/sox/src/sox.c,v retrieving revision 1.367 retrieving revision 1.368 diff -u -d -r1.367 -r1.368 --- sox.c 26 Oct 2008 07:21:52 -0000 1.367 +++ sox.c 26 Oct 2008 09:34:06 -0000 1.368 @@ -1456,13 +1456,6 @@ calculate_combiner_signal_parameters(); set_combiner_and_output_encoding_parameters(); calculate_output_signal_parameters(); - - /* Now take account of any net speed change specified by user effects by - * adjusting the nominal sample rate at the output of the combiner. This - * cannot be done inside calculate_combiner_signal_parameters since - * it must be done after calculate_output_signal_parameters. */ - combiner_signal.rate *= sox_effects_globals.speed; - open_output_file(); if (!effects_chain) Index: speed.c =================================================================== RCS file: /cvsroot/sox/sox/src/speed.c,v retrieving revision 1.40 retrieving revision 1.41 diff -u -d -r1.40 -r1.41 --- speed.c 29 Mar 2008 20:10:24 -0000 1.40 +++ speed.c 26 Oct 2008 09:34:06 -0000 1.41 @@ -1,5 +1,5 @@ /* libSoX Effect: Adjust the audio speed (pitch and tempo together) - * (c) 2006 ro...@us... + * (c) 2006,8 ro...@us... * * 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 @@ -24,22 +24,22 @@ #include "sox_i.h" #include <string.h> +typedef struct { + double factor; +} priv_t; + static int getopts(sox_effect_t * effp, int n, char * * argv) { + priv_t * p = (priv_t *) effp->priv; sox_bool is_cents = sox_false; - double speed; - - /* Be quietly compatible with the old speed effect: */ - if (n != 0 && strcmp(*argv, "-c") == 0) - is_cents = sox_true, ++argv, --n; if (n == 1) { char c, dummy; - int scanned = sscanf(*argv, "%lf%c %c", &speed, &c, &dummy); + int scanned = sscanf(*argv, "%lf%c %c", &p->factor, &c, &dummy); if (scanned == 1 || (scanned == 2 && c == 'c')) { is_cents |= scanned == 2; - if (is_cents || speed > 0) { - effp->global_info->speed *= is_cents? pow(2., speed/1200) : speed; + if (is_cents || p->factor > 0) { + p->factor = is_cents? pow(2., p->factor / 1200) : p->factor; return SOX_SUCCESS; } } @@ -47,10 +47,30 @@ return lsx_usage(effp); } +static int start(sox_effect_t * effp) +{ + priv_t * p = (priv_t *) effp->priv; + + if (p->factor == 1) + return SOX_EFF_NULL; + + effp->out_signal.rate = effp->in_signal.rate * p->factor; + return SOX_SUCCESS; +} + +static int flow(sox_effect_t * effp, const sox_sample_t * ibuf, + sox_sample_t * obuf, size_t * isamp, size_t * osamp) +{ + size_t len = *isamp = *osamp = min(*isamp, *osamp); + memcpy(obuf, ibuf, len * sizeof(*osamp)); + (void)effp; + return SOX_SUCCESS; +} + sox_effect_handler_t const * sox_speed_effect_fn(void) { static sox_effect_handler_t handler = { - "speed", "factor[c]", SOX_EFF_NULL | SOX_EFF_LENGTH, - getopts, 0, 0, 0, 0, 0, 0}; + "speed", "factor[c]",SOX_EFF_NULL|SOX_EFF_MCHAN|SOX_EFF_RATE|SOX_EFF_LENGTH, + getopts, start, flow, 0, 0, 0, sizeof(priv_t)}; return &handler; } --- pitch.c DELETED --- Index: sox.h =================================================================== RCS file: /cvsroot/sox/sox/src/sox.h,v retrieving revision 1.75 retrieving revision 1.76 diff -u -d -r1.75 -r1.76 --- sox.h 25 Oct 2008 07:56:24 -0000 1.75 +++ sox.h 26 Oct 2008 09:34:06 -0000 1.76 @@ -448,7 +448,6 @@ typedef struct sox_effect sox_effect_t; struct sox_effects_globals { /* Global parameters (for effects) */ sox_plot_t plot; /* To help the user choose effect & options */ - double speed; /* Gather up all speed changes here, then resample */ sox_globals_t * global_info; }; typedef struct sox_effects_globals sox_effects_globals_t; Index: Makefile.am =================================================================== RCS file: /cvsroot/sox/sox/src/Makefile.am,v retrieving revision 1.164 retrieving revision 1.165 diff -u -d -r1.164 -r1.165 --- Makefile.am 25 Oct 2008 11:50:47 -0000 1.164 +++ Makefile.am 26 Oct 2008 09:34:06 -0000 1.165 @@ -267,7 +267,7 @@ echo.c echos.c effects.c effects.h effects_i.c fade.c fft4g.c fft4g.h \ fifo.h filter.c flanger.c input.c ladspa.c loudness.c mcompand.c \ mixer.c noiseprof.c noisered.c noisered.h normalise.c output.c pad.c \ - pan.c phaser.c pitch.c polyphas.c rabbit.c rate.c \ + pan.c phaser.c polyphas.c rabbit.c rate.c \ rate_filters.h rate_half_fir.h rate_poly_fir0.h rate_poly_fir.h \ remix.c repeat.c resample.c reverb.c reverse.c silence.c skeleff.c \ speed.c splice.c stat.c swap.c stretch.c synth.c tempo.c tremolo.c \ Index: CMakeLists.txt =================================================================== RCS file: /cvsroot/sox/sox/src/CMakeLists.txt,v retrieving revision 1.44 retrieving revision 1.45 diff -u -d -r1.44 -r1.45 --- CMakeLists.txt 25 Oct 2008 11:50:47 -0000 1.44 +++ CMakeLists.txt 26 Oct 2008 09:34:06 -0000 1.45 @@ -13,7 +13,7 @@ else(${ver} LESS 403) add_definitions(-Wtraditional-conversion) endif(${ver} LESS 403) - #add_definitions(-Werror) + add_definitions(-Werror) endif(CMAKE_COMPILER_IS_GNUCC) if (NOT EXTERNAL_GSM) @@ -28,16 +28,16 @@ # Format with: !xargs echo|tr ' ' '\n'|sort|column|expand|sed 's/^/ /' set(effects_srcs - bend earwax mixer rate stat - biquad echo noiseprof remix stretch - biquads echos noisered repeat swap - chorus fade normalise resample synth - compand fft4g output reverb tempo - compandt filter pad reverse tremolo - contrast flanger pan silence trim - dcshift input phaser skeleff vol - delay loudness pitch speed - dither mcompand polyphas splice + bend earwax mixer remix stretch + biquad echo noiseprof repeat swap + biquads echos noisered resample synth + chorus fade normalise reverb tempo + compand fft4g output reverse tremolo + compandt filter pad silence trim + contrast flanger pan skeleff vol + dcshift input phaser speed + delay loudness polyphas splice + dither mcompand rate stat ) set(formats_srcs 8svx dat ima-fmt s3-fmt u3-fmt Index: tempo.c =================================================================== RCS file: /cvsroot/sox/sox/src/tempo.c,v retrieving revision 1.16 retrieving revision 1.17 diff -u -d -r1.16 -r1.17 --- tempo.c 24 Oct 2008 02:15:25 -0000 1.16 +++ tempo.c 26 Oct 2008 09:34:06 -0000 1.17 @@ -1,5 +1,5 @@ -/* libSoX effect: change tempo (alter duration, maintain pitch) - * Copyright (c) 2007 ro...@us... +/* libSoX effect: change tempo (and duration) or pitch (maintain duration) + * Copyright (c) 2007,8 ro...@us... * Based on ideas from Olli Parviainen's SoundTouch Library. * * This library is free software; you can redistribute it and/or modify it @@ -304,3 +304,55 @@ }; return &handler; } + +/*---------------------------------- pitch -----------------------------------*/ + +static int pitch_getopts(sox_effect_t * effp, int argc, char **argv) +{ + double d; + char dummy, arg[100], **argv2 = malloc(argc * sizeof(*argv2)); + int result, pos = (argc > 1 && !strcmp(argv[1], "-q"))? 2 : 1; + + if (argc <= pos || sscanf(argv[pos], "%lf %c", &d, &dummy) != 1) + return lsx_usage(effp); + + d = pow(2., d / 1200); /* cents --> factor */ + sprintf(arg, "%g", 1 / d); + memcpy(argv2, argv, argc * sizeof(*argv2)); + argv2[pos] = arg; + result = getopts(effp, argc, argv2); + free(argv2); + return result; +} + +static int pitch_start(sox_effect_t * effp) +{ + priv_t * p = (priv_t *) effp->priv; + int result = start(effp); + + effp->out_signal.rate = effp->in_signal.rate / p->factor; + return result; +} + +sox_effect_handler_t const * sox_pitch_effect_fn(void) +{ + static sox_effect_handler_t handler; + handler = *sox_tempo_effect_fn(); + handler.name = "pitch"; + handler.usage = "[-q] shift-in-cents [segment-ms [search-ms [overlap-ms]]]", + handler.getopts = pitch_getopts; + handler.start = pitch_start; + handler.flags &= ~SOX_EFF_LENGTH; + return &handler; +} + +/*------------------------- key (old name for pitch) -------------------------*/ + +sox_effect_handler_t const * sox_key_effect_fn(void) +{ + static sox_effect_handler_t handler; + handler = *sox_pitch_effect_fn(); + handler.name = "key"; + handler.flags |= SOX_EFF_DEPRECATED; + return &handler; +} |