예제 #1
0
        /// <summary> 由<see cref="byte"/>陣列組成<see cref="MPEGLayer3WaveFormat"/>結構 </summary>
        public static MPEGLayer3WaveFormat FromArray(byte[] datas)
        {
            if (datas.Length < 30)
            {
                throw new InvalidCastException("Invalid datas");
            }

            MemoryStream         ms     = new MemoryStream(datas);
            BinaryReader         reader = new BinaryReader(ms);
            MPEGLayer3WaveFormat ml3wf  = new MPEGLayer3WaveFormat();

            ml3wf.wfx             = WaveFormatEx.FromArray(reader.ReadBytes((int)WaveFormatEx.StructureSize));
            ml3wf.wID             = reader.ReadUInt16();
            ml3wf.fdwFlags        = reader.ReadUInt32();
            ml3wf.nBlockSize      = reader.ReadUInt16();
            ml3wf.nFramesPerBlock = reader.ReadUInt16();
            ml3wf.nCodecDelay     = reader.ReadUInt16();
            reader.Close();
            ms.Dispose();

            return(ml3wf);
        }
예제 #2
0
        /// <summary> 由<see cref="byte"/>陣列組成<see cref="WaveFormatEx"/>結構 </summary>
        public static WaveFormatEx FromArray(byte[] datas)
        {
            if (datas.Length < 18)
            {
                throw new InvalidCastException("Invalid datas");
            }

            MemoryStream ms     = new MemoryStream(datas);
            BinaryReader reader = new BinaryReader(ms);
            WaveFormatEx wfx    = new WaveFormatEx();

            wfx.wFormatTag      = reader.ReadUInt16();
            wfx.nChannels       = reader.ReadUInt16();
            wfx.nSamplesPerSec  = reader.ReadUInt32();
            wfx.nAvgBytesPerSec = reader.ReadUInt32();
            wfx.nBlockAlign     = reader.ReadUInt16();
            wfx.wBitsPerSample  = reader.ReadUInt16();
            wfx.cbSize          = reader.ReadUInt16();
            reader.Close();
            ms.Dispose();

            return(wfx);
        }