public void PlaySound(PianoKey key) { if (soundDict.TryGetValue(key, out CachedSound sound)) { AddMixerInput(new CachedSoundSampleProvider(sound)); } }
public PianoPlayer(int sampleRate = 44100, int channelCount = 2) { foreach (string filename in System.IO.Directory.EnumerateFiles("..\\..\\..\\..\\samples")) { //var components = filename var nameComponents = System.IO.Path.GetFileName(filename).Split('.'); if ((!filename.Contains("-old")) && nameComponents[1] == "pp") { var noteInfo = nameComponents[2]; var key = PianoKey.Parse(noteInfo); if (key != null) { key = new PianoKey(key.Octave + 1, key.Note); var ar = new CachedSound(filename); soundDict.Add(key, ar); } } } Console.WriteLine("Loaded sounds."); outputDevice = new DirectSoundOut(60); mixer = new MixingSampleProvider(WaveFormat.CreateIeeeFloatWaveFormat(sampleRate, channelCount)); mixer.ReadFully = true; outputDevice.Init(mixer); outputDevice.Play(); }
public PianoKeyPressEvent(PianoKey Key, bool Pressed) { this.Key = Key; this.Pressed = Pressed; }