History

Bugfixes to trim effect. Allows crossfade script to work without pops.

cbagwell committed 22 years ago

Commit c4a08031 parent d3a8f865 files · +100 −91Browse files

Unified · Split

5 files
  1. Changelog +4 −0
  2. scripts/crossfade_cat.sh +7 −7
  3. src/fade.c +7 −6
  4. src/sox.c +2 −2
  5. src/trim.c +80 −76
Changelog+4−0
@@ -41,6 +41,10 @@ sox-12.17.6 · 40 unmodified lines
41 to not result in the original file.41 to not result in the original file.
42 o Fixed a possible overflow in lots of effects were MIN42 o Fixed a possible overflow in lots of effects were MIN
43 value was treated as -MAX instead of -MAX-1.43 value was treated as -MAX instead of -MAX-1.
44 o Modifed sox so its OK for effects to not process any
45 input or output bytes as long as they return ST_EOF.
46 o Bugfix to trim effect were bytes were left off the end
47 of the file when output length was specified.
44 48
45sox-12.17.549sox-12.17.5
46-----------50-----------
scripts/crossfade_cat.sh+7−7
@@ -45,21 +45,21 @@ fi · 44 unmodified lines
45 45
46fade_first_opts=46fade_first_opts=
47if [ "$fade_first" == "yes" ]; then47if [ "$fade_first" == "yes" ]; then
48 fade_first_opts="fade h 0 0:0:$fade_length"48 fade_first_opts="fade t 0 0:0:$fade_length"
49fi49fi
50 50
51fade_second_opts=51fade_second_opts=
52if [ "$fade_second" == "yes" ]; then52if [ "$fade_second" == "yes" ]; then
53 fade_second_opts="fade h 0:0:$fade_length"53 fade_second_opts="fade t 0:0:$fade_length"
54fi54fi
55 55
56echo "crossfade and concatenate files"56echo "crossfade and concatenate files"
57echo57echo
58echo "Finding length of $first_file..."58echo "Finding length of $first_file..."
59first_length=`$SOX "$first_file" 2>&1 -e stat | grep Length | cut -d : -f 2 | cut -d . -f 1 | cut -f 1`59first_length=`$SOX "$first_file" 2>&1 -e stat | grep Length | cut -d : -f 2 | cut -f 1`
60echo "Length is $first_length"60echo "Length is $first_length seconds"
61 61
62trim_length=`expr $first_length - $fade_length`62trim_length=`echo "$first_length - $fade_length" | bc`
63 63
64# Get crossfade section from first file and optionally do the fade out64# Get crossfade section from first file and optionally do the fade out
65echo "Obtaining $fade_length seconds of fade out portion from $first_file..."65echo "Obtaining $fade_length seconds of fade out portion from $first_file..."
@@ -79,7 +79,7 @@ $SOX song1.wav crossfade.wav song2.wav mix.wav · 13 unmodified lines
79 79
80echo -e "Removing temporary files...\n" 80echo -e "Removing temporary files...\n"
81rm fadeout.wav fadein.wav crossfade.wav song1.wav song2.wav81rm fadeout.wav fadein.wav crossfade.wav song1.wav song2.wav
82mins=`expr $trim_length / 60`82mins=`echo "$trim_length / 60" | bc`
83secs=`expr $trim_length % 60`83secs=`echo "$trim_length % 60" | bc`
84echo "The crossfade in mix.wav occurs at around $mins mins $secs secs"84echo "The crossfade in mix.wav occurs at around $mins mins $secs secs"
85 85
src/fade.c+7−6
@@ -230,8 +230,9 @@ int st_fade_flow(eff_t effp, st_sample_t *ibuf, st_sample_t *obuf, · 229 unmodified lines
230 t_ibuf = (fade->samplesdone < 0 ? 0 : *ibuf);230 t_ibuf = (fade->samplesdone < 0 ? 0 : *ibuf);
231 231
232 if ((fade->samplesdone >= fade->in_start) &&232 if ((fade->samplesdone >= fade->in_start) &&
233 (fade->out_stop == 0 || fade->samplesdone < fade->out_stop))233 (!fade->do_out || fade->samplesdone < fade->out_stop))
234 { /* something to generate output */234 { /* something to generate output */
235
235 if (fade->samplesdone < fade->in_stop)236 if (fade->samplesdone < fade->in_stop)
236 { /* fade-in phase, increase gain */237 { /* fade-in phase, increase gain */
237 *obuf = t_ibuf *238 *obuf = t_ibuf *
@@ -239,14 +240,11 @@ int st_fade_flow(eff_t effp, st_sample_t *ibuf, st_sample_t *obuf, · 1 unmodified line
239 fade->in_stop - fade->in_start,240 fade->in_stop - fade->in_start,
240 fade->in_fadetype);241 fade->in_fadetype);
241 } /* endif fade-in */242 } /* endif fade-in */
242 243 else if (!fade->do_out || fade->samplesdone < fade->out_start)
243 if (fade->samplesdone >= fade->in_stop &&
244 (!fade->do_out || fade->samplesdone < fade->out_start))
245 { /* steady gain phase */244 { /* steady gain phase */
246 *obuf = t_ibuf;245 *obuf = t_ibuf;
247 } /* endif steady phase */246 } /* endif steady phase */
248 247 else
249 if (fade->do_out && fade->samplesdone >= fade->out_start)
250 { /* fade-out phase, decrease gain */248 { /* fade-out phase, decrease gain */
251 *obuf = t_ibuf *249 *obuf = t_ibuf *
252 fade_gain(fade->out_stop - fade->samplesdone,250 fade_gain(fade->out_stop - fade->samplesdone,
@@ -261,6 +259,9 @@ int st_fade_flow(eff_t effp, st_sample_t *ibuf, st_sample_t *obuf, · 8 unmodified lines
261 t_output = 0;259 t_output = 0;
262 } /* endif something to output */260 } /* endif something to output */
263 261
262 /* samplesdone < 0 means we are inventing samples right now
263 * and so not consuming (happens when in_start < 0).
264 */
264 if (fade->samplesdone >= 0 )265 if (fade->samplesdone >= 0 )
265 { /* Something to input */266 { /* Something to input */
266 *isamp += 1;267 *isamp += 1;
src/sox.c+2−2
@@ -988,10 +988,10 @@ int e; · 987 unmodified lines
988 efftab[e].olen = odonel + odoner;988 efftab[e].olen = odonel + odoner;
989 done = idonel + idoner + odonel + odoner;989 done = idonel + idoner + odonel + odoner;
990 }990 }
991 if (done == 0)
992 st_fail("Effect took & gave no samples!");
993 if (effstatus == ST_EOF)991 if (effstatus == ST_EOF)
994 return -1;992 return -1;
993 if (done == 0)
994 st_fail("Effect took & gave no samples!");
995 return 1;995 return 1;
996}996}
997 997
src/trim.c+80−76
@@ -45,41 +45,41 @@ int st_trim_getopts(eff_t effp, int n, char **argv) · 44 unmodified lines
45 * time related strings.45 * time related strings.
46 */46 */
47 switch (n) {47 switch (n) {
48 case 2:48 case 2:
49 trim->length_str = malloc(strlen(argv[1])+1);49 trim->length_str = malloc(strlen(argv[1])+1);
50 if (!trim->length_str)50 if (!trim->length_str)
51 {51 {
52 st_fail("Could not allocate memory");52 st_fail("Could not allocate memory");
53 return(ST_EOF);53 return(ST_EOF);
54 }54 }
55 strcpy(trim->length_str,argv[1]);55 strcpy(trim->length_str,argv[1]);
56 /* Do a dummy parse to see if it will fail */56 /* Do a dummy parse to see if it will fail */
57 if (st_parsesamples(0, trim->length_str,57 if (st_parsesamples(0, trim->length_str,
58 &trim->length, 't') != ST_SUCCESS)58 &trim->length, 't') != ST_SUCCESS)
59 {59 {
60 st_fail(TRIM_USAGE);60 st_fail(TRIM_USAGE);
61 return(ST_EOF);61 return(ST_EOF);
62 }62 }
63 case 1:63 case 1:
64 trim->start_str = malloc(strlen(argv[0])+1);64 trim->start_str = malloc(strlen(argv[0])+1);
65 if (!trim->start_str)65 if (!trim->start_str)
66 {66 {
67 st_fail("Could not allocate memory");67 st_fail("Could not allocate memory");
68 return(ST_EOF);68 return(ST_EOF);
69 }69 }
70 strcpy(trim->start_str,argv[0]);70 strcpy(trim->start_str,argv[0]);
71 /* Do a dummy parse to see if it will fail */71 /* Do a dummy parse to see if it will fail */
72 if (st_parsesamples(0, trim->start_str,72 if (st_parsesamples(0, trim->start_str,
73 &trim->start, 't') != ST_SUCCESS)73 &trim->start, 't') != ST_SUCCESS)
74 {74 {
75 st_fail(TRIM_USAGE);75 st_fail(TRIM_USAGE);
76 return(ST_EOF);76 return(ST_EOF);
77 }77 }
78 break;78 break;
79 default:79 default:
80 st_fail(TRIM_USAGE);80 st_fail(TRIM_USAGE);
81 return ST_EOF;81 return ST_EOF;
82 break;82 break;
83 83
84 }84 }
85 return (ST_SUCCESS);85 return (ST_SUCCESS);
@@ -93,24 +93,25 @@ int st_trim_start(eff_t effp) · 7 unmodified lines
93 trim_t trim = (trim_t) effp->priv;93 trim_t trim = (trim_t) effp->priv;
94 94
95 if (st_parsesamples(effp->ininfo.rate, trim->start_str,95 if (st_parsesamples(effp->ininfo.rate, trim->start_str,
96 &trim->start, 't') != ST_SUCCESS)96 &trim->start, 't') != ST_SUCCESS)
97 {97 {
98 st_fail(TRIM_USAGE);98 st_fail(TRIM_USAGE);
99 return(ST_EOF);99 return(ST_EOF);
100 }100 }
101 /* Account for # of channels */101 /* Account for # of channels */
102 trim->start *= effp->ininfo.channels;102 trim->start *= effp->ininfo.channels;
103
103 if (trim->length_str)104 if (trim->length_str)
104 {105 {
105 if (st_parsesamples(effp->ininfo.rate, trim->length_str,106 if (st_parsesamples(effp->ininfo.rate, trim->length_str,
106 &trim->length, 't') != ST_SUCCESS)107 &trim->length, 't') != ST_SUCCESS)
107 {108 {
108 st_fail(TRIM_USAGE);109 st_fail(TRIM_USAGE);
109 return(ST_EOF);110 return(ST_EOF);
110 }111 }
111 }112 }
112 else113 else
113 trim->length = 0;114 trim->length = 0;
114 115
115 /* Account for # of channels */116 /* Account for # of channels */
116 trim->length *= effp->ininfo.channels;117 trim->length *= effp->ininfo.channels;
@@ -144,35 +145,35 @@ int st_trim_flow(eff_t effp, st_sample_t *ibuf, st_sample_t *obuf, · 27 unmodified lines
144 * If so then we can skip trimming from the front side.145 * If so then we can skip trimming from the front side.
145 */146 */
146 if (!trim->trimmed) {147 if (!trim->trimmed) {
147 if ((trim->index+done) <= trim->start) {148 if ((trim->index+done) <= trim->start) {
148 /* If we haven't read more then "start" samples, return that149 /* If we haven't read more then "start" samples, return that
149 * we've read all this buffer without outputing anything150 * we've read all this buffer without outputing anything
150 */151 */
151 *osamp = 0;152 *osamp = 0;
152 *isamp = done;153 *isamp = done;
153 trim->index += done;154 trim->index += done;
154 return (ST_SUCCESS);155 return (ST_SUCCESS);
155 } else {156 } else {
156 start_trim = 1;157 start_trim = 1;
157 /* We've read at least "start" samples. Now find158 /* We've read at least "start" samples. Now find
158 * out where our target data begins and subtract that159 * out where our target data begins and subtract that
159 * from the total to be copied this round.160 * from the total to be copied this round.
160 */161 */
161 offset = trim->start - trim->index;162 offset = trim->start - trim->index;
162 done -= offset;163 done -= offset;
163 }164 }
164 } /* !trimmed */165 } /* !trimmed */
165 166
166 if (trim->trimmed || start_trim) {167 if (trim->trimmed || start_trim) {
167 if (trim->length && ((trim->trimmed+done) >= trim->length)) {168 if (trim->length && ((trim->trimmed+done) >= trim->length)) {
168 /* Since we know the end is in this block, we set done169 /* Since we know the end is in this block, we set done
169 * to the desired length less the amount already read.170 * to the desired length less the amount already read.
170 */171 */
171 done = trim->length - trim->trimmed;172 done = trim->length - trim->trimmed;
172 finished = 1;173 finished = 1;
173 }174 }
174 175
175 trim->trimmed += done;176 trim->trimmed += done;
176 }177 }
177 178
178 memcpy(obuf, ibuf+offset, done * sizeof(st_sample_t));179 memcpy(obuf, ibuf+offset, done * sizeof(st_sample_t));
@@ -181,10 +182,13 @@ int st_trim_flow(eff_t effp, st_sample_t *ibuf, st_sample_t *obuf, · 2 unmodified lines
181 *isamp = offset + done;182 *isamp = offset + done;
182 trim->index += done;183 trim->index += done;
183 184
184 if (finished)185 /* return ST_EOF when nothing consumed and we detect
185 return (ST_EOF);186 * we are finished.
187 */
188 if (finished && !done)
189 return (ST_EOF);
186 else190 else
187 return (ST_SUCCESS);191 return (ST_SUCCESS);
188}192}
189 193
190/*194/*
@@ -196,9 +200,9 @@ int st_trim_stop(eff_t effp) · 5 unmodified lines
196 trim_t trim = (trim_t) effp->priv;200 trim_t trim = (trim_t) effp->priv;
197 201
198 if (trim->start_str)202 if (trim->start_str)
199 free(trim->start_str);203 free(trim->start_str);
200 if (trim->length_str)204 if (trim->length_str)
201 free(trim->length_str);205 free(trim->length_str);
202 206
203 return (ST_SUCCESS);207 return (ST_SUCCESS);
204}208}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t