const TempoDelayEffect = ({ input, output, mix, feedback, beats }, { bpm }) => {
  const delay = useDelay();
  const timeSamples = useMonoSignal();
  for (let i = 0; i < beats.length; i++) {
    timeSamples[i] = beats[i] * (60 / bpm[i]) * sampleRate;
  }
  const delayed = delay(input, timeSamples, feedback);
  for (let i = 0; i < input.length; i ++) {
    output[i] = ((1 - mix[i]) * input[i]) + (mix[i] * delayed[i]);
  }
};

this.constructDevice = () => constructPerChannelDevice({
  implementation: TempoDelayEffect,
  inputs: {
    input: stereo('In'),
    mix: numberSetting('Mix', { defaultValue: 0.3, min: 0, max: 1 }),
    feedback: numberSetting('Feedback', { defaultValue: 0.25, min: 0, max: 1 }),
    beats: numberSetting('Beats', { defaultValue: 0.75, min: 0, max: 4 }),
  },
  outputs: {
    output: stereo('Out'),
  }
});
