Changeset e2f1e6d for src/io/source_sndfile.c
- Timestamp:
- Dec 20, 2018, 8:30:50 PM (5 years ago)
- Branches:
- feature/autosink, feature/cnn, feature/crepe, fix/ffmpeg5, master
- Children:
- f56f795
- Parents:
- 9630fa8 (diff), a2019c4 (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
r9630fa8 re2f1e6d 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++) { 204 read_data->data[j] = 0; 205 } 206 } 206 *read = (int)FLOOR(s->ratio * length + .5); 207 208 aubio_source_pad_output (read_data, *read); 207 209 208 210 } … … 211 213 uint_t i,j, input_channels = s->input_channels; 212 214 /* do actual reading */ 213 sf_count_t read_samples = aubio_sf_read_smpl (s->handle, s->scratch_data, s->scratch_size); 215 uint_t length = aubio_source_validate_input_length("source_sndfile", s->path, 216 s->hop_size, read_data->length); 217 uint_t channels = aubio_source_validate_input_channels("source_sndfile", 218 s->path, s->input_channels, read_data->height); 219 sf_count_t read_samples = aubio_sf_read_smpl (s->handle, s->scratch_data, 220 length * s->input_channels); 221 222 length = MIN(read_samples / s->input_channels, length); 214 223 215 224 /* where to store de-interleaved data */ … … 224 233 } 225 234 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 } 235 for (j = 0; j < length; j++) { 236 for (i = 0; i < channels; i++) { 237 ptr_data[i][j] = s->scratch_data[j * input_channels + i]; 251 238 } 252 239 } … … 265 252 #endif /* HAVE_SAMPLERATE */ 266 253 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 254 *read = (int)FLOOR(s->ratio * length + .5); 255 256 aubio_source_pad_multi_output(read_data, input_channels, *read); 277 257 } 278 258
Note: See TracChangeset
for help on using the changeset viewer.