Changes in src/io/source_wavread.c [c0a1906:b40c149]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/io/source_wavread.c
rc0a1906 rb40c149 25 25 #include "fvec.h" 26 26 #include "fmat.h" 27 #include "ioutils.h" 27 28 #include "source_wavread.h" 28 29 29 #include <errno.h>30 31 30 #define AUBIO_WAVREAD_BUFSIZE 1024 32 31 33 #define SHORT_TO_FLOAT(x) (smpl_t)(x * 3.0517578125e-05)32 //#define SHORT_TO_FLOAT(x) (smpl_t)(x * 3.0517578125e-05) 34 33 35 34 struct _aubio_source_wavread_t { … … 100 99 s->fid = fopen((const char *)path, "rb"); 101 100 if (!s->fid) { 102 AUBIO_ ERR("source_wavread: Failed opening %s (System error: %s)\n", s->path, strerror(errno));101 AUBIO_STRERR("source_wavread: Failed opening %s (%s)\n", s->path, errorstr); 103 102 goto beach; 104 103 } … … 133 132 bytes_junk += read_little_endian(buf, 4); 134 133 if (fseek(s->fid, bytes_read + bytes_junk, SEEK_SET) != 0) { 135 AUBIO_ ERR("source_wavread: Failed opening %s (could not seek past JUNK Chunk: %s)\n",136 s->path, strerror(errno));134 AUBIO_STRERR("source_wavread: Failed opening %s (could not seek past JUNK Chunk: %s)\n", 135 s->path, errorstr); 137 136 goto beach; 138 137 } … … 261 260 bytes_junk += read_little_endian(buf, 4); 262 261 if (fseek(s->fid, bytes_read + bytes_junk, SEEK_SET) != 0) { 263 AUBIO_ ERR("source_wavread: could not seek past unknown chunk in %s (%s)\n",264 s->path, strerror(errno));262 AUBIO_STRERR("source_wavread: could not seek past unknown chunk in %s (%s)\n", 263 s->path, errorstr); 265 264 goto beach; 266 265 } … … 348 347 uint_t end = 0; 349 348 uint_t total_wrote = 0; 349 uint_t length = aubio_source_validate_input_length("source_wavread", s->path, 350 s->hop_size, read_data->length); 350 351 if (s->fid == NULL) { 351 352 AUBIO_ERR("source_wavread: could not read from %s (file not opened)\n", … … 353 354 return; 354 355 } 355 while (total_wrote < s->hop_size) {356 end = MIN(s->read_samples - s->read_index, s->hop_size- total_wrote);356 while (total_wrote < length) { 357 end = MIN(s->read_samples - s->read_index, length - total_wrote); 357 358 for (i = 0; i < end; i++) { 358 359 read_data->data[i + total_wrote] = 0; … … 363 364 } 364 365 total_wrote += end; 365 if (total_wrote < s->hop_size) {366 if (total_wrote < length) { 366 367 uint_t wavread_read = 0; 367 368 aubio_source_wavread_readframe(s, &wavread_read); … … 375 376 } 376 377 } 377 if (total_wrote < s->hop_size) { 378 for (i = end; i < s->hop_size; i++) { 379 read_data->data[i] = 0.; 380 } 381 } 378 379 aubio_source_pad_output (read_data, total_wrote); 380 382 381 *read = total_wrote; 383 382 } … … 387 386 uint_t end = 0; 388 387 uint_t total_wrote = 0; 388 uint_t length = aubio_source_validate_input_length("source_wavread", s->path, 389 s->hop_size, read_data->length); 390 uint_t channels = aubio_source_validate_input_channels("source_wavread", 391 s->path, s->input_channels, read_data->height); 389 392 if (s->fid == NULL) { 390 393 AUBIO_ERR("source_wavread: could not read from %s (file not opened)\n", … … 392 395 return; 393 396 } 394 while (total_wrote < s->hop_size) {395 end = MIN(s->read_samples - s->read_index, s->hop_size- total_wrote);396 for (j = 0; j < read_data->height; j++) {397 while (total_wrote < length) { 398 end = MIN(s->read_samples - s->read_index, length - total_wrote); 399 for (j = 0; j < channels; j++) { 397 400 for (i = 0; i < end; i++) { 398 401 read_data->data[j][i + total_wrote] = s->output->data[j][i]; … … 400 403 } 401 404 total_wrote += end; 402 if (total_wrote < s->hop_size) {405 if (total_wrote < length) { 403 406 uint_t wavread_read = 0; 404 407 aubio_source_wavread_readframe(s, &wavread_read); … … 412 415 } 413 416 } 414 if (total_wrote < s->hop_size) { 415 for (j = 0; j < read_data->height; j++) { 416 for (i = end; i < s->hop_size; i++) { 417 read_data->data[j][i] = 0.; 418 } 419 } 420 } 417 418 aubio_source_pad_multi_output(read_data, s->input_channels, total_wrote); 419 421 420 *read = total_wrote; 422 421 } … … 442 441 ret = fseek(s->fid, s->seek_start + pos * s->blockalign, SEEK_SET); 443 442 if (ret != 0) { 444 AUBIO_ ERR("source_wavread: could not seek %s at %d (%s)\n", s->path, pos, strerror(errno));443 AUBIO_STRERR("source_wavread: could not seek %s at %d (%s)\n", s->path, pos, errorstr); 445 444 return AUBIO_FAIL; 446 445 } … … 463 462 } 464 463 if (fclose(s->fid)) { 465 AUBIO_ ERR("source_wavread: could not close %s (%s)\n", s->path, strerror(errno));464 AUBIO_STRERR("source_wavread: could not close %s (%s)\n", s->path, errorstr); 466 465 return AUBIO_FAIL; 467 466 }
Note: See TracChangeset
for help on using the changeset viewer.