playWave method

  1. @override
SynthizerWave playWave({
  1. required WaveType waveType,
  2. required double frequency,
  3. int partials = 1,
  4. double gain = 0.7,
})
override

Play a wave.

Implementation

@override
SynthizerWave playWave({
  required final WaveType waveType,
  required final double frequency,
  final int partials = 1,
  final double gain = 0.7,
}) {
  if (partials < 1) {
    throw StateError('Synthizer does not like `partials` being less than 1.');
  }
  final FastSineBankGenerator generator;
  switch (waveType) {
    case WaveType.sine:
      generator = context.createSine(
        frequency,
        partials,
      );
      break;
    case WaveType.triangle:
      generator = context.createTriangle(
        frequency,
        partials,
      );
      break;
    case WaveType.square:
      generator = context.createSquare(
        frequency,
        partials,
      );
      break;
    case WaveType.saw:
      generator = context.createSaw(
        frequency,
        partials,
      );
      break;
  }
  generator.gain.value = gain;
  source.addGenerator(generator);
  return SynthizerWave(
    backend: backend,
    generator: generator,
  );
}