magnetophon / DigiDrie

A monster monophonic synth, written in faust.
GNU Affero General Public License v3.0
21 stars 0 forks source link

Tempo Sync #4

Closed ryukau closed 4 years ago

ryukau commented 4 years ago

Continued from: https://github.com/ryukau/LV2Plugins/issues/29

I don't follow. I can not really read C++ code, sorry. Will DPF send tempo and position info to my faust code?

DPF can send tempo in BPM.

For position, it will be the frame count to the next beat (integer), or fraction of a beat (float). Frame count to the next bar is also possible to provide.

All these values will be updated for each DSP processing cycle.

magnetophon commented 4 years ago

That sounds great, looking forward to using it.

All these values will be updated for each DSP processing cycle.

Do you mean each sample, so iow audio rate, or each sample block, iow control rate, like the faders?

ryukau commented 4 years ago

Update will be done in control rate.

magnetophon commented 4 years ago

OK, thanks.

ryukau commented 4 years ago

Currently I'm using Faust's --one-sample option. So I could also provide a trigger signal which outputs 1 at the start of beat and/or bar, and outputs 0 otherwise.

When you defined h/vslider or other UI primitive to receive tempo sync information, please let me know the name of it.

magnetophon commented 4 years ago

What does --one-sample do? I don't understand the help text:

  -os         --one-sample                generate one sample computation.
ryukau commented 4 years ago

On plugin, DSP method is called for each time DAW sends empty buffer. It looks like below:

// float** means 2D array here. 1D for channels, and other 1D for frames.
void run(int bufferSize, float** input, float** output) {
  for (/* each frame */) {
    for (/* each channel */) { 
      // Do some DSP processing.
    }
  }
}

In real code, there's usually no for loop over the channel count. I put it to make it explicit.

Without --one-sample, Faust outputs C++ code that takes entire buffer and fills it, like the code above.

With --one-sample, Faust output C++ code that takes only 1 frame, and it looks like code below.

// Notice that argument is float*, not float**. So it's 1D array of channels.
void run(int bufferSize, float* input, float* output) {
  for (/* each channel */) { 
    // Do some DSP processing.
  }
}

I'm using --one-sample to supply accurate gate timing for MIDI note-on/off.