| @@ -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 | else | 113 | 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 that | 149 | /* If we haven't read more then "start" samples, return that |
| 149 | * we've read all this buffer without outputing anything | 150 | * 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 find | 158 | /* We've read at least "start" samples. Now find |
| 158 | * out where our target data begins and subtract that | 159 | * 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 done | 169 | /* 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 | else | 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 | 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 | } |