Changeset 4c72a9c


Ignore:
Timestamp:
Dec 20, 2018, 7:44:51 PM (5 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/timestretch, fix/ffmpeg5, master
Children:
49ac58e0
Parents:
4edba9d
Message:

[source_apple_audio] use input validation and padding helpers

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/io/source_apple_audio.c

    r4edba9d r4c72a9c  
    2525#include "fvec.h"
    2626#include "fmat.h"
     27#include "ioutils.h"
    2728#include "io/source_apple_audio.h"
    2829
     
    210211  uint_t c, v;
    211212  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);
    212215  smpl_t *data = (smpl_t*)s->bufferList.mBuffers[0].mData;
    213216
    214   for (v = 0; v < loadedPackets; v++) {
     217  length = MIN(loadedPackets, length);
     218
     219  for (v = 0; v < length; v++) {
    215220    read_to->data[v] = 0.;
    216221    for (c = 0; c < s->channels; c++) {
     
    220225  }
    221226  // short read, fill with zeros
    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;
     227  aubio_source_pad_output(read_to, length);
     228
     229  *read = (uint_t)length;
    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);
    234238  UInt32 loadedPackets = aubio_source_apple_audio_read_frame(s);
    235239  smpl_t *data = (smpl_t*)s->bufferList.mBuffers[0].mData;
    236240
    237   for (v = 0; v < loadedPackets; v++) {
    238     for (c = 0; c < read_to->height; c++) {
     241  length = MIN(loadedPackets, length);
     242
     243  for (v = 0; v < length; v++) {
     244    for (c = 0; c < channels; c++) {
    239245      read_to->data[c][v] = data[ v * s->channels + c];
    240246    }
    241247  }
    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;
     248
     249  aubio_source_pad_multi_output(read_to, s->channels, (uint_t)length);
     250
     251  *read = (uint_t)length;
    262252}
    263253
Note: See TracChangeset for help on using the changeset viewer.