const sampleRateMultiplier = sampleRate / 1000;

const TimeDelayEffect = ({ input, output, mix, feedback, milliseconds }) => {
  const delay = useDelay();
  const timeSamples = useMonoSignal();
  for (let i = 0; i < milliseconds.length; i++) {
    timeSamples[i] = milliseconds[i] * (sampleRateMultiplier);
  }
  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: TimeDelayEffect,
  inputs: {
    input: stereo('In'),
    mix: numberSetting('Mix', { defaultValue: 0.3, min: 0, max: 1 }),
    feedback: numberSetting('Feedback', { defaultValue: 0.25, min: 0, max: 1 }),
    milliseconds: numberSetting('Milliseconds', { defaultValue: 150, min: 0, max: 5000 }),
  },
  outputs: {
    output: stereo('Out'),
  }
});
