private IEnumerator <ArraySegment <byte> > ReadFlacSpliter(FlacStreaminfo info, Stream body) { IFlacReader reader = null; try { streaminfo = info; ValidateBitPerSample(streaminfo.BitsPerSample); ValidateTotalSamples(streaminfo.TotalSampleCount); reader = new FlacSpliteReader(streaminfo, body, true); InitializeHelpers(reader); while (reader.Read()) { if (reader.RecordType == FlacRecordType.Frame) { yield return(ReadFrame(reader)); } } } finally { if (reader != null) { reader.Close(); } } }
private void InitializeHelpers(IFlacReader reader) { sampleTransform = WaveSampleTransformerFactory.CreateWaveSampleTransformer(reader.Streaminfo.BitsPerSample); int bufferSize = reader.Streaminfo.MaxBlockSize * ((reader.Streaminfo.ChannelsCount * reader.Streaminfo.BitsPerSample) >> 3); pcmBuffer = new byte[bufferSize]; }
internal override IEnumerable <int> MixSamples(IFlacReader reader) { int blockSize = reader.BlockSize; int channelCount = reader.Streaminfo.ChannelsCount; List <int[]> channelData = new List <int[]>(channelCount); while (reader.Read() && reader.RecordType == FlacRecordType.Subframe) { int[] data = reader.ReadSubframeValues(); channelData.Add(data); } for (int i = 0; i < blockSize; i++) { for (int j = 0; j < channelCount; j++) { yield return(channelData[j][i]); } } }
internal override IEnumerable <int> MixSamples(IFlacReader reader) { if (!reader.Read() || reader.RecordType != FlacRecordType.Subframe) { throw new FlacException("Right channel expected"); } int[] left = reader.ReadSubframeValues(); if (!reader.Read() || reader.RecordType != FlacRecordType.Subframe) { throw new FlacException("Side channel expected"); } int[] side = reader.ReadSubframeValues(); for (int i = 0; i < left.Length; i++) { yield return(left[i]); yield return(left[i] - side[i]); } reader.Read(); }
internal override IEnumerable <int> MixSamples(IFlacReader reader) { if (!reader.Read() || reader.RecordType != FlacRecordType.Subframe) { throw new FlacException("Mid channel expected"); } int[] mid = reader.ReadSubframeValues(); if (!reader.Read() || reader.RecordType != FlacRecordType.Subframe) { throw new FlacException("Side channel expected"); } int[] side = reader.ReadSubframeValues(); for (int i = 0; i < mid.Length; i++) { int right = mid[i] - (side[i] >> 1); yield return(right + side[i]); yield return(right); } reader.Read(); }
private ArraySegment <byte> ReadFrame(IFlacReader reader) { int read = sampleTransform.PackData(reader.GetValues(), pcmBuffer); return(new ArraySegment <byte>(pcmBuffer, 0, read)); }
internal abstract IEnumerable <int> MixSamples(IFlacReader reader);