Changeset 466dff3 for examples/jackio.c


Ignore:
Timestamp:
Dec 7, 2013, 4:09:00 AM (11 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:
3da8187
Parents:
44e94f3c
Message:

examples/: large refactoring, improve option management, remove old stuff, move blocking logic to jackio

File:
1 edited

Legend:

Unmodified
Added
Removed
  • examples/jackio.c

    r44e94f3c r466dff3  
    11/*
    2   Copyright (C) 2003-2009 Paul Brossier <piem@aubio.org>
     2  Copyright (C) 2003-2013 Paul Brossier <piem@aubio.org>
    33
    44  This file is part of aubio.
     
    3636
    3737/**
    38  * jack device structure 
     38 * jack device structure
    3939 */
    4040struct _aubio_jack_t
     
    7070  /** jack processing function */
    7171  aubio_process_func_t callback;
     72  /** internal fvec */
     73  fvec_t *ibuf;
     74  fvec_t *obuf;
     75  uint_t hop_size;
     76  int pos;
    7277};
    7378
     
    7580static aubio_jack_t *aubio_jack_alloc (uint_t ichan, uint_t ochan,
    7681    uint_t imidichan, uint_t omidichan);
    77 static uint_t aubio_jack_free (aubio_jack_t * jack_setup);
    7882/* jack callback functions */
    7983static int aubio_jack_process (jack_nframes_t nframes, void *arg);
     
    8185
    8286aubio_jack_t *
    83 new_aubio_jack (uint_t ichan, uint_t ochan,
    84     uint_t imidichan, uint_t omidichan, aubio_process_func_t callback)
     87new_aubio_jack (uint_t hop_size, uint_t ichan, uint_t ochan,
     88    uint_t imidichan, uint_t omidichan)
    8589{
    8690  aubio_jack_t *jack_setup = aubio_jack_alloc (ichan, ochan,
     
    149153  }
    150154
    151   /* set processing callback */
    152   jack_setup->callback = callback;
     155  /* get sample rate */
     156  jack_setup->samplerate = jack_get_sample_rate (jack_setup->client);
     157
     158  jack_setup->hop_size = hop_size;
     159  jack_setup->ibuf = new_fvec(hop_size);
     160  jack_setup->obuf = new_fvec(hop_size);
     161  jack_setup->pos = 0;
    153162  return jack_setup;
    154163
     
    160169
    161170uint_t
    162 aubio_jack_activate (aubio_jack_t * jack_setup)
    163 {
    164   /* get sample rate */
    165   jack_setup->samplerate = jack_get_sample_rate (jack_setup->client);
     171aubio_jack_get_samplerate (aubio_jack_t * jack_setup) {
     172  return jack_setup->samplerate;
     173}
     174
     175uint_t
     176aubio_jack_activate (aubio_jack_t * jack_setup, aubio_process_func_t callback)
     177{
     178  /* set processing callback */
     179  jack_setup->callback = callback;
    166180  /* actual jack process activation */
    167181  if (jack_activate (jack_setup->client)) {
     
    177191  /* bug : should disconnect all ports first */
    178192  jack_client_close (jack_setup->client);
    179   aubio_jack_free (jack_setup);
    180193}
    181194
     
    209222}
    210223
    211 static uint_t
    212 aubio_jack_free (aubio_jack_t * jack_setup)
     224void
     225del_aubio_jack (aubio_jack_t * jack_setup)
    213226{
    214227  if (jack_setup->omidichan && jack_setup->midi_out_ring) {
    215228    jack_ringbuffer_free (jack_setup->midi_out_ring);
    216229  }
     230  del_fvec (jack_setup->ibuf);
     231  del_fvec (jack_setup->obuf);
    217232  AUBIO_FREE (jack_setup->oports);
    218233  AUBIO_FREE (jack_setup->iports);
     
    220235  AUBIO_FREE (jack_setup->obufs);
    221236  AUBIO_FREE (jack_setup);
    222   return AUBIO_OK;
    223237}
    224238
     
    232246
    233247static void process_midi_output (aubio_jack_t * dev, jack_nframes_t nframes);
     248
     249static int block_process(aubio_jack_t *dev,
     250    smpl_t **input, smpl_t **output, int nframes) {
     251  unsigned int j;       /*frames*/
     252  for (j=0;j<(unsigned)nframes;j++) {
     253    /* put synthnew in output */
     254    output[0][j] = fvec_read_sample(dev->obuf, dev->pos);
     255    /* write input to datanew */
     256    fvec_write_sample(dev->ibuf, input[0][j], dev->pos);
     257    /*time for fft*/
     258    if (dev->pos == (int)(dev->hop_size) - 1) {
     259      /* block loop */
     260      dev->callback(dev->ibuf, dev->obuf);
     261      /* end of block loop */
     262      dev->pos = -1; /* so it will be zero next j loop */
     263    }
     264    dev->pos++;
     265  }
     266  return 1;
     267}
    234268
    235269static int
     
    249283  }
    250284#ifndef AUBIO_JACK_NEEDS_CONVERSION
    251   dev->callback (dev->ibufs, dev->obufs, nframes);
     285  block_process(dev, dev->ibufs, dev->obufs, nframes);
    252286#else
    253287  uint_t j;
     
    257291    }
    258292  }
    259   dev->callback (dev->sibufs, dev->sobufs, nframes);
     293  block_process(dev, dev->sibufs, dev->sobufs, nframes);
    260294  for (j = 0; j < MIN (nframes, AUBIO_JACK_MAX_FRAMES); j++) {
    261295    for (i = 0; i < dev->ochan; i++) {
Note: See TracChangeset for help on using the changeset viewer.