Changeset bfab39c for src


Ignore:
Timestamp:
Aug 30, 2016, 3:07:04 PM (8 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch, yinfft+
Children:
4b251ae
Parents:
3f961c4
Message:

src/io/source_wavread.c: skip junk chunk

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/io/source_wavread.c

    r3f961c4 rbfab39c  
    7272aubio_source_wavread_t * new_aubio_source_wavread(const char_t * path, uint_t samplerate, uint_t hop_size) {
    7373  aubio_source_wavread_t * s = AUBIO_NEW(aubio_source_wavread_t);
    74   size_t bytes_read = 0, bytes_expected = 44;
     74  size_t bytes_read = 0, bytes_junk = 0, bytes_expected = 44;
    7575  unsigned char buf[5];
    7676  unsigned int format, channels, sr, byterate, blockalign, duration, bitspersample;//, data_size;
     
    124124  bytes_read += fread(buf, 1, 4, s->fid);
    125125  buf[4] = '\0';
     126
     127  // check if we have a JUNK Chunk
     128  if ( strcmp((const char *)buf, "JUNK") == 0 ) {
     129    bytes_junk = fread(buf, 1, 4, s->fid);
     130    buf[4] = '\0';
     131    bytes_junk += read_little_endian(buf, 4);
     132    if (fseek(s->fid, bytes_read + bytes_junk, SEEK_SET) != 0) {
     133      AUBIO_ERR("source_wavread: could not seek past JUNK Chunk in %s (%s)\n",
     134          s->path, strerror(errno));
     135      goto beach;
     136    }
     137    bytes_read += bytes_junk;
     138    bytes_expected += bytes_junk;
     139    // now really read the fmt chunk
     140    fread(buf, 1, 4, s->fid);
     141    buf[4] = '\0';
     142  }
     143
     144  // get the fmt chunk
    126145  if ( strcmp((const char *)buf, "fmt ") != 0 ) {
    127     AUBIO_ERR("source_wavread: fmt RIFF header in %s\n", s->path);
     146    AUBIO_ERR("source_wavread: failed finding fmt RIFF header in %s\n", s->path);
    128147    goto beach;
    129148  }
Note: See TracChangeset for help on using the changeset viewer.