private IEnumerator <ArraySegment <byte> > ReadFlac(FlacReader reader)
        {
            try
            {
                while (reader.Read())
                {
                    if (reader.RecordType == FlacRecordType.MetadataBlock &&
                        reader.MetadataBlockType == FlacMetadataBlockType.Streaminfo)
                    {
                        streaminfo = reader.Streaminfo;
                        ValidateBitPerSample(streaminfo.BitsPerSample);
                        ValidateTotalSamples(streaminfo.TotalSampleCount);
                        InitializeHelpers(reader);

                        byte[] waveHeader = CreateWaveHeader();

                        yield return(new ArraySegment <byte>(waveHeader));
                    }
                    else if (reader.RecordType == FlacRecordType.Frame)
                    {
                        yield return(ReadFrame(reader));
                    }
                }
            }
            finally
            {
                reader.Close();
            }
        }
        private void InitializeHelpers(FlacReader reader)
        {
            sampleTransform = WaveSampleTransformerFactory.CreateWave16SampleTransformer(reader.Streaminfo.BitsPerSample);

            int bufferSize =
                reader.Streaminfo.MaxBlockSize * ((reader.Streaminfo.ChannelsCount * BitsPerSample) >> 3);

            pcmBuffer = new byte[bufferSize];
        }
        public Wave16OverFlacStream(FlacReader reader)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }

            this.dataSource = ReadFlac(reader);
        }
Beispiel #4
0
        internal override IEnumerable<int> MixSamples(FlacReader 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();
        }
Beispiel #5
0
        internal override IEnumerable<int> MixSamples(FlacReader 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();
        }
Beispiel #6
0
        internal override IEnumerable<int> MixSamples(FlacReader 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(FlacReader 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(FlacReader 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(FlacReader 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();
        }
Beispiel #10
0
        public WaveOverFlacStream(FlacReader reader)
        {
            if (reader == null) throw new ArgumentNullException("reader");

            this.dataSource = ReadFlac(reader);
            this.mode = WaveOverFlacStreamMode.Decode;
            EnsureHeaderRead();
        }
Beispiel #11
0
 internal abstract IEnumerable<int> MixSamples(FlacReader reader);
        public Wave16OverFlacStream(FlacReader reader)
        {
            if (reader == null) throw new ArgumentNullException("reader");

            this.dataSource = ReadFlac(reader);
        }
 private ArraySegment<byte> ReadFrame(FlacReader reader)
 {
     int read = sampleTransform.PackData(reader.GetValues(), pcmBuffer);
     return new ArraySegment<byte>(pcmBuffer, 0, read);
 }
        private IEnumerator<ArraySegment<byte>> ReadFlac(FlacReader reader)
        {
            try
            {
                while (reader.Read())
                {
                    if (reader.RecordType == FlacRecordType.MetadataBlock &&
                        reader.MetadataBlockType == FlacMetadataBlockType.Streaminfo)
                    {
                        streaminfo = reader.Streaminfo;
                        ValidateBitPerSample(streaminfo.BitsPerSample);
                        ValidateTotalSamples(streaminfo.TotalSampleCount);
                        InitializeHelpers(reader);

                        byte[] waveHeader = CreateWaveHeader();

                        yield return new ArraySegment<byte>( waveHeader );
                    }
                    else if (reader.RecordType == FlacRecordType.Frame)
                    {
                        yield return ReadFrame(reader);
                    }
                }
            }
            finally
            {
                reader.Close();
            }
        }
        private void InitializeHelpers(FlacReader reader)
        {
            sampleTransform = WaveSampleTransformerFactory.CreateWave16SampleTransformer(reader.Streaminfo.BitsPerSample);

            int bufferSize =
                reader.Streaminfo.MaxBlockSize * ((reader.Streaminfo.ChannelsCount * BitsPerSample) >> 3);
            pcmBuffer = new byte[bufferSize];
        }
Beispiel #16
0
 internal abstract IEnumerable <int> MixSamples(FlacReader reader);
        private ArraySegment <byte> ReadFrame(FlacReader reader)
        {
            int read = sampleTransform.PackData(reader.GetValues(), pcmBuffer);

            return(new ArraySegment <byte>(pcmBuffer, 0, read));
        }