Changeset 8aed26d


Ignore:
Timestamp:
Jul 15, 2012, 8:18:28 PM (8 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/constantq, feature/pitchshift, feature/pydocstrings, feature/timestretch, master, pitchshift, sampler, timestretch, yinfft+
Children:
42e6a5e
Parents:
11a1abe
Message:

src/io/sink*: read write size instead of returning it

Location:
src/io
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/io/sink.c

    r11a1abe r8aed26d  
    2323#include "fvec.h"
    2424#include "io/sink.h"
     25#ifdef __APPLE__
     26#include "io/sink_apple_audio.h"
     27#endif /* __APPLE__ */
     28#ifdef HAVE_SNDFILE
     29#include "io/sink_sndfile.h"
     30#endif
    2531
    2632struct _aubio_sink_t {
    27   uint_t hopsize;
    28   uint_t samplerate;
     33  void *sink;
    2934};
    3035
    31 aubio_sink_t * new_aubio_sink(char_t * uri, uint_t hop_size, uint_t samplerate) {
     36aubio_sink_t * new_aubio_sink(char_t * uri, uint_t samplerate) {
    3237  aubio_sink_t * s = AUBIO_NEW(aubio_sink_t);
    33   return s;
     38#ifdef __APPLE__
     39  s->sink = (void *)new_aubio_sink_apple_audio(uri, samplerate);
     40  if (s->sink) return s;
     41#else /* __APPLE__ */
     42#if HAVE_SNDFILE
     43  s->sink = (void *)new_aubio_sink_sndfile(uri, samplerate);
     44  if (s->sink) return s;
     45#endif /* HAVE_SNDFILE */
     46#endif /* __APPLE__ */
     47  if (s->sink == NULL) { AUBIO_FREE(s); return NULL; }
    3448}
    3549
    36 void aubio_sink_do(aubio_sink_t * s, fvec_t * write_data, uint_t * written) {
     50void aubio_sink_do(aubio_sink_t * s, fvec_t * write_data, uint_t write) {
    3751}
    3852
  • src/io/sink.h

    r11a1abe r8aed26d  
    3333
    3434typedef struct _aubio_sink_t aubio_sink_t;
    35 aubio_sink_t * new_aubio_sink(char_t * method, uint_t hop_size, uint_t samplerate);
    36 void aubio_sink_do(aubio_sink_t * s, fvec_t * write_data, uint_t * written);
     35aubio_sink_t * new_aubio_sink(char_t * method, uint_t samplerate);
     36void aubio_sink_do(aubio_sink_t * s, fvec_t * write_data, uint_t written);
    3737void del_aubio_sink(aubio_sink_t * s);
    3838
  • src/io/sink_sndfile.c

    r11a1abe r8aed26d  
    3434
    3535struct _aubio_sink_sndfile_t {
    36   uint_t hop_size;
    3736  uint_t samplerate;
    3837  uint_t channels;
     
    4342};
    4443
    45 aubio_sink_sndfile_t * new_aubio_sink_sndfile(char_t * path, uint_t samplerate, uint_t hop_size) {
     44aubio_sink_sndfile_t * new_aubio_sink_sndfile(char_t * path, uint_t samplerate) {
    4645  aubio_sink_sndfile_t * s = AUBIO_NEW(aubio_sink_sndfile_t);
    4746
     
    5150  }
    5251
    53   s->hop_size = hop_size;
    5452  s->samplerate = samplerate;
     53  s->max_size = MAX_SIZE;
    5554  s->channels = 1;
    5655  s->path = path;
     
    7271  }     
    7372
    74   s->scratch_size = s->hop_size*s->channels;
     73  s->scratch_size = s->max-size*s->channels;
    7574  /* allocate data for de/interleaving reallocated when needed. */
    7675  if (s->scratch_size >= MAX_SIZE * MAX_CHANNELS) {
    7776    AUBIO_ERR("%d x %d exceeds maximum aubio_sink_sndfile buffer size %d\n",
    78         s->hop_size, s->channels, MAX_CHANNELS * MAX_CHANNELS);
     77        s->max_size, s->channels, MAX_CHANNELS * MAX_CHANNELS);
    7978    return NULL;
    8079  }
     
    8483}
    8584
    86 void aubio_sink_sndfile_do(aubio_sink_sndfile_t *s, fvec_t * write, uint_t * written){
     85void aubio_sink_sndfile_do(aubio_sink_sndfile_t *s, fvec_t * write_data, uint_t write){
    8786  sf_count_t written_frames = 0;
    8887  int i, j,     channels = s->channels;
    89   int nsamples = channels*(*written);
     88  int nsamples = channels*write;
    9089  smpl_t *pwrite;
     90
     91  if (write > s->max_size) {
     92    write = s->max_size;
     93    AUBIO_WRN("trying to write %d frames, but only %d can be written at a time",
     94      write, s->max_frames);
     95  }
    9196
    9297  /* interleaving data  */
    9398  for ( i = 0; i < channels; i++) {
    94     pwrite = (smpl_t *)write->data;
    95     for (j=0; j < s->hop_size; j++) {
     99    pwrite = (smpl_t *)write_data->data;
     100    for (j=0; j < write; j++) {
    96101      s->scratch_data[channels*j+i] = pwrite[j];
    97102    }
    98103  }
    99   written_frames = sf_write_float (s->handle, s->scratch_data, nsamples);
    100   *written = written_frames/channels;
     104
     105  uint_t written = sf_write_float (s->handle, s->scratch_data, nsamples);
     106  if (written/channels != write) {
     107    AUBIO_WRN("trying to write %d frames to %s, but only %d could be written",
     108      write, s->path, written);
     109  }
    101110  return;
    102111}
  • src/io/sink_sndfile.h

    r11a1abe r8aed26d  
    3333
    3434typedef struct _aubio_sink_sndfile_t aubio_sink_sndfile_t;
    35 aubio_sink_sndfile_t * new_aubio_sink_sndfile(char_t * method, uint_t hop_size, uint_t samplerate);
    36 void aubio_sink_sndfile_do(aubio_sink_sndfile_t * s, fvec_t * write_data, uint_t * written);
     35aubio_sink_sndfile_t * new_aubio_sink_sndfile(char_t * method, uint_t samplerate);
     36void aubio_sink_sndfile_do(aubio_sink_sndfile_t * s, fvec_t * write_data, uint_t write);
    3737void del_aubio_sink_sndfile(aubio_sink_sndfile_t * s);
    3838
Note: See TracChangeset for help on using the changeset viewer.