Beispiel #1
0
        void ReadAudioChunk(BitStream bs, int channel)
        {
            uint frameAudioLength        = 0;
            uint audioDecompressedLength = 0;

            bool compressed = ((audioFlags[channel] & (int)ARFlags.Compressed) == (int)ARFlags.Compressed);
            bool is16       = ((audioFlags[channel] & (int)ARFlags.Is16Bit) == (int)ARFlags.Is16Bit);
            bool stereo     = ((audioFlags[channel] & (int)ARFlags.Stereo) == (int)ARFlags.Stereo);

            bs.AssertAtByteBoundary();

            bs.DebugFirst();

            Console.WriteLine("reading audio chunk length");
            frameAudioLength = bs.ReadDWord();
            Console.WriteLine("audio chunk length = {0}", frameAudioLength);

            if (compressed)
            {
                audioDecompressedLength = bs.ReadDWord();
                Console.WriteLine("decompressed audio length = {0}", audioDecompressedLength);


                byte[] streamBuf = new byte[frameAudioLength];
                bs.Read(streamBuf, 0, streamBuf.Length);

                audioOut[channel] = new byte[audioDecompressedLength];

                if (is16)
                {
                    if (stereo)
                    {
                        Decompress16Stereo(new BitStream(streamBuf), new MemoryStream(audioOut[channel]));
                    }
                    else
                    {
                        Decompress16Mono(new BitStream(streamBuf), new MemoryStream(audioOut[channel]));
                    }
                }
                else
                if (stereo)
                {
                    Decompress8Stereo(new BitStream(streamBuf), new MemoryStream(audioOut[channel]));
                }
                else
                {
                    Decompress8Mono(new BitStream(streamBuf), new MemoryStream(audioOut[channel]));
                }
            }
            else
            {
                audioOut[channel] = new byte[frameAudioLength];
                bs.Read(audioOut[channel], 0, (int)frameAudioLength);
            }
        }
Beispiel #2
0
        void ReadPaletteChunk(BitStream bs)
        {
            byte[] new_palette = new byte[256 * 3];

            bs.AssertAtByteBoundary();

            bs.ZeroReadCount();

            int paletteLength = bs.ReadByte();

            Console.WriteLine("palette chunk is {0} bytes long", paletteLength * 4);

            //			byte[] palBuf = new byte[paletteLength * 4 - 1];
            //			bs.Read (palBuf, 0, palBuf.Length);
            //			MemoryStream palStream = new MemoryStream (palBuf, false);

            BitStream palStream = bs;
            int       new_index = 0, index = 0;

            while (new_index < 256)
            {
                byte p = (byte)palStream.ReadByte();
                if ((p & 0x80) == 0x80)
                {
                    int count = (p & 0x7f) + 1;
                    //					Console.WriteLine ("copy1 {0} entries, from {1} to {2}", count, index, new_index);
                    Array.Copy(palette, index * 3, new_palette, new_index * 3, count * 3);
                    index     += count;
                    new_index += count;
                }
                else if ((p & 0x40) == 0x40)
                {
                    int count     = (p & 0x3f) + 1;
                    int tmp_index = palStream.ReadByte();
                    //					Console.WriteLine ("copy2 {0} entries, from {1} to {2}", count, tmp_index, new_index);
                    Array.Copy(palette, tmp_index * 3, new_palette, new_index * 3, count * 3);
                    new_index += count;
                }
                else if ((p & 0xc0) == 0x00)
                {
                    int b = p & 0x3f;
                    int g = palStream.ReadByte() & 0x3f;
                    int r = palStream.ReadByte() & 0x3f;
                    new_palette [new_index * 3]     = palmap[r];
                    new_palette [new_index * 3 + 1] = palmap[g];
                    new_palette [new_index * 3 + 2] = palmap[b];
                    //					Console.WriteLine ("Assign palette[{0}] = {1},{2},{3}", new_index,
                    //							   palmap[r], palmap[g], palmap[b]);
                    new_index++;
                }
            }

            palette = new_palette;
            //			Console.WriteLine ("read {0} bytes toward filling the palette", palBuf.Length + 1);
        }
Beispiel #3
0
		void ReadAudioChunk (BitStream bs, int channel)
		{
			uint frameAudioLength = 0;
			uint audioDecompressedLength = 0;

			bool compressed = ((audioFlags[channel] & (int)ARFlags.Compressed) == (int)ARFlags.Compressed);
			bool is16 = ((audioFlags[channel] & (int)ARFlags.Is16Bit) == (int)ARFlags.Is16Bit);
			bool stereo = ((audioFlags[channel] & (int)ARFlags.Stereo) == (int)ARFlags.Stereo);

			bs.AssertAtByteBoundary ();

			bs.DebugFirst ();

			Console.WriteLine ("reading audio chunk length");
			frameAudioLength = bs.ReadDWord ();
			Console.WriteLine ("audio chunk length = {0}", frameAudioLength);

			if (compressed) {
				audioDecompressedLength = bs.ReadDWord ();
				Console.WriteLine ("decompressed audio length = {0}", audioDecompressedLength);


				byte[] streamBuf = new byte[frameAudioLength];
				bs.Read (streamBuf, 0, streamBuf.Length);

				audioOut[channel] = new byte[audioDecompressedLength];

				if (is16)
					if (stereo)
						Decompress16Stereo (new BitStream (streamBuf), new MemoryStream (audioOut[channel]));
					else
						Decompress16Mono (new BitStream (streamBuf), new MemoryStream (audioOut[channel]));
				else
					if (stereo)
						Decompress8Stereo (new BitStream (streamBuf), new MemoryStream (audioOut[channel]));
					else
						Decompress8Mono (new BitStream (streamBuf), new MemoryStream (audioOut[channel]));
			}
			else {
				audioOut[channel] = new byte[frameAudioLength];
				bs.Read (audioOut[channel], 0, (int)frameAudioLength);
			}
		}
Beispiel #4
0
		void ReadPaletteChunk (BitStream bs)
		{
			byte[] new_palette = new byte[256 * 3];

			bs.AssertAtByteBoundary ();

			bs.ZeroReadCount ();

			int paletteLength = bs.ReadByte();
			Console.WriteLine ("palette chunk is {0} bytes long", paletteLength * 4);

			//			byte[] palBuf = new byte[paletteLength * 4 - 1];
			//			bs.Read (palBuf, 0, palBuf.Length);
			//			MemoryStream palStream = new MemoryStream (palBuf, false);

			BitStream palStream = bs;
			int new_index = 0, index = 0;
			while (new_index < 256) {
				byte p = (byte)palStream.ReadByte();
				if ((p & 0x80) == 0x80) {
					int count = (p & 0x7f) + 1;
					//					Console.WriteLine ("copy1 {0} entries, from {1} to {2}", count, index, new_index);
					Array.Copy (palette, index * 3, new_palette, new_index * 3, count * 3);
					index += count;
					new_index += count;
				}
				else if ((p & 0x40) == 0x40) {
					int count = (p & 0x3f) + 1;
					int tmp_index = palStream.ReadByte();
					//					Console.WriteLine ("copy2 {0} entries, from {1} to {2}", count, tmp_index, new_index);
					Array.Copy (palette, tmp_index * 3, new_palette, new_index * 3, count * 3);
					new_index += count;
				}
				else if ((p & 0xc0) == 0x00) {
					int b = p & 0x3f;
					int g = palStream.ReadByte() & 0x3f;
					int r = palStream.ReadByte() & 0x3f;
					new_palette [new_index * 3] = palmap[r];
					new_palette [new_index * 3 + 1] = palmap[g];
					new_palette [new_index * 3 + 2] = palmap[b];
					//					Console.WriteLine ("Assign palette[{0}] = {1},{2},{3}", new_index,
					//							   palmap[r], palmap[g], palmap[b]);
					new_index ++;
				}
			}

			palette = new_palette;
			//			Console.WriteLine ("read {0} bytes toward filling the palette", palBuf.Length + 1);
		}