Exemple #1
0
		static byte[] GenerateSoundFile(byte[] buffer, byte[] footer)
		{
			byte[] sound_file;

			using (MemoryStream ms = new MemoryStream())
			using (IO.EndianWriter write = new IO.EndianWriter(ms))
			{
				write.Write("RIFF", "RIFF".Length);
				write.Write(uint.MinValue);
				write.Write("WAVEdata", "WAVEdata".Length);
				write.Write(uint.MinValue);

				write.Write(buffer);

				if(footer != null)
					write.Write(footer);

				int size = (int)ms.Length;

				// Write file size to RIFF header
				write.Seek(4);
				write.Write(size - 8);

				// Write data size to WAVE header
				write.Seek(16);
				write.Write(buffer.Length);

				sound_file = ms.ToArray();
			}

			return sound_file;
		}
Exemple #2
0
        public void UpdateValue(ref byte[] packet, object value, long pos, Type type)
        {
            MemoryStream temp = new MemoryStream();
            temp.Write(packet, 0, packet.Length);

            EndianWriter toc = new EndianWriter(temp, false);
            toc.Seek((int)pos, SeekOrigin.Begin);

            value = Convert.ChangeType(value, type);

            if (type == typeof(Byte))
            {
                toc.Write((Byte)value);
            }
            else if (type == typeof(UInt16))
            {
                toc.Write((UInt16)value);
            }
            else if (type == typeof(UInt32))
            {
                toc.Write((UInt32)value);
            }
            else if (type == typeof(UInt64))
            {
                toc.Write((UInt64)value);
            }
            else if (type == typeof(Single))
            {
                toc.Write((Single)value);
            }
            else
            {
                throw new Exception("Not supported type!");
            }

            toc.Close();

            MemoryStream myStream = (MemoryStream)toc.BaseStream;
            packet = myStream.ToArray();
        }