public IEnumerable <ISampleProvider> CreateArpeggioSamples(IEnumerable <int> chordKeyNumbers, int length, double speed) { if (!chordKeyNumbers.Any()) { return(null); } List <ISampleProvider> arpeggioInputs = new List <ISampleProvider>(); for (int i = 0; i <= length; i++) { foreach (var num in chordKeyNumbers) { var squareWave = new SignalGenerator() { Gain = 0.12, Frequency = MusicalMathHelper.CalculateFrequency(num, 4), Type = SignalGeneratorType.Square }; var trimmed = new OffsetSampleProvider(squareWave); var trimmedWithTimeSpan = trimmed.Take(TimeSpan.FromSeconds(speed)); arpeggioInputs.Add(trimmedWithTimeSpan); } } return(arpeggioInputs); }
public void PlayKey(int keyNumber) { var squareWave = new SignalGenerator() { Gain = 0.12, Frequency = MusicalMathHelper.CalculateFrequency(keyNumber, 4), Type = SignalGeneratorType.Square }; var trimmed = new OffsetSampleProvider(squareWave); var trimmedWithTimeSpan = trimmed.Take(TimeSpan.FromSeconds(0.4)); WaveformPlayer.Instance.PlayWaveform(trimmedWithTimeSpan); }