Ignore:
Timestamp:
Dec 5, 2018, 10:34:39 PM (5 years ago)
Author:
Paul Brossier <piem@piem.org>
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.
Message:

Merge branch 'master' into feature/pitchshift

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/io/source_wavread.c

    r5b46bc3 r633400d  
    1919*/
    2020
    21 #include "config.h"
     21#include "aubio_priv.h"
    2222
    2323#ifdef HAVE_WAVREAD
    2424
    25 #include "aubio_priv.h"
    2625#include "fvec.h"
    2726#include "fmat.h"
     
    7776  aubio_source_wavread_t * s = AUBIO_NEW(aubio_source_wavread_t);
    7877  size_t bytes_read = 0, bytes_junk = 0, bytes_expected = 44;
    79   unsigned char buf[5];
     78  unsigned char buf[5] = "\0";
    8079  unsigned int format, channels, sr, byterate, blockalign, duration, bitspersample;//, data_size;
    8180
     
    110109  buf[4] = '\0';
    111110  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);
    113112    goto beach;
    114113  }
     
    121120  buf[4] = '\0';
    122121  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);
    124123    goto beach;
    125124  }
     
    135134    bytes_junk += read_little_endian(buf, 4);
    136135    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",
    138137          s->path, strerror(errno));
    139138      goto beach;
     
    148147  // get the fmt chunk
    149148  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);
    151150    goto beach;
    152151  }
     
    157156  if ( format != 16 ) {
    158157    // 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);
    160159    goto beach;
    161160  }
    162161  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);
    164163    goto beach;
    165164  }
     
    168167  bytes_read += fread(buf, 1, 2, s->fid);
    169168  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);
    171170    goto beach;
    172171  }
     
    191190  bytes_read += fread(buf, 1, 2, s->fid);
    192191  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  }
    193212#if 0
    194213  if ( bitspersample != 16 ) {
     
    200219
    201220  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);
    203222    goto beach;
    204223  }
    205224
    206225  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);
    208227    goto beach;
    209228  }
     
    330349  uint_t end = 0;
    331350  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  }
    332356  while (total_wrote < s->hop_size) {
    333357    end = MIN(s->read_samples - s->read_index, s->hop_size - total_wrote);
     
    364388  uint_t end = 0;
    365389  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  }
    366395  while (total_wrote < s->hop_size) {
    367396    end = MIN(s->read_samples - s->read_index, s->hop_size - total_wrote);
     
    404433uint_t aubio_source_wavread_seek (aubio_source_wavread_t * s, uint_t pos) {
    405434  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  }
    406439  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);
    407441    return AUBIO_FAIL;
    408442  }
     
    426460
    427461uint_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;
    430464  }
    431465  if (fclose(s->fid)) {
Note: See TracChangeset for help on using the changeset viewer.