public byte[] Save(int program) { byte[] data = new byte [32]; data[0] = priority; data[1] = mode; data[2] = volume; data[3] = panning; data[4] = centernote; data[5] = pitchshift; data[6] = minimumnote; data[7] = maximumnote; data[8] = vibratowidth; data[9] = vibratotime; data[10] = portamentowidth; data[11] = portamentotime; data[12] = pitchbendminimum; data[13] = pitchbendmaximum; data[14] = 0xB1; data[15] = 0xB2; BitConv.ToInt16(data, 16, adsr1); BitConv.ToInt16(data, 18, adsr2); BitConv.ToInt16(data, 20, (short)program); BitConv.ToInt16(data, 22, wave); BitConv.ToInt16(data, 24, 0xC0); BitConv.ToInt16(data, 26, 0xC1); BitConv.ToInt16(data, 28, 0xC2); BitConv.ToInt16(data, 30, 0xC3); return(data); }
public RIFF ToDLSRegion() { RIFF rgn = new RIFF("rgn "); byte[] rgnh = new byte [12]; BitConv.ToInt16(rgnh, 0, minimumnote); BitConv.ToInt16(rgnh, 2, maximumnote); BitConv.ToInt16(rgnh, 4, 0); BitConv.ToInt16(rgnh, 6, 127); BitConv.ToInt16(rgnh, 8, 0); BitConv.ToInt16(rgnh, 10, 0); rgn.Items.Add(new RIFFData("rgnh", rgnh)); byte[] wsmp = new byte [20 /* 36 */]; BitConv.ToInt32(wsmp, 0, 20); BitConv.ToInt16(wsmp, 4, centernote); BitConv.ToInt16(wsmp, 6, pitchshift); BitConv.ToInt32(wsmp, 8, volume - 64 << 16); BitConv.ToInt32(wsmp, 12, 0); BitConv.ToInt32(wsmp, 16, 0 /* 1 */); /*BitConv.ToInt32(wsmp,20,16); * BitConv.ToInt32(wsmp,24,0); * BitConv.ToInt32(wsmp,28,LOOPSTART); * BitConv.ToInt32(wsmp,28,LOOPLENGTH);*/ rgn.Items.Add(new RIFFData("wsmp", wsmp)); byte[] wlnk = new byte [12]; BitConv.ToInt16(wlnk, 0, 0); BitConv.ToInt16(wlnk, 2, 0); BitConv.ToInt32(wlnk, 4, 3); // ??? BitConv.ToInt32(wlnk, 8, wave - 1); rgn.Items.Add(new RIFFData("wlnk", wlnk)); return(rgn); }
public override UnprocessedChunk Unprocess(int chunkid) { byte[] data = new byte [Length]; BitConv.ToInt16(data, 0, Magic); BitConv.ToInt16(data, 2, Type); BitConv.ToInt32(data, 4, chunkid); BitConv.ToInt32(data, 8, entries.Count); // Checksum is here, but calculated later int offset = 20 + entries.Count * 4; for (int i = 0; i < entries.Count; i++) { UnprocessedEntry entry = entries[i].Unprocess(); byte[] entrydata = entry.Save(); offset += entry.HeaderLength; Aligner.Align(ref offset, Alignment); offset -= entry.HeaderLength; if (offset + entrydata.Length > Length) { throw new PackingException(); } BitConv.ToInt32(data, 16 + i * 4, offset); entrydata.CopyTo(data, offset); offset += entrydata.Length; } BitConv.ToInt32(data, 16 + entries.Count * 4, offset); int checksum = CalculateChecksum(data); BitConv.ToInt32(data, 12, checksum); return(new UnprocessedChunk(data)); }
public byte[] SaveZ() { byte[] data = new byte [2]; int zdata = (z << 4) | unknownz; BitConv.ToInt16(data, 0, (short)zdata); return(data); }
public byte[] SaveB() { byte[] data = new byte [2]; int value = (vertexc << 4) | unknown2; BitConv.ToInt16(data, 0, (short)value); return(data); }
public byte[] Save() { byte[] data = new byte [2592 + 32 * 16 * programs.Count]; BitConv.ToInt32(data, 0, Magic); BitConv.ToInt32(data, 4, isoldversion ? OldVersion : Version); BitConv.ToInt32(data, 8, 0); BitConv.ToInt32(data, 12, data.Length + vbsize * 16); BitConv.ToInt16(data, 16, -0x1112); int tonecount = 0; foreach (VHProgram program in programs.Values) { tonecount += program.Tones.Count; } BitConv.ToInt16(data, 18, (short)programs.Count); BitConv.ToInt16(data, 20, (short)tonecount); BitConv.ToInt16(data, 22, (short)waves.Count); data[24] = volume; data[25] = panning; data[26] = attribute1; data[27] = attribute2; BitConv.ToInt32(data, 28, -1); for (int i = 0; i < 128; i++) { if (programs.ContainsKey(i)) { programs[i].Save().CopyTo(data, 32 + 16 * i); } else { new VHProgram(isoldversion).Save().CopyTo(data, 32 + 16 * i); } } int ii = 0; foreach (KeyValuePair <int, VHProgram> kvp in programs) { VHProgram program = kvp.Value; for (int j = 0; j < 16; j++) { if (j < program.Tones.Count) { program.Tones[j].Save(kvp.Key).CopyTo(data, 2080 + 32 * 16 * ii + 32 * j); } else { new VHTone(isoldversion).Save(kvp.Key).CopyTo(data, 2080 + 32 * 16 * ii + 32 * j); } } ii++; } for (int i = 0; i < waves.Count; i++) { BitConv.ToInt16(data, 2080 + 32 * 16 * programs.Count + 2 + i * 2, (short)(waves[i] * 2)); } return(data); }
public byte[] Save() { byte[] data = new byte [8]; BitConv.ToInt16(data, 0, vertexa); BitConv.ToInt16(data, 2, vertexb); BitConv.ToInt16(data, 4, vertexc); BitConv.ToInt16(data, 6, unknown); return(data); }
public byte[] SaveXY() { byte[] data = new byte [4]; int xdata = (x << 4) | unknownx; int ydata = (y << 4) | unknowny; BitConv.ToInt16(data, 0, (short)xdata); BitConv.ToInt16(data, 2, (short)ydata); return(data); }
public byte[] Save() { byte[] data = new byte [16]; data[0] = (byte)tones.Count; data[1] = volume; data[2] = priority; data[3] = mode; data[4] = panning; data[5] = isoldversion ? (byte)0x00 : (byte)0xFF; BitConv.ToInt16(data, 6, attribute); BitConv.ToInt32(data, 8, -1); BitConv.ToInt32(data, 12, -1); return(data); }
public byte[] Save() { byte[] data = new byte [4 + values.Count * 2]; if (values.Count > short.MaxValue) { throw new Exception(); } BitConv.ToInt16(data, 0, (short)values.Count); BitConv.ToInt16(data, 2, unknown1); for (int i = 0; i < values.Count; i++) { BitConv.ToInt16(data, 4 + i * 2, values[i]); } return(data); }
public static void ToInt16(Endianness endianness, byte[] str, int offset, short value) { switch (endianness) { case Endianness.LittleEndian: BitConv.ToInt16(str, offset, value); break; case Endianness.BigEndian: BEBitConv.ToInt16(str, offset, value); break; default: throw new ArgumentException("Endianness is invalid."); } }
// Based on code by bITmASTER and nextvolume // http://psxsdk.googlecode.com/svn-history/r13/trunk/tools/vag2wav.c public byte[] ToPCM(ref double s0, ref double s1) { byte[] result = new byte [28 * 2]; int factor = info & 0xF; int predict = (info >> 4) & 0xF; for (int i = 0; i < 14; i++) { int adl = data[i] & 0xF; int adh = (data[i] & 0xF0) >> 4; short l = ADPCMConv.FromADPCM(adl, factor, predict, ref s0, ref s1); short h = ADPCMConv.FromADPCM(adh, factor, predict, ref s0, ref s1); BitConv.ToInt16(result, i * 4 + 0, l); BitConv.ToInt16(result, i * 4 + 2, h); } return(result); }
public static RIFF ToWave(byte[] data, int samplerate) { if (data == null) { throw new ArgumentNullException("data"); } byte[] format = new byte [16]; BitConv.ToInt16(format, 0, 1); BitConv.ToInt16(format, 2, 1); BitConv.ToInt32(format, 4, samplerate); BitConv.ToInt32(format, 8, samplerate * 2); BitConv.ToInt16(format, 12, 2); BitConv.ToInt16(format, 14, 16); RIFF wave = new RIFF("WAVE"); wave.Items.Add(new RIFFData("fmt ", format)); wave.Items.Add(new RIFFData("data", data)); return(wave); }
public byte[] Save() { SortedDictionary <short, EntityProperty> properties = new SortedDictionary <short, EntityProperty>(extraproperties); foreach (KeyValuePair <short, FieldInfo> pair in propertyfields) { short id = pair.Key; FieldInfo field = pair.Value; EntityProperty property = EntityProperty.LoadFromField(field.GetValue(this)); if (property != null) { properties.Add(id, property); } } byte[] header = new byte [16 + 8 * properties.Count]; List <byte> result = new List <byte>(); int i = 0; int offset = header.Length - 12; foreach (KeyValuePair <short, EntityProperty> pair in properties) { EntityProperty property = pair.Value; BitConv.ToInt16(header, 16 + 8 * i + 0, pair.Key); unchecked { BitConv.ToInt16(header, 16 + 8 * i + 2, (short)offset); } header[16 + 8 * i + 4] = (byte)(property.Type | ((i == properties.Count - 1) ? 128 : 0) | (property.IsSparse ? 64 : 0) | (property.HasMetaValues ? 32 : 0)); header[16 + 8 * i + 5] = property.ElementSize; BitConv.ToInt16(header, 16 + 8 * i + 6, property.Unknown); byte[] propertydata = property.Save(); i++; offset += propertydata.Length; result.AddRange(propertydata); } BitConv.ToInt32(header, 0, offset + 12); BitConv.ToInt32(header, 4, 0); BitConv.ToInt32(header, 8, 0); BitConv.ToInt32(header, 12, properties.Count); result.InsertRange(0, header); return(result.ToArray()); }
public byte[] Save() { int zlow = (z >> 3) & 0xFF; int zmid = (z >> 11) & 0x3; int zhigh = (z >> 13) & 0x7; byte[] data = new byte [8]; data[0] = red; data[1] = green; data[2] = blue; data[3] = (byte)zlow; BitConv.ToInt16(data, 4, x); data[4] |= (byte)(zmid << 1); BitConv.ToInt16(data, 6, y); data[6] |= (byte)(zhigh); if (lightingflag) { data[4] |= 1; } return(data); }
public byte[] Save() { byte[] data = new byte [56 + vertices.Count * 6 + 2]; BitConv.ToInt32(data, 0, vertices.Count); BitConv.ToInt32(data, 4, modeleid); BitConv.ToInt32(data, 8, xoffset); BitConv.ToInt32(data, 12, yoffset); BitConv.ToInt32(data, 16, zoffset); BitConv.ToInt32(data, 20, x1); BitConv.ToInt32(data, 24, y1); BitConv.ToInt32(data, 28, z1); BitConv.ToInt32(data, 32, x2); BitConv.ToInt32(data, 36, y2); BitConv.ToInt32(data, 40, z2); BitConv.ToInt32(data, 44, xglobal); BitConv.ToInt32(data, 48, yglobal); BitConv.ToInt32(data, 52, zglobal); for (int i = 0; i < vertices.Count; i++) { vertices[i].Save().CopyTo(data, 56 + i * 6); } BitConv.ToInt16(data, 56 + vertices.Count * 6, unknown); return(data); }
protected override void SaveElement(byte[] data, short value) { BitConv.ToInt16(data, 0, value); }
protected override void SaveElement(byte[] data, EntityPosition value) { BitConv.ToInt16(data, 0, value.X); BitConv.ToInt16(data, 2, value.Y); BitConv.ToInt16(data, 4, value.Z); }
public override byte[] Save() { if (rows.Count == 0) { return(new byte [0]); } int length; if (IsSparse) { length = rows.Count * 2; } else { length = 2; } if (HasMetaValues) { length += rows.Count * 2; } Aligner.Align(ref length, 4); foreach (EntityPropertyRow <T> row in rows) { length += row.Values.Count * ElementSize; } Aligner.Align(ref length, 4); byte[] data = new byte [length]; int offset = 0; if (IsSparse) { foreach (EntityPropertyRow <T> row in rows) { BitConv.ToInt16(data, offset, (short)row.Values.Count); offset += 2; } } else { BitConv.ToInt16(data, offset, (short)rows[0].Values.Count); offset += 2; } if (HasMetaValues) { foreach (EntityPropertyRow <T> row in rows) { if (!row.MetaValue.HasValue) { throw new InvalidOperationException("EntityPropertyRow MetaValues must be consistently present or non-present."); } BitConv.ToInt16(data, offset, row.MetaValue.Value); offset += 2; } } Aligner.Align(ref offset, 4); byte[] elementdata = new byte [ElementSize]; foreach (EntityPropertyRow <T> row in rows) { foreach (T value in row.Values) { SaveElement(elementdata, value); elementdata.CopyTo(data, offset); offset += ElementSize; } } return(data); }