Ignore:
Timestamp:
Dec 4, 2009, 1:46:40 AM (14 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:
aea235c
Parents:
c17a0ee
Message:

examples: switch to mono

File:
1 edited

Legend:

Unmodified
Added
Removed
  • examples/sndfileio.c

    rc17a0ee r4621cd6  
    9696        aubio_sndfile_t * f = AUBIO_NEW(aubio_sndfile_t);
    9797        f->samplerate    = fmodel->samplerate;
    98         f->channels      = fmodel->channels;
     98        f->channels      = 1; //fmodel->channels;
    9999        f->format        = fmodel->format;
    100100        aubio_sndfile_open_wo(f, outputname);
     
    125125/* read frames from file in data
    126126 *  return the number of frames actually read */
    127 int aubio_sndfile_read(aubio_sndfile_t * f, int frames, fvec_t * read) {
     127int aubio_sndfile_read(aubio_sndfile_t * f, int frames, fvec_t ** read) {
    128128        sf_count_t read_frames;
    129129        int i,j, channels = f->channels;
     
    150150        /* de-interleaving data  */
    151151        for (i=0; i<channels; i++) {
    152                 pread = (smpl_t *)fvec_get_channel(read,i);
     152                pread = (smpl_t *)fvec_get_data(read[i]);
    153153                for (j=0; j<aread; j++) {
    154154                        pread[j] = (smpl_t)f->tmpdata[channels*j+i];
     
    158158}
    159159
     160int
     161aubio_sndfile_read_mono (aubio_sndfile_t * f, int frames, fvec_t * read)
     162{
     163  sf_count_t read_frames;
     164  int i, j, channels = f->channels;
     165  int nsamples = frames * channels;
     166  int aread;
     167  smpl_t *pread;
     168
     169  /* allocate data for de/interleaving reallocated when needed. */
     170  if (nsamples >= f->size) {
     171    AUBIO_ERR ("Maximum aubio_sndfile_read buffer size exceeded.");
     172    return -1;
     173    /*
     174    AUBIO_FREE(f->tmpdata);
     175    f->tmpdata = AUBIO_ARRAY(float,nsamples);
     176    */
     177  }
     178  //f->size = nsamples;
     179
     180  /* do actual reading */
     181  read_frames = sf_read_float (f->handle, f->tmpdata, nsamples);
     182
     183  aread = (int) FLOOR (read_frames / (float) channels);
     184
     185  /* de-interleaving data  */
     186  pread = (smpl_t *) fvec_get_data (read);
     187  for (i = 0; i < channels; i++) {
     188    for (j = 0; j < aread; j++) {
     189      pread[j] += (smpl_t) f->tmpdata[channels * j + i];
     190    }
     191  }
     192  for (j = 0; j < aread; j++) {
     193    pread[j] /= (smpl_t)channels;
     194  }
     195
     196  return aread;
     197}
     198
    160199/* write 'frames' samples to file from data
    161200 *   return the number of frames actually written
    162201 */
    163 int aubio_sndfile_write(aubio_sndfile_t * f, int frames, fvec_t * write) {
     202int aubio_sndfile_write(aubio_sndfile_t * f, int frames, fvec_t ** write) {
    164203        sf_count_t written_frames = 0;
    165204        int i, j,       channels = f->channels;
     
    180219        /* interleaving data  */
    181220        for (i=0; i<channels; i++) {
    182                 pwrite = (smpl_t *)fvec_get_channel(write,i);
     221                pwrite = (smpl_t *)fvec_get_data(write[i]);
    183222                for (j=0; j<frames; j++) {
    184223                        f->tmpdata[channels*j+i] = (float)pwrite[j];
Note: See TracChangeset for help on using the changeset viewer.