-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathkisspectrum.c
627 lines (504 loc) · 20.1 KB
/
kisspectrum.c
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
/*
Raspberry Kiss Spectrum : KisSpectrum
Copyright (c) 2017-2018, Evariste F5OEO
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
//
// Todo List
// Average FFT
// Title for each Window
// Use a general input (touchscreen/mouse/midi controler/omnirig)
//
#define PROGRAM_VERSION "0.0.1"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <ctype.h>
#include "VG/openvg.h"
#include "VG/vgu.h"
#include "fontinfo.h"
#include "shapes.h"
#include <math.h>
#include <getopt.h>
#include <signal.h>
#include <errno.h>
#include <liquid/liquid.h>
#include "colormaps.py"
#define FFT_SIZE 1024
FILE *input;
static char keep_running=0;
static void CleanAll()
{
}
static void signal_handler(int signo)
{
if (signo == SIGINT)
fputs("\nCaught SIGINT\n", stderr);
else if (signo == SIGTERM)
fputs("\nCaught SIGTERM\n", stderr);
else if (signo == SIGHUP)
fputs("\nCaught SIGHUP\n", stderr);
else if (signo == SIGPIPE)
fputs("\nReceived SIGPIPE.\n", stderr);
else
fprintf(stderr, "\nCaught signal: %d\n", signo);
CleanAll();
keep_running = 0;
}
static unsigned int m_ColorTbl[256];
#define WALPHA(x) (x << 24)
#define WBLUE(x) (x << 16)
#define WGREEN(x) (x << 8)
#define WRED(x) (x)
unsigned int setRgb(int r,int g,int b)
{
return r|(g<<8)|(b<<16)|(0xFF<<24);
}
static void InitColorWaterFall()
{
// default waterfall color scheme
for (int i = 0; i < 256; i++)
{
m_ColorTbl[i]=setRgb(_viridis_data[i][0]*255,_viridis_data[i][1]*255,_viridis_data[i][2]*255);
}
}
unsigned int SetColorFromFloat(float value)
{
if(value>1.0) value=1.0;
if(value<0.0) value=0.0;
int Index=(value*255.0);
return m_ColorTbl[Index];
}
unsigned int SetColorFromInt(int value)
{
if(value<0) value=0;
if(value>255) value=255;
int Index=(value);
return m_ColorTbl[Index];
}
#ifdef __ARM_NEON__
/*
void u8tofloat(
size_t nsamples,
unsigned char* buf,
std::complex<float>* fo)
{
// Number to subtract from samples for normalization
// See http://cgit.osmocom.org/gr-osmosdr/tree/lib/rtl/rtl_source_c.cc#n176
const float32_t norm_ = 127.4f / 128.0f;
float32x4_t norm = vld1q_dup_f32(&norm_);
// Iterate over samples in blocks of 4 (each sample has I and Q)
for (uint32_t i = 0; i < (nsamples / 4); i++) {
uint32x4_t ui;
ui[0] = buf[i * 8 + 0];
ui[1] = buf[i * 8 + 2];
ui[2] = buf[i * 8 + 4];
ui[3] = buf[i * 8 + 6];
uint32x4_t uq;
uq[0] = buf[i * 8 + 1];
uq[1] = buf[i * 8 + 3];
uq[2] = buf[i * 8 + 5];
uq[3] = buf[i * 8 + 7];
// Convert to float32x4 and divide by 2^7 (128)
float32x4_t fi = vcvtq_n_f32_u32(ui, 7);
float32x4_t fq = vcvtq_n_f32_u32(uq, 7);
// Subtract to normalize to [-1.0, 1.0]
float32x4x2_t fiq;
fiq.val[0] = vsubq_f32(fi, norm);
fiq.val[1] = vsubq_f32(fq, norm);
// Store in output
vst2q_f32((float*) (&fo[i * 4]), fiq);
}
}
*/
#endif
static void Init()
{
// register signal handlers
if (signal(SIGINT, signal_handler) == SIG_ERR)
fputs("Warning: Can not install signal handler for SIGINT\n", stderr);
if (signal(SIGTERM, signal_handler) == SIG_ERR)
fputs("Warning: Can not install signal handler for SIGTERM\n", stderr);
if (signal(SIGHUP, signal_handler) == SIG_ERR)
fputs("Warning: Can not install signal handler for SIGHUP\n", stderr);
if (signal(SIGPIPE, signal_handler) == SIG_ERR)
fputs("Warning: Can not install signal handler for SIGPIPE\n", stderr);
InitColorWaterFall();
}
void print_usage()
{
fprintf(stderr,\
"kisspectrum -%s\n\
Usage:kisspectrum -i File [-t IQType] [-s SampleRate] [-r FrameRate][-h] \n\
-i Input IQ File I16 format (default stdin) \n\
-t IQType {float,u8,i16} (default float) \n\
-s SampleRate (default 1024K) \n\
-r Display Framertae (default 25) \n\
-h help (print this help).\n\
Example : .\\kisspectrum -i - \n\
\n", \
PROGRAM_VERSION);
} /* end function print_usage */
// coordpoint marks a coordinate, preserving a previous color
void coordpoint(VGfloat x, VGfloat y, VGfloat size, VGfloat pcolor[4]) {
Fill(128, 0, 0, 0.3);
Circle(x, y, size);
setfill(pcolor);
}
int main(int argc, char *argv[]) {
int a;
int anyargs = 1;
enum {TYPE_FLOAT,TYPE_U8,TYPE_I16};
unsigned int SampleRate=1024000;
int fps=25;
int TypeInput=TYPE_FLOAT;
input = stdin;
int SampleSize=sizeof(float complex);
while (1)
{
a = getopt(argc, argv, "i:t:s:r:h");
if (a == -1)
{
if (anyargs) break;
else a = 'h'; //print usage and exit
}
anyargs = 1;
switch (a)
{
case 'i': // InputFile
input = fopen(optarg, "r");
if (NULL == input)
{
fprintf(stderr, "Unable to open '%s': %s\n",
optarg, strerror(errno));
exit(EXIT_FAILURE);
}
break;
case 't': // Input Type
if (strcmp("float", optarg) == 0) {TypeInput = TYPE_FLOAT;SampleSize=sizeof(float complex);}
if (strcmp("i16", optarg) == 0) {TypeInput = TYPE_I16;SampleSize=2*sizeof(short);}
if (strcmp("u8", optarg) == 0) {TypeInput = TYPE_U8;SampleSize=2*sizeof(unsigned char);}
break;
case 's': // SampleRate in Symbol/s
SampleRate = atoi(optarg);
break;
case 'r': // Frame/s
fps = atoi(optarg);
if(fps>25) fps=25; //Fixme should be teh framerate of screen mode
break;
case 'h': // help
print_usage();
exit(0);
break;
case -1:
break;
case '?':
if (isprint(optopt))
{
fprintf(stderr, "kisspectrum `-%c'.\n", optopt);
}
else
{
fprintf(stderr, "kisspectrum: unknown option character `\\x%x'.\n", optopt);
}
print_usage();
exit(1);
break;
default:
print_usage();
exit(1);
break;
}/* end switch a */
}/* end while getopt() */
Init();
int FFTSize = 1024;
float complex * iqin = (float complex*) malloc(FFTSize *sizeof(float complex));
float complex * fftout = (float complex*) malloc(FFTSize * sizeof(float complex));
float complex * fftavg = (float complex*) malloc(FFTSize * sizeof(float complex));
float complex *derot_out=(float complex*) malloc(FFTSize * sizeof(float complex));
unsigned char *iqin_u8=NULL;
if(TypeInput==TYPE_U8) iqin_u8=(unsigned char*) malloc(FFTSize * SampleSize);
short *iqin_i16=NULL;
if(TypeInput==TYPE_I16) iqin_i16=(short*) malloc(FFTSize * SampleSize);
fftplan fft_plan = fft_create_plan(FFTSize, iqin, fftout, LIQUID_FFT_FORWARD, 0);
int width, height;
init(&width, &height); // Graphics initialization
fprintf(stderr,"Display resolution = %dx%d\n",width,height);
Start(width, height); // Start the picture
VGfloat *PowerFFTx=(VGfloat*)malloc(sizeof(VGfloat)*FFTSize);
VGfloat *PowerFFTy=(VGfloat*)malloc(sizeof(VGfloat)*FFTSize);
int OscilloWidth=(width-FFTSize);
VGfloat *Oscillo_rex=(VGfloat*)malloc(sizeof(VGfloat)*FFTSize);
VGfloat *Oscillo_rey=(VGfloat*)malloc(sizeof(VGfloat)*FFTSize);
VGfloat *Oscillo_imx=(VGfloat*)malloc(sizeof(VGfloat)*FFTSize);
VGfloat *Oscillo_imy=(VGfloat*)malloc(sizeof(VGfloat)*FFTSize);
int ConstellationWidth=(width-FFTSize);
//VGfloat *Constellationx=(VGfloat*)malloc(sizeof(VGfloat)*FFTSize);
//VGfloat *Constellationy=(VGfloat*)malloc(sizeof(VGfloat)*FFTSize);
int WaterfallHeight=height/2;
int WaterfallWidth=FFTSize;
// 32 bit RGBA FFT
unsigned int *fftImage=malloc(WaterfallWidth*(WaterfallHeight)*sizeof(unsigned int));
unsigned int *fftLine=malloc(WaterfallWidth*sizeof(unsigned int));
// 32 bit RGBA Constellation
unsigned int *fftImageConstellation=malloc(ConstellationWidth*(height/2)*sizeof(unsigned int));
int ftype = LIQUID_FIRFILT_RRC; // filter type
unsigned int k = 8; // samples/symbol
unsigned int m = 3; // filter delay (symbols)
float beta = 0.35f; // filter excess bandwidth factor
int ms = LIQUID_MODEM_BPSK; // modulation scheme (can be unknown)
symtrack_cccf symtrack = symtrack_cccf_create(ftype,k,m,beta,ms);
//symtrack_cccf_set_bandwidth(symtrack,0.1);
iirfilt_crcf dc_blocker = iirfilt_crcf_create_dc_blocker(0.001);
Background(0, 0, 0); // Black background
Fill(255, 255, 255, 1);
BackgroundRGB(0,0,0,1);
End();
Line(FFTSize/2,0,FFTSize/2,10);
Stroke(0, 0, 255, 1);
Line(0,height-300,256,height-300);
StrokeWidth(2);
StrokeWidth(1);
Stroke(150, 150, 200, 1);
keep_running=1;
int WaterfallY=0;
VGfloat stops[] = {
0.0, 1.0, 1.0, 1.0, 1.0,
0.5, 0.5, 0.5, 0.5, 1.0,
1.0, 0.0, 0.0, 0.0, 1.0
};
int SkipSamples=(SampleRate-(FFTSize*fps))/fps;
SkipSamples=(SkipSamples/FFTSize)*FFTSize;
int TheoricFrameRate=SampleRate/FFTSize;
int ShowFrame=TheoricFrameRate/fps;
printf("TheoricFrameRate %d=%d/%d Showframe =%d\n",TheoricFrameRate,SampleRate,FFTSize,ShowFrame);
if(SkipSamples<0) SkipSamples=0;
fprintf(stderr,"Skip Samples = %d\n",SkipSamples);
int SkipByte=SampleSize*SkipSamples;
char *Dummy=malloc(SkipByte*SampleSize);
int SpectrumPosX=0;//(width-FFTSize)/2;
int SpectrumPosY=height/2;
int WaterfallPosX=0;//(width-WaterfallWidth)/2;
int WaterfallPosY=0;
int OscilloPosX=FFTSize;
int OscilloPosY=height/2;
int ConstellationPosX=FFTSize;
int ConstellationPosY=0;
float FloorDb=220.0;
float ScaleFFT=1.0;
int Splash=0;
int NumFrame=0;
fprintf(stderr,"Warning displayed only 1 IQ buffer every %d\n",ShowFrame);
while(keep_running)
{
int Len=0;
NumFrame++;
//while(fread(Dummy,1,SkipByte,input)==0);
switch(TypeInput)
{
case TYPE_FLOAT:
{
Len=fread(iqin,sizeof(float),FFTSize,input);
if(Len==0) break;
}
break;
case TYPE_U8:
{
Len=fread(iqin_u8,sizeof(char),FFTSize*2,input);
if(Len==0) break;
for(int i=0;i<Len/2;i++)
{
iqin[i]=(iqin_u8[i*2]-127.5)/127.0+_Complex_I *(iqin_u8[i*2+1]-127.5)/127.0;
}
}
break;
case TYPE_I16:
{
Len=fread(iqin_i16,sizeof(short),FFTSize*2,input);
//printf("FFTSize=%d SampleSize=%d,Len =%d\n",FFTSize,SampleSize,Len);
if(Len==0) break;
for(int i=0;i<Len/2;i++)
{
iqin[i]=iqin_i16[i*2]/32767.0+ _Complex_I *iqin_i16[i*2+1]/32767.0;
iirfilt_crcf_execute(dc_blocker, iqin[i], &iqin[i]);
}
}
break;
}
if(Len<=0) break;
//if((NumFrame%ShowFrame)!=0) continue;
#define AVERAGE
#ifdef AVERAGE
fft_execute(fft_plan);
for(int i=0;i<FFTSize;i++)
{
fftavg[i]+=fftout[i];
}
#endif
if((NumFrame%ShowFrame)==0)
{
#ifndef AVERAGE
fft_execute(fft_plan);
for(int i=0;i<FFTSize;i++)
{
fftavg[i]+=fftout[i];
}
#endif
for(int i=0;i<FFTSize;i++)
{
#ifdef AVERAGE
fftavg[i]=fftavg[i]/(float)ShowFrame;
#else
fftavg[i]=fftavg[i];
#endif
//fftavg[i]+=fftavg[i]/(float)ShowFrame;
}
memset(fftImageConstellation,0,ConstellationWidth*(height/2)*sizeof(unsigned int)); // Constellation is black : Fixme ; need a window of I/Q constell for summing and averaging
//symtrack_cccf_reset(symtrack);
float dbpeak=-200;
for(int i=FFTSize/2;i<FFTSize;i++)
{
PowerFFTx[i-FFTSize/2]=i-FFTSize/2+SpectrumPosX;
float dbAmp=20.0*log(cabsf(fftavg[i])/FFTSize);
if(dbAmp>dbpeak) dbpeak=dbAmp;
unsigned int idbAmp=(unsigned int)((dbAmp+FloorDb)*height/2.0/FloorDb*ScaleFFT);
PowerFFTy[i-FFTSize/2]=idbAmp+SpectrumPosY;
//printf("%f %u\n",dbAmp,idbAmp);
//FillLinearGradient(PowerFFTx[i-FFTSize/2],height/2,PowerFFTx[i-FFTSize/2],PowerFFTy[i-FFTSize/2],stops,3);
//Rect(PowerFFTx[i-FFTSize/2], height/2, 1, PowerFFTy[i-FFTSize/2]);
unsigned int idbAmpColor=(unsigned int)((dbAmp+FloorDb)*2*ScaleFFT);//(unsigned int)((dbAmp+200));
// fftImage[(WaterfallWidth)*(WaterfallHeight-1)+i-WaterfallWidth/2]=SetColorFromInt(idbAmpColor);
fftLine[i-WaterfallWidth/2]=SetColorFromInt(idbAmpColor);
//VGfloat shapecolor[4];
//shapecolor=SetColorFromInt(idbAmpColor);
// coordpoint(PowerFFTx[i-FFTSize/2],PowerFFTy[i-FFTSize/2],1,shapecolor);
Oscillo_imx[i]=OscilloPosX+i*OscilloWidth/FFTSize;
Oscillo_imy[i]=OscilloPosY+height/4+cimagf(iqin[i])*height/4;
Oscillo_rey[i]=OscilloPosY+height/4+crealf(iqin[i])*height/4;
/* int PointY=(cimagf(iqin[i])+1.0)/2.0*height/2;
int PointX=(crealf(iqin[i])+1.0)/2.0*ConstellationWidth;
int Point=PointX+ConstellationWidth*PointY;
if(Point<ConstellationWidth*height/2)
fftImageConstellation[Point]=SetColorFromFloat((cabsf(iqin[i])+1.0)/4.0);*/
}
for(int i=0;i<FFTSize/2;i++)
{
PowerFFTx[i+FFTSize/2]=i+FFTSize/2+SpectrumPosX;
float dbAmp=20.0*log(cabsf(fftavg[i])/FFTSize);
if(dbAmp>dbpeak) dbpeak=dbAmp;
unsigned int idbAmp=(unsigned int)((dbAmp+FloorDb)*height/2.0/FloorDb*ScaleFFT);
PowerFFTy[i+FFTSize/2]=idbAmp+SpectrumPosY;
unsigned int idbAmpColor=(unsigned int)((dbAmp+FloorDb)*2*ScaleFFT);//(unsigned int)((dbAmp+200));
// printf("dbAmp %f ->%d\n",dbAmp,idbAmpColor);
//unsigned int idbAmpColor=(unsigned int)((dbAmp)+200);
//fftImage[(WaterfallWidth)*(WaterfallHeight-1)+i+WaterfallWidth/2]=SetColorFromInt(idbAmpColor);
fftLine[i+WaterfallWidth/2]=SetColorFromInt(idbAmpColor);
Oscillo_imx[i]=OscilloPosX+i*OscilloWidth/FFTSize;
Oscillo_imy[i]=OscilloPosY+height/4+cimagf(iqin[i])*height/4;
Oscillo_rey[i]=OscilloPosY+height/4+crealf(iqin[i])*height/4;
/*
int PointY=(cimagf(iqin[i])+1.0)/2.0*height/2;
int PointX=(crealf(iqin[i])+1.0)/2.0*ConstellationWidth;
int Point=PointX+ConstellationWidth*PointY;
if(Point<ConstellationWidth*height/2)
fftImageConstellation[Point]=SetColorFromFloat((cabsf(iqin[i])+1.0)/4.0);*/
}
//unsigned int idbAmpColor=(unsigned int)((dbpeak+FloorDb)*2*ScaleFFT);
//unsigned int ColorAverage=SetColorFromInt(idbAmpColor);
//Stroke(ColorAverage&0xff,(ColorAverage>>8)&0xFF,(ColorAverage>>16)&0xFF, 1);
}
// QPSK symbol tracking
int num_written=0;
// symtrack_cccf_reset(symtrack);
if((NumFrame%ShowFrame)==0)
{
ClipRect(OscilloPosX, height/2, width-FFTSize, height/2);
WindowClear();
ClipEnd();
//Scale(0.8,1);
ClipRect(0, height/2,FFTSize, height/2);
//Translate(0,-1);
//Scale(1,1);
Stroke(0, 128, 192, 0.8);
Polyline(PowerFFTx, PowerFFTy, FFTSize);
float RemanenceRate=8;
vgCopyPixels(0,height/2,0,height/2+RemanenceRate,FFTSize,height/2-RemanenceRate);
/*
for(int i=0;i<10;i++)
{
vgCopyPixels(0,height/2,0,height/2+i,FFTSize,height/2*((10-i)/10.0));
//vgCopyPixels(0,height/2+(i*height/2)/10.0,0,height/2+(i*height/2)/10.0+(10-i*i),FFTSize,(height/2)/10.0);
//vgCopyPixels(0,height-(height/2)*i/10.0,0,height-(height/2)*i/10.0+i,FFTSize,(height/2)/10.0-i);
}*/
ClipEnd();
if(Splash<fps*5)
{
//Title
char sTitle[100];
Stroke(0, 128, 128, 1);
sprintf(sTitle,"KisSpectrum (F5OEO)");
Fill(0,128-Splash,128-Splash, 1);
Text(FFTSize,height-50, sTitle, SerifTypeface, 20);
Splash++;
}
//Scale(0,0);
//Translate(0,0);
//Stroke(128, 0, 0, 1);
Polyline(Oscillo_imx, Oscillo_rey, FFTSize);
Stroke(0, 128, 0, 1);
Polyline(Oscillo_imx, Oscillo_imy, FFTSize);
// ClipRect(WaterfallPosX, WaterfallPosY, WaterfallWidth, WaterfallHeight);
// makeimage(WaterfallPosX,WaterfallPosY,WaterfallWidth,WaterfallHeight,(VGubyte *)fftImage);
makeimage(WaterfallPosX,height/2-1,WaterfallWidth,1,(VGubyte *)fftLine);
vgCopyPixels(0,0,0,1,FFTSize,height/2);
//ClipEnd();
symtrack_cccf_execute_block(symtrack,iqin, FFTSize,derot_out, &num_written);
for(int i=0;i<num_written;i++)
{
int PointY=(cimagf(derot_out[i])+1.5)/3.0*height/2;
int PointX=(crealf(derot_out[i])+1.5)/3.0*ConstellationWidth;
int Point=PointX+ConstellationWidth*PointY;
//printf("Derot %d\n", Point);
if((Point>0)&&(Point<ConstellationWidth*height/2))
fftImageConstellation[Point]=SetColorFromFloat(1.0);
/*else
fprintf(stderr,"%f+i%f\n",crealf(derot_out[i]),cimagf(derot_out[i]));*/
}
makeimage(ConstellationPosX,ConstellationPosY,ConstellationWidth,height/2,(VGubyte *)fftImageConstellation);
for(int i=0;i<FFTSize;i++) fftavg[i]=0;
End();
}
// NumFrame++; // End the picture
}
End(); // End the picture
free(PowerFFTx);
free(PowerFFTy);
fft_destroy_plan(fft_plan);
free(iqin);
free(fftout);
free(fftavg);
free(fftImage);
finish();
exit(0);
}