| @@ -45,41 +45,41 @@ int st_trim_getopts(eff_t effp, int n, char **argv) · 44 unmodified lines |
| 45 | 45 | * time related strings. |
| 46 | 46 | */ |
| 47 | 47 | switch (n) { |
| 48 | | − case 2: |
| 49 | | − trim->length_str = malloc(strlen(argv[1])+1); |
| 50 | | − if (!trim->length_str) |
| 51 | | − { |
| 52 | | − st_fail("Could not allocate memory"); |
| 53 | | − return(ST_EOF); |
| 54 | | − } |
| 55 | | − strcpy(trim->length_str,argv[1]); |
| 56 | | − /* Do a dummy parse to see if it will fail */ |
| 57 | | − if (st_parsesamples(0, trim->length_str, |
| 58 | | − &trim->length, 't') != ST_SUCCESS) |
| 59 | | − { |
| 60 | | − st_fail(TRIM_USAGE); |
| 61 | | − return(ST_EOF); |
| 62 | | − } |
| 63 | | − case 1: |
| 64 | | − trim->start_str = malloc(strlen(argv[0])+1); |
| 65 | | − if (!trim->start_str) |
| 66 | | − { |
| 67 | | − st_fail("Could not allocate memory"); |
| 68 | | − return(ST_EOF); |
| 69 | | − } |
| 70 | | − strcpy(trim->start_str,argv[0]); |
| 71 | | − /* Do a dummy parse to see if it will fail */ |
| 72 | | − if (st_parsesamples(0, trim->start_str, |
| 73 | | − &trim->start, 't') != ST_SUCCESS) |
| 74 | | − { |
| 75 | | − st_fail(TRIM_USAGE); |
| 76 | | − return(ST_EOF); |
| 77 | | − } |
| 78 | | − break; |
| 79 | | − default: |
| 80 | | − st_fail(TRIM_USAGE); |
| 81 | | − return ST_EOF; |
| 82 | | − break; |
| 48 | + case 2: |
| 49 | + trim->length_str = malloc(strlen(argv[1])+1); |
| 50 | + if (!trim->length_str) |
| 51 | + { |
| 52 | + st_fail("Could not allocate memory"); |
| 53 | + return(ST_EOF); |
| 54 | + } |
| 55 | + strcpy(trim->length_str,argv[1]); |
| 56 | + /* Do a dummy parse to see if it will fail */ |
| 57 | + if (st_parsesamples(0, trim->length_str, |
| 58 | + &trim->length, 't') != ST_SUCCESS) |
| 59 | + { |
| 60 | + st_fail(TRIM_USAGE); |
| 61 | + return(ST_EOF); |
| 62 | + } |
| 63 | + case 1: |
| 64 | + trim->start_str = malloc(strlen(argv[0])+1); |
| 65 | + if (!trim->start_str) |
| 66 | + { |
| 67 | + st_fail("Could not allocate memory"); |
| 68 | + return(ST_EOF); |
| 69 | + } |
| 70 | + strcpy(trim->start_str,argv[0]); |
| 71 | + /* Do a dummy parse to see if it will fail */ |
| 72 | + if (st_parsesamples(0, trim->start_str, |
| 73 | + &trim->start, 't') != ST_SUCCESS) |
| 74 | + { |
| 75 | + st_fail(TRIM_USAGE); |
| 76 | + return(ST_EOF); |
| 77 | + } |
| 78 | + break; |
| 79 | + default: |
| 80 | + st_fail(TRIM_USAGE); |
| 81 | + return ST_EOF; |
| 82 | + break; |
| 83 | 83 | |
| 84 | 84 | } |
| 85 | 85 | return (ST_SUCCESS); |
| @@ -93,24 +93,25 @@ int st_trim_start(eff_t effp) · 7 unmodified lines |
| 93 | 93 | trim_t trim = (trim_t) effp->priv; |
| 94 | 94 | |
| 95 | 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); |
| 99 | | − return(ST_EOF); |
| 98 | + st_fail(TRIM_USAGE); |
| 99 | + return(ST_EOF); |
| 100 | 100 | } |
| 101 | 101 | /* Account for # of channels */ |
| 102 | 102 | trim->start *= effp->ininfo.channels; |
| 103 | + |
| 103 | 104 | if (trim->length_str) |
| 104 | 105 | { |
| 105 | | − if (st_parsesamples(effp->ininfo.rate, trim->length_str, |
| 106 | | − &trim->length, 't') != ST_SUCCESS) |
| 107 | | − { |
| 108 | | − st_fail(TRIM_USAGE); |
| 109 | | − return(ST_EOF); |
| 110 | | − } |
| 106 | + if (st_parsesamples(effp->ininfo.rate, trim->length_str, |
| 107 | + &trim->length, 't') != ST_SUCCESS) |
| 108 | + { |
| 109 | + st_fail(TRIM_USAGE); |
| 110 | + return(ST_EOF); |
| 111 | + } |
| 111 | 112 | } |
| 112 | 113 | else |
| 113 | | − trim->length = 0; |
| 114 | + trim->length = 0; |
| 114 | 115 | |
| 115 | 116 | /* Account for # of channels */ |
| 116 | 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 | 145 | * If so then we can skip trimming from the front side. |
| 145 | 146 | */ |
| 146 | 147 | if (!trim->trimmed) { |
| 147 | | − if ((trim->index+done) <= trim->start) { |
| 148 | | − /* If we haven't read more then "start" samples, return that |
| 149 | | − * we've read all this buffer without outputing anything |
| 150 | | − */ |
| 151 | | − *osamp = 0; |
| 152 | | − *isamp = done; |
| 153 | | − trim->index += done; |
| 154 | | − return (ST_SUCCESS); |
| 155 | | − } else { |
| 156 | | − start_trim = 1; |
| 157 | | − /* We've read at least "start" samples. Now find |
| 158 | | − * out where our target data begins and subtract that |
| 159 | | − * from the total to be copied this round. |
| 160 | | − */ |
| 161 | | − offset = trim->start - trim->index; |
| 162 | | − done -= offset; |
| 163 | | − } |
| 148 | + if ((trim->index+done) <= trim->start) { |
| 149 | + /* If we haven't read more then "start" samples, return that |
| 150 | + * we've read all this buffer without outputing anything |
| 151 | + */ |
| 152 | + *osamp = 0; |
| 153 | + *isamp = done; |
| 154 | + trim->index += done; |
| 155 | + return (ST_SUCCESS); |
| 156 | + } else { |
| 157 | + start_trim = 1; |
| 158 | + /* We've read at least "start" samples. Now find |
| 159 | + * out where our target data begins and subtract that |
| 160 | + * from the total to be copied this round. |
| 161 | + */ |
| 162 | + offset = trim->start - trim->index; |
| 163 | + done -= offset; |
| 164 | + } |
| 164 | 165 | } /* !trimmed */ |
| 165 | 166 | |
| 166 | 167 | if (trim->trimmed || start_trim) { |
| 167 | | − if (trim->length && ((trim->trimmed+done) >= trim->length)) { |
| 168 | | − /* Since we know the end is in this block, we set done |
| 169 | | − * to the desired length less the amount already read. |
| 170 | | − */ |
| 171 | | − done = trim->length - trim->trimmed; |
| 172 | | − finished = 1; |
| 173 | | − } |
| 174 | | − |
| 175 | | − trim->trimmed += done; |
| 168 | + if (trim->length && ((trim->trimmed+done) >= trim->length)) { |
| 169 | + /* Since we know the end is in this block, we set done |
| 170 | + * to the desired length less the amount already read. |
| 171 | + */ |
| 172 | + done = trim->length - trim->trimmed; |
| 173 | + finished = 1; |
| 174 | + } |
| 175 | + |
| 176 | + trim->trimmed += done; |
| 176 | 177 | } |
| 177 | 178 | |
| 178 | 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 | 182 | *isamp = offset + done; |
| 182 | 183 | trim->index += done; |
| 183 | 184 | |
| 184 | | − if (finished) |
| 185 | | − return (ST_EOF); |
| 185 | + /* return ST_EOF when nothing consumed and we detect |
| 186 | + * we are finished. |
| 187 | + */ |
| 188 | + if (finished && !done) |
| 189 | + return (ST_EOF); |
| 186 | 190 | 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 | 200 | trim_t trim = (trim_t) effp->priv; |
| 197 | 201 | |
| 198 | 202 | if (trim->start_str) |
| 199 | | − free(trim->start_str); |
| 203 | + free(trim->start_str); |
| 200 | 204 | if (trim->length_str) |
| 201 | | − free(trim->length_str); |
| 205 | + free(trim->length_str); |
| 202 | 206 | |
| 203 | 207 | return (ST_SUCCESS); |
| 204 | 208 | } |