public bool ReadBlock()
        {
            bool ret;

            ret = SampleSource.Read();

            return(ret);
        }
        /// <summary>
        ///     This method is called when Sample load is requested, if you return a Sample
        ///     it will return it from the user else it will keep trying all the other SampleLoaders
        ///     until it does get one
        /// </summary>
        /// <param name="path">File path of the sound to load.</param>
        /// <param name="streamed">If set to true the sound will be loaded in piece by piece rather than all at once.</param>
        /// <returns>New Sample instance or NULL if this factory can't load the given audio sample file format.</returns>
        protected override Sample RequestLoad(object path, bool streamed)
        {
            // Load in the audio file's data.
            Stream stream = StreamFactory.RequestStream(path, StreamMode.Open);

            if (stream == null)
            {
                return(null);
            }
            if (stream.ReadByte() != 'O' || stream.ReadByte() != 'g' || stream.ReadByte() != 'g' || stream.ReadByte() != 'S')
            {
                stream.Close();
                return(null);
            }
            stream.Position = 0;

            byte[] data = new byte[stream.Length];
            stream.Read(data, 0, (int)stream.Length);
            stream.Close();

            // Create an audiere memory file to place our data into.
            ManagedAudiere.File file          = Audiere.CreateMemoryFile(new MemoryFileBuffer(data, data.Length));
            SampleSource        audiereSample = Audiere.OpenSampleSource(file);
            SampleFormatData    sampleFormat  = audiereSample.GetFormat();

            int size = audiereSample.Length * (Audiere.GetSampleSize(sampleFormat.sample_format) * sampleFormat.channel_count);
            MemoryFileBuffer audiereBuffer = new MemoryFileBuffer(new byte[size], size);

            audiereSample.Read(audiereSample.Length, audiereBuffer);

            // Put the audiere audio buffer into a new sample buffer.
            byte[] pcmBuffer = audiereBuffer.GetBuffer();
            Sample sample    = null;

            if (sampleFormat.channel_count == 1)
            {
                sample = new Sample(SampleFormat.MONO16LE, pcmBuffer.Length);
            }
            else
            {
                sample = new Sample(SampleFormat.STEREO16LE, pcmBuffer.Length);
            }

            sample.SampleRate    = sampleFormat.sample_rate;
            sample.ChannelCount  = sampleFormat.channel_count;
            sample.BlockAlign    = Audiere.GetSampleSize(sampleFormat.sample_format) * sampleFormat.channel_count;
            sample.ByteRate      = sample.SampleRate * sample.BlockAlign;
            sample.BitsPerSample = Audiere.GetSampleSize(sampleFormat.sample_format) * 8;

            for (int i = 0; i < pcmBuffer.Length; i++)
            {
                sample.Data[i] = pcmBuffer[i];
            }

            return(sample);
        }
Exemple #3
0
        public bool ReadBlock()
        {
            bool success;

            do
            {
                /* will loop every 100ms (timeout set up in SharedMem object) */
                success = SampleSource.Read();
            } while (success && SampleSource.SamplesRead == 0);

            /* collect as many samples as the current read block size has */
            if (success)
            {
                SamplesThisBlock += SampleSource.SamplesPerBlock;
            }

            if (SamplesThisBlock >= SamplesPerBlock)
            {
                //RX_FFT.Components.GDI.Log.AddMessage("ShmemSampleSource", "Full block");
                SamplesThisBlock = 0;
                SampleSource.Flush();

                /* transfer done, if needed start next one */
                if (success)
                {
                    if (TransferMode == eTransferMode.Block)
                    {
                        USBRX.ReadBlockReceived();
                    }
                }
                else
                {
                    if (USBRX.DeviceLost)
                    {
                        RX_FFT.Components.GDI.Log.AddMessage("USBRX -> DeviceLost");
                        if (DeviceDisappeared != null)
                        {
                            DeviceDisappeared(this, null);
                        }
                    }
                }
            }

            return(success);
        }
Exemple #4
0
        public bool ReadBlock()
        {
            bool ret;

            ret = SampleSource.Read();
            if (SampleSource.SamplesAvailable > SamplesPerBlock * 50)
            {
                FlushData = true;
            }

            if (FlushData)
            {
                SampleSource.Flush();
                FlushData = false;
            }

            return(ret);
        }
Exemple #5
0
        private void ProcessMain()
        {
            while (Processing)
            {
                if (SampleSource.Read())
                {
                    if (SampleSource.SamplesRead > 0)
                    {
                        lock (SampleSource.SampleBufferLock)
                        {
                            for (int pos = 0; pos < SampleSource.SamplesRead; pos++)
                            {
                                double I = SampleSource.SourceSamplesI[pos];
                                double Q = SampleSource.SourceSamplesQ[pos];

                                //iqPlot.Process(I, Q);
                                scope.Process(I, Q);
                            }
                        }
                    }
                }
            }
        }