private MipMap ReadMipMapHeader(BinaryReader reader) { var mipMap = new MipMap(); mipMap.DivisionFactor = reader.ReadInt32(); // number of samples per peak int numberOfPeakSamples = reader.ReadInt32(); mipMap.Peaks = new PeakValues[numberOfPeakSamples]; return(mipMap); }
private void ReadMipMapData(BinaryReader reader, MipMap mipMap) { for (int n = 0; n < mipMap.Peaks.Length; n++) { mipMap.Peaks[n] = new PeakValues(Channels); for (int ch = 0; ch < Channels; ch++) { mipMap.Peaks[n].Channels[ch].Max = reader.ReadInt16(); if (magicHeader == "RPKN") // 1.1 { mipMap.Peaks[n].Channels[ch].Min = reader.ReadInt16(); } else // 1.0, mirror the positive peak { mipMap.Peaks[n].Channels[ch].Min = (short)(0 - mipMap.Peaks[n].Channels[ch].Max); } } } }
public MipMap GetPeaks(string fileName, int samplesPerPeak) { if (fileName.EndsWith(".ReaPeaks", StringComparison.CurrentCultureIgnoreCase)) { var reaPeaks = new ReaPeaksFileReader(fileName); return(reaPeaks.MipMaps[1]); } MipMap m = new MipMap(); m.DivisionFactor = samplesPerPeak; List <PeakValues> peaks = new List <PeakValues>(); using (var reader = GetReader(fileName)) { int channels = reader.WaveFormat.Channels; int stepSize = samplesPerPeak * channels * (reader.WaveFormat.BitsPerSample / 8); WaveBuffer buffer = new WaveBuffer(stepSize); int read; while ((read = reader.Read(buffer.ByteBuffer, 0, stepSize)) > 0) { PeakValues peakValues = new PeakValues(reader.WaveFormat.Channels); int samples = read / 2; // assume 16 bit for (int index = 0; index < samples; index++) { int ch = index % channels; peakValues.Channels[ch].Max = Math.Max(peakValues.Channels[ch].Max, buffer.ShortBuffer[index]); peakValues.Channels[ch].Min = Math.Min(peakValues.Channels[ch].Min, buffer.ShortBuffer[index]); } peaks.Add(peakValues); } } m.Peaks = peaks.ToArray(); return(m); }