Changeset 2589ea9 for src/io/source_sndfile.c
- Timestamp:
- Dec 20, 2018, 6:28:29 PM (6 years ago)
- Branches:
- feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/timestretch, fix/ffmpeg5, master
- Children:
- 2a94eca
- Parents:
- 9b5aa50
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/io/source_sndfile.c
r9b5aa50 r2589ea9 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->input_channels * length); 177 178 length = MIN(read_samples / s->input_channels, length); 173 179 174 180 /* where to store de-interleaved data */ … … 184 190 185 191 /* de-interleaving and down-mixing data */ 186 for (j = 0; j < read_samples / input_channels; j++) {192 for (j = 0; j < length; j++) { 187 193 ptr_data[j] = 0; 188 194 for (i = 0; i < input_channels; i++) { … … 198 204 #endif /* HAVE_SAMPLERATE */ 199 205 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++) {206 *read = (int)FLOOR(s->ratio * length + .5); 207 208 if (*read < read_data->length) { 209 for (j = *read; j < read_data->length; j++) { 204 210 read_data->data[j] = 0; 205 211 } … … 211 217 uint_t i,j, input_channels = s->input_channels; 212 218 /* do actual reading */ 213 sf_count_t read_samples = aubio_sf_read_smpl (s->handle, s->scratch_data, s->scratch_size); 219 uint_t length = aubio_source_validate_input_length("source_sndfile", s->path, 220 s->hop_size, read_data->length); 221 uint_t channels = aubio_source_validate_input_channels("source_sndfile", 222 s->path, s->input_channels, read_data->height); 223 sf_count_t read_samples = aubio_sf_read_smpl (s->handle, s->scratch_data, 224 length * s->input_channels); 225 226 length = MIN(read_samples / s->input_channels, length); 214 227 215 228 /* where to store de-interleaved data */ … … 224 237 } 225 238 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 } 239 for (j = 0; j < length; j++) { 240 for (i = 0; i < channels; i++) { 241 ptr_data[i][j] = s->scratch_data[j * input_channels + i]; 251 242 } 252 243 } … … 265 256 #endif /* HAVE_SAMPLERATE */ 266 257 267 *read = (int)FLOOR(s->ratio * read_samples / input_channels+ .5);268 269 if (*read < s->hop_size) {258 *read = (int)FLOOR(s->ratio * length + .5); 259 260 if (*read < read_data->length) { 270 261 for (i = 0; i < read_data->height; i++) { 271 for (j = *read; j < s->hop_size; j++) {262 for (j = *read; j < read_data->length; j++) { 272 263 read_data->data[i][j] = 0.; 273 264 }
Note: See TracChangeset
for help on using the changeset viewer.