public AudioResource(SpectrumVideoDemodConfig config, CanvasContext ctx) { //Set this.label = config.label; //Get demodulator switch (config.demodType) { case "WBFM": demodulator = new WbFmDemodulator(); break; default: throw new Exception("Unknown demodulator type."); } //Make buffers bufferSize = ctx.BufferSize; generalBuffer = UnsafeBuffer.Create(ctx.BufferSize, out generalBufferComplexPtr); generalBufferFloatPtr = (float *)generalBufferComplexPtr; audioABuffer = UnsafeBuffer.Create(ctx.BufferSize, out audioABufferPtr); audioBBuffer = UnsafeBuffer.Create(ctx.BufferSize, out audioBBufferPtr); //Init audio demodDecimator = ComplexDecimator.CalculateDecimator(ctx.DecimatedSampleRate, config.demodBandwidth, 20, config.demodBandwidth * 0.05f, out float demodSampleRate); float actualAudioRate = demodulator.Configure(ctx.BufferSize, demodSampleRate, config.outputSampleRate); audioResampler = new ArbitraryStereoResampler(actualAudioRate, config.outputSampleRate, ctx.BufferSize); //Create output output = ctx.OutputProvider.GetAudioOutput(config.outputFilename, config.outputSampleRate, bufferSize); }
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(); }
public ViewGenerator(SavedViewData info, int bufferSize, float sampleRate) { //Set this.info = info; this.bufferSize = bufferSize; //Configure offset mutator = new DownConverter(1); mutator.SampleRate = sampleRate; mutator.Frequency = info.offset; //Configure decimator decimator = new ComplexDecimator(sampleRate, sampleRate / info.decimation, (int)info.decimation); sampleRate /= info.decimation; //Get component list and image size components = info.CreateComponents(sampleRate, out width, out height); //Find out what workers are required foreach (var c in components) { fftRequired = fftRequired || c.RequiresFft; demodulatorRequired = demodulatorRequired || c.RequiresAudio; } //Create these workers if (fftRequired) { fft = new FFTProcessorComplex(info.fftSize); } if (demodulatorRequired) { //Set up decimator audioDecimationRate = DecimationUtil.CalculateDecimationRate(sampleRate, info.audioBandwidth, out audioOutputRate); audioDecimator = new ComplexDecimator(sampleRate, info.audioBandwidth, audioDecimationRate); //Set up demodulator demodulator = new WbFmDemodulator(); demodulator.Configure(bufferSize, audioOutputRate); } //Initialize all foreach (var c in components) { c.Init(info, fft, demodulator); } //Create buffers iqBuffer = UnsafeBuffer.Create(bufferSize, sizeof(Complex)); iqPtr = (Complex *)iqBuffer; }
protected override void PrepareBenchmark(int sampleRate, int bufferSize) { //Create buffers iqBuffer = UnsafeBuffer.Create(bufferSize, out iqBufferPtr); audioABuffer = UnsafeBuffer.Create(bufferSize, out audioABufferPtr); audioBBuffer = UnsafeBuffer.Create(bufferSize, out audioBBufferPtr); //Create IQ decimator decimator = ComplexDecimator.CalculateDecimator(sampleRate, bandwidth, 15, bandwidth * 0.05f, out float decimatedIqRate); //Create demodulator demod = new WbFmDemodulator(); demod.Configure(bufferSize, sampleRate, DecimationUtil.CalculateDecimationRate(decimatedIqRate, outputRateTarget, out float actualOutputRate)); demod.UseRds(); }