Exemplo n.º 1
0
Arquivo: lv2.c Projeto: aelse/setBfree
static uint32_t synthSound (B3S *instance, uint32_t written, uint32_t nframes, float **out) {
  B3S* b3s = (B3S*)instance;

  while (written < nframes) {
    int nremain = nframes - written;

    if (b3s->boffset >= BUFFER_SIZE_SAMPLES)  {
      b3s->boffset = 0;
      oscGenerateFragment (instance->inst->synth, b3s->bufA, BUFFER_SIZE_SAMPLES);
      preamp (instance->inst->preamp, b3s->bufA, b3s->bufB, BUFFER_SIZE_SAMPLES);
      reverb (instance->inst->reverb, b3s->bufB, b3s->bufC, BUFFER_SIZE_SAMPLES);
#ifdef WITH_SIGNATURE
      scramble (b3s, b3s->bufC, BUFFER_SIZE_SAMPLES);
#endif
      whirlProc3(instance->inst->whirl, b3s->bufC, b3s->bufL[0], b3s->bufL[1], b3s->bufD[0], b3s->bufD[1], BUFFER_SIZE_SAMPLES);

    }

    int nread = MIN(nremain, (BUFFER_SIZE_SAMPLES - b3s->boffset));

    memcpy(&out[0][written], &b3s->bufL[0][b3s->boffset], nread*sizeof(float));
    memcpy(&out[1][written], &b3s->bufL[1][b3s->boffset], nread*sizeof(float));

    written+=nread;
    b3s->boffset+=nread;
  }
  return written;
}
Exemplo n.º 2
0
int jack_audio_callback (jack_nframes_t nframes, void *arg) {
  jack_default_audio_sample_t **out = j_output_bufferptrs;
  int i;

  void *jack_midi_buf = NULL;
  int midi_events = 0;
  jack_nframes_t midi_tme_proc = 0;

  if (!synth_ready) {
    for (i=0;i<AUDIO_CHANNELS;i++) {
      out[i] = (jack_default_audio_sample_t*) jack_port_get_buffer (j_output_port[i], nframes);
      memset(out[i], 0, nframes*sizeof(jack_default_audio_sample_t));
    }
    return (0);
  }

  if (use_jack_midi) {
    jack_midi_buf = jack_port_get_buffer(jack_midi_port, nframes);
    midi_events = jack_midi_get_event_count(jack_midi_buf);
  }

  for (i=0;i<AUDIO_CHANNELS;i++) {
    out[i] = (jack_default_audio_sample_t*) jack_port_get_buffer (j_output_port[i], nframes);
  }

  static int boffset = BUFFER_SIZE_SAMPLES;

  jack_nframes_t written = 0;

  while (written < nframes) {
    int nremain = nframes - written;

    if (boffset >= BUFFER_SIZE_SAMPLES)  {
      if (use_jack_midi) {
	for (i=0; i<midi_events; i++) {
	  jack_midi_event_t ev;
	  jack_midi_event_get(&ev, jack_midi_buf, i);
	  if (ev.time >= written && ev.time < (written + BUFFER_SIZE_SAMPLES))
	    parse_raw_midi_data(arg, ev.buffer, ev.size);
	}
	midi_tme_proc = written + BUFFER_SIZE_SAMPLES;
      }
      boffset = 0;
      oscGenerateFragment (inst.synth, bufA, BUFFER_SIZE_SAMPLES);
      preamp (inst.preamp, bufA, bufB, BUFFER_SIZE_SAMPLES);
      reverb (inst.reverb, bufB, bufC, BUFFER_SIZE_SAMPLES);

#ifdef HAVE_ZITACONVOLVE
      whirlProc2(inst.whirl,
	  bufC,
	  NULL, NULL,
	  bufH[0], bufH[1],
	  bufD[0], bufD[1],
	  BUFFER_SIZE_SAMPLES);

      const float *horn[2] = { bufH[0], bufH[1] };
      const float *drum[2] = { bufD[0], bufD[1] };
      float *out[2] = { bufJ[0], bufJ[1] };

      convolve(horn, out, 2, BUFFER_SIZE_SAMPLES);
      mixdown(out, drum, AUDIO_CHANNELS, BUFFER_SIZE_SAMPLES);
#else
      whirlProc(inst.whirl, bufC, bufJ[0], bufJ[1], BUFFER_SIZE_SAMPLES);
#endif
    }

    int nread = MIN(nremain, (BUFFER_SIZE_SAMPLES - boffset));

    for (i=0;i< AUDIO_CHANNELS; i++) {
      memcpy(&out[i][written], &bufJ[i][boffset], nread*sizeof(float));
    }
    written+=nread;
    boffset+=nread;
  }

  if (use_jack_midi) {
    /* process remaining MIDI events
     * IF nframes < BUFFER_SIZE_SAMPLES OR nframes != N * BUFFER_SIZE_SAMPLES
     */
    for (i=0; i<midi_events; i++) {
      jack_midi_event_t ev;
      jack_midi_event_get(&ev, jack_midi_buf, i);
      if (ev.time >= midi_tme_proc)
	parse_raw_midi_data(arg, ev.buffer, ev.size);
    }
  }

  return(0);
}