예제 #1
0
        public override bool Read()
        {
            lock (SampleBufferLock)
            {
                int read = InputStream.Read(InBuffer, 0, InBuffer.Length);

                if (read != InBuffer.Length)
                {
                    SamplesRead = 0;
                    return(false);
                }

                ForwardData(InBuffer);

                if (InternalOversampling > 1)
                {
                    ByteUtil.SamplesFromBinary(InBuffer, OversampleI, OversampleQ, DataFormat, InvertedSpectrum);
                    IOversampler.Resample(OversampleI, ref SourceSamplesI);
                    QOversampler.Resample(OversampleQ, ref SourceSamplesQ);
                }
                else
                {
                    ByteUtil.SamplesFromBinary(InBuffer, SourceSamplesI, SourceSamplesQ, DataFormat, InvertedSpectrum);
                }

                SamplesRead = SourceSamplesI.Length;

                SaveData();
            }
            return(true);
        }
예제 #2
0
        public override bool Read()
        {
            /* buffer overrun? */
            if (ShmemChannel.Length > ShmemChannel.bufferSize * 0.9f)
            {
                BufferOverrun = true;
            }

            /* in case we should use some other input buffer */
            if (NextInBufferAvailable)
            {
                NextInBufferAvailable = false;
                InBuffer = NextInBuffer;
            }

            /* when the rate has changed */
            if (ShmemChannel.Rate != 0 && InputSamplingRate != ShmemChannel.Rate / 2)
            {
                ForceInputRate(ShmemChannel.Rate / 2);
            }

            int read = ShmemChannel.Read(InBuffer, 0, InBuffer.Length);

            if (TraceReads)
            {
                Log.AddMessage("ShmemSamplesource", "Read Block: " + read + "/" + InBuffer.Length + " (" + ShmemChannel.Length + " available)");
            }

            /* in case buffer size has changed meanwhile, return */
            if (NextInBufferAvailable)
            {
                SamplesRead = 0;
                return(true);
            }

            /* seems we have timed out */
            if (read == 0)
            {
                SamplesRead = 0;
                return(false);
            }

            /* in case we could not read enough bytes, return */
            if (read != InBuffer.Length)
            {
                SamplesRead = 0;
                return(false);
            }

            lock (SampleBufferLock)
            {
                if (InternalOversampling != 1)
                {
                    ByteUtil.SamplesFromBinary(InBuffer, OversampleI, OversampleQ, DataFormat, InvertedSpectrum);
                    IOversampler.Resample(OversampleI, ref SourceSamplesI);
                    QOversampler.Resample(OversampleQ, ref SourceSamplesQ);
                }
                else
                {
                    ByteUtil.SamplesFromBinary(InBuffer, SourceSamplesI, SourceSamplesQ, DataFormat, InvertedSpectrum);
                }

                SamplesRead = SourceSamplesI.Length;

                SaveData();
            }
            return(true);
        }