Changeset 7a02ce9 for src/io/source_sndfile.c
- Timestamp:
- Apr 1, 2019, 1:30:22 AM (6 years ago)
- Branches:
- feature/cnn, feature/crepe, feature/timestretch, fix/ffmpeg5, master
- Children:
- 65f7886
- Parents:
- 1301f66 (diff), 439ba7b (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/io/source_sndfile.c
r1301f66 r7a02ce9 27 27 #include "fvec.h" 28 28 #include "fmat.h" 29 #include "ioutils.h" 29 30 #include "source_sndfile.h" 30 31 … … 170 171 uint_t i,j, input_channels = s->input_channels; 171 172 /* read from file into scratch_data */ 172 sf_count_t read_samples = aubio_sf_read_smpl (s->handle, s->scratch_data, s->scratch_size); 173 uint_t length = aubio_source_validate_input_length("source_sndfile", s->path, 174 s->hop_size, read_data->length); 175 sf_count_t read_samples = aubio_sf_read_smpl (s->handle, s->scratch_data, 176 s->scratch_size); 177 uint_t read_length = read_samples / s->input_channels; 173 178 174 179 /* where to store de-interleaved data */ 175 180 smpl_t *ptr_data; 181 182 if (!s->handle) { 183 AUBIO_ERR("source_sndfile: could not read from %s (file was closed)\n", 184 s->path); 185 *read = 0; 186 return; 187 } 188 176 189 #ifdef HAVE_SAMPLERATE 177 190 if (s->ratio != 1) { … … 180 193 #endif /* HAVE_SAMPLERATE */ 181 194 { 195 read_length = MIN(length, read_length); 182 196 ptr_data = read_data->data; 183 197 } 184 198 185 199 /* de-interleaving and down-mixing data */ 186 for (j = 0; j < read_ samples / input_channels; j++) {200 for (j = 0; j < read_length; j++) { 187 201 ptr_data[j] = 0; 188 202 for (i = 0; i < input_channels; i++) { … … 198 212 #endif /* HAVE_SAMPLERATE */ 199 213 200 *read = (int)FLOOR(s->ratio * read_samples / input_channels + .5); 201 202 if (*read < s->hop_size) { 203 for (j = *read; j < s->hop_size; j++) { 204 read_data->data[j] = 0; 205 } 206 } 214 *read = MIN(length, (uint_t)FLOOR(s->ratio * read_length + .5)); 215 216 aubio_source_pad_output (read_data, *read); 207 217 208 218 } … … 211 221 uint_t i,j, input_channels = s->input_channels; 212 222 /* do actual reading */ 213 sf_count_t read_samples = aubio_sf_read_smpl (s->handle, s->scratch_data, s->scratch_size); 223 uint_t length = aubio_source_validate_input_length("source_sndfile", s->path, 224 s->hop_size, read_data->length); 225 uint_t channels = aubio_source_validate_input_channels("source_sndfile", 226 s->path, s->input_channels, read_data->height); 227 sf_count_t read_samples = aubio_sf_read_smpl (s->handle, s->scratch_data, 228 s->scratch_size); 229 uint_t read_length = read_samples / s->input_channels; 214 230 215 231 /* where to store de-interleaved data */ 216 232 smpl_t **ptr_data; 233 234 if (!s->handle) { 235 AUBIO_ERR("source_sndfile: could not read from %s (file was closed)\n", 236 s->path); 237 *read = 0; 238 return; 239 } 240 217 241 #ifdef HAVE_SAMPLERATE 218 242 if (s->ratio != 1) { … … 221 245 #endif /* HAVE_SAMPLERATE */ 222 246 { 247 read_length = MIN(read_length, length); 223 248 ptr_data = read_data->data; 224 249 } 225 250 226 if (read_data->height < input_channels) { 227 // destination matrix has less channels than the file; copy only first 228 // channels of the file, de-interleaving data 229 for (j = 0; j < read_samples / input_channels; j++) { 230 for (i = 0; i < read_data->height; i++) { 231 ptr_data[i][j] = s->scratch_data[j * input_channels + i]; 232 } 233 } 234 } else { 235 // destination matrix has as many or more channels than the file; copy each 236 // channel from the file to the destination matrix, de-interleaving data 237 for (j = 0; j < read_samples / input_channels; j++) { 238 for (i = 0; i < input_channels; i++) { 239 ptr_data[i][j] = s->scratch_data[j * input_channels + i]; 240 } 241 } 242 } 243 244 if (read_data->height > input_channels) { 245 // destination matrix has more channels than the file; copy last channel 246 // of the file to each additional channels, de-interleaving data 247 for (j = 0; j < read_samples / input_channels; j++) { 248 for (i = input_channels; i < read_data->height; i++) { 249 ptr_data[i][j] = s->scratch_data[j * input_channels + (input_channels - 1)]; 250 } 251 for (j = 0; j < read_length; j++) { 252 for (i = 0; i < channels; i++) { 253 ptr_data[i][j] = s->scratch_data[j * input_channels + i]; 251 254 } 252 255 } … … 265 268 #endif /* HAVE_SAMPLERATE */ 266 269 267 *read = (int)FLOOR(s->ratio * read_samples / input_channels + .5); 268 269 if (*read < s->hop_size) { 270 for (i = 0; i < read_data->height; i++) { 271 for (j = *read; j < s->hop_size; j++) { 272 read_data->data[i][j] = 0.; 273 } 274 } 275 } 276 270 *read = MIN(length, (uint_t)FLOOR(s->ratio * read_length + .5)); 271 272 aubio_source_pad_multi_output(read_data, input_channels, *read); 277 273 } 278 274
Note: See TracChangeset
for help on using the changeset viewer.