예제 #1
0
파일: Form1.cs 프로젝트: Roman-Port/LibSDR
        private void Form1_Load(object sender, EventArgs e)
        {
            //Add all entries to the pie graph to start off with
            for (int i = 0; i < 32; i++)
            {
                rdsGroupChart.Series["Groups"].Points.AddXY("", 0);
                rdsGroupChart.Series["Groups"].Points[i].IsVisibleInLegend = false;
            }

            //Configure table
            rdsHistory.Columns.Add(GenerateColumn("PI", 40));
            rdsHistory.Columns.Add(GenerateColumn("Group", 50));
            rdsHistory.Columns.Add(GenerateColumn("Description", -1));

            //Create buffers
            iqBuffer    = UnsafeBuffer.Create(BUFFER_SIZE, out iqBufferPtr);
            audioBuffer = UnsafeBuffer.Create(BUFFER_SIZE, out audioBufferPtr);

            //Open USB device
            usb    = new LibUSBProvider();
            device = AirSpyDevice.OpenDevice(usb);

            //Configure radio
            device.SetLinearGain(gain.Value / 100f);
            device.CenterFrequency = (long)(freq.Value * 1000000);
            device.SampleRate      = 3000000;
            device.StartRx();

            //Create filter
            var filterBuilder = new LowPassFilterBuilder(device.SampleRate, BANDWIDTH / 2)
                                .SetAutomaticTapCount(BANDWIDTH * 0.1f, 50)
                                .SetWindow();

            filter = ComplexFirFilter.CreateFirFilter(filterBuilder, filterBuilder.GetDecimation(out float decimatedSampleRate));

            //Create FM and RDS
            fm = new WbFmDemodulator();
            fm.Configure(BUFFER_SIZE, decimatedSampleRate, 48000);
            fm.OnStereoDetected += Fm_OnStereoDetected;
            fm.OnRdsDetected    += Fm_OnRdsDetected;
            rds = new RdsClient();
            fm.OnRdsFrameEmitted += (ulong frame) => rds.ProcessFrame(frame);

            //Bind RDS client commands
            rds.ProgramService.OnPartialTextReceived += ProgramService_OnPartialTextReceived;
            rds.PiCode.OnPiCodeChanged          += PiCode_OnPiCodeChanged;
            rds.ProgramType.OnCategoryChanged   += ProgramType_OnCategoryChanged;
            rds.RadioText.OnPartialTextReceived += RadioText_OnPartialTextReceived;
            rds.OnCommand += Rds_OnCommand;

            //Create worker thread
            worker = new Thread(WorkerThread);
            worker.IsBackground = true;
            worker.Start();
        }
예제 #2
0
        static void Main(string[] args)
        {
            LibUSBProvider provider = new LibUSBProvider();
            var            testd    = provider.FindDevices(0x1d50, 0x60a1)[0];

            testd.OpenDevice();

            var b     = new LibSDR.Components.IO.USB.UsbBuffer(512);
            int testr = testd.BulkTransfer(LibSDR.Components.IO.USB.UsbTransferDirection.READ, 0x01, b, 1000);


            AirSpyDevice device = AirSpyDevice.OpenDevice(provider);

            device.StartRx();
            device.SampleRate = 10000000;
            //device.SampleRate = 3000000;

            if (true)
            {
                device.CenterFrequency = 93700000;
                device.SetLinearGain(6 / 21f);
            }
            else
            {
                device.CenterFrequency = 144430000;
                device.SetLinearGain(2 / 21f);
            }

            test = new WavFileWriter(new FileStream("F:\\test.wav", FileMode.Create), (int)device.SampleRate, 2, LibSDR.Components.IO.SampleFormat.Short16, 1 << 16);

            UnsafeBuffer buffer = UnsafeBuffer.Create(1 << 16, out Complex * bufferPtr);

            while (true)
            {
                int read = device.Read(bufferPtr, 1 << 16, 1000);
                test.Write(bufferPtr, read);
                test.FinalizeFile();
            }
        }