Read() public static method

public static Read ( Stream s ) : Chunk
s Stream
return Chunk
示例#1
0
            protected override bool BufferData(Stream baseStream, Queue <byte> data)
            {
                if (dataSize <= 0)
                {
                    return(true);
                }

                var chunk = Chunk.Read(baseStream);

                for (var n = 0; n < chunk.CompressedSize; n++)
                {
                    var b = baseStream.ReadUInt8();

                    var t = DecodeSample(b, ref index, ref currentSample);
                    data.Enqueue((byte)t);
                    data.Enqueue((byte)(t >> 8));
                    baseOffset += 2;

                    if (baseOffset < outputSize)
                    {
                        /* possible that only half of the final byte is used! */
                        t = DecodeSample((byte)(b >> 4), ref index, ref currentSample);
                        data.Enqueue((byte)t);
                        data.Enqueue((byte)(t >> 8));
                        baseOffset += 2;
                    }
                }

                dataSize -= 8 + chunk.CompressedSize;

                return(dataSize <= 0);
            }
示例#2
0
        public static bool LoadSound(Stream s, out byte[] rawData, out int sampleRate)
        {
            rawData = null;

            sampleRate = s.ReadUInt16();
            var dataSize   = s.ReadInt32();
            var outputSize = s.ReadInt32();

            var readFlag = s.ReadByte();

            if (!Enum.IsDefined(typeof(SoundFlags), readFlag))
            {
                return(false);
            }

            var readFormat = s.ReadByte();

            if (!Enum.IsDefined(typeof(SoundFormat), readFormat))
            {
                return(false);
            }

            var output        = new byte[outputSize];
            var offset        = 0;
            var index         = 0;
            var currentSample = 0;

            while (dataSize > 0)
            {
                var chunk = Chunk.Read(s);
                for (var n = 0; n < chunk.CompressedSize; n++)
                {
                    var b = s.ReadUInt8();

                    var t = DecodeSample(b, ref index, ref currentSample);
                    output[offset++] = (byte)t;
                    output[offset++] = (byte)(t >> 8);

                    if (offset < outputSize)
                    {
                        /* possible that only half of the final byte is used! */
                        t = DecodeSample((byte)(b >> 4), ref index, ref currentSample);
                        output[offset++] = (byte)t;
                        output[offset++] = (byte)(t >> 8);
                    }
                }

                dataSize -= 8 + chunk.CompressedSize;
            }

            rawData = output;
            return(true);
        }