예제 #1
0
        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();
                }
            }
        }
예제 #2
0
        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];
        }
예제 #3
0
        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]);
                }
            }
        }
예제 #4
0
        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();
        }
예제 #5
0
        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();
        }
예제 #6
0
        private ArraySegment <byte> ReadFrame(IFlacReader reader)
        {
            int read = sampleTransform.PackData(reader.GetValues(), pcmBuffer);

            return(new ArraySegment <byte>(pcmBuffer, 0, read));
        }
예제 #7
0
 internal abstract IEnumerable <int> MixSamples(IFlacReader reader);