-
Notifications
You must be signed in to change notification settings - Fork 0
/
Display.cs
4107 lines (3611 loc) · 169 KB
/
Display.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//=================================================================
// Display.cs
//=================================================================
// Copyright (C) 2011,2012 S56A YT7PWR
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//=================================================================
using System;
using System.IO;
using System.Collections;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Imaging;
using System.Threading;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using SlimDX;
using SlimDX.Direct3D9;
using SlimDX.Windows;
namespace CWExpert
{
#region structures
struct Vertex
{
public Vector4 Position;
public int Color;
}
struct DXRectangle
{
public int x1;
public int x2;
public int x3;
public int x4;
public int y1;
public int y2;
public int y3;
public int y4;
}
struct VerticalString
{
public int pos_x;
public int pos_y;
public string label;
public Color color;
}
struct HorizontalString
{
public int pos_x;
public int pos_y;
public string label;
public Color color;
}
#endregion
#if(DirectX)
#region DirectX
static class DX
{
#region Variable Declaration
public static CWExpert MainForm;
public const float CLEAR_FLAG = -999.999F; // for resetting buffers
public const int BUFFER_SIZE = 4096;
public static float[] new_display_data; // Buffer used to store the new data from the DSP for the display
public static float[] new_waterfall_data; // Buffer used to store the new data from the DSP for the waterfall
public static float[] current_display_data; // Buffer used to store the current data for the display
public static float[] current_waterfall_data; // Buffer used to store the current data for the scope
public static float[] waterfall_display_data; // Buffer for waterfall
public static float[] average_buffer; // Averaged display data buffer for Panadapter
public static float[] average_waterfall_buffer; // Averaged display data buffer for Waterfall
public static float[] peak_buffer; // Peak hold display data buffer
public static string background_image = ".\\picDisplay.png";
public static bool SDRmode = false;
private static SlimDX.Direct3D9.Device device = null;
private static Texture PanadapterTexture = null;
private static Texture WaterfallTexture = null;
private static Sprite Panadapter_Sprite = null;
private static Sprite Waterfall_Sprite = null;
private static Rectangle Panadapter_texture_size;
private static Rectangle Waterfall_texture_size;
private static AutoResetEvent Panadapter_Event;
private static AutoResetEvent Waterfall_Event;
private static DXRectangle VFOArect;
private static DXRectangle VFOBrect;
private static VertexBuffer VerLine_vb = null;
private static VertexBuffer HorLine_vb = null;
private static VertexBuffer VerLines_vb = null;
private static VertexBuffer HorLines_vb = null;
private static VertexBuffer PanLine_vb = null;
private static VertexBuffer PanLine_vb_fill = null;
private static Vertex[] PanLine_verts = null;
private static Vertex[] PanLine_verts_fill = null;
private static Vertex[] ScopeLine_verts = null;
private static VertexBuffer ScopeLine_vb = null;
private static VertexBuffer ScopeLine_vb_monitor = null;
private static float[] waterfallX_data = null;
private static float[] panadapterX_data = null;
private static float[] panadapterX_scope_data = null;
private static float[] panadapterX_scope_data_mark = null;
private static float[] panadapterX_scope_data_space = null;
private static Bitmap waterfall_bmp = null;
private static Device waterfall_dx_device = null;
public static TuneMode tuning_mode = TuneMode.Off;
private static byte[] waterfall_memory;
private static int waterfall_bmp_size;
private static int waterfall_bmp_stride;
private static DataStream waterfall_data_stream;
private static Rectangle waterfall_rect;
private static Mutex RenderMutex = new Mutex();
#endregion
#region Properties
private static DisplayMode display_mode = DisplayMode.PANAFALL;
public static DisplayMode DisplayMode
{
get { return display_mode; }
set
{
RenderMutex.WaitOne();
display_mode = value;
RenderMutex.ReleaseMutex();
}
}
private static RenderType directx_render_type = RenderType.HARDWARE;
public static RenderType DirectXRenderType
{
get { return directx_render_type; }
set { directx_render_type = value; }
}
private static bool reverse_waterfall = false;
public static bool ReverseWaterfall
{
get { return reverse_waterfall; }
set { reverse_waterfall = value; }
}
private static double losc_hz;
public static double LOSC
{
get { return losc_hz; }
set { losc_hz = value; }
}
private static double vfoa_hz;
public static double VFOA
{
get { return vfoa_hz; }
set { vfoa_hz = value; }
}
private static double vfoa_hz_mark;
public static double VFOA_MARK
{
get { return vfoa_hz_mark; }
set { vfoa_hz_mark = value; }
}
private static double vfoa_hz_space;
public static double VFOA_SPACE
{
get { return vfoa_hz_space; }
set { vfoa_hz_space = value; }
}
private static double vfob_hz;
public static double VFOB
{
get { return vfob_hz; }
set { vfob_hz = value; }
}
private static double vfob_hz_mark;
public static double VFOB_MARK
{
get { return vfob_hz_mark; }
set { vfob_hz_mark = value; }
}
private static double vfob_hz_space;
public static double VFOB_SPACE
{
get { return vfob_hz_space; }
set { vfob_hz_space = value; }
}
private static float[] scope_min;
public static float[] ScopeMin
{
get { return scope_min; }
set { scope_min = value; }
}
private static float[] scope_max;
public static float[] ScopeMax
{
get { return scope_max; }
set { scope_max = value; }
}
private static float[] scope_min_mark;
public static float[] ScopeMinMark
{
get { return scope_min_mark; }
set { scope_min_mark = value; }
}
private static float[] scope_max_mark;
public static float[] ScopeMaxMark
{
get { return scope_max_mark; }
set { scope_max_mark = value; }
}
private static float[] scope_min_space;
public static float[] ScopeMinSpace
{
get { return scope_min_space; }
set { scope_min_space = value; }
}
private static float[] scope_max_space;
public static float[] ScopeMaxSpace
{
get { return scope_max_space; }
set { scope_max_space = value; }
}
private static bool refresh_panadapter_grid = false;
public static bool RefreshPanadapterGrid
{
set { refresh_panadapter_grid = value; }
}
public static bool smooth_line = false;
public static bool pan_fill = false;
private static System.Drawing.Font pan_font = new System.Drawing.Font("System", 10);
public static System.Drawing.Font PanFont
{
get { return pan_font; }
set
{
pan_font = value;
refresh_panadapter_grid = true;
if (!MainForm.booting)
{
if (panadapter_font != null)
panadapter_font.Dispose();
panadapter_font = new SlimDX.Direct3D9.Font(device, pan_font);
}
}
}
private static SlimDX.Direct3D9.Font panadapter_font = null;
public static SlimDX.Direct3D9.Font PanadapterFont
{
get { return panadapter_font; }
set
{
panadapter_font = value;
}
}
private static Color pan_fill_color = Color.FromArgb(100, 0, 0, 127);
public static Color PanFillColor
{
get { return pan_fill_color; }
set { pan_fill_color = value; }
}
private static Color display_text_background = Color.FromArgb(255, 127, 127, 127);
public static Color DisplayTextBackground
{
get { return display_text_background; }
set { display_text_background = value; }
}
private static Color display_filter_color = Color.FromArgb(65, 255, 255, 255);
public static Color DisplayFilterColor
{
get { return display_filter_color; }
set { display_filter_color = value; }
}
private static bool show_horizontal_grid = true;
public static bool Show_Horizontal_Grid
{
set
{
show_horizontal_grid = value;
refresh_panadapter_grid = true;
}
}
private static bool show_vertical_grid = true;
public static bool Show_Vertical_Grid
{
set
{
show_vertical_grid = value;
refresh_panadapter_grid = true;
}
}
private static int waterfall_update_period = 50; // in ms
public static int WaterfallUpdatePeriod
{
get { return waterfall_update_period; }
set { waterfall_update_period = value; }
}
private static Color main_rx_zero_line_color = Color.LightSkyBlue;
public static Color MainRXZeroLine
{
get { return main_rx_zero_line_color; }
set
{
main_rx_zero_line_color = value;
}
}
private static Color sub_rx_zero_line_color = Color.LightSkyBlue;
public static Color SubRXZeroLine
{
get { return sub_rx_zero_line_color; }
set
{
sub_rx_zero_line_color = value;
}
}
private static Color main_rx_filter_color = Color.FromArgb(100, 0, 100, 100); // green
public static Color MainRXFilterColor
{
get { return main_rx_filter_color; }
set
{
main_rx_filter_color = value;
}
}
private static Color second_rx_filter_color = Color.FromArgb(100, 0, 0, 255); // blue
public static Color SecondRXFilterColor
{
get { return second_rx_filter_color; }
set
{
second_rx_filter_color = value;
}
}
private static bool rx2_enabled = false;
public static bool RX2Enabled
{
get { return rx2_enabled; }
set
{
rx2_enabled = value;
}
}
private static bool split_enabled = false;
public static bool SplitEnabled
{
get { return split_enabled; }
set
{
split_enabled = value;
}
}
private static bool show_freq_offset = false;
public static bool ShowFreqOffset
{
get { return show_freq_offset; }
set
{
show_freq_offset = value;
}
}
private static Color band_edge_color = Color.Red;
public static Color BandEdgeColor
{
get { return band_edge_color; }
set
{
band_edge_color = value;
}
}
public static bool panadapter_target_focused = false;
private static int panadapter_H = 0; // target height
private static int panadapter_W = 0; // target width
private static Control panadapter_target = null;
public static Control PanadapterTarget
{
get { return panadapter_target; }
set
{
panadapter_target = value;
panadapter_H = panadapter_target.Height;
panadapter_W = panadapter_target.Width;
}
}
public static bool waterfall_target_focused = false;
private static int waterfall_H = 0; // target height
private static int waterfall_W = 0; // target width
private static Control waterfall_target = null;
public static Control WaterfallTarget
{
get { return waterfall_target; }
set
{
waterfall_target = value;
waterfall_H = waterfall_target.Height;
waterfall_W = waterfall_target.Width;
}
}
private static double rx_display_low = 0;
public static double RXDisplayLow
{
get { return rx_display_low; }
set
{
rx_display_low = value;
refresh_panadapter_grid = true;
}
}
private static double rx_display_high = 2000;
public static double RXDisplayHigh
{
get { return rx_display_high; }
set
{
rx_display_high = value;
refresh_panadapter_grid = true;
}
}
private static float preamp_offset = 0.0f;
public static float PreampOffset
{
get { return preamp_offset; }
set { preamp_offset = value; }
}
private static float display_cal_offset; // display calibration offset per volume setting in dB
public static float DisplayCalOffset
{
get { return display_cal_offset; }
set { display_cal_offset = value; }
}
private static int display_cursor_x; // x-coord of the cursor when over the display
public static int DisplayCursorX
{
get { return display_cursor_x; }
set { display_cursor_x = value; }
}
private static int rtty_cursor_x1; // RTTY cursor when over the display
public static int RTTYCursorX1
{
get { return rtty_cursor_x1; }
set { rtty_cursor_x1 = value; }
}
private static int rtty_cursor_x2; // RTTY cursor when over the display
public static int RTTYCursorX2
{
get { return rtty_cursor_x2; }
set { rtty_cursor_x2 = value; }
}
private static int display_cursor_y; // y-coord of the cursor when over the display
public static int DisplayCursorY
{
get { return display_cursor_y; }
set { display_cursor_y = value; }
}
private static int scope_time = 50;
public static int ScopeTime
{
get { return scope_time; }
set { scope_time = value; }
}
private static int sample_rate = 48000;
public static int SampleRate
{
get { return sample_rate; }
set { sample_rate = value; }
}
private static bool high_swr = false;
public static bool HighSWR
{
get { return high_swr; }
set { high_swr = value; }
}
private static bool mox = false;
public static bool MOX
{
get { return mox; }
set { mox = value; }
}
private static float max_x; // x-coord of maxmimum over one display pass
public static float MaxX
{
get { return max_x; }
set { max_x = value; }
}
private static float scope_max_x; // x-coord of maxmimum over one display pass
public static float ScopeMaxX
{
get { return scope_max_x; }
set { scope_max_x = value; }
}
private static float max_y; // y-coord of maxmimum over one display pass
public static float MaxY
{
get { return max_y; }
set { max_y = value; }
}
private static float scope_max_y; // y-coord of maxmimum over one display pass
public static float ScopeMaxY
{
get { return scope_max_y; }
set { scope_max_y = value; }
}
private static bool average_on = false; // True if the Average button is pressed
public static bool AverageOn
{
get { return average_on; }
set
{
average_on = value;
if (!average_on) ResetDisplayAverage();
}
}
private static bool data_ready = false; // True when there is new display data ready from the DSP
public static bool DataReady
{
get { return data_ready; }
set { data_ready = value; }
}
private static bool waterfall_data_ready; // True when there is new display data ready from the DSP
public static bool WaterfallDataReady
{
get { return waterfall_data_ready; }
set { waterfall_data_ready = value; }
}
public static float display_avg_mult_old = 1 - (float)1 / 2;
public static float display_avg_mult_new = (float)1 / 2;
private static int display_avg_num_blocks = 100;
public static int DisplayAvgBlocks
{
get { return display_avg_num_blocks; }
set
{
display_avg_num_blocks = value;
display_avg_mult_old = 1 - (float)1 / display_avg_num_blocks;
display_avg_mult_new = (float)1 / display_avg_num_blocks;
}
}
public static float waterfall_avg_mult_old = 1 - (float)1 / 18;
public static float waterfall_avg_mult_new = (float)1 / 18;
private static int waterfall_avg_num_blocks = 18;
public static int WaterfallAvgBlocks
{
get { return waterfall_avg_num_blocks; }
set
{
waterfall_avg_num_blocks = value;
waterfall_avg_mult_old = 1 - (float)1 / waterfall_avg_num_blocks;
waterfall_avg_mult_new = (float)1 / waterfall_avg_num_blocks;
}
}
private static int spectrum_grid_max = -50;
public static int SpectrumGridMax
{
get { return spectrum_grid_max; }
set
{
spectrum_grid_max = value;
refresh_panadapter_grid = true;
}
}
private static int spectrum_grid_min = -150;
public static int SpectrumGridMin
{
get { return spectrum_grid_min; }
set
{
spectrum_grid_min = value;
refresh_panadapter_grid = true;
}
}
private static int spectrum_grid_step = 10;
public static int SpectrumGridStep
{
get { return spectrum_grid_step; }
set
{
spectrum_grid_step = value;
refresh_panadapter_grid = true;
}
}
private static Color grid_text_color = Color.Yellow;
public static Color GridTextColor
{
get { return grid_text_color; }
set
{
grid_text_color = value;
refresh_panadapter_grid = true;
}
}
private static Color grid_zero_color = Color.Red;
public static Color GridZeroColor
{
get { return grid_zero_color; }
set
{
grid_zero_color = value;
}
}
private static Color grid_color = Color.FromArgb(30, Color.Blue);
public static Color GridColor
{
get { return grid_color; }
set
{
grid_color = Color.FromArgb(50, value);
refresh_panadapter_grid = true;
}
}
private static Pen data_line_pen = new Pen(new SolidBrush(Color.WhiteSmoke), display_line_width);
private static Color data_line_color = Color.WhiteSmoke;
public static Color DataLineColor
{
get { return data_line_color; }
set
{
data_line_color = value;
data_line_pen = new Pen(new SolidBrush(data_line_color), display_line_width);
}
}
private static Color display_filter_tx_color = Color.Yellow;
public static Color DisplayFilterTXColor
{
get { return display_filter_tx_color; }
set
{
display_filter_tx_color = value;
}
}
private static bool draw_tx_filter = false;
public static bool DrawTXFilter
{
get { return draw_tx_filter; }
set
{
draw_tx_filter = value;
}
}
private static bool draw_tx_cw_freq = false;
public static bool DrawTXCWFreq
{
get { return draw_tx_cw_freq; }
set
{
draw_tx_cw_freq = value;
}
}
private static Color display_background_color = Color.Black;
public static Color DisplayBackgroundColor
{
get { return display_background_color; }
set
{
display_background_color = value;
}
}
private static Color waterfall_low_color = Color.Black;
public static Color WaterfallLowColor
{
get { return waterfall_low_color; }
set { waterfall_low_color = value; }
}
private static Color waterfall_mid_color = Color.Red;
public static Color WaterfallMidColor
{
get { return waterfall_mid_color; }
set { waterfall_mid_color = value; }
}
private static Color waterfall_high_color = Color.Pink;
public static Color WaterfallHighColor
{
get { return waterfall_high_color; }
set { waterfall_high_color = value; }
}
private static float waterfall_high_threshold = 200.0F;
public static float WaterfallHighThreshold
{
get { return waterfall_high_threshold; }
set { waterfall_high_threshold = value; }
}
private static float waterfall_low_threshold = -200.0F;
public static float WaterfallLowThreshold
{
get { return waterfall_low_threshold; }
set { waterfall_low_threshold = value; }
}
private static float display_line_width = 1.0F;
public static float DisplayLineWidth
{
get { return display_line_width; }
set
{
display_line_width = value;
data_line_pen = new Pen(new SolidBrush(data_line_color), display_line_width);
}
}
#endregion
#region Misc routine
public static void ResetDisplayAverage()
{
if (average_buffer != null)
{
average_buffer[0] = CLEAR_FLAG; // set reset flag
average_waterfall_buffer[0] = CLEAR_FLAG;
}
}
#endregion
#region Routines
public static void WaterfallInit()
{
average_waterfall_buffer = new float[BUFFER_SIZE]; // initialize averaging buffer array
average_waterfall_buffer[0] = CLEAR_FLAG; // set the clear flag
new_waterfall_data = new float[BUFFER_SIZE];
current_waterfall_data = new float[BUFFER_SIZE];
waterfall_display_data = new float[BUFFER_SIZE];
for (int i = 0; i < BUFFER_SIZE; i++)
{
new_waterfall_data[i] = -200.0f;
current_waterfall_data[i] = -200.0f;
waterfall_display_data[i] = -200.0f;
}
waterfall_bmp = new Bitmap(waterfall_target.Width, waterfall_target.Height,
System.Drawing.Imaging.PixelFormat.Format24bppRgb);
}
public static bool DirectXInit()
{
if (!MainForm.booting)
{
try
{
if (!MainForm.booting)
{
rendering = false;
switch (display_mode)
{
case DisplayMode.PANADAPTER:
case DisplayMode.PANAFALL:
case DisplayMode.PANASCOPE:
panadapter_target = (Control)MainForm.picPanadapter;
panadapter_W = panadapter_target.Width;
panadapter_H = panadapter_target.Height;
waterfall_target = (Control)MainForm.picWaterfall;
waterfall_H = waterfall_target.Height;
waterfall_W = waterfall_target.Width;
waterfallX_data = new float[waterfall_W];
panadapterX_scope_data = new float[waterfall_W * 2];
panadapterX_scope_data_mark = new float[waterfall_W * 2];
panadapterX_scope_data_space = new float[waterfall_W * 2];
Audio.ScopeDisplayWidth = waterfall_W;
break;
case DisplayMode.PANAFALL_INV:
case DisplayMode.PANASCOPE_INV:
panadapter_target = (Control)MainForm.picWaterfall;
panadapter_W = panadapter_target.Width;
panadapter_H = panadapter_target.Height;
waterfall_target = (Control)MainForm.picPanadapter;
waterfall_H = waterfall_target.Height;
waterfall_W = waterfall_target.Width;
waterfallX_data = new float[waterfall_W];
panadapterX_scope_data = new float[waterfall_W * 2];
Audio.ScopeDisplayWidth = waterfall_W;
break;
case DisplayMode.WATERFALL:
waterfall_target = (Control)MainForm.picWaterfall;
break;
default:
panadapter_H = panadapter_target.Height;
panadapter_W = panadapter_target.Width;
panadapterX_scope_data = new float[panadapter_W];
panadapter_target = (Control)MainForm.picPanadapter;
break;
}
panadapterX_data = new float[panadapter_target.Width];
refresh_panadapter_grid = true;
average_buffer = new float[BUFFER_SIZE]; // initialize averaging buffer array
average_buffer[0] = CLEAR_FLAG; // set the clear flag
average_waterfall_buffer = new float[BUFFER_SIZE]; // initialize averaging buffer array
average_waterfall_buffer[0] = CLEAR_FLAG; // set the clear flag
peak_buffer = new float[BUFFER_SIZE];
peak_buffer[0] = CLEAR_FLAG;
new_display_data = new float[BUFFER_SIZE];
new_waterfall_data = new float[BUFFER_SIZE];
current_display_data = new float[BUFFER_SIZE];
current_waterfall_data = new float[BUFFER_SIZE];
waterfall_display_data = new float[BUFFER_SIZE];
for (int i = 0; i < BUFFER_SIZE; i++)
{
new_display_data[i] = 0.0f;
new_waterfall_data[i] = 0.0f;
current_display_data[i] = 0.0f;
current_waterfall_data[i] = 0.0f;
waterfall_display_data[i] = 0.0f;
}
PresentParameters presentParms = new PresentParameters();
presentParms.Windowed = true;
presentParms.SwapEffect = SwapEffect.Discard;
presentParms.BackBufferFormat = SlimDX.Direct3D9.Format.Unknown;
presentParms.BackBufferHeight = panadapter_target.Height;
presentParms.BackBufferWidth = panadapter_target.Width;
presentParms.BackBufferCount = 1;
presentParms.BackBufferFormat = Format.X8R8G8B8;
PresentParameters waterfall_presentParms = new PresentParameters();
waterfall_presentParms.Windowed = true;
waterfall_presentParms.SwapEffect = SwapEffect.Discard;
waterfall_presentParms.BackBufferFormat = SlimDX.Direct3D9.Format.Unknown;
waterfall_presentParms.BackBufferHeight = waterfall_target.Height;
waterfall_presentParms.BackBufferWidth = waterfall_target.Width;
waterfall_presentParms.BackBufferCount = 1;
waterfall_presentParms.BackBufferFormat = Format.X8R8G8B8;
switch (directx_render_type)
{
case RenderType.HARDWARE:
try
{
device = new Device(new Direct3D(), 0, DeviceType.Hardware,
panadapter_target.Handle, CreateFlags.HardwareVertexProcessing |
CreateFlags.FpuPreserve | CreateFlags.Multithreaded, presentParms);
waterfall_dx_device = new Device(new Direct3D(), 0,
DeviceType.Hardware, waterfall_target.Handle,
CreateFlags.HardwareVertexProcessing | CreateFlags.FpuPreserve |
CreateFlags.Multithreaded, waterfall_presentParms);
}
catch (Direct3D9Exception ex)
{
MessageBox.Show("DirectX hardware init error!" + ex.ToString());
}
break;
case RenderType.SOFTWARE:
{
try
{
device = new Device(new Direct3D(), 0,
DeviceType.Hardware,
panadapter_target.Handle, CreateFlags.SoftwareVertexProcessing |
CreateFlags.FpuPreserve, presentParms);
waterfall_dx_device = new Device(new Direct3D(), 0,
DeviceType.Hardware, waterfall_target.Handle,
CreateFlags.SoftwareVertexProcessing | CreateFlags.FpuPreserve,
waterfall_presentParms);
}
catch (Direct3D9Exception ex)
{
MessageBox.Show("DirectX software init error!\n" + ex.ToString());
return false;
}
}
break;
}
var vertexElems = new[] {
new VertexElement(0, 0, DeclarationType.Float4, DeclarationMethod.Default, DeclarationUsage.PositionTransformed, 0),
new VertexElement(0, 16, DeclarationType.Color, DeclarationMethod.Default, DeclarationUsage.Color, 0),
VertexElement.VertexDeclarationEnd
};
var vertexElems1 = new[] {
new VertexElement(0, 0, DeclarationType.Float4, DeclarationMethod.Default, DeclarationUsage.PositionTransformed, 0),
new VertexElement(0, 16, DeclarationType.Color, DeclarationMethod.Default, DeclarationUsage.Color, 0),
VertexElement.VertexDeclarationEnd
};
var vertexDecl = new VertexDeclaration(device, vertexElems);
device.VertexDeclaration = vertexDecl;
var vertexDecl1 = new VertexDeclaration(waterfall_dx_device, vertexElems1);
waterfall_dx_device.VertexDeclaration = vertexDecl1;
waterfall_bmp = new System.Drawing.Bitmap(waterfall_target.Width, waterfall_target.Height,
System.Drawing.Imaging.PixelFormat.Format32bppPArgb);
BitmapData bitmapData = waterfall_bmp.LockBits(
new Rectangle(0, 0, waterfall_bmp.Width, waterfall_bmp.Height),
ImageLockMode.ReadWrite, waterfall_bmp.PixelFormat);
waterfall_bmp_size = bitmapData.Stride * waterfall_bmp.Height;
waterfall_bmp_stride = bitmapData.Stride;
waterfall_memory = new byte[waterfall_bmp_size];
waterfall_bmp.UnlockBits(bitmapData);
waterfall_rect = new Rectangle(0, 0, waterfall_target.Width, waterfall_target.Height);
panadapter_font = new SlimDX.Direct3D9.Font(device, pan_font);
if (File.Exists(background_image))
{
PanadapterTexture = Texture.FromFile(device, background_image, panadapter_target.Width, panadapter_target.Height,
1, Usage.None, Format.Unknown, Pool.Managed, SlimDX.Direct3D9.Filter.Default, SlimDX.Direct3D9.Filter.Default, 0);
Panadapter_texture_size.Width = panadapter_target.Width;
Panadapter_texture_size.Height = panadapter_target.Height;
Panadapter_Sprite = new Sprite(device);
WaterfallTexture = Texture.FromFile(waterfall_dx_device, background_image, waterfall_target.Width, waterfall_target.Height,
1, Usage.None, Format.X8R8G8B8, Pool.Managed, SlimDX.Direct3D9.Filter.Default, SlimDX.Direct3D9.Filter.Default, 0);
Waterfall_texture_size.Width = waterfall_target.Width;
Waterfall_texture_size.Height = waterfall_target.Height;
Waterfall_Sprite = new Sprite(waterfall_dx_device);