Changeset cf19b8a


Ignore:
Timestamp:
Nov 29, 2016, 12:06:21 PM (3 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/constantq, feature/pitchshift, feature/pydocstrings, feature/timestretch, master, sampler, yinfft+
Children:
bb96d02
Parents:
c8e08c2
Message:

src/io/ioutils.h: add functions to check samplerate and channels, use in sink_*.c

Location:
src
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • src/aubio_priv.h

    rc8e08c2 rcf19b8a  
    197197#define AUBIO_SPRINTF                sprintf
    198198
     199#define AUBIO_MAX_SAMPLERATE (192000*8)
     200#define AUBIO_MAX_CHANNELS 1024
     201
    199202/* pi and 2*pi */
    200203#ifndef M_PI
  • src/io/sink_apple_audio.c

    rc8e08c2 rcf19b8a  
    2727#include "fmat.h"
    2828#include "io/sink_apple_audio.h"
     29#include "io/ioutils.h"
    2930
    3031// CFURLRef, CFURLCreateWithFileSystemPath, ...
     
    7475  s->channels = 0;
    7576
    76   // negative samplerate given, abort
    77   if ((sint_t)samplerate < 0) goto beach;
    7877  // zero samplerate given. do not open yet
    79   if ((sint_t)samplerate == 0) return s;
     78  if ((sint_t)samplerate == 0) {
     79    return s;
     80  }
     81  // invalid samplerate given, abort
     82  if (aubio_io_validate_samplerate("sink_apple_audio", s->path, samplerate)) {
     83    goto beach;
     84  }
    8085
    8186  s->samplerate = samplerate;
     
    95100uint_t aubio_sink_apple_audio_preset_samplerate(aubio_sink_apple_audio_t *s, uint_t samplerate)
    96101{
    97   if ((sint_t)(samplerate) <= 0) return AUBIO_FAIL;
     102  if (aubio_io_validate_samplerate("sink_apple_audio", s->path, samplerate)) {
     103    return AUBIO_FAIL;
     104  }
    98105  s->samplerate = samplerate;
    99106  // automatically open when both samplerate and channels have been set
     
    106113uint_t aubio_sink_apple_audio_preset_channels(aubio_sink_apple_audio_t *s, uint_t channels)
    107114{
    108   if ((sint_t)(channels) <= 0) return AUBIO_FAIL;
     115  if (aubio_io_validate_channels("sink_apple_audio", s->path, channels)) {
     116    return AUBIO_FAIL;
     117  }
    109118  s->channels = channels;
    110119  // automatically open when both samplerate and channels have been set
  • src/io/sink_sndfile.c

    rc8e08c2 rcf19b8a  
    3030#include "fmat.h"
    3131#include "io/sink_sndfile.h"
     32#include "io/ioutils.h"
    3233
    3334#define MAX_CHANNELS 6
     
    7071  s->channels = 0;
    7172
    72   // negative samplerate given, abort
    73   if ((sint_t)samplerate < 0) goto beach;
    7473  // zero samplerate given. do not open yet
    75   if ((sint_t)samplerate == 0) return s;
     74  if ((sint_t)samplerate == 0) {
     75    return s;
     76  }
     77  // invalid samplerate given, abort
     78  if (aubio_io_validate_samplerate("sink_sndfile", s->path, samplerate)) {
     79    goto beach;
     80  }
    7681
    7782  s->samplerate = samplerate;
     
    9095uint_t aubio_sink_sndfile_preset_samplerate(aubio_sink_sndfile_t *s, uint_t samplerate)
    9196{
    92   if ((sint_t)(samplerate) <= 0) return AUBIO_FAIL;
     97  if (aubio_io_validate_samplerate("sink_sndfile", s->path, samplerate)) {
     98    return AUBIO_FAIL;
     99  }
    93100  s->samplerate = samplerate;
    94101  // automatically open when both samplerate and channels have been set
     
    101108uint_t aubio_sink_sndfile_preset_channels(aubio_sink_sndfile_t *s, uint_t channels)
    102109{
    103   if ((sint_t)(channels) <= 0) return AUBIO_FAIL;
     110  if (aubio_io_validate_channels("sink_sndfile", s->path, channels)) {
     111    return AUBIO_FAIL;
     112  }
    104113  s->channels = channels;
    105114  // automatically open when both samplerate and channels have been set
  • src/io/sink_wavwrite.c

    rc8e08c2 rcf19b8a  
    2828#include "fmat.h"
    2929#include "io/sink_wavwrite.h"
     30#include "io/ioutils.h"
    3031
    3132#include <errno.h>
     
    105106  s->channels = 0;
    106107
    107   // negative samplerate given, abort
    108   if ((sint_t)samplerate < 0) goto beach;
    109108  // zero samplerate given. do not open yet
    110   if ((sint_t)samplerate == 0) return s;
    111   // samplerate way too large, fail
    112   if ((sint_t)samplerate > 192000 * 4) goto beach;
     109  if ((sint_t)samplerate == 0) {
     110    return s;
     111  }
     112  // invalid samplerate given, abort
     113  if (aubio_io_validate_samplerate("sink_wavwrite", s->path, samplerate)) {
     114    goto beach;
     115  }
    113116
    114117  s->samplerate = samplerate;
     
    130133uint_t aubio_sink_wavwrite_preset_samplerate(aubio_sink_wavwrite_t *s, uint_t samplerate)
    131134{
    132   if ((sint_t)(samplerate) <= 0) return AUBIO_FAIL;
     135  if (aubio_io_validate_samplerate("sink_wavwrite", s->path, samplerate)) {
     136    return AUBIO_FAIL;
     137  }
    133138  s->samplerate = samplerate;
    134139  // automatically open when both samplerate and channels have been set
     
    141146uint_t aubio_sink_wavwrite_preset_channels(aubio_sink_wavwrite_t *s, uint_t channels)
    142147{
    143   if ((sint_t)(channels) <= 0) return AUBIO_FAIL;
     148  if (aubio_io_validate_channels("sink_wavwrite", s->path, channels)) {
     149    return AUBIO_FAIL;
     150  }
    144151  s->channels = channels;
    145152  // automatically open when both samplerate and channels have been set
Note: See TracChangeset for help on using the changeset viewer.