Chorus.create constructor

Chorus.create({
  1. required int sampleRate,
  2. required double delay,
  3. required double depth,
  4. required double frequency,
})

Implementation

factory Chorus.create({required int sampleRate,
                       required double delay,
                       required double depth,
                       required double frequency})
{
  List<double> delayTable = List<double>.filled((sampleRate / frequency).round(), 0);

  for (var t = 0; t < delayTable.length; t++)
  {
      var phase = 2 * pi * t / delayTable.length;
      delayTable[t] = sampleRate * (delay + depth * sin(phase));
  }

  int sampleCount = ((sampleRate * (delay + depth)) + 2).toInt();

  return Chorus(
    bufferL: List<double>.filled(sampleCount, 0),
    bufferR: List<double>.filled(sampleCount, 0),
    delayTable: delayTable,
    bufferIndexL: 0,
    bufferIndexR: 0,
    delayTableIndexL: 0,
    delayTableIndexR: delayTable.length ~/ 4);
}