Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/io/source_wavread.c

    rb40c149 rc0a1906  
    2525#include "fvec.h"
    2626#include "fmat.h"
    27 #include "ioutils.h"
    2827#include "source_wavread.h"
    2928
     29#include <errno.h>
     30
    3031#define AUBIO_WAVREAD_BUFSIZE 1024
    3132
    32 //#define SHORT_TO_FLOAT(x) (smpl_t)(x * 3.0517578125e-05)
     33#define SHORT_TO_FLOAT(x) (smpl_t)(x * 3.0517578125e-05)
    3334
    3435struct _aubio_source_wavread_t {
     
    99100  s->fid = fopen((const char *)path, "rb");
    100101  if (!s->fid) {
    101     AUBIO_STRERR("source_wavread: Failed opening %s (%s)\n", s->path, errorstr);
     102    AUBIO_ERR("source_wavread: Failed opening %s (System error: %s)\n", s->path, strerror(errno));
    102103    goto beach;
    103104  }
     
    132133    bytes_junk += read_little_endian(buf, 4);
    133134    if (fseek(s->fid, bytes_read + bytes_junk, SEEK_SET) != 0) {
    134       AUBIO_STRERR("source_wavread: Failed opening %s (could not seek past JUNK Chunk: %s)\n",
    135           s->path, errorstr);
     135      AUBIO_ERR("source_wavread: Failed opening %s (could not seek past JUNK Chunk: %s)\n",
     136          s->path, strerror(errno));
    136137      goto beach;
    137138    }
     
    260261    bytes_junk += read_little_endian(buf, 4);
    261262    if (fseek(s->fid, bytes_read + bytes_junk, SEEK_SET) != 0) {
    262       AUBIO_STRERR("source_wavread: could not seek past unknown chunk in %s (%s)\n",
    263           s->path, errorstr);
     263      AUBIO_ERR("source_wavread: could not seek past unknown chunk in %s (%s)\n",
     264          s->path, strerror(errno));
    264265      goto beach;
    265266    }
     
    347348  uint_t end = 0;
    348349  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);
    351350  if (s->fid == NULL) {
    352351    AUBIO_ERR("source_wavread: could not read from %s (file not opened)\n",
     
    354353    return;
    355354  }
    356   while (total_wrote < length) {
    357     end = MIN(s->read_samples - s->read_index, length - total_wrote);
     355  while (total_wrote < s->hop_size) {
     356    end = MIN(s->read_samples - s->read_index, s->hop_size - total_wrote);
    358357    for (i = 0; i < end; i++) {
    359358      read_data->data[i + total_wrote] = 0;
     
    364363    }
    365364    total_wrote += end;
    366     if (total_wrote < length) {
     365    if (total_wrote < s->hop_size) {
    367366      uint_t wavread_read = 0;
    368367      aubio_source_wavread_readframe(s, &wavread_read);
     
    376375    }
    377376  }
    378 
    379   aubio_source_pad_output (read_data, total_wrote);
    380 
     377  if (total_wrote < s->hop_size) {
     378    for (i = end; i < s->hop_size; i++) {
     379      read_data->data[i] = 0.;
     380    }
     381  }
    381382  *read = total_wrote;
    382383}
     
    386387  uint_t end = 0;
    387388  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);
    392389  if (s->fid == NULL) {
    393390    AUBIO_ERR("source_wavread: could not read from %s (file not opened)\n",
     
    395392    return;
    396393  }
    397   while (total_wrote < length) {
    398     end = MIN(s->read_samples - s->read_index, length - total_wrote);
    399     for (j = 0; j < channels; j++) {
     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++) {
    400397      for (i = 0; i < end; i++) {
    401398        read_data->data[j][i + total_wrote] = s->output->data[j][i];
     
    403400    }
    404401    total_wrote += end;
    405     if (total_wrote < length) {
     402    if (total_wrote < s->hop_size) {
    406403      uint_t wavread_read = 0;
    407404      aubio_source_wavread_readframe(s, &wavread_read);
     
    415412    }
    416413  }
    417 
    418   aubio_source_pad_multi_output(read_data, s->input_channels, total_wrote);
    419 
     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  }
    420421  *read = total_wrote;
    421422}
     
    441442  ret = fseek(s->fid, s->seek_start + pos * s->blockalign, SEEK_SET);
    442443  if (ret != 0) {
    443     AUBIO_STRERR("source_wavread: could not seek %s at %d (%s)\n", s->path, pos, errorstr);
     444    AUBIO_ERR("source_wavread: could not seek %s at %d (%s)\n", s->path, pos, strerror(errno));
    444445    return AUBIO_FAIL;
    445446  }
     
    462463  }
    463464  if (fclose(s->fid)) {
    464     AUBIO_STRERR("source_wavread: could not close %s (%s)\n", s->path, errorstr);
     465    AUBIO_ERR("source_wavread: could not close %s (%s)\n", s->path, strerror(errno));
    465466    return AUBIO_FAIL;
    466467  }
Note: See TracChangeset for help on using the changeset viewer.