Changes in / [e2f1e6d:9630fa8]


Ignore:
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • .travis.yml

    re2f1e6d r9630fa8  
    1919      os: linux
    2020      compiler: gcc
    21       env: HAVE_AUBIO_DOUBLE=1 CFLAGS="-O3" WAFOPTS="--enable-fftw3 --disable-avcodec"
     21      env: HAVE_AUBIO_DOUBLE=1 CFLAGS="-O3" WAFOPTS="--enable-fftw3"
    2222    - python: 2.7
    2323      os: linux
  • src/aubio_priv.h

    re2f1e6d r9630fa8  
    325325#endif
    326326
    327 #if !defined(_MSC_VER)
    328 #define AUBIO_STRERROR(errno,buf,len) strerror_r(errno, buf, len)
    329 #else
    330 #define AUBIO_STRERROR(errno,buf,len) strerror_s(buf, len, errno)
    331 #endif
    332 
    333327/* handy shortcuts */
    334328#define DB2LIN(g) (POW(10.0,(g)*0.05f))
  • src/io/ioutils.c

    re2f1e6d r9630fa8  
    2020
    2121#include "aubio_priv.h"
    22 #include "fmat.h"
    2322
    2423uint_t
     
    5251  }
    5352  return AUBIO_OK;
    54 }
    55 
    56 uint_t
    57 aubio_source_validate_input_length(const char_t *kind, const char_t *path,
    58     uint_t hop_size, uint_t read_data_length)
    59 {
    60   uint_t length = hop_size;
    61   if (hop_size < read_data_length) {
    62     AUBIO_WRN("%s: partial read from %s, trying to read %d frames, but"
    63         " hop_size is %d\n", kind, path, read_data_length, hop_size);
    64   } else if (hop_size > read_data_length) {
    65     AUBIO_WRN("%s: partial read from %s, trying to read %d frames into"
    66         " a buffer of length %d\n", kind, path, hop_size, read_data_length);
    67     length = read_data_length;
    68   }
    69   return length;
    70 }
    71 
    72 uint_t
    73 aubio_source_validate_input_channels(const char_t *kind, const char_t *path,
    74     uint_t source_channels, uint_t read_data_height)
    75 {
    76   uint_t channels = source_channels;
    77   if (read_data_height < source_channels) {
    78     AUBIO_WRN("%s: partial read from %s, trying to read %d channels,"
    79         " but found output of height %d\n", kind, path, source_channels,
    80         read_data_height);
    81     channels = read_data_height;
    82   } else if (read_data_height > source_channels) {
    83     // do not show a warning when trying to read into more channels than
    84     // the input source.
    85 #if 0
    86     AUBIO_WRN("%s: partial read from %s, trying to read %d channels,"
    87         " but found output of height %d\n", kind, path, source_channels,
    88         read_data_height);
    89 #endif
    90     channels = source_channels;
    91   }
    92   return channels;
    93 }
    94 
    95 void
    96 aubio_source_pad_output (fvec_t *read_data, uint_t source_read)
    97 {
    98   if (source_read < read_data->length) {
    99     AUBIO_MEMSET(read_data->data + source_read, 0,
    100         (read_data->length - source_read) * sizeof(smpl_t));
    101   }
    102 }
    103 
    104 void
    105 aubio_source_pad_multi_output (fmat_t *read_data,
    106     uint_t source_channels, uint_t source_read) {
    107   uint_t i;
    108   if (source_read < read_data->length) {
    109     for (i = 0; i < read_data->height; i++) {
    110       AUBIO_MEMSET(read_data->data[i] + source_read, 0,
    111           (read_data->length - source_read) * sizeof(smpl_t));
    112     }
    113   }
    114 
    115   // destination matrix has more channels than the file
    116   // copy channels from the source to extra output channels
    117   if (read_data->height > source_channels) {
    118     for (i = source_channels; i < read_data->height; i++) {
    119       AUBIO_MEMCPY(read_data->data[i], read_data->data[i % source_channels],
    120           sizeof(smpl_t) * read_data->length);
    121     }
    122   }
    12353}
    12454
  • src/io/ioutils.h

    re2f1e6d r9630fa8  
    5454    uint_t channels);
    5555
    56 /** validate length of source output
    57 
    58   \param kind       the object kind to report on
    59   \param path       the path to report on
    60   \param hop_size   number of frames to be read
    61   \param read_data_length actual length of input
    62 
    63   \return hop_size or the maximum number of frames that can be written
    64 */
    65 uint_t
    66 aubio_source_validate_input_length(const char_t *kind, const char_t *path,
    67     uint_t hop_size, uint_t read_data_length);
    68 
    69 /** validate height of source output
    70 
    71   \param kind       the object kind to report on
    72   \param path       the path to report on
    73   \param source_channels maximum number of channels that can be written
    74   \param read_data_height actual height of input
    75 
    76   \return write_data_height or the maximum number of channels
    77 */
    78 uint_t
    79 aubio_source_validate_input_channels(const char_t *kind, const char_t *path,
    80     uint_t source_channels, uint_t read_data_height);
    81 
    82 /** pad end of source output vector with zeroes
    83 
    84   \param read_data   output vector to pad
    85   \param source_read number of frames read
    86 
    87 */
    88 void
    89 aubio_source_pad_output (fvec_t *read_data, uint_t source_read);
    90 
    91 /** pad end of source output matrix with zeroes
    92 
    93   \param read_data   output matrix to pad
    94   \param source_channels number of channels in the source
    95   \param source_read number of frames read
    96 
    97 */
    98 void
    99 aubio_source_pad_multi_output (fmat_t *read_data, uint_t source_channels,
    100         uint_t source_read);
    101 
    102 /** validate length of sink input
     56/** validate length of input
    10357
    10458  \param kind       the object kind to report on
    10559  \param path       the path to report on
    10660  \param max_size   maximum number of frames that can be written
    107   \param write_data_length actual length of input
     61  \param write_data_length actual length of input vector/matrix
    10862  \param write number of samples asked
    10963
     
    11468    uint_t max_size, uint_t write_data_length, uint_t write);
    11569
    116 /** validate height of sink input
     70/** validate height of input
    11771
    11872  \param kind       the object kind to report on
    11973  \param path       the path to report on
    120   \param sink_channels maximum number of channels that can be written
     74  \param max_size  maximum number of channels that can be written
    12175  \param write_data_height actual height of input matrix
    12276
  • src/io/sink_vorbis.c

    re2f1e6d r9630fa8  
    3737#include <time.h> // time
    3838
    39 #define MAX_SIZE 4096
     39#define MAX_SIZE 2048
    4040
    4141struct _aubio_sink_vorbis_t {
     
    6464void del_aubio_sink_vorbis (aubio_sink_vorbis_t *s);
    6565
    66 static uint_t aubio_sink_vorbis_write_page(aubio_sink_vorbis_t *s);
    67 
    6866aubio_sink_vorbis_t * new_aubio_sink_vorbis (const char_t *uri,
    6967    uint_t samplerate)
     
    120118  s->fid = fopen((const char *)s->path, "wb");
    121119  if (!s->fid) {
    122     char errorstr[256];
    123     AUBIO_STRERROR(errno, errorstr, sizeof(errorstr));
    124     AUBIO_ERR("sink_vorbis: Error opening file \'%s\' (%s)\n",
    125         s->path, errorstr);
     120    AUBIO_ERR("sink_vorbis: Error opening file %s (%s)\n",
     121        s->path, strerror(errno));
    126122    return AUBIO_FAIL;
    127123  }
     
    148144  // write header
    149145  {
     146    int ret = 0;
     147    size_t wrote;
    150148    ogg_packet header;
    151149    ogg_packet header_comm;
     
    162160    while (1)
    163161    {
    164       if (!ogg_stream_flush(&s->os, &s->og)) break;
    165       if (aubio_sink_vorbis_write_page(s)) return AUBIO_FAIL;
     162      ret = ogg_stream_flush(&s->os, &s->og);
     163      if (ret==0) break;
     164      wrote = fwrite(s->og.header, 1, s->og.header_len, s->fid);
     165      ret = (wrote == (unsigned)s->og.header_len);
     166      wrote = fwrite(s->og.body,   1, s->og.body_len,   s->fid);
     167      ret &= (wrote == (unsigned)s->og.body_len);
     168      if (ret == 0) {
     169        AUBIO_ERR("sink_vorbis: failed writing \'%s\' to disk (%s)\n",
     170            s->path, strerror(errno));
     171        return AUBIO_FAIL;
     172      }
    166173    }
    167174  }
     
    205212}
    206213
    207 static
    208 uint_t aubio_sink_vorbis_write_page(aubio_sink_vorbis_t *s) {
     214void aubio_sink_vorbis_write(aubio_sink_vorbis_t *s)
     215{
    209216  int result;
    210217  size_t wrote;
    211   wrote = fwrite(s->og.header, 1, s->og.header_len, s->fid);
    212   result = (wrote == (unsigned)s->og.header_len);
    213   wrote = fwrite(s->og.body, 1, s->og.body_len,     s->fid);
    214   result &= (wrote == (unsigned)s->og.body_len);
    215   if (result == 0) {
    216     char errorstr[256];
    217     AUBIO_STRERROR(errno, errorstr, sizeof(errorstr));
    218     AUBIO_ERR("sink_vorbis: failed writing \'%s\' to disk (%s)\n",
    219         s->path, errorstr);
    220     return AUBIO_FAIL;
    221   }
    222   return AUBIO_OK;
    223 }
    224 
    225 static
    226 void aubio_sink_vorbis_write(aubio_sink_vorbis_t *s)
    227 {
    228218  // pre-analysis
    229219  while (vorbis_analysis_blockout(&s->vd, &s->vb) == 1) {
     
    237227
    238228      while (1) {
    239         if (!ogg_stream_pageout (&s->os, &s->og)) break;
    240         aubio_sink_vorbis_write_page(s);
     229        result = ogg_stream_pageout (&s->os, &s->og);
     230        if (result == 0) break;
     231        wrote = fwrite(s->og.header, 1, s->og.header_len, s->fid);
     232        result = (wrote == (unsigned)s->og.header_len);
     233        wrote = fwrite(s->og.body, 1, s->og.body_len,     s->fid);
     234        result &= (wrote == (unsigned)s->og.body_len);
     235        if (result == 0) {
     236          AUBIO_WRN("sink_vorbis: failed writing \'%s\' to disk (%s)\n",
     237              s->path, strerror(errno));
     238        }
    241239        if (ogg_page_eos(&s->og)) break;
    242240      }
     
    293291    }
    294292    // tell vorbis how many frames were written
    295     vorbis_analysis_wrote(&s->vd, (long)length);
     293    vorbis_analysis_wrote(&s->vd, (long)write);
    296294  }
    297295
     
    308306
    309307  if (s->fid && fclose(s->fid)) {
    310     char errorstr[256];
    311     AUBIO_STRERROR(errno, errorstr, sizeof(errorstr));
    312     AUBIO_ERR("sink_vorbis: Error closing file \'%s\' (%s)\n",
    313         s->path, errorstr);
     308    AUBIO_ERR("sink_vorbis: Error closing file %s (%s)\n",
     309        s->path, strerror(errno));
    314310    return AUBIO_FAIL;
    315311  }
  • src/io/sink_wavwrite.c

    re2f1e6d r9630fa8  
    163163  unsigned char buf[5];
    164164  uint_t byterate, blockalign;
    165   size_t written = 0;
    166165
    167166  /* open output file */
    168167  s->fid = fopen((const char *)s->path, "wb");
    169168  if (!s->fid) {
    170     char errorstr[256];
    171     AUBIO_STRERROR(errno, errorstr, sizeof(errorstr));
    172     AUBIO_ERR("sink_wavwrite: could not open %s (%s)\n", s->path, errorstr);
     169    AUBIO_ERR("sink_wavwrite: could not open %s (%s)\n", s->path, strerror(errno));
    173170    goto beach;
    174171  }
    175172
    176173  // ChunkID
    177   written += fwrite("RIFF", 4, 1, s->fid);
     174  fwrite("RIFF", 4, 1, s->fid);
    178175
    179176  // ChunkSize (0 for now, actual size will be written in _close)
    180   written += fwrite(write_little_endian(0, buf, 4), 4, 1, s->fid);
     177  fwrite(write_little_endian(0, buf, 4), 4, 1, s->fid);
    181178
    182179  // Format
    183   written += fwrite("WAVE", 4, 1, s->fid);
     180  fwrite("WAVE", 4, 1, s->fid);
    184181
    185182  // Subchunk1ID
    186   written += fwrite("fmt ", 4, 1, s->fid);
     183  fwrite("fmt ", 4, 1, s->fid);
    187184
    188185  // Subchunk1Size
    189   written += fwrite(write_little_endian(16, buf, 4), 4, 1, s->fid);
     186  fwrite(write_little_endian(16, buf, 4), 4, 1, s->fid);
    190187
    191188  // AudioFormat
    192   written += fwrite(write_little_endian(1, buf, 2), 2, 1, s->fid);
     189  fwrite(write_little_endian(1, buf, 2), 2, 1, s->fid);
    193190
    194191  // NumChannels
    195   written += fwrite(write_little_endian(s->channels, buf, 2), 2, 1, s->fid);
     192  fwrite(write_little_endian(s->channels, buf, 2), 2, 1, s->fid);
    196193
    197194  // SampleRate
    198   written += fwrite(write_little_endian(s->samplerate, buf, 4), 4, 1, s->fid);
     195  fwrite(write_little_endian(s->samplerate, buf, 4), 4, 1, s->fid);
    199196
    200197  // ByteRate
    201198  byterate = s->samplerate * s->channels * s->bitspersample / 8;
    202   written += fwrite(write_little_endian(byterate, buf, 4), 4, 1, s->fid);
     199  fwrite(write_little_endian(byterate, buf, 4), 4, 1, s->fid);
    203200
    204201  // BlockAlign
    205202  blockalign = s->channels * s->bitspersample / 8;
    206   written += fwrite(write_little_endian(blockalign, buf, 2), 2, 1, s->fid);
     203  fwrite(write_little_endian(blockalign, buf, 2), 2, 1, s->fid);
    207204
    208205  // BitsPerSample
    209   written += fwrite(write_little_endian(s->bitspersample, buf, 2), 2, 1, s->fid);
     206  fwrite(write_little_endian(s->bitspersample, buf, 2), 2, 1, s->fid);
    210207
    211208  // Subchunk2ID
    212   written += fwrite("data", 4, 1, s->fid);
     209  fwrite("data", 4, 1, s->fid);
    213210
    214211  // Subchunk1Size (0 for now, actual size will be written in _close)
    215   written += fwrite(write_little_endian(0, buf, 4), 4, 1, s->fid);
    216 
    217   // fwrite(*, *, 1, s->fid) was called 13 times, check success
    218   if (written != 13) {
    219     char errorstr[256];
    220     AUBIO_STRERROR(errno, errorstr, sizeof(errorstr));
    221     AUBIO_WRN("sink_wavwrite: writing header to %s failed, expected %d"
    222         " write but got only %d (%s)\n", s->path, 13, written, errorstr);
    223     return AUBIO_FAIL;
    224   }
     212  fwrite(write_little_endian(0, buf, 4), 4, 1, s->fid);
    225213
    226214  s->scratch_size = s->max_size * s->channels;
     
    239227}
    240228
    241 static
    242 void aubio_sink_wavwrite_write_frames(aubio_sink_wavwrite_t *s, uint_t write)
    243 {
    244   uint_t written_frames = 0;
    245 
    246   written_frames = fwrite(s->scratch_data, 2 * s->channels, write, s->fid);
    247 
    248   if (written_frames != write) {
    249     char errorstr[256];
    250     AUBIO_STRERROR(errno, errorstr, sizeof(errorstr));
    251     AUBIO_WRN("sink_wavwrite: trying to write %d frames to %s, but only %d"
    252         " could be written (%s)\n", write, s->path, written_frames, errorstr);
    253   }
    254   s->total_frames_written += written_frames;
    255 }
    256229
    257230void aubio_sink_wavwrite_do(aubio_sink_wavwrite_t *s, fvec_t * write_data, uint_t write){
    258   uint_t c = 0, i = 0;
     231  uint_t c = 0, i = 0, written_frames = 0;
    259232  uint_t length = aubio_sink_validate_input_length("sink_wavwrite", s->path,
    260233      s->max_size, write_data->length, write);
     
    265238    }
    266239  }
    267 
    268   aubio_sink_wavwrite_write_frames(s, length);
     240  written_frames = fwrite(s->scratch_data, 2, length * s->channels, s->fid);
     241
     242  if (written_frames != write) {
     243    AUBIO_WRN("sink_wavwrite: trying to write %d frames to %s, "
     244        "but only %d could be written\n", write, s->path, written_frames);
     245  }
     246  s->total_frames_written += written_frames;
     247  return;
    269248}
    270249
    271250void aubio_sink_wavwrite_do_multi(aubio_sink_wavwrite_t *s, fmat_t * write_data, uint_t write){
    272   uint_t c = 0, i = 0;
     251  uint_t c = 0, i = 0, written_frames = 0;
    273252
    274253  uint_t channels = aubio_sink_validate_input_channels("sink_wavwrite", s->path,
     
    282261    }
    283262  }
    284 
    285   aubio_sink_wavwrite_write_frames(s, length);
     263  written_frames = fwrite(s->scratch_data, 2, length * s->channels, s->fid);
     264
     265  if (written_frames != write * s->channels) {
     266    AUBIO_WRN("sink_wavwrite: trying to write %d frames to %s, "
     267        "but only %d could be written\n", write, s->path, written_frames / s->channels);
     268  }
     269  s->total_frames_written += written_frames;
     270  return;
    286271}
    287272
     
    289274  uint_t data_size = s->total_frames_written * s->bitspersample * s->channels / 8;
    290275  unsigned char buf[5];
    291   size_t written = 0, err = 0;
    292276  if (!s->fid) return AUBIO_FAIL;
    293277  // ChunkSize
    294   err += fseek(s->fid, 4, SEEK_SET);
    295   written += fwrite(write_little_endian(data_size + 36, buf, 4), 4, 1, s->fid);
     278  fseek(s->fid, 4, SEEK_SET);
     279  fwrite(write_little_endian(data_size + 36, buf, 4), 4, 1, s->fid);
    296280  // Subchunk2Size
    297   err += fseek(s->fid, 40, SEEK_SET);
    298   written += fwrite(write_little_endian(data_size, buf, 4), 4, 1, s->fid);
    299   if (written != 2 || err != 0) {
    300     char errorstr[256];
    301     AUBIO_STRERROR(errno, errorstr, sizeof(errorstr));
    302     AUBIO_WRN("sink_wavwrite: updating header of %s failed, expected %d"
    303         " write but got only %d (%s)\n", s->path, 2, written, errorstr);
    304   }
     281  fseek(s->fid, 40, SEEK_SET);
     282  fwrite(write_little_endian(data_size, buf, 4), 4, 1, s->fid);
    305283  // close file
    306284  if (fclose(s->fid)) {
    307     char errorstr[256];
    308     AUBIO_STRERROR(errno, errorstr, sizeof(errorstr));
    309     AUBIO_ERR("sink_wavwrite: Error closing file %s (%s)\n", s->path, errorstr);
     285    AUBIO_ERR("sink_wavwrite: Error closing file %s (%s)\n", s->path, strerror(errno));
    310286  }
    311287  s->fid = NULL;
  • src/io/source_apple_audio.c

    re2f1e6d r9630fa8  
    2525#include "fvec.h"
    2626#include "fmat.h"
    27 #include "ioutils.h"
    2827#include "io/source_apple_audio.h"
    2928
     
    211210  uint_t c, v;
    212211  UInt32 loadedPackets = aubio_source_apple_audio_read_frame(s);
    213   uint_t length = aubio_source_validate_input_length("source_apple_audio",
    214       s->path, s->block_size, read_to->length);
    215212  smpl_t *data = (smpl_t*)s->bufferList.mBuffers[0].mData;
    216213
    217   length = MIN(loadedPackets, length);
    218 
    219   for (v = 0; v < length; v++) {
     214  for (v = 0; v < loadedPackets; v++) {
    220215    read_to->data[v] = 0.;
    221216    for (c = 0; c < s->channels; c++) {
     
    225220  }
    226221  // short read, fill with zeros
    227   aubio_source_pad_output(read_to, length);
    228 
    229   *read = (uint_t)length;
     222  if (loadedPackets < s->block_size) {
     223    for (v = loadedPackets; v < s->block_size; v++) {
     224      read_to->data[v] = 0.;
     225    }
     226  }
     227
     228  *read = (uint_t)loadedPackets;
     229  return;
    230230}
    231231
    232232void aubio_source_apple_audio_do_multi(aubio_source_apple_audio_t *s, fmat_t * read_to, uint_t * read) {
    233233  uint_t c, v;
    234   uint_t length = aubio_source_validate_input_length("source_apple_audio",
    235       s->path, s->block_size, read_to->length);
    236   uint_t channels = aubio_source_validate_input_channels("source_apple_audio",
    237       s->path, s->channels, read_to->height);
    238234  UInt32 loadedPackets = aubio_source_apple_audio_read_frame(s);
    239235  smpl_t *data = (smpl_t*)s->bufferList.mBuffers[0].mData;
    240236
    241   length = MIN(loadedPackets, length);
    242 
    243   for (v = 0; v < length; v++) {
    244     for (c = 0; c < channels; c++) {
     237  for (v = 0; v < loadedPackets; v++) {
     238    for (c = 0; c < read_to->height; c++) {
    245239      read_to->data[c][v] = data[ v * s->channels + c];
    246240    }
    247241  }
    248 
    249   aubio_source_pad_multi_output(read_to, s->channels, (uint_t)length);
    250 
    251   *read = (uint_t)length;
     242  // if read_data has more channels than the file
     243  if (read_to->height > s->channels) {
     244    // copy last channel to all additional channels
     245    for (v = 0; v < loadedPackets; v++) {
     246      for (c = s->channels; c < read_to->height; c++) {
     247        read_to->data[c][v] = data[ v * s->channels + (s->channels - 1)];
     248      }
     249    }
     250  }
     251  // short read, fill with zeros
     252  if (loadedPackets < s->block_size) {
     253    for (v = loadedPackets; v < s->block_size; v++) {
     254      for (c = 0; c < read_to->height; c++) {
     255        read_to->data[c][v] = 0.;
     256      }
     257    }
     258  }
     259
     260  *read = (uint_t)loadedPackets;
     261  return;
    252262}
    253263
  • src/io/source_avcodec.c

    re2f1e6d r9630fa8  
    6161#include "fvec.h"
    6262#include "fmat.h"
    63 #include "ioutils.h"
    6463#include "source_avcodec.h"
    6564
     
    490489  uint_t end = 0;
    491490  uint_t total_wrote = 0;
    492   uint_t length = aubio_source_validate_input_length("source_avcodec", s->path,
    493       s->hop_size, read_data->length);
    494   while (total_wrote < length) {
    495     end = MIN(s->read_samples - s->read_index, length - total_wrote);
     491  while (total_wrote < s->hop_size) {
     492    end = MIN(s->read_samples - s->read_index, s->hop_size - total_wrote);
    496493    for (i = 0; i < end; i++) {
    497494      read_data->data[i + total_wrote] = 0.;
     
    503500    }
    504501    total_wrote += end;
    505     if (total_wrote < length) {
     502    if (total_wrote < s->hop_size) {
    506503      uint_t avcodec_read = 0;
    507504      aubio_source_avcodec_readframe(s, &avcodec_read);
     
    515512    }
    516513  }
    517 
    518   aubio_source_pad_output(read_data, total_wrote);
    519 
     514  if (total_wrote < s->hop_size) {
     515    for (i = total_wrote; i < s->hop_size; i++) {
     516      read_data->data[i] = 0.;
     517    }
     518  }
    520519  *read = total_wrote;
    521520}
     
    526525  uint_t end = 0;
    527526  uint_t total_wrote = 0;
    528   uint_t length = aubio_source_validate_input_length("source_wavread", s->path,
    529       s->hop_size, read_data->length);
    530   uint_t channels = aubio_source_validate_input_channels("source_wavread",
    531       s->path, s->input_channels, read_data->height);
    532   while (total_wrote < length) {
    533     end = MIN(s->read_samples - s->read_index, length - total_wrote);
    534     for (j = 0; j < channels; j++) {
     527  while (total_wrote < s->hop_size) {
     528    end = MIN(s->read_samples - s->read_index, s->hop_size - total_wrote);
     529    for (j = 0; j < read_data->height; j++) {
    535530      for (i = 0; i < end; i++) {
    536531        read_data->data[j][i + total_wrote] =
     
    539534    }
    540535    total_wrote += end;
    541     if (total_wrote < length) {
     536    if (total_wrote < s->hop_size) {
    542537      uint_t avcodec_read = 0;
    543538      aubio_source_avcodec_readframe(s, &avcodec_read);
     
    551546    }
    552547  }
    553 
    554   aubio_source_pad_multi_output(read_data, s->input_channels, total_wrote);
    555 
     548  if (total_wrote < s->hop_size) {
     549    for (j = 0; j < read_data->height; j++) {
     550      for (i = total_wrote; i < s->hop_size; i++) {
     551        read_data->data[j][i] = 0.;
     552      }
     553    }
     554  }
    556555  *read = total_wrote;
    557556}
  • src/io/source_sndfile.c

    re2f1e6d r9630fa8  
    2727#include "fvec.h"
    2828#include "fmat.h"
    29 #include "ioutils.h"
    3029#include "source_sndfile.h"
    3130
     
    171170  uint_t i,j, input_channels = s->input_channels;
    172171  /* read from file into scratch_data */
    173   uint_t length = aubio_source_validate_input_length("source_sndfile", s->path,
    174       s->hop_size, read_data->length);
    175   sf_count_t read_samples = aubio_sf_read_smpl (s->handle, s->scratch_data,
    176       s->input_channels * length);
    177 
    178   length = MIN(read_samples / s->input_channels, length);
     172  sf_count_t read_samples = aubio_sf_read_smpl (s->handle, s->scratch_data, s->scratch_size);
    179173
    180174  /* where to store de-interleaved data */
     
    190184
    191185  /* de-interleaving and down-mixing data  */
    192   for (j = 0; j < length; j++) {
     186  for (j = 0; j < read_samples / input_channels; j++) {
    193187    ptr_data[j] = 0;
    194188    for (i = 0; i < input_channels; i++) {
     
    204198#endif /* HAVE_SAMPLERATE */
    205199
    206   *read = (int)FLOOR(s->ratio * length + .5);
    207 
    208   aubio_source_pad_output (read_data, *read);
     200  *read = (int)FLOOR(s->ratio * read_samples / input_channels + .5);
     201
     202  if (*read < s->hop_size) {
     203    for (j = *read; j < s->hop_size; j++) {
     204      read_data->data[j] = 0;
     205    }
     206  }
    209207
    210208}
     
    213211  uint_t i,j, input_channels = s->input_channels;
    214212  /* do actual reading */
    215   uint_t length = aubio_source_validate_input_length("source_sndfile", s->path,
    216       s->hop_size, read_data->length);
    217   uint_t channels = aubio_source_validate_input_channels("source_sndfile",
    218       s->path, s->input_channels, read_data->height);
    219   sf_count_t read_samples = aubio_sf_read_smpl (s->handle, s->scratch_data,
    220       length * s->input_channels);
    221 
    222   length = MIN(read_samples / s->input_channels, length);
     213  sf_count_t read_samples = aubio_sf_read_smpl (s->handle, s->scratch_data, s->scratch_size);
    223214
    224215  /* where to store de-interleaved data */
     
    233224  }
    234225
    235   for (j = 0; j < length; j++) {
    236     for (i = 0; i < channels; i++) {
    237       ptr_data[i][j] = s->scratch_data[j * input_channels + i];
     226  if (read_data->height < input_channels) {
     227    // destination matrix has less channels than the file; copy only first
     228    // channels of the file, de-interleaving data
     229    for (j = 0; j < read_samples / input_channels; j++) {
     230      for (i = 0; i < read_data->height; i++) {
     231        ptr_data[i][j] = s->scratch_data[j * input_channels + i];
     232      }
     233    }
     234  } else {
     235    // destination matrix has as many or more channels than the file; copy each
     236    // channel from the file to the destination matrix, de-interleaving data
     237    for (j = 0; j < read_samples / input_channels; j++) {
     238      for (i = 0; i < input_channels; i++) {
     239        ptr_data[i][j] = s->scratch_data[j * input_channels + i];
     240      }
     241    }
     242  }
     243
     244  if (read_data->height > input_channels) {
     245    // destination matrix has more channels than the file; copy last channel
     246    // of the file to each additional channels, de-interleaving data
     247    for (j = 0; j < read_samples / input_channels; j++) {
     248      for (i = input_channels; i < read_data->height; i++) {
     249        ptr_data[i][j] = s->scratch_data[j * input_channels + (input_channels - 1)];
     250      }
    238251    }
    239252  }
     
    252265#endif /* HAVE_SAMPLERATE */
    253266
    254   *read = (int)FLOOR(s->ratio * length + .5);
    255 
    256   aubio_source_pad_multi_output(read_data, input_channels, *read);
     267  *read = (int)FLOOR(s->ratio * read_samples / input_channels + .5);
     268
     269  if (*read < s->hop_size) {
     270    for (i = 0; i < read_data->height; i++) {
     271      for (j = *read; j < s->hop_size; j++) {
     272        read_data->data[i][j] = 0.;
     273      }
     274    }
     275  }
     276
    257277}
    258278
  • src/io/source_wavread.c

    re2f1e6d r9630fa8  
    2525#include "fvec.h"
    2626#include "fmat.h"
    27 #include "ioutils.h"
    2827#include "source_wavread.h"
    2928
     
    349348  uint_t end = 0;
    350349  uint_t total_wrote = 0;
    351   uint_t length = aubio_source_validate_input_length("source_wavread", s->path,
    352       s->hop_size, read_data->length);
    353350  if (s->fid == NULL) {
    354351    AUBIO_ERR("source_wavread: could not read from %s (file not opened)\n",
     
    356353    return;
    357354  }
    358   while (total_wrote < length) {
    359     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);
    360357    for (i = 0; i < end; i++) {
    361358      read_data->data[i + total_wrote] = 0;
     
    366363    }
    367364    total_wrote += end;
    368     if (total_wrote < length) {
     365    if (total_wrote < s->hop_size) {
    369366      uint_t wavread_read = 0;
    370367      aubio_source_wavread_readframe(s, &wavread_read);
     
    378375    }
    379376  }
    380 
    381   aubio_source_pad_output (read_data, total_wrote);
    382 
     377  if (total_wrote < s->hop_size) {
     378    for (i = end; i < s->hop_size; i++) {
     379      read_data->data[i] = 0.;
     380    }
     381  }
    383382  *read = total_wrote;
    384383}
     
    388387  uint_t end = 0;
    389388  uint_t total_wrote = 0;
    390   uint_t length = aubio_source_validate_input_length("source_wavread", s->path,
    391       s->hop_size, read_data->length);
    392   uint_t channels = aubio_source_validate_input_channels("source_wavread",
    393       s->path, s->input_channels, read_data->height);
    394389  if (s->fid == NULL) {
    395390    AUBIO_ERR("source_wavread: could not read from %s (file not opened)\n",
     
    397392    return;
    398393  }
    399   while (total_wrote < length) {
    400     end = MIN(s->read_samples - s->read_index, length - total_wrote);
    401     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++) {
    402397      for (i = 0; i < end; i++) {
    403398        read_data->data[j][i + total_wrote] = s->output->data[j][i];
     
    405400    }
    406401    total_wrote += end;
    407     if (total_wrote < length) {
     402    if (total_wrote < s->hop_size) {
    408403      uint_t wavread_read = 0;
    409404      aubio_source_wavread_readframe(s, &wavread_read);
     
    417412    }
    418413  }
    419 
    420   aubio_source_pad_multi_output(read_data, s->input_channels, total_wrote);
    421 
     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  }
    422421  *read = total_wrote;
    423422}
  • tests/src/io/base-source_custom.h

    re2f1e6d r9630fa8  
    9494  if (read != hop_size) return 1;
    9595
    96   // read again in undersized vector
    97   del_fvec(vec);
    98   vec = new_fvec(hop_size - 1);
    99   aubio_source_custom_do(s, vec, &read);
    100   if (read != hop_size - 1) return 1;
    101 
    102   // read again in oversized vector
    103   del_fvec(vec);
    104   vec = new_fvec(hop_size + 1);
    105   aubio_source_custom_do(s, vec, &read);
    106   if (read != hop_size) return 1;
    107 
    10896  // seek to 0
    10997  if(aubio_source_custom_seek(s, 0)) return 1;
    11098
    11199  // read again as multiple channels
    112   aubio_source_custom_do_multi(s, mat, &read);
    113   if (read != hop_size) return 1;
    114 
    115   // read again as multiple channels in an undersized matrix
    116   del_fmat(mat);
    117   mat = new_fmat(channels - 1, hop_size);
    118   aubio_source_custom_do_multi(s, mat, &read);
    119   if (read != hop_size) return 1;
    120 
    121   // read again as multiple channels in an undersized matrix
    122   del_fmat(mat);
    123   mat = new_fmat(channels, hop_size - 1);
    124   aubio_source_custom_do_multi(s, mat, &read);
    125   if (read != hop_size - 1) return 1;
    126 
    127   // read again as multiple channels in an oversized matrix
    128   del_fmat(mat);
    129   mat = new_fmat(channels + 1, hop_size);
    130   aubio_source_custom_do_multi(s, mat, &read);
    131   if (read != hop_size) return 1;
    132 
    133   // read again as multiple channels in an oversized matrix
    134   del_fmat(mat);
    135   mat = new_fmat(channels, hop_size + 1);
    136100  aubio_source_custom_do_multi(s, mat, &read);
    137101  if (read != hop_size) return 1;
  • tests/src/io/test-source.c

    re2f1e6d r9630fa8  
    9090  if (read != hop_size) return 1;
    9191
    92   // read again in undersized vector
    93   del_fvec(vec);
    94   vec = new_fvec(hop_size - 1);
    95   aubio_source_do(s, vec, &read);
    96   if (read != hop_size - 1) return 1;
    97 
    98   // read again in oversized vector
    99   del_fvec(vec);
    100   vec = new_fvec(hop_size + 1);
    101   aubio_source_do(s, vec, &read);
    102   if (read != hop_size) return 1;
    103 
    10492  // seek to 0
    10593  if(aubio_source_seek(s, 0)) return 1;
    10694
    10795  // read again as multiple channels
    108   aubio_source_do_multi(s, mat, &read);
    109   if (read != hop_size) return 1;
    110 
    111   // read again as multiple channels in an undersized matrix
    112   del_fmat(mat);
    113   mat = new_fmat(channels - 1, hop_size);
    114   aubio_source_do_multi(s, mat, &read);
    115   if (read != hop_size) return 1;
    116 
    117   // read again as multiple channels in an undersized matrix
    118   del_fmat(mat);
    119   mat = new_fmat(channels, hop_size - 1);
    120   aubio_source_do_multi(s, mat, &read);
    121   if (read != hop_size - 1) return 1;
    122 
    123   // read again as multiple channels in an oversized matrix
    124   del_fmat(mat);
    125   mat = new_fmat(channels + 1, hop_size);
    126   aubio_source_do_multi(s, mat, &read);
    127   if (read != hop_size) return 1;
    128 
    129   // read again as multiple channels in an oversized matrix
    130   del_fmat(mat);
    131   mat = new_fmat(channels, hop_size + 1);
    13296  aubio_source_do_multi(s, mat, &read);
    13397  if (read != hop_size) return 1;
Note: See TracChangeset for help on using the changeset viewer.