public byte[] RetrieveRawData() { byte[] data = new byte[this.DataRawSize]; this.Entries .AsParallel() .ForAll(entry => { byte[] buffer; switch (entry.Codec) { case 0: buffer = entry.Data; break; case 1: buffer = Vima.Decompress(entry.Data, entry.RawSize); break; default: throw new NotSupportedException(); } buffer.CopyTo(data, entry.RawOffset); }); return(data); }
public void SetRawData(byte[] data, int bitsPerSample, int sampleRate, int channels) { if (data == null) { throw new ArgumentNullException("data"); } if (bitsPerSample != 16) { throw new ArgumentOutOfRangeException("bitsPerSample"); } if (sampleRate <= 0) { throw new ArgumentOutOfRangeException("sampleRate"); } if (channels < 1 || channels > 2) { throw new ArgumentOutOfRangeException("channels"); } this.Entries.Clear(); this.Codecs.Clear(); this.Codecs.Add("NULL"); this.Codecs.Add("VIMA"); this.BitsPerSample = bitsPerSample; this.SampleRate = sampleRate; this.Channels = channels; this.DataRawSize = data.Length; int remaining = data.Length; while (remaining > 0) { var rawData = new byte[remaining > 8192 ? 8192 : remaining]; Array.Copy(data, data.Length - remaining, rawData, 0, rawData.Length); var compressedData = Vima.Compress(rawData, channels); this.Entries.Add(new ImcEntry { Codec = 1, RawSize = rawData.Length, CompressedSize = compressedData.Length, Data = compressedData }); remaining -= rawData.Length; } this.ComputeEntriesOffsets(); }
public byte[] RetrieveRawData(int start, int end) { start *= this.BlockAlign; end *= this.BlockAlign; if (start < 0 || start > this.DataRawSize) { throw new ArgumentOutOfRangeException("start"); } if (end < start || end > this.DataRawSize) { throw new ArgumentOutOfRangeException("end"); } byte[] data = new byte[end - start]; this.Entries .Where(t => t.RawOffset >= start && t.RawOffset + t.RawSize <= end) .AsParallel() .ForAll(entry => { byte[] buffer; switch (entry.Codec) { case 0: buffer = entry.Data; break; case 1: buffer = Vima.Decompress(entry.Data, entry.RawSize); break; default: throw new NotSupportedException(); } int left = Math.Max(entry.RawOffset, start); int right = Math.Min(entry.RawOffset + entry.RawSize, end); Array.Copy(buffer, left - entry.RawOffset, data, left, right - left); }); return(data); }