Changeset 633400d for src/io/source_wavread.c
- Timestamp:
- Dec 5, 2018, 10:34:39 PM (5 years ago)
- Branches:
- feature/cnn, feature/crepe, feature/pitchshift, feature/timestretch, fix/ffmpeg5, master
- Children:
- 283a619a
- Parents:
- 5b46bc3 (diff), f19db54 (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_wavread.c
r5b46bc3 r633400d 19 19 */ 20 20 21 #include " config.h"21 #include "aubio_priv.h" 22 22 23 23 #ifdef HAVE_WAVREAD 24 24 25 #include "aubio_priv.h"26 25 #include "fvec.h" 27 26 #include "fmat.h" … … 77 76 aubio_source_wavread_t * s = AUBIO_NEW(aubio_source_wavread_t); 78 77 size_t bytes_read = 0, bytes_junk = 0, bytes_expected = 44; 79 unsigned char buf[5] ;78 unsigned char buf[5] = "\0"; 80 79 unsigned int format, channels, sr, byterate, blockalign, duration, bitspersample;//, data_size; 81 80 … … 110 109 buf[4] = '\0'; 111 110 if ( strcmp((const char *)buf, "RIFF") != 0 ) { 112 AUBIO_ERR("source_wavread: could not find RIFF header in %s\n", s->path);111 AUBIO_ERR("source_wavread: Failed opening %s (could not find RIFF header)\n", s->path); 113 112 goto beach; 114 113 } … … 121 120 buf[4] = '\0'; 122 121 if ( strcmp((const char *)buf, "WAVE") != 0 ) { 123 AUBIO_ERR("source_wavread: wrong format in RIFF header in %s\n", s->path);122 AUBIO_ERR("source_wavread: Failed opening %s (wrong format in RIFF header)\n", s->path); 124 123 goto beach; 125 124 } … … 135 134 bytes_junk += read_little_endian(buf, 4); 136 135 if (fseek(s->fid, bytes_read + bytes_junk, SEEK_SET) != 0) { 137 AUBIO_ERR("source_wavread: could not seek past JUNK Chunk in %s (%s)\n",136 AUBIO_ERR("source_wavread: Failed opening %s (could not seek past JUNK Chunk: %s)\n", 138 137 s->path, strerror(errno)); 139 138 goto beach; … … 148 147 // get the fmt chunk 149 148 if ( strcmp((const char *)buf, "fmt ") != 0 ) { 150 AUBIO_ERR("source_wavread: failed finding fmt RIFF header in %s\n", s->path);149 AUBIO_ERR("source_wavread: Failed opening %s (could not find 'fmt ' in RIFF header)\n", s->path); 151 150 goto beach; 152 151 } … … 157 156 if ( format != 16 ) { 158 157 // TODO accept format 18 159 AUBIO_ERR("source_wavread: file %s is not encoded with PCM\n", s->path);158 AUBIO_ERR("source_wavread: Failed opening %s (not encoded with PCM)\n", s->path); 160 159 goto beach; 161 160 } 162 161 if ( buf[1] || buf[2] | buf[3] ) { 163 AUBIO_ERR("source_wavread: Subchunk1Size should be 0, in %s\n", s->path);162 AUBIO_ERR("source_wavread: Failed opening %s (Subchunk1Size should be 0)\n", s->path); 164 163 goto beach; 165 164 } … … 168 167 bytes_read += fread(buf, 1, 2, s->fid); 169 168 if ( buf[0] != 1 || buf[1] != 0) { 170 AUBIO_ERR("source_wavread: AudioFormat should be PCM, in %s\n", s->path);169 AUBIO_ERR("source_wavread: Failed opening %s (AudioFormat should be PCM)\n", s->path); 171 170 goto beach; 172 171 } … … 191 190 bytes_read += fread(buf, 1, 2, s->fid); 192 191 bitspersample = read_little_endian(buf, 2); 192 193 if ( channels == 0 ) { 194 AUBIO_ERR("source_wavread: Failed opening %s (number of channels can not be 0)\n", s->path); 195 goto beach; 196 } 197 198 if ( (sint_t)sr <= 0 ) { 199 AUBIO_ERR("source_wavread: Failed opening %s (samplerate can not be <= 0)\n", s->path); 200 goto beach; 201 } 202 203 if ( byterate == 0 ) { 204 AUBIO_ERR("source_wavread: Failed opening %s (byterate can not be 0)\n", s->path); 205 goto beach; 206 } 207 208 if ( bitspersample == 0 ) { 209 AUBIO_ERR("source_wavread: Failed opening %s (bitspersample can not be 0)\n", s->path); 210 goto beach; 211 } 193 212 #if 0 194 213 if ( bitspersample != 16 ) { … … 200 219 201 220 if ( byterate * 8 != sr * channels * bitspersample ) { 202 AUBIO_ERR("source_wavread: wrong byterate in %s\n", s->path);221 AUBIO_ERR("source_wavread: Failed opening %s (wrong byterate)\n", s->path); 203 222 goto beach; 204 223 } 205 224 206 225 if ( blockalign * 8 != channels * bitspersample ) { 207 AUBIO_ERR("source_wavread: wrong blockalign in %s\n", s->path);226 AUBIO_ERR("source_wavread: Failed opening %s (wrong blockalign)\n", s->path); 208 227 goto beach; 209 228 } … … 330 349 uint_t end = 0; 331 350 uint_t total_wrote = 0; 351 if (s->fid == NULL) { 352 AUBIO_ERR("source_wavread: could not read from %s (file not opened)\n", 353 s->path); 354 return; 355 } 332 356 while (total_wrote < s->hop_size) { 333 357 end = MIN(s->read_samples - s->read_index, s->hop_size - total_wrote); … … 364 388 uint_t end = 0; 365 389 uint_t total_wrote = 0; 390 if (s->fid == NULL) { 391 AUBIO_ERR("source_wavread: could not read from %s (file not opened)\n", 392 s->path); 393 return; 394 } 366 395 while (total_wrote < s->hop_size) { 367 396 end = MIN(s->read_samples - s->read_index, s->hop_size - total_wrote); … … 404 433 uint_t aubio_source_wavread_seek (aubio_source_wavread_t * s, uint_t pos) { 405 434 uint_t ret = 0; 435 if (s->fid == NULL) { 436 AUBIO_ERR("source_wavread: could not seek %s (file not opened?)\n", s->path, pos); 437 return AUBIO_FAIL; 438 } 406 439 if ((sint_t)pos < 0) { 440 AUBIO_ERR("source_wavread: could not seek %s at %d (seeking position should be >= 0)\n", s->path, pos); 407 441 return AUBIO_FAIL; 408 442 } … … 426 460 427 461 uint_t aubio_source_wavread_close (aubio_source_wavread_t * s) { 428 if ( !s->fid) {429 return AUBIO_ FAIL;462 if (s->fid == NULL) { 463 return AUBIO_OK; 430 464 } 431 465 if (fclose(s->fid)) {
Note: See TracChangeset
for help on using the changeset viewer.