Ignore:
Timestamp:
Apr 1, 2019, 1:30:06 AM (5 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/cnn, feature/crepe, feature/pitchshift, feature/timestretch, fix/ffmpeg5, master
Children:
7a02ce9
Parents:
5f57ea9 (diff), f55630c (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

    r5f57ea9 r439ba7b  
    2525#include "fvec.h"
    2626#include "fmat.h"
     27#include "ioutils.h"
    2728#include "source_wavread.h"
    2829
    29 #include <errno.h>
    30 
    3130#define AUBIO_WAVREAD_BUFSIZE 1024
    3231
    33 #define SHORT_TO_FLOAT(x) (smpl_t)(x * 3.0517578125e-05)
     32//#define SHORT_TO_FLOAT(x) (smpl_t)(x * 3.0517578125e-05)
    3433
    3534struct _aubio_source_wavread_t {
     
    10099  s->fid = fopen((const char *)path, "rb");
    101100  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);
    103102    goto beach;
    104103  }
     
    133132    bytes_junk += read_little_endian(buf, 4);
    134133    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);
    137136      goto beach;
    138137    }
     
    261260    bytes_junk += read_little_endian(buf, 4);
    262261    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);
    265264      goto beach;
    266265    }
     
    348347  uint_t end = 0;
    349348  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);
    350351  if (s->fid == NULL) {
    351352    AUBIO_ERR("source_wavread: could not read from %s (file not opened)\n",
     
    353354    return;
    354355  }
    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);
    357358    for (i = 0; i < end; i++) {
    358359      read_data->data[i + total_wrote] = 0;
     
    363364    }
    364365    total_wrote += end;
    365     if (total_wrote < s->hop_size) {
     366    if (total_wrote < length) {
    366367      uint_t wavread_read = 0;
    367368      aubio_source_wavread_readframe(s, &wavread_read);
     
    375376    }
    376377  }
    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
    382381  *read = total_wrote;
    383382}
     
    387386  uint_t end = 0;
    388387  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);
    389392  if (s->fid == NULL) {
    390393    AUBIO_ERR("source_wavread: could not read from %s (file not opened)\n",
     
    392395    return;
    393396  }
    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++) {
    397400      for (i = 0; i < end; i++) {
    398401        read_data->data[j][i + total_wrote] = s->output->data[j][i];
     
    400403    }
    401404    total_wrote += end;
    402     if (total_wrote < s->hop_size) {
     405    if (total_wrote < length) {
    403406      uint_t wavread_read = 0;
    404407      aubio_source_wavread_readframe(s, &wavread_read);
     
    412415    }
    413416  }
    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
    421420  *read = total_wrote;
    422421}
     
    442441  ret = fseek(s->fid, s->seek_start + pos * s->blockalign, SEEK_SET);
    443442  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);
    445444    return AUBIO_FAIL;
    446445  }
     
    463462  }
    464463  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);
    466465    return AUBIO_FAIL;
    467466  }
Note: See TracChangeset for help on using the changeset viewer.