ngscopeclient v0.1-rc1
TestWaveformSource.h
Go to the documentation of this file.
1/***********************************************************************************************************************
2* *
3* libscopehal *
4* *
5* Copyright (c) 2012-2025 Andrew D. Zonenberg and contributors *
6* All rights reserved. *
7* *
8* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the *
9* following conditions are met: *
10* *
11* * Redistributions of source code must retain the above copyright notice, this list of conditions, and the *
12* following disclaimer. *
13* *
14* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the *
15* following disclaimer in the documentation and/or other materials provided with the distribution. *
16* *
17* * Neither the name of the author nor the names of any contributors may be used to endorse or promote products *
18* derived from this software without specific prior written permission. *
19* *
20* THIS SOFTWARE IS PROVIDED BY THE AUTHORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
21* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL *
22* THE AUTHORS BE HELD LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
23* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR *
24* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
25* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
26* POSSIBILITY OF SUCH DAMAGE. *
27* *
28***********************************************************************************************************************/
29
37#ifndef TestWaveformSource_h
38#define TestWaveformSource_h
39
40#include "VulkanFFTPlan.h"
41#include <random>
42
43struct __attribute__((packed)) DegradeSerialDataPushConstants
44{
45 uint32_t numSamples;
46 uint32_t samplesPerThread;
47 uint32_t rngSeed;
48 uint32_t inputOffset;
49 float scale;
50 float sigma;
51};
52
53struct __attribute__((packed)) NoisySinePushConstants
54{
55 uint32_t numSamples;
56 uint32_t samplesPerThread;
57 uint32_t rngSeed;
58 float startPhase;
59 float scale;
60 float sigma;
61 float radiansPerSample;
62};
63
64struct __attribute__((packed)) NoisySineSumPushConstants
65{
66 uint32_t numSamples;
67 uint32_t samplesPerThread;
68 uint32_t rngSeed;
69 float startPhase1;
70 float startPhase2;
71 float scale;
72 float sigma;
73 float radiansPerSample1;
74 float radiansPerSample2;
75};
76
85{
86public:
87 TestWaveformSource(std::minstd_rand& rng);
88 virtual ~TestWaveformSource();
89
91 TestWaveformSource& operator=(const TestWaveformSource&) =delete;
92
94 vk::raii::CommandBuffer& cmdBuf,
95 std::shared_ptr<QueueHandle> queue,
97 float amplitude,
98 float startphase,
99 float period,
100 int64_t sampleperiod,
101 size_t depth,
102 float noise_stdev = 0.01);
103
105 vk::raii::CommandBuffer& cmdBuf,
106 std::shared_ptr<QueueHandle> queue,
108 float amplitude,
109 float startphase1,
110 float startphase2,
111 float period1,
112 float period2,
113 int64_t sampleperiod,
114 size_t depth,
115 float noise_stdev = 0.01);
116
117 void GeneratePRBS31(
118 vk::raii::CommandBuffer& cmdBuf,
119 std::shared_ptr<QueueHandle> queue,
121 float amplitude,
122 float period,
123 int64_t sampleperiod,
124 size_t depth,
125 bool lpf = true,
126 float noise_stdev = 0.01);
127
128 void Generate8b10b(
129 vk::raii::CommandBuffer& cmdBuf,
130 std::shared_ptr<QueueHandle> queue,
132 float amplitude,
133 float period,
134 int64_t sampleperiod,
135 size_t depth,
136 bool lpf = true,
137 float noise_stdev = 0.01);
138
140 float vlo,
141 float vhi,
142 int64_t sampleperiod,
143 size_t depth);
144
147 int64_t sampleperiod,
148 size_t depth,
149 bool lpf,
150 float noise_stdev,
151 vk::raii::CommandBuffer& cmdBuf,
152 std::shared_ptr<QueueHandle> queue);
153
154protected:
155
157 std::minstd_rand& m_rng;
158
161
164
167
169 std::unique_ptr<VulkanFFTPlan> m_vkForwardPlan;
170
172 std::unique_ptr<VulkanFFTPlan> m_vkReversePlan;
173
176
179
182
185
188
191
194
197
200
203
206
207 void InterpolateSparameters(float bin_hz, size_t nouts);
208};
209
210#endif
Declaration of VulkanFFTPlan.
Encapsulates a Vulkan compute pipeline and all necessary resources to use it.
Definition: ComputePipeline.h:55
A set of S-parameters.
Definition: SParameters.h:201
Helper class for generating test waveforms.
Definition: TestWaveformSource.h:85
WaveformBase * GenerateStep(float vlo, float vhi, int64_t sampleperiod, size_t depth)
Generates a step waveform.
Definition: TestWaveformSource.cpp:95
ComputePipeline m_channelEmulationComputePipeline
Compute pipeline for channel emulation.
Definition: TestWaveformSource.h:187
SParameters m_sparams
S-parameters of the channel.
Definition: TestWaveformSource.h:199
std::unique_ptr< VulkanFFTPlan > m_vkForwardPlan
FFT plan.
Definition: TestWaveformSource.h:169
AcceleratorBuffer< float > m_resampledSparamCosines
Serial channel S-parameter imaginary part.
Definition: TestWaveformSource.h:181
AcceleratorBuffer< float > m_reverseOutBuf
Output buffer for IFFTs.
Definition: TestWaveformSource.h:166
ComputePipeline m_degradeComputePipeline
Compute pipeline for DegradeSerialData.
Definition: TestWaveformSource.h:196
void GenerateNoisySinewave(vk::raii::CommandBuffer &cmdBuf, std::shared_ptr< QueueHandle > queue, UniformAnalogWaveform *wfm, float amplitude, float startphase, float period, int64_t sampleperiod, size_t depth, float noise_stdev=0.01)
Generates a sinewave with AWGN added.
Definition: TestWaveformSource.cpp:130
void Generate8b10b(vk::raii::CommandBuffer &cmdBuf, std::shared_ptr< QueueHandle > queue, UniformAnalogWaveform *wfm, float amplitude, float period, int64_t sampleperiod, size_t depth, bool lpf=true, float noise_stdev=0.01)
Generates a K28.5 D16.2 (1000base-X / SGMII idle) waveform through a lossy channel with AWGN.
Definition: TestWaveformSource.cpp:305
double m_cachedBinSize
FFT bin size, in Hz.
Definition: TestWaveformSource.h:175
size_t m_cachedRawSize
Input size of FFT as of last cache update.
Definition: TestWaveformSource.h:205
ComputePipeline m_noisySineSumComputePipeline
Compute pipeline for noisy sinewave sum generation.
Definition: TestWaveformSource.h:193
std::unique_ptr< VulkanFFTPlan > m_vkReversePlan
Inverse FFT plan.
Definition: TestWaveformSource.h:172
AcceleratorBuffer< float > m_forwardOutBuf
Output buffer for FFTs.
Definition: TestWaveformSource.h:163
ComputePipeline m_noisySineComputePipeline
Compute pipeline for noisy sinewave generation.
Definition: TestWaveformSource.h:190
ComputePipeline m_rectangularComputePipeline
Compute pipeline for our window function.
Definition: TestWaveformSource.h:184
void GenerateNoisySinewaveSum(vk::raii::CommandBuffer &cmdBuf, std::shared_ptr< QueueHandle > queue, UniformAnalogWaveform *wfm, float amplitude, float startphase1, float startphase2, float period1, float period2, int64_t sampleperiod, size_t depth, float noise_stdev=0.01)
Generates a sum of two sinewaves with AWGN added.
Definition: TestWaveformSource.cpp:181
void GeneratePRBS31(vk::raii::CommandBuffer &cmdBuf, std::shared_ptr< QueueHandle > queue, UniformAnalogWaveform *wfm, float amplitude, float period, int64_t sampleperiod, size_t depth, bool lpf=true, float noise_stdev=0.01)
Generates a PRBS-31 waveform through a lossy channel with AWGN.
Definition: TestWaveformSource.cpp:236
void InterpolateSparameters(float bin_hz, size_t nouts)
Recalculate the cached S-parameters used for channel emulation.
Definition: TestWaveformSource.cpp:528
AcceleratorBuffer< float > m_forwardInBuf
Input buffer for FFTs.
Definition: TestWaveformSource.h:160
std::minstd_rand & m_rng
Random number generator.
Definition: TestWaveformSource.h:157
void DegradeSerialData(UniformAnalogWaveform *cap, int64_t sampleperiod, size_t depth, bool lpf, float noise_stdev, vk::raii::CommandBuffer &cmdBuf, std::shared_ptr< QueueHandle > queue)
Takes an idealized serial data stream and turns it into something less pretty.
Definition: TestWaveformSource.cpp:381
size_t m_cachedNumPoints
FFT point count as of last cache update.
Definition: TestWaveformSource.h:202
AcceleratorBuffer< float > m_resampledSparamSines
Serial channel S-parameter real part.
Definition: TestWaveformSource.h:178
A waveform sampled at uniform intervals.
Definition: Waveform.h:371
Base class for all Waveform specializations.
Definition: Waveform.h:59