public byte[] ToMIDI() { RIFF riff = new RIFF("MIDI"); byte[] mthd = new byte [6]; BEBitConv.ToInt16(mthd, 0, 0); BEBitConv.ToInt16(mthd, 2, 1); BEBitConv.ToInt16(mthd, 4, resolution); riff.Items.Add(new RIFFData("MThd", mthd)); byte[] mtrk = new byte [15 + data.Length]; mtrk[0] = 0; mtrk[1] = 0xFF; mtrk[2] = 0x51; mtrk[3] = 0x03; MIDIConv.To3BE(mtrk, 4, tempo); mtrk[7] = 0; mtrk[8] = 0xFF; mtrk[9] = 0x58; mtrk[10] = 0x04; BEBitConv.ToInt16(mtrk, 11, rhythm); mtrk[13] = 0x18; mtrk[14] = 0x08; data.CopyTo(mtrk, 15); riff.Items.Add(new RIFFData("MTrk", mtrk)); return(riff.SaveBody(Endianness.BigEndian)); }
public byte[] Save() { int length = 6; foreach (SEQ seq in seqs) { length += 13; length += seq.Data.Length; } byte[] data = new byte [length]; BEBitConv.ToInt32(data, 0, Magic); BEBitConv.ToInt16(data, 4, Version); int offset = 6; for (int i = 0; i < seqs.Count; i++) { SEQ seq = seqs[i]; BEBitConv.ToInt16(data, offset, (short)i); BEBitConv.ToInt16(data, offset + 2, seq.Resolution); MIDIConv.To3BE(data, offset + 4, seq.Tempo); BEBitConv.ToInt16(data, offset + 7, seq.Rhythm); BEBitConv.ToInt32(data, offset + 9, seq.Data.Length); offset += 13; seq.Data.CopyTo(data, offset); offset += seq.Data.Length; } return(data); }
public byte[] Save() { byte[] result = new byte [15 + data.Length]; BEBitConv.ToInt32(result, 0, Magic); BEBitConv.ToInt32(result, 4, Version); BEBitConv.ToInt16(result, 8, resolution); MIDIConv.To3BE(result, 10, tempo); BEBitConv.ToInt16(result, 13, rhythm); data.CopyTo(result, 15); return(result); }