1 /* 2 * oscilloscope.h 3 * 4 * Created on: 27 Feb 2020 5 * Author: crocoduck 6 */ 7 8 #ifndef PLUGINS_OSCILLOSCOPE_H_ 9 #define PLUGINS_OSCILLOSCOPE_H_ 10 11 #include <core/plugin.h> 12 #include <metadata/plugins.h> 13 #include <core/util/Bypass.h> 14 #include <core/util/Delay.h> 15 #include <core/util/Oversampler.h> 16 #include <core/util/Trigger.h> 17 #include <core/util/Oscillator.h> 18 #include <core/filters/FilterBank.h> 19 20 namespace lsp 21 { 22 class oscilloscope_base: public plugin_t 23 { 24 protected: 25 26 enum ch_update_t 27 { 28 UPD_SCPMODE = 1 << 0, 29 30 UPD_ACBLOCK_X = 1 << 1, 31 UPD_ACBLOCK_Y = 1 << 2, 32 UPD_ACBLOCK_EXT = 1 << 3, 33 34 UPD_OVERSAMPLER_X = 1 << 4, 35 UPD_OVERSAMPLER_Y = 1 << 5, 36 UPD_OVERSAMPLER_EXT = 1 << 6, 37 38 UPD_XY_RECORD_TIME = 1 << 7, 39 40 UPD_HOR_SCALES = 1 << 8, 41 42 UPD_PRETRG_DELAY = 1 << 9, 43 44 UPD_SWEEP_GENERATOR = 1 << 10, 45 46 UPD_VER_SCALES = 1 << 11, 47 48 UPD_TRIGGER_INPUT = 1 << 12, 49 UPD_TRIGGER_HOLD = 1 << 13, 50 UPD_TRIGGER = 1 << 14, 51 UPD_TRGGER_RESET = 1 << 15 52 }; 53 54 enum ch_mode_t 55 { 56 CH_MODE_XY, 57 CH_MODE_TRIGGERED, 58 CH_MODE_GONIOMETER, 59 60 CH_MODE_DFL = CH_MODE_TRIGGERED 61 }; 62 63 enum ch_sweep_type_t 64 { 65 CH_SWEEP_TYPE_SAWTOOTH, 66 CH_SWEEP_TYPE_TRIANGULAR, 67 CH_SWEEP_TYPE_SINE, 68 69 CH_SWEEP_TYPE_DFL = CH_SWEEP_TYPE_SAWTOOTH 70 }; 71 72 enum ch_trg_input_t 73 { 74 CH_TRG_INPUT_Y, 75 CH_TRG_INPUT_EXT, 76 77 CH_TRG_INPUT_DFL = CH_TRG_INPUT_Y 78 }; 79 80 enum ch_coupling_t 81 { 82 CH_COUPLING_AC, 83 CH_COUPLING_DC, 84 85 CH_COUPLING_DFL = CH_COUPLING_DC 86 }; 87 88 enum ch_state_t 89 { 90 CH_STATE_LISTENING, 91 CH_STATE_SWEEPING 92 }; 93 94 typedef struct dc_block_t 95 { 96 float fAlpha; 97 float fGain; 98 } dc_block_t; 99 100 typedef struct ch_state_stage_t 101 { 102 size_t nPV_pScpMode; 103 104 size_t nPV_pCoupling_x; 105 size_t nPV_pCoupling_y; 106 size_t nPV_pCoupling_ext; 107 size_t nPV_pOvsMode; 108 109 size_t nPV_pTrgInput; 110 float fPV_pVerDiv; 111 float fPV_pVerPos; 112 float fPV_pTrgLevel; 113 float fPV_pTrgHys; 114 size_t nPV_pTrgMode; 115 float fPV_pTrgHold; 116 size_t nPV_pTrgType; 117 118 float fPV_pTimeDiv; 119 float fPV_pHorDiv; 120 float fPV_pHorPos; 121 122 size_t nPV_pSweepType; 123 124 float fPV_pXYRecordTime; 125 } ch_state_stage_t; 126 127 typedef struct channel_t 128 { 129 ch_mode_t enMode; 130 ch_sweep_type_t enSweepType; 131 ch_trg_input_t enTrgInput; 132 ch_coupling_t enCoupling_x; 133 ch_coupling_t enCoupling_y; 134 ch_coupling_t enCoupling_ext; 135 136 FilterBank sDCBlockBank_x; 137 FilterBank sDCBlockBank_y; 138 FilterBank sDCBlockBank_ext; 139 140 over_mode_t enOverMode; 141 size_t nOversampling; 142 size_t nOverSampleRate; 143 144 Oversampler sOversampler_x; 145 Oversampler sOversampler_y; 146 Oversampler sOversampler_ext; 147 148 Delay sPreTrgDelay; 149 150 Trigger sTrigger; 151 152 Oscillator sSweepGenerator; 153 154 float *vTemp; 155 float *vData_x; 156 float *vData_y; 157 float *vData_ext; 158 float *vData_y_delay; 159 float *vDisplay_x; 160 float *vDisplay_y; 161 float *vDisplay_s; // Strobe 162 163 float *vIDisplay_x; 164 float *vIDisplay_y; 165 size_t nIDisplay; 166 167 size_t nDataHead; 168 size_t nDisplayHead; 169 size_t nSamplesCounter; 170 bool bClearStream; 171 172 size_t nPreTrigger; 173 size_t nSweepSize; 174 175 float fVerStreamScale; 176 float fVerStreamOffset; 177 178 size_t nXYRecordSize; 179 float fHorStreamScale; 180 float fHorStreamOffset; 181 182 bool bAutoSweep; 183 size_t nAutoSweepLimit; 184 size_t nAutoSweepCounter; 185 186 ch_state_t enState; 187 188 size_t nUpdate; 189 ch_state_stage_t sStateStage; 190 bool bUseGlobal; 191 bool bFreeze; 192 bool bVisible; 193 194 float *vIn_x; 195 float *vIn_y; 196 float *vIn_ext; 197 198 float *vOut_x; 199 float *vOut_y; 200 201 IPort *pIn_x; 202 IPort *pIn_y; 203 IPort *pIn_ext; 204 205 IPort *pOut_x; 206 IPort *pOut_y; 207 208 IPort *pOvsMode; 209 IPort *pScpMode; 210 IPort *pCoupling_x; 211 IPort *pCoupling_y; 212 IPort *pCoupling_ext; 213 214 IPort *pSweepType; 215 IPort *pTimeDiv; 216 IPort *pHorDiv; 217 IPort *pHorPos; 218 219 IPort *pVerDiv; 220 IPort *pVerPos; 221 222 IPort *pTrgHys; 223 IPort *pTrgLev; 224 IPort *pTrgHold; 225 IPort *pTrgMode; 226 IPort *pTrgType; 227 IPort *pTrgInput; 228 IPort *pTrgReset; 229 230 IPort *pGlobalSwitch; 231 IPort *pFreezeSwitch; 232 IPort *pSoloSwitch; 233 IPort *pMuteSwitch; 234 235 IPort *pStream; 236 } channel_t; 237 238 protected: 239 dc_block_t sDCBlockParams; 240 size_t nChannels; 241 channel_t *vChannels; 242 uint8_t *pData; 243 244 // Common Controls 245 IPort *pStrobeHistSize; 246 IPort *pXYRecordTime; 247 IPort *pFreeze; 248 249 // Channel Selector 250 IPort *pChannelSelector; 251 252 // Global ports: 253 IPort *pOvsMode; 254 IPort *pScpMode; 255 IPort *pCoupling_x; 256 IPort *pCoupling_y; 257 IPort *pCoupling_ext; 258 259 IPort *pSweepType; 260 IPort *pTimeDiv; 261 IPort *pHorDiv; 262 IPort *pHorPos; 263 264 IPort *pVerDiv; 265 IPort *pVerPos; 266 267 IPort *pTrgHys; 268 IPort *pTrgLev; 269 IPort *pTrgHold; 270 IPort *pTrgMode; 271 IPort *pTrgType; 272 IPort *pTrgInput; 273 IPort *pTrgReset; 274 275 float_buffer_t *pIDisplay; // Inline display buffer 276 277 protected: 278 over_mode_t get_oversampler_mode(size_t portValue); 279 ch_mode_t get_scope_mode(size_t portValue); 280 ch_sweep_type_t get_sweep_type(size_t portValue); 281 ch_trg_input_t get_trigger_input(size_t portValue); 282 ch_coupling_t get_coupling_type(size_t portValue); 283 trg_mode_t get_trigger_mode(size_t portValue); 284 trg_type_t get_trigger_type(size_t portValue); 285 286 protected: 287 void update_dc_block_filter(FilterBank &rFilterBank); 288 void reconfigure_dc_block_filters(); 289 void do_sweep_step(channel_t *c, float strobe_value); 290 float *select_trigger_input(float *extPtr, float* yPtr, ch_trg_input_t input); 291 inline void set_oversampler(Oversampler &over, over_mode_t mode); 292 inline void set_sweep_generator(channel_t *c); 293 inline void configure_oversamplers(channel_t *c, over_mode_t mode); 294 void init_state_stage(channel_t *c); 295 void commit_staged_state_change(channel_t *c); 296 bool graph_stream(channel_t *c); 297 298 public: 299 explicit oscilloscope_base(const plugin_metadata_t &metadata, size_t channels); 300 virtual ~oscilloscope_base(); 301 302 public: 303 virtual void init(IWrapper *wrapper); 304 virtual void destroy(); 305 306 virtual void update_settings(); 307 virtual void update_sample_rate(long sr); 308 309 virtual void process(size_t samples); 310 311 virtual void dump(IStateDumper *v) const; 312 313 virtual bool inline_display(ICanvas *cv, size_t width, size_t height); 314 }; 315 316 class oscilloscope_x1: public oscilloscope_base, public oscilloscope_x1_metadata 317 { 318 public: 319 oscilloscope_x1(); 320 virtual ~oscilloscope_x1(); 321 }; 322 323 class oscilloscope_x2: public oscilloscope_base, public oscilloscope_x2_metadata 324 { 325 public: 326 oscilloscope_x2(); 327 virtual ~oscilloscope_x2(); 328 }; 329 330 class oscilloscope_x4: public oscilloscope_base, public oscilloscope_x4_metadata 331 { 332 public: 333 oscilloscope_x4(); 334 virtual ~oscilloscope_x4(); 335 }; 336 } 337 338 #endif /* PLUGINS_OSCILLOSCOPE_H_ */ 339