-
Notifications
You must be signed in to change notification settings - Fork 7
/
plot.c
executable file
·6634 lines (5535 loc) · 197 KB
/
plot.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
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
/*
* MDFourier
* A Fourier Transform analysis tool to compare game console audio
* http://junkerhq.net/MDFourier/
*
* Copyright (C)2019-2020 Artemio Urbina
*
* This file is part of the 240p Test Suite
*
* 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 software 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 software; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Requires the FFTW library:
* http://www.fftw.org/
*
*/
#include "plot.h"
#include "log.h"
#include "freq.h"
#include "diff.h"
#include "cline.h"
#include "windows.h"
#include "profile.h"
#ifdef OPENMP_ENABLE
#include <omp.h>
#endif
#define SORT_NAME AmplitudeDifferences
#define SORT_TYPE FlatAmplDifference
#define SORT_CMP(x, y) ((x).refAmplitude < (y).refAmplitude ? -1 : ((x).refAmplitude == (y).refAmplitude ? 0 : 1))
#include "sort.h" // https://github.com/swenson/sort/
#define SORT_NAME AverageByFrequency
#define SORT_TYPE AveragedFrequencies
#define SORT_CMP(x, y) ((x).avgfreq < (y).avgfreq ? -1 : ((x).avgfreq == (y).avgfreq ? 0 : 1))
#include "sort.h" // https://github.com/swenson/sort/
#define SORT_NAME FlatFrequenciesByAmplitude
#define SORT_TYPE FlatFrequency
#define SORT_CMP(x, y) ((x).amplitude < (y).amplitude ? -1 : ((x).amplitude == (y).amplitude ? 0 : 1))
#include "sort.h" // https://github.com/swenson/sort/
#define SORT_NAME PhaseDifferencesByFrequency
#define SORT_TYPE FlatPhase
#define SORT_CMP(x, y) ((x).hertz < (y).hertz ? -1 : ((x).hertz == (y).hertz ? 0 : 1))
#include "sort.h" // https://github.com/swenson/sort/
#define SORT_NAME AmplitudeDifferencesBlock
#define SORT_TYPE AmplDifference
#define SORT_CMP(x, y) ((x).diffAmplitude < (y).diffAmplitude ? -1 : ((x).diffAmplitude == (y).diffAmplitude ? 0 : 1))
#include "sort.h" // https://github.com/swenson/sort/
#define DIFFERENCE_TITLE "DIFFERENT AMPLITUDES [%s]"
#define DIFFERENCE_TITLE_LEFT "DIFFERENT AMPLITUDES LEFT CHANNEL [%s]"
#define DIFFERENCE_TITLE_RIGHT "DIFFERENT AMPLITUDES RIGHT CHANNEL [%s]"
#define EXTRA_TITLE_TS_REF "Comparison - MISSING FREQUENCIES - Time Spectrogram [%s] (Expected in Comparison)"
#define EXTRA_TITLE_TS_REF_LEFT "Comparison - MISSING FREQUENCIES LEFT CHANNEL - Time Spectrogram [%s] (Expected in Comparison)"
#define EXTRA_TITLE_TS_REF_RIGHT "Comparison - MISSING FREQUENCIES RIGHT CHANNEL - Time Spectrogram [%s] (Expected in Comparison)"
#define EXTRA_TITLE_TS_COM "Comparison - EXTRA FREQUENCIES - Time Spectrogram [%s] (Not in Reference)"
#define EXTRA_TITLE_TS_COM_LEFT "Comparison - EXTRA FREQUENCIES LEFT CHANNEL - Time Spectrogram [%s] (Not in Reference)"
#define EXTRA_TITLE_TS_COM_RIGHT "Comparison - EXTRA FREQUENCIES RIGHT CHANNEL - Time Spectrogram [%s] (Not in Reference)"
#define SPECTROGRAM_TITLE_REF "Reference - SPECTROGRAM [%s]"
#define SPECTROGRAM_TITLE_REF_LEFT "Reference - SPECTROGRAM LEFT CHANNEL [%s]"
#define SPECTROGRAM_TITLE_REF_RIGHT "Reference - SPECTROGRAM RIGHT CHANNEL [%s]"
#define SPECTROGRAM_TITLE_COM "Comparison - SPECTROGRAM [%s]"
#define SPECTROGRAM_TITLE_COM_LEFT "Comparison - SPECTROGRAM LEFT CHANNEL [%s]"
#define SPECTROGRAM_TITLE_COM_RIGHT "Comparison - SPECTROGRAM RIGHT CHANNEL [%s]"
#define TSPECTROGRAM_TITLE_REF "Reference - TIME SPECTROGRAM [%s]"
#define TSPECTROGRAM_TITLE_REF_LFT "Reference - TIME SPECTROGRAM LEFT CHANNEL [%s]"
#define TSPECTROGRAM_TITLE_REF_RGHT "Reference - TIME SPECTROGRAM RIGHT CHANNEL [%s]"
#define TSPECTROGRAM_TITLE_COM "Comparison - TIME SPECTROGRAM [%s]"
#define TSPECTROGRAM_TITLE_COM_LFT "Comparison - TIME SPECTROGRAM LEFT CHANNEL [%s]"
#define TSPECTROGRAM_TITLE_COM_RGHT "Comparison - TIME SPECTROGRAM RIGHT CHANNEL [%s]"
#define DIFFERENCE_AVG_TITLE "DIFFERENT AMPLITUDES AVERAGED [%s]"
#define DIFFERENCE_AVG_TITLE_STEREO "DIFFERENT AMPLITUDES STEREO AVERAGED [%s]"
#define DIFFERENCE_AVG_TITLE_LEFT "DIFFERENT AMPLITUDES LEFT CHANNEL AVERAGED [%s]"
#define DIFFERENCE_AVG_TITLE_RIGHT "DIFFERENT AMPLITUDES RIGHT CHANNEL AVERAGED [%s]"
#define NOISE_TITLE "NOISE FLOOR AVERAGED"
#define NOISE_AVG_TITLE "NOISE FLOOR AVERAGED"
#define SPECTROGRAM_NOISE_REF "Reference NOISE FLOOR - Spectrogram [%s]"
#define SPECTROGRAM_NOISE_REF_LEFT "Reference NOISE FLOOR LEFT - Spectrogram [%s]"
#define SPECTROGRAM_NOISE_REF_RIGHT "Reference NOISE FLOOR RIGHT - Spectrogram [%s]"
#define SPECTROGRAM_NOISE_COM "Comparison NOISE FLOOR - Spectrogram [%s]"
#define SPECTROGRAM_NOISE_COM_LEFT "Comparison NOISE FLOOR LEFT - Spectrogram [%s]"
#define SPECTROGRAM_NOISE_COM_RIGHT "Comparison NOISE FLOOR RIGHT - Spectrogram [%s]"
#define WAVEFORM_TITLE_REF "Reference - WAVEFORM [%s]"
#define WAVEFORM_TITLE_COM "Comparison - WAVEFORM [%s]"
#define PHASE_DIFF_TITLE "PHASE DIFFERENCE [%s]"
#define PHASE_DIFF_TITLE_LEFT "PHASE DIFFERENCE LEFT CHANNEL [%s]"
#define PHASE_DIFF_TITLE_RIGHT "PHASE DIFFERENCE RIGHT CHANNEL [%s]"
#define PHASE_SIG_TITLE_REF "Reference - PHASE [%s]"
#define PHASE_SIG_TITLE_REF_LEFT "Reference - PHASE LEFT CHANNEL [%s]"
#define PHASE_SIG_TITLE_REF_RIGHT "Reference - PHASE RIGHT CHANNEL [%s]"
#define PHASE_SIG_TITLE_COM "Comparison - PHASE [%s]"
#define PHASE_SIG_TITLE_COM_LEFT "Comparison - PHASE LEFT CHANNEL [%s]"
#define PHASE_SIG_TITLE_COM_RIGHT "Comparison - PHASE RIGHT CHANNEL [%s]"
#define TS_DIFFERENCE_TITLE "DIFFERENT AMPLITUDES - TIME SPECTROGRAM [%s]"
#define SPECTROGRAM_CLK_REF "Reference CLK - Spectrogram [%s]"
#define SPECTROGRAM_CLK_COM "Comparison CLK - Spectrogram [%s]"
#define BAR_HEADER "Matched frequencies w/diff amplitude"
#define BAR_DIFF "w/any amplitude difference"
#define BAR_WITHIN "within [0 to \\+-%gdB]"
#define BAR_WITHIN_PERFECT "within (0 to \\+-%gdB]"
#define BAR_PERFECT "Perfect Matches"
#define BAR_UNMATCHED "Unmatched frequencies"
#define BAR_MISSING "Missing"
#define BAR_EXTRA "Extra"
#define ALL_LABEL "ALL"
#define BAR_WIDTH config->plotResX/40
#define BAR_HEIGHT config->plotResY/60
#define WARN_LOW 0
#define WARN_HIGH 1
#define WARN_NONE 2
#define HORZ_SCALE_STEP 1000
#define VERT_SCALE_STEP 3
#define VERT_SCALE_STEP_BAR 3
#define COLOR_BARS_WIDTH_SCALE 220
#define DIFFERENCE_FOLDER "Difference"
#define SPECTROGRAM_FOLDER "Spectrograms"
#define WAVEFORM_FOLDER "Waveforms"
#define PHASE_FOLDER "Phase"
#define MISSING_FOLDER "MissingAndExtra"
#define WAVEFORMDIFF_FOLDER "Waveform-Diff"
#define WAVEFORMDIR_AMPL "Amplitudes"
#define WAVEFORMDIR_MISS "Missing"
#define WAVEFORMDIR_EXTRA "Extra"
#define T_SPECTR_FOLDER "TimeSpectrograms"
#define NOISEFLOOR_FOLDER "NoiseFloor"
#define CLK_FOLDER "CLK"
//#define TESTWARNINGS
#define SYNC_DEBUG_SCALE 8
char *GetCurrentPathAndChangeToResultsFolder(parameters *config)
{
char *CurrentPath = NULL;
CurrentPath = (char*)malloc(sizeof(char)*FILENAME_MAX);
if(!CurrentPath)
return NULL;
if(!GetCurrentDir(CurrentPath, sizeof(char)*FILENAME_MAX))
{
free(CurrentPath);
logmsg("Could not get current path\n");
return NULL;
}
if(chdir(config->folderName) == -1)
{
free(CurrentPath);
logmsg("Could not open folder %s for results\n", config->folderName);
return NULL;
}
return CurrentPath;
}
void ReturnToMainPath(char **CurrentPath)
{
if(!*CurrentPath)
return;
if(chdir(*CurrentPath) == -1)
logmsg("Could not open working folder %s\n", CurrentPath);
free(*CurrentPath);
*CurrentPath = NULL;
}
void StartPlot(char *name, struct timespec* start, parameters *config)
{
logmsg(name);
if(config->clock)
clock_gettime(CLOCK_MONOTONIC, start);
}
void EndPlot(char *name, struct timespec* start, struct timespec* end, parameters *config)
{
logmsg("\n");
if(config->clock)
{
double elapsedSeconds;
clock_gettime(CLOCK_MONOTONIC, end);
elapsedSeconds = TimeSpecToSeconds(end) - TimeSpecToSeconds(start);
logmsg(" - clk: %s took %0.2fs\n", name, elapsedSeconds);
}
}
char *PushFolder(char *name)
{
char *CurrentPath = NULL;
CurrentPath = (char*)malloc(sizeof(char)*FILENAME_MAX);
if(!CurrentPath)
return NULL;
if(!GetCurrentDir(CurrentPath, sizeof(char)*FILENAME_MAX))
{
free(CurrentPath);
logmsg("ERROR: Could not get current path\n");
return NULL;
}
if(!CreateFolder(name))
{
free(CurrentPath);
logmsg("ERROR: Could not create %s subfolder\n", name);
return NULL;
}
if(chdir(name) == -1)
{
free(CurrentPath);
logmsg("ERROR: Could not open folder %s for results\n", name);
return NULL;
}
return CurrentPath;
}
void PlotResults(AudioSignal *ReferenceSignal, AudioSignal *ComparisonSignal, parameters *config)
{
struct timespec start, end;
char *CurrentPath = NULL, *MainPath = NULL;
if(config->clock)
clock_gettime(CLOCK_MONOTONIC, &start);
MainPath = PushMainPath(config);
CurrentPath = GetCurrentPathAndChangeToResultsFolder(config);
if(config->plotDifferences || config->averagePlot)
{
struct timespec lstart, lend;
StartPlot(" - Difference", &lstart, config);
PlotAmpDifferences(config);
//PlotDifferenceTimeSpectrogram(config);
EndPlot("Differences", &lstart, &lend, config);
printf(" - Preliminary results in %s%s\n",
config->outputPath,
config->folderName);
}
if(config->plotMissing)
{
if(!config->FullTimeSpectroScale)
{
struct timespec lstart, lend;
StartPlot(" - Missing and Extra Frequencies", &lstart, config);
if(config->usesStereo)
{
char *returnFolder = NULL;
returnFolder = PushFolder(MISSING_FOLDER);
if(!returnFolder)
return;
#ifdef OPENMP_ENABLE
#pragma omp parallel for
#endif
for (int i = 0; i < 2; i++)
{
if (i == 0 && ReferenceSignal->AudioChannels == 2)
{
PlotTimeSpectrogramUnMatchedContent(ReferenceSignal, CHANNEL_LEFT, config);
logmsg(PLOT_ADVANCE_CHAR);
PlotTimeSpectrogramUnMatchedContent(ReferenceSignal, CHANNEL_RIGHT, config);
logmsg(PLOT_ADVANCE_CHAR);
}
if (i == 1 && ComparisonSignal->AudioChannels == 2)
{
PlotTimeSpectrogramUnMatchedContent(ComparisonSignal, CHANNEL_LEFT, config);
logmsg(PLOT_ADVANCE_CHAR);
PlotTimeSpectrogramUnMatchedContent(ComparisonSignal, CHANNEL_RIGHT, config);
logmsg(PLOT_ADVANCE_CHAR);
}
}
ReturnToMainPath(&returnFolder);
}
#ifdef OPENMP_ENABLE
#pragma omp parallel for
#endif
for (int i = 0; i < 2; i++)
{
if (i == 0)
{
PlotTimeSpectrogramUnMatchedContent(ReferenceSignal, CHANNEL_STEREO, config);
logmsg(PLOT_ADVANCE_CHAR);
}
else
{
PlotTimeSpectrogramUnMatchedContent(ComparisonSignal, CHANNEL_STEREO, config);
logmsg(PLOT_ADVANCE_CHAR);
}
}
EndPlot("Missing and Extra", &lstart, &lend, config);
}
else
logmsg(" X Skipped: Missing and Extra Frequencies, due to range\n");
}
if(config->plotSpectrogram)
{
int typeCount = 0, someStereo = 0, doRefAll = 0, doCompAll = 0;
struct timespec lstart, lend;
char *returnFolder = NULL;
char tmpNameRef[BUFFER_SIZE/2], tmpNameComp[BUFFER_SIZE/2];
long int sizeRef = 0, sizeComp = 0;
FlatFrequency *freqsRef = NULL, *freqsComp = NULL;
StartPlot(" - Spectrograms", &lstart, config);
#ifdef OPENMP_ENABLE
#pragma omp parallel for
#endif
for(int i = 0; i < 2; i++)
{
if(i == 0)
freqsRef = CreateSpectrogramFrequencies(ReferenceSignal, &sizeRef, 0, config);
else
freqsComp = CreateSpectrogramFrequencies(ComparisonSignal, &sizeComp, 0, config);
}
//Create subfolder if needed
typeCount = GetActiveBlockTypesNoRepeat(config);
someStereo = config->referenceSignal->AudioChannels == 2 || config->comparisonSignal->AudioChannels == 2;
if (typeCount > 1 || someStereo)
{
returnFolder = PushFolder(SPECTROGRAM_FOLDER);
if (!returnFolder)
return;
}
ShortenFileName(basename(ReferenceSignal->SourceFile), tmpNameRef, BUFFER_SIZE/2);
ShortenFileName(basename(ComparisonSignal->SourceFile), tmpNameComp, BUFFER_SIZE/2);
#ifdef OPENMP_ENABLE
#pragma omp parallel for
#endif
for(int i = 0; i < 2; i++)
{
if(i == 0)
{
if(PlotEachTypeSpectrogram(freqsRef, sizeRef, tmpNameRef, ReferenceSignal->role, config, ReferenceSignal) > 1)
doRefAll = 1;
}
else
{
if(PlotEachTypeSpectrogram(freqsComp, sizeComp, tmpNameComp, ComparisonSignal->role, config, ComparisonSignal) > 1)
doCompAll = 1;
}
}
if (typeCount > 1 || someStereo)
{
ReturnToMainPath(&returnFolder);
returnFolder = NULL;
}
if(doRefAll && doCompAll)
{
#ifdef OPENMP_ENABLE
#pragma omp parallel for
#endif
for(int i = 0; i < 2; i++)
{
if(i == 0)
{
PlotAllSpectrogram(freqsRef, sizeRef, tmpNameRef, ReferenceSignal->role, config);
logmsg(PLOT_ADVANCE_CHAR);
}
else
{
PlotAllSpectrogram(freqsComp, sizeComp, tmpNameComp, ComparisonSignal->role, config);
logmsg(PLOT_ADVANCE_CHAR);
}
}
}
if(freqsRef)
{
free(freqsRef);
freqsRef = NULL;
}
if(freqsComp)
{
free(freqsComp);
freqsComp = NULL;
}
EndPlot("Spectrogram", &lstart, &lend, config);
if(config->plotNoiseFloor)
{
StartPlot(" - Noise Floor Spectrograms", &lstart, config);
#ifdef OPENMP_ENABLE
#pragma omp parallel for
#endif
for(int i = 0; i < 2; i++)
{
if(i == 0)
freqsRef = CreateSpectrogramFrequencies(ReferenceSignal, &sizeRef, 1, config);
else
freqsComp = CreateSpectrogramFrequencies(ComparisonSignal, &sizeComp, 1, config);
}
if(freqsRef)
{
PlotNoiseFloorSpectrogram(freqsRef, sizeRef, tmpNameRef, ReferenceSignal->role, config, ReferenceSignal);
logmsg(PLOT_ADVANCE_CHAR);
free(freqsRef);
}
if(freqsComp)
{
PlotNoiseFloorSpectrogram(freqsComp, sizeComp, tmpNameComp, ComparisonSignal->role, config, ComparisonSignal);
logmsg(PLOT_ADVANCE_CHAR);
free(freqsComp);
}
EndPlot("Noise Floor Spectrogram", &lstart, &lend, config);
}
}
if(config->clkMeasure)
{
struct timespec lstart, lend;
char *returnFolder = NULL;
StartPlot(" - Clocks", &lstart, config);
returnFolder = PushFolder(CLK_FOLDER);
if(!returnFolder)
return;
#ifdef OPENMP_ENABLE
#pragma omp parallel for
#endif
for (int i = 0; i < 2; i++)
{
if (i == 0)
PlotCLKSpectrogram(ReferenceSignal, config);
else
PlotCLKSpectrogram(ComparisonSignal, config);
}
ReturnToMainPath(&returnFolder);
EndPlot("Clocks", &lstart, &lend, config);
}
if(config->plotTimeSpectrogram)
{
struct timespec lstart, lend;
char* returnFolder = NULL;
StartPlot(" - Time Spectrogram", &lstart, config);
if(config->usesStereo)
{
returnFolder = PushFolder(T_SPECTR_FOLDER);
if(!returnFolder)
return;
#ifdef OPENMP_ENABLE
#pragma omp parallel for
#endif
for (int i = 0; i < 2; i++)
{
if (i == 0)
{
if (ReferenceSignal->AudioChannels == 2)
{
PlotTimeSpectrogram(ReferenceSignal, CHANNEL_LEFT, config);
logmsg(PLOT_ADVANCE_CHAR);
PlotTimeSpectrogram(ReferenceSignal, CHANNEL_RIGHT, config);
logmsg(PLOT_ADVANCE_CHAR);
}
}
else
{
if (ComparisonSignal->AudioChannels == 2)
{
PlotTimeSpectrogram(ComparisonSignal, CHANNEL_LEFT, config);
logmsg(PLOT_ADVANCE_CHAR);
PlotTimeSpectrogram(ComparisonSignal, CHANNEL_RIGHT, config);
logmsg(PLOT_ADVANCE_CHAR);
}
}
}
ReturnToMainPath(&returnFolder);
}
if (GetActiveBlockTypesNoRepeat(config))
{
returnFolder = PushFolder(T_SPECTR_FOLDER);
if (!returnFolder)
return;
#ifdef OPENMP_ENABLE
#pragma omp parallel for
#endif
for (int i = 0; i < config->types.typeCount; i++)
{
int type = 0;
type = config->types.typeArray[i].type;
if (type > TYPE_CONTROL && !config->types.typeArray[i].IsaddOnData)
{
PlotSingleTypeTimeSpectrogram(ReferenceSignal, CHANNEL_STEREO, type, config);
logmsg(PLOT_ADVANCE_CHAR);
PlotSingleTypeTimeSpectrogram(ComparisonSignal, CHANNEL_STEREO, type, config);
logmsg(PLOT_ADVANCE_CHAR);
}
}
ReturnToMainPath(&returnFolder);
}
#ifdef OPENMP_ENABLE
#pragma omp parallel for
#endif
for (int i = 0; i < 2; i++)
{
if (i == 0)
{
PlotTimeSpectrogram(ReferenceSignal, CHANNEL_STEREO, config);
logmsg(PLOT_ADVANCE_CHAR);
}
else
{
PlotTimeSpectrogram(ComparisonSignal, CHANNEL_STEREO, config);
logmsg(PLOT_ADVANCE_CHAR);
}
}
EndPlot("Time Spectrogram", &lstart, &lend, config);
}
if(config->plotPhase)
{
struct timespec lstart, lend;
StartPlot(" - Phase", &lstart, config);
PlotPhaseDifferences(config);
//PlotPhaseFromSignal(ReferenceSignal, config);
//PlotPhaseFromSignal(ComparisonSignal, config);
logmsg(PLOT_ADVANCE_CHAR);
EndPlot("Phase", &lstart, &lend, config);
}
if(config->plotNoiseFloor)
{
if(!config->noSyncProfile)
{
if(ReferenceSignal->hasSilenceBlock && ComparisonSignal->hasSilenceBlock)
{
struct timespec lstart, lend;
StartPlot(" - Noise Floor", &lstart, config);
PlotNoiseFloor(ReferenceSignal, config);
EndPlot("Noise Floor", &lstart, &lend, config);
}
else
logmsg(" X Noise Floor graphs ommited: no noise floor value found.\n");
}
else
logmsg(" X Noise floor plots make no sense with current parameters.\n");
}
if((config->hasTimeDomain && config->plotTimeDomain) || config->plotAllNotes)
{
struct timespec lstart, lend;
char *returnFolder = NULL;
returnFolder = PushFolder(WAVEFORM_FOLDER);
if(!returnFolder)
{
ReturnToMainPath(&CurrentPath);
return;
}
StartPlot(" - Waveform Graphs ", &lstart, config);
#ifdef OPENMP_ENABLE
#pragma omp parallel for
#endif
for (int i = 0; i < 2; i++)
{
if (i == 0)
PlotTimeDomainGraphs(ReferenceSignal, config);
else
PlotTimeDomainGraphs(ComparisonSignal, config);
}
EndPlot("Waveform", &lstart, &lend, config);
ReturnToMainPath(&returnFolder);
}
if(config->plotTimeDomainHiDiff)
{
if(FindDifferenceAveragesperBlock(config->thresholdAmplitudeHiDif, config->thresholdMissingHiDif, config->thresholdExtraHiDif, config))
{
struct timespec lstart, lend;
StartPlot(" - Time Domain Graphs from highly different notes\n ", &lstart, config);
PlotTimeDomainHighDifferenceGraphs(ReferenceSignal, config);
PlotTimeDomainHighDifferenceGraphs(ComparisonSignal, config);
EndPlot("Time Domain Graphs", &lstart, &lend, config);
}
}
ReturnToMainPath(&CurrentPath);
PopMainPath(&MainPath);
if(config->clock)
{
double elapsedSeconds;
clock_gettime(CLOCK_MONOTONIC, &end);
elapsedSeconds = TimeSpecToSeconds(&end) - TimeSpecToSeconds(&start);
logmsg(" - clk: Plotting PNGs took %0.2fs\n", elapsedSeconds);
}
}
void PlotAmpDifferences(parameters *config)
{
long int size = 0;
FlatAmplDifference *amplDiff = NULL;
amplDiff = CreateFlatDifferences(config, &size, normalPlot);
if(!amplDiff)
{
logmsg("Not enough memory for plotting\n");
return;
}
if(config->outputCSV)
SaveCSVAmpDiff(amplDiff, size, config->compareName, config);
if(config->plotDifferences)
{
int typeCount = 0, plotAll = 0, someStereo = 0;
someStereo = config->referenceSignal->AudioChannels == 2 || config->comparisonSignal->AudioChannels == 2;
typeCount = GetActiveBlockTypesNoRepeat(config);
if (typeCount > 1 || someStereo)
{
if (PlotEachTypeDifferentAmplitudes(amplDiff, size, config->compareName, config) > 1)
plotAll = 1;
}
else
plotAll = 1;
if (plotAll)
{
PlotAllDifferentAmplitudes(amplDiff, size, CHANNEL_STEREO, config->compareName, config);
if(config->channelBalance == 0 && config->referenceSignal->AudioChannels == 2 && config->comparisonSignal->AudioChannels == 2)
{
char name[2*BUFFER_SIZE];
char *returnFolder = NULL;
returnFolder = PushFolder(DIFFERENCE_FOLDER);
if (!returnFolder)
return;
sprintf(name, "%s_%c", config->compareName, CHANNEL_LEFT);
PlotAllDifferentAmplitudes(amplDiff, size, CHANNEL_LEFT, name, config);
logmsg(PLOT_ADVANCE_CHAR);
sprintf(name, "%s_%c", config->compareName, CHANNEL_RIGHT);
PlotAllDifferentAmplitudes(amplDiff, size, CHANNEL_RIGHT, name, config);
logmsg(PLOT_ADVANCE_CHAR);
ReturnToMainPath(&returnFolder);
}
logmsg(PLOT_ADVANCE_CHAR);
}
}
if(config->averagePlot)
PlotDifferentAmplitudesAveraged(amplDiff, size, config->compareName, config);
free(amplDiff);
amplDiff = NULL;
}
void PlotDifferentAmplitudesWithBetaFunctions(parameters *config)
{
long int size = 0;
FlatAmplDifference *amplDiff = NULL;
amplDiff = CreateFlatDifferences(config, &size, normalPlot);
if(!amplDiff)
{
logmsg("Not enough memory for plotting\n");
return;
}
for(int o = 0; o < 6; o++)
{
config->outputFilterFunction = o;
PlotAllDifferentAmplitudes(amplDiff, size, CHANNEL_STEREO, config->compareName, config);
}
free(amplDiff);
amplDiff = NULL;
}
/*
void PlotFreqMissing(parameters *config)
{
long int size = 0;
FlatFrequency *freqDiff = NULL;
freqDiff = CreateFlatMissing(config, &size);
if(PlotEachTypeMissingFrequencies(freqDiff, size, config->compareName, config) > 1)
{
PlotAllMissingFrequencies(freqDiff, size, config->compareName, config);
logmsg(PLOT_ADVANCE_CHAR);
}
free(freqDiff);
freqDiff = NULL;
}
*/
FlatFrequency *CreateSpectrogramFrequencies(AudioSignal *Signal, long int *size, int NoiseFloor, parameters *config)
{
FlatFrequency *frequencies = NULL;
if(!size)
return NULL;
*size = 0;
if (config->clock)
{
struct timespec start, end;
double elapsedSeconds;
clock_gettime(CLOCK_MONOTONIC, &start);
frequencies = CreateFlatFrequencies(Signal, size, NoiseFloor, config);
clock_gettime(CLOCK_MONOTONIC, &end);
elapsedSeconds = TimeSpecToSeconds(&end) - TimeSpecToSeconds(&start);
logmsg(" - clk: %s took %0.2fs\n", "CreateFlatFrequencies", elapsedSeconds);
}
else
frequencies = CreateFlatFrequencies(Signal, size, NoiseFloor, config);
return(frequencies);
}
void PlotNoiseFloor(AudioSignal *Signal, parameters *config)
{
long int size = 0;
FlatAmplDifference *amplDiff = NULL;
amplDiff = CreateFlatDifferences(config, &size, floorPlot);
if(!amplDiff)
{
logmsg("Not enough memory for plotting\n");
return;
}
//PlotNoiseDifferentAmplitudes(amplDiff, size, config->compareName, config, Signal);
//if(config->averagePlot)
PlotNoiseDifferentAmplitudesAveraged(amplDiff, size, config->compareName, config, Signal);
free(amplDiff);
amplDiff = NULL;
}
int FillPlotExtra(PlotFile *plot, char *name, int sizex, int sizey, double x0, double y0, double x1, double y1, double penWidth, double leftMarginSize, parameters *config)
{
int rt = 0;
if(!plot)
return 0;
rt = FillPlot(plot, name, x0, y0, x1, y1, penWidth, leftMarginSize, config);
plot->sizex = sizex;
plot->sizey = sizey;
return(rt);
}
#if defined (WIN32)
int checkPathLen(char* file, parameters* config)
{
int len = 0;
char* CurrentPath = NULL;
if (!config)
return 0;
CurrentPath = (char*)malloc(sizeof(char) * FILENAME_MAX);
if (!CurrentPath)
return 0;
if (!GetCurrentDir(CurrentPath, sizeof(char) * FILENAME_MAX))
{
free(CurrentPath);
logmsg("Could not get current path\n");
return 0;
}
len = strlen(CurrentPath) + strlen(file) + 1;
if(len >= MAX_PATH)
{
int lfile = strlen(file);
int third = lfile/3;
logmsg("\nWARNING: Path + file exceeds OS MAX_PATH: ");
if(MAX_PATH > strlen(CurrentPath) + third*2 + 1)
{
int pos = 0;
for(pos = 0; pos < third; pos++)
file[third + pos] = file[lfile - third + pos];
file[third] = '_';
file[third + pos] = '\0';
len = strlen(CurrentPath) + strlen(file) + 1;
logmsg("Shortened to %s\n", file);
}
else
logmsg("Path too long, move MDFourier to a shorter PATH.\n");
}
free(CurrentPath);
return 1;
}
#endif
int FillPlot(PlotFile *plot, char *name, double x0, double y0, double x1, double y1, double penWidth, double leftMarginSize, parameters *config)
{
double dX = 0, dY = 0;
if(!plot)
return 0;
plot->plotter = NULL;
plot->plotter_params = NULL;
plot->file = NULL;
ComposeFileNameoPath(plot->FileName, name, ".png", config);
#if defined (WIN32)
checkPathLen(plot->FileName, config);
#endif
plot->sizex = config->plotResX;
plot->sizey = config->plotResY;
plot->Rx0 = x0;
plot->Rx1 = x1;
plot->Ry0 = y0;
plot->Ry1 = y1;
plot->leftmargin = leftMarginSize;
dX = X0BORDER*fabs(x0 - x1)*leftMarginSize;
dY = Y0BORDER*fabs(y0 - y1);
plot->x0 = x0-dX;
plot->y0 = y0-dY;
dX = X1BORDER*fabs(x0 - x1);
dY = Y1BORDER*fabs(y0 - y1);
plot->x1 = x1+dX;
plot->y1 = y1+dY;
plot->penWidth = penWidth;
plot->SpecialWarning = NULL;
return 1;
}
int CreatePlotFile(PlotFile *plot, parameters *config)
{
char size[20];
plot->file = fopen(plot->FileName, "wb");
if(!plot->file)
{
logmsg("ERROR: Couldn't create graph file %s\n", plot->FileName);
return 0;
}
sprintf(size, "%dx%d", plot->sizex, plot->sizey);
plot->plotter_params = pl_newplparams ();
if(!plot->plotter_params)
{
logmsg("ERROR: Couldn't create plotter_params\n");
return 0;
}
pl_setplparam (plot->plotter_params, "BITMAPSIZE", size);
if((plot->plotter = pl_newpl_r("png", stdin, plot->file, stderr, plot->plotter_params)) == NULL)
{
logmsg("ERROR: Couldn't create Plotter\n");
return 0;
}
if(pl_openpl_r(plot->plotter) < 0)
{
logmsg("ERROR: Couldn't open Plotter\n");
return 0;
}
pl_fspace_r(plot->plotter, plot->x0, plot->y0, plot->x1, plot->y1);
pl_flinewidth_r(plot->plotter, plot->penWidth);
if(config->whiteBG)
pl_bgcolor_r(plot->plotter, 0xffff, 0xffff, 0xffff);
else
pl_bgcolor_r(plot->plotter, 0, 0, 0);
pl_erase_r(plot->plotter);
/*
SetPenColor(COLOR_GREEN, 0xffff, plot);
pl_fbox_r(plot->plotter, plot->Rx0, plot->Ry0, plot->Rx1, plot->Ry1);
pl_endsubpath_r(plot->plotter);
*/
return 1;
}
int ClosePlot(PlotFile *plot)
{
if(pl_closepl_r(plot->plotter) < 0)
{
logmsg("ERROR: Couldn't close Plotter\n");
return 0;
}
if(pl_deletepl_r(plot->plotter) < 0)
{
logmsg("ERROR: Couldn't delete Plotter\n");
return 0;
}
plot->plotter = NULL;
if(pl_deleteplparams(plot->plotter_params) < 0)
{
logmsg("ERROR: Couldn't delete Plotter Params\n");
return 0;
}
plot->plotter_params = NULL;
fclose(plot->file);
plot->file = NULL;
return 1;
}
void DrawBisectionLines(PlotFile *plot, parameters *config)
{
if(config->SetBisectionLines)
{
char label[20];
// Red color for lines
pl_pencolor_r (plot->plotter, 0xffff, 0, 0);
// Draw Bisection lines
pl_fline_r(plot->plotter, transformtoLog(config->BisectionHertz, config), -1*config->maxDbPlotZC, transformtoLog(config->BisectionHertz, config), config->maxDbPlotZC);
pl_endpath_r(plot->plotter);
pl_fline_r(plot->plotter, transformtoLog(config->startHzPlot+1, config), config->BisectionAmplitude, transformtoLog(config->endHzPlot, config), config->BisectionAmplitude);
pl_endpath_r(plot->plotter);
// Draw Frequency Label
pl_savestate_r(plot->plotter);
pl_fspace_r(plot->plotter, 0-X0BORDER*config->plotResX*plot->leftmargin, -1*config->plotResY/2-Y0BORDER*config->plotResY, config->plotResX+X1BORDER*config->plotResX, config->plotResY/2+Y1BORDER*config->plotResY);
pl_ffontname_r(plot->plotter, PLOT_FONT);
pl_ffontsize_r(plot->plotter, FONT_SIZE_1);
pl_fmove_r(plot->plotter, config->plotResX/config->endHzPlot*transformtoLog(config->BisectionHertz, config), config->plotResY/2);
sprintf(label, "%gHz", config->BisectionHertz);
pl_alabel_r(plot->plotter, 'c', 'b', label);
pl_restorestate_r(plot->plotter);