Ignore:
Timestamp:
Feb 23, 2014, 5:00:26 PM (10 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/pydocstrings, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch, yinfft+
Children:
f3bb92c
Parents:
870ad70
Message:

src/io/sink_sndfile.h: add do_multi, preset_samplerate, preset_channels, get_samplerate, and get_channels

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/io/sink_sndfile.c

    r870ad70 r14ac1db  
    11/*
    2   Copyright (C) 2012 Paul Brossier <piem@aubio.org>
     2  Copyright (C) 2012-2014 Paul Brossier <piem@aubio.org>
    33
    44  This file is part of aubio.
     
    4545};
    4646
     47uint_t aubio_sink_sndfile_open(aubio_sink_sndfile_t *s);
     48
    4749aubio_sink_sndfile_t * new_aubio_sink_sndfile(char_t * path, uint_t samplerate) {
    4850  aubio_sink_sndfile_t * s = AUBIO_NEW(aubio_sink_sndfile_t);
    49   SF_INFO sfinfo;
     51  s->max_size = MAX_SIZE;
     52  s->path = path;
    5053
    5154  if (path == NULL) {
     
    5457  }
    5558
     59  s->samplerate = 0;
     60  s->channels = 0;
     61
     62  // negative samplerate given, abort
     63  if ((sint_t)samplerate < 0) goto beach;
     64  // zero samplerate given. do not open yet
     65  if ((sint_t)samplerate == 0) return s;
     66
    5667  s->samplerate = samplerate;
    57   s->max_size = MAX_SIZE;
    5868  s->channels = 1;
    59   s->path = path;
    6069
     70  if (aubio_sink_sndfile_open(s) != AUBIO_OK) {;
     71    goto beach;
     72  }
     73  return s;
     74
     75beach:
     76  del_aubio_sink_sndfile(s);
     77  return NULL;
     78}
     79
     80uint_t aubio_sink_sndfile_preset_samplerate(aubio_sink_sndfile_t *s, uint_t samplerate)
     81{
     82  if ((sint_t)(samplerate) <= 0) return AUBIO_FAIL;
     83  s->samplerate = samplerate;
     84  // automatically open when both samplerate and channels have been set
     85  if (s->samplerate != 0 && s->channels != 0) {
     86    return aubio_sink_sndfile_open(s);
     87  }
     88  return AUBIO_OK;
     89}
     90
     91uint_t aubio_sink_sndfile_preset_channels(aubio_sink_sndfile_t *s, uint_t channels)
     92{
     93  if ((sint_t)(channels) <= 0) return AUBIO_FAIL;
     94  s->channels = channels;
     95  // automatically open when both samplerate and channels have been set
     96  if (s->samplerate != 0 && s->channels != 0) {
     97    return aubio_sink_sndfile_open(s);
     98  }
     99  return AUBIO_OK;
     100}
     101
     102uint_t aubio_sink_sndfile_get_samplerate(aubio_sink_sndfile_t *s)
     103{
     104  return s->samplerate;
     105}
     106
     107uint_t aubio_sink_sndfile_get_channels(aubio_sink_sndfile_t *s)
     108{
     109  return s->channels;
     110}
     111
     112uint_t aubio_sink_sndfile_open(aubio_sink_sndfile_t *s) {
    61113  /* set output format */
     114  SF_INFO sfinfo;
    62115  AUBIO_MEMSET(&sfinfo, 0, sizeof (sfinfo));
    63116  sfinfo.samplerate = s->samplerate;
     
    71124    /* show libsndfile err msg */
    72125    AUBIO_ERR("sink_sndfile: Failed opening %s. %s\n", s->path, sf_strerror (NULL));
    73     AUBIO_FREE(s);
    74     return NULL;
     126    return AUBIO_FAIL;
    75127  }     
    76128
     
    80132    AUBIO_ERR("sink_sndfile: %d x %d exceeds maximum aubio_sink_sndfile buffer size %d\n",
    81133        s->max_size, s->channels, MAX_CHANNELS * MAX_CHANNELS);
    82     AUBIO_FREE(s);
    83     return NULL;
     134    return AUBIO_FAIL;
    84135  }
    85136  s->scratch_data = AUBIO_ARRAY(float,s->scratch_size);
    86137
    87   return s;
     138  return AUBIO_OK;
    88139}
    89140
Note: See TracChangeset for help on using the changeset viewer.