public static byte[] CreateTone(MusicNote note, TimeSpan duration, PCMModifiers mods) { mods.Init(); using (MemoryStream stream = new MemoryStream()) { BinaryWriter writer = new BinaryWriter(stream); WriteNote(writer, new MidiNote() { Note = note, Duration = duration, }, mods); return(stream.ToArray()); } }
public static byte[] ConvertMidi(Sequence sequence, PCMModifiers mods) { mods.Init(); var notes = GetNotes(sequence); int length = (int)Math.Round(notes.LastOrDefault().End.TotalSeconds *mods.SampleRate); byte[] data = new byte[length]; using (MemoryStream stream = new MemoryStream(data)) { BinaryWriter writer = new BinaryWriter(stream); foreach (MidiNote note in notes) { WriteNote(writer, note, mods); } return(stream.ToArray()); } }