Пример #1
0
        public bool Open(Stream fs)
        {
            var WavStartPos = fs.Position;

            Wave = MarshalUtil.ReadStruct <CWAV>(fs);
            fs.Seek(WavStartPos + Wave.InfoChunkOffset, SeekOrigin.Begin);
            InfoBlob      = MarshalUtil.ReadStruct <CWAVINFO>(fs);
            BitsPerSample = (byte)(InfoBlob.Type == 1 ? 16 : 8);

            var ChannelsBaseOffset = fs.Position - 4;

            //read the channel data pointers based on the number of channels
            ChannelDataPointers = new CWAVChannelDataPointer[InfoBlob.Channels];
            for (var i = 0; i < InfoBlob.Channels; i++)
            {
                ChannelDataPointers[i] = MarshalUtil.ReadStruct <CWAVChannelDataPointer>(fs);
            }
            //read the channel data fron the offsets
            ChannelDatas = new CWAVChannelData[InfoBlob.Channels];
            for (var i = 0; i < InfoBlob.Channels; i++)
            {
                fs.Seek(ChannelsBaseOffset + ChannelDataPointers[i].Offset, SeekOrigin.Begin);
                ChannelDatas[i] = MarshalUtil.ReadStruct <CWAVChannelData>(fs);
            }
            fs.Seek(WavStartPos + Wave.DataChunkOffset, SeekOrigin.Begin);
            DataBlob = MarshalUtil.ReadStruct <DATABlobHeader>(fs);
            var DataBaseOffset = fs.Position - 4;

            ChannelsRawData = new byte[InfoBlob.Channels][];
            for (var i = 0; i < InfoBlob.Channels; i++)
            {
                fs.Seek(DataBaseOffset + (long)ChannelDatas[i].Offset, SeekOrigin.Begin);
                ChannelsRawData[i] = new byte[InfoBlob.NumberOfSamples * (BitsPerSample / 8)];
                fs.Read(ChannelsRawData[i], 0, ChannelsRawData[i].Length);
            }
            return(true);
        }
Пример #2
0
 public bool Open(Stream fs)
 {
     var WavStartPos = fs.Position;
     Wave = MarshalUtil.ReadStruct<CWAV>(fs);
     fs.Seek(WavStartPos + Wave.InfoChunkOffset, SeekOrigin.Begin);
     InfoBlob = MarshalUtil.ReadStruct<CWAVINFO>(fs);
     BitsPerSample = (byte)(InfoBlob.Type == 1 ? 16 : 8);
     
     var ChannelsBaseOffset = fs.Position - 4;
     //read the channel data pointers based on the number of channels
     ChannelDataPointers = new CWAVChannelDataPointer[InfoBlob.Channels];
     for (var i = 0; i < InfoBlob.Channels;i++ ) 
         ChannelDataPointers[i] = MarshalUtil.ReadStruct<CWAVChannelDataPointer>(fs);
     //read the channel data fron the offsets
     ChannelDatas = new CWAVChannelData[InfoBlob.Channels];
     for (var i = 0; i < InfoBlob.Channels; i++)
     {
         fs.Seek(ChannelsBaseOffset + ChannelDataPointers[i].Offset, SeekOrigin.Begin);
         ChannelDatas[i] = MarshalUtil.ReadStruct<CWAVChannelData>(fs);
     }
     fs.Seek(WavStartPos + Wave.DataChunkOffset, SeekOrigin.Begin);
     DataBlob = MarshalUtil.ReadStruct<DATABlobHeader>(fs);
     var DataBaseOffset = fs.Position - 4;
     ChannelsRawData = new byte[InfoBlob.Channels][];
     for (var i = 0; i < InfoBlob.Channels; i++)
     {
         fs.Seek(DataBaseOffset + (long)ChannelDatas[i].Offset, SeekOrigin.Begin);
         ChannelsRawData[i] = new byte[InfoBlob.NumberOfSamples * (BitsPerSample / 8)];
         fs.Read(ChannelsRawData[i], 0, ChannelsRawData[i].Length);
     }
     return true;
 }