Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/io/sink_sndfile.c

    rd2be104 r33d0242  
    2020
    2121
    22 #include "config.h"
     22#include "aubio_priv.h"
    2323
    2424#ifdef HAVE_SNDFILE
     
    2626#include <sndfile.h>
    2727
    28 #include "aubio_priv.h"
    2928#include "fvec.h"
    3029#include "fmat.h"
    3130#include "io/sink_sndfile.h"
    32 
    33 #define MAX_CHANNELS 6
     31#include "io/ioutils.h"
     32
    3433#define MAX_SIZE 4096
    3534
     
    7069  s->channels = 0;
    7170
    72   // negative samplerate given, abort
    73   if ((sint_t)samplerate < 0) goto beach;
    7471  // zero samplerate given. do not open yet
    75   if ((sint_t)samplerate == 0) return s;
     72  if ((sint_t)samplerate == 0) {
     73    return s;
     74  }
     75  // invalid samplerate given, abort
     76  if (aubio_io_validate_samplerate("sink_sndfile", s->path, samplerate)) {
     77    goto beach;
     78  }
    7679
    7780  s->samplerate = samplerate;
     
    9093uint_t aubio_sink_sndfile_preset_samplerate(aubio_sink_sndfile_t *s, uint_t samplerate)
    9194{
    92   if ((sint_t)(samplerate) <= 0) return AUBIO_FAIL;
     95  if (aubio_io_validate_samplerate("sink_sndfile", s->path, samplerate)) {
     96    return AUBIO_FAIL;
     97  }
    9398  s->samplerate = samplerate;
    9499  // automatically open when both samplerate and channels have been set
     
    101106uint_t aubio_sink_sndfile_preset_channels(aubio_sink_sndfile_t *s, uint_t channels)
    102107{
    103   if ((sint_t)(channels) <= 0) return AUBIO_FAIL;
     108  if (aubio_io_validate_channels("sink_sndfile", s->path, channels)) {
     109    return AUBIO_FAIL;
     110  }
    104111  s->channels = channels;
    105112  // automatically open when both samplerate and channels have been set
     
    133140  if (s->handle == NULL) {
    134141    /* show libsndfile err msg */
    135     AUBIO_ERR("sink_sndfile: Failed opening %s. %s\n", s->path, sf_strerror (NULL));
     142    AUBIO_ERR("sink_sndfile: Failed opening \"%s\" with %d channels, %dHz: %s\n",
     143        s->path, s->channels, s->samplerate, sf_strerror (NULL));
    136144    return AUBIO_FAIL;
    137145  }
     
    139147  s->scratch_size = s->max_size*s->channels;
    140148  /* allocate data for de/interleaving reallocated when needed. */
    141   if (s->scratch_size >= MAX_SIZE * MAX_CHANNELS) {
     149  if (s->scratch_size >= MAX_SIZE * AUBIO_MAX_CHANNELS) {
     150    abort();
    142151    AUBIO_ERR("sink_sndfile: %d x %d exceeds maximum aubio_sink_sndfile buffer size %d\n",
    143         s->max_size, s->channels, MAX_CHANNELS * MAX_CHANNELS);
     152        s->max_size, s->channels, MAX_SIZE * AUBIO_MAX_CHANNELS);
    144153    return AUBIO_FAIL;
    145154  }
Note: See TracChangeset for help on using the changeset viewer.