Changeset 439ba7b for src/io/ioutils.c


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/ioutils.c

    r5f57ea9 r439ba7b  
    2020
    2121#include "aubio_priv.h"
     22#include "fmat.h"
    2223
    2324uint_t
     
    5152  }
    5253  return AUBIO_OK;
     54}
     55
     56uint_t
     57aubio_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
     72uint_t
     73aubio_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
     95void
     96aubio_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
     104void
     105aubio_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  }
    53123}
    54124
Note: See TracChangeset for help on using the changeset viewer.