-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProject_3.cpp
More file actions
1776 lines (1517 loc) · 54 KB
/
Copy pathProject_3.cpp
File metadata and controls
1776 lines (1517 loc) · 54 KB
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
/**
* @file main.cpp
* @author Jennifer Freeman (freemjc@mcmaster.ca)
* @brief
* @version 0.1
* @date 2021-12-19
*
* @copyright Copyright (c) 2021
*
*/
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <sstream>
#include <cmath>
#include <complex>
#include <algorithm>
using namespace std;
// ============================================================================================= //
// Begin class wav_file //
/**
* @brief WAV audio file class.
*
*/
class wav_file
{
public:
// ===========
// Constructor
// ===========
/**
* @brief Construct a new wav file object from file name.
*
* @param input_string string of wav file name, (ex. "filename.wav").
*/
wav_file(const string &input_string)
{
read_wav(input_string);
}
/**
* @brief Construct a new wav file object from existing wav_file object.
*
* @param wav wav_file object to extract header and sampling rate.
* @param dat vector containing audio signal data.
*/
wav_file(wav_file &wav, vector<complex<double>> &dat)
{
// Use the same header and sampling rate from input wav_file.
header = wav.header;
f_samp = wav.f_samp;
// Convert data to 16-bit.
for (uint64_t j = 0; j < dat.size(); j++)
{
double real_part = real(dat[j]);
int16_t round_real = (int16_t)round(real_part);
data.push_back(round_real);
}
}
// =======================
// Public member functions
// =======================
/**
* @brief Read in WAV file.
*
* @param input_string string of wav file name, (ex. "filename.wav").
*/
void read_wav(const string &input_string)
{
string s; // String to store input.
string wav_identifier; // String to store expected WAV identifier.
string format_size; // Size of format in header.
string current; // Current input value.
int16_t temp; // Temporary variable to store input values.
int16_t bits_persamp; // Bits per sample.
uint64_t data_section = 0; // Size of data section in file.
uint64_t power = 1; // Nearest power of 2 to data size.
uint64_t data_size = 1; // Size of data in 2-bytes.
uint64_t max_data_size = 1.2e7; // Maximum allowable data size (12 MB).
// Open input file.
ifstream input(input_string, ios::binary);
if (!input.is_open())
{
throw ios_base::failure("Error opening input file! \n");
};
// Seek to WAV identifier position.
input.seekg(8);
// Get WAV identifier.
for (uint32_t i = 0; i < 4; i++)
{
current = (char)input.get();
wav_identifier.insert(i, current);
}
if (wav_identifier != "WAVE")
{
throw invalid_argument("Not a .WAV file.");
}
input.seekg(16);
// Get size of format data in header.
for (uint32_t i = 0; i < 4; i++)
{
current = (char)input.get();
format_size.insert(i, current);
}
// Read in WAV header (44 bytes).
input.seekg(0);
for (uint32_t k = 0; k < (20 + *(uint32_t *)&format_size[0] + 8); k++)
{
current = (char)input.get();
header.insert(k, current);
}
// Verify file is 16-bit.
bits_persamp = *(int16_t *)&header[34];
if (bits_persamp != 16)
{
throw invalid_argument("Not a 16-bit .WAV file.");
}
// Get data section size.
data_section = *(int32_t *)&header[20 + *(uint32_t *)&format_size[0] + 4];
// Check file size.
if (data_section > max_data_size)
{
throw invalid_argument("File size is larger than maximum allowable (12 MB).");
}
// Ensure data section is a multiple of 2.
if (data_section % 2 != 0)
{
data_section = data_section + 1;
}
// Calculate size of data in 16 bits.
data_size = data_section / 2;
// Compute next closest power of two to data size.
while (power <= data_size)
{
power *= 2;
}
// Seek to data chunk.
input.seekg(44);
// Read in data.
for (uint64_t i = 0; i < data_size; i++)
{
input.read((char *)&temp, sizeof(int16_t));
data.push_back((int16_t)temp);
}
// Resize data to include padding.
data.resize(power);
input.close();
// Get sampling rate.
f_samp = *(uint32_t *)&header[24];
//Get the number of channels
channel = *(uint16_t *)&header[22];
}
/**
* @brief Write WAV file.
*
* @param outfile string of outfile name (ex. "Outfile.wav")
*/
void write_wav(string &outfile)
{
// Create output WAV file.
ofstream output_wav(outfile, ios::binary);
if (!output_wav.is_open())
{
throw ios_base::failure("Error opening input file! \n");
}
// Write WAV file header.
for (uint64_t i = 0; i < header.size(); i++)
{
output_wav.write(&header[i], sizeof(int8_t));
}
// Write WAV data with real part of complex inverse FFT values.
for (uint64_t j = 0; j < data.size(); j++)
{
output_wav.write((char *)&data[j], sizeof(int16_t));
}
output_wav.close();
}
/**
* @brief Size of padded data in WAV file.
*
* @return uint64_t size of vector.
*/
uint64_t datasize()
{
return data.size();
}
/**
* @brief Get the 16-bit audio signal data and convert to complex<double>.
*
* @return vector<complex<double>> vector of converted signal.
*/
vector<complex<double>> get_data()
{
vector<complex<double>> new_vec(data.begin(), data.end());
return new_vec;
}
/**
* @brief Get the 44-byte header string from the WAV file.
*
* @return string header string.
*/
string get_header()
{
return header;
}
/**
* @brief Get the sampling rate from the WAV file..
*
* @return uint32_t sampling rate (ex. 44100 Hz)
*/
uint32_t get_samp()
{
return f_samp;
}
/**
* @brief Get the channel number of the WAV file.
*
* @return uint16_t channel number. 1 = mono, 2 = stereo.
*/
uint16_t get_channel()
{
return channel;
}
/**
* @brief Get the size of the data section from the WAV file in bytes (excluding padding).
*
* @return uint32_t size of the data section in bytes.
*/
uint32_t orig_size()
{
uint32_t format_size = *(uint32_t *)&header[16];
uint32_t data_section = *(int32_t *)&header[20 + format_size + 4];
return data_section;
}
/**
* @brief Update header to reflect new WAV file sizes.
*
* @param s size in bytes of data section in new WAV file.
*/
void update_size(uint32_t s)
{
uint32_t format_size = *(uint32_t *)&header[16];
// Update data section size.
header[20 + format_size + 4] = (unsigned char)s;
header[20 + format_size + 5] = (unsigned char)(s >> 8);
header[20 + format_size + 6] = (unsigned char)(s >> 16);
header[20 + format_size + 7] = (unsigned char)(s >> 24);
uint32_t file_size = ((uint32_t)header.size() - 8) + s;
// Update total file size.
header[4] = (unsigned char)file_size;
header[5] = (unsigned char)(file_size >> 8);
header[6] = (unsigned char)(file_size >> 16);
header[7] = (unsigned char)(file_size >> 24);
}
/**
* @brief Update header to reflect new sampling rate for new WAV files.
*
* @param f sampling rate.
*/
void update_fsamp(uint32_t f)
{
// Update sampling rate in header.
header[24] = (unsigned char)f;
header[25] = (unsigned char)(f >> 8);
header[26] = (unsigned char)(f >> 16);
header[27] = (unsigned char)(f >> 24);
}
private:
// ============
// Private data
// ============
/**
* @brief Header in WAV file.
*
*/
string header;
/**
* @brief Data in WAV file.
*
*/
vector<int16_t> data;
/**
* @brief Sampling rate in Hz.
*
*/
uint32_t f_samp;
/**
* @brief Number of channels in WAV file.
*
*/
uint16_t channel;
};
// End class wav_file //
// ============================================================================================= //
// ============================================================================================= //
// Begin class frequency //
/**
* @brief frequency class
*
*/
class frequency
{
public:
// ===========
// Constructor
// ===========
/**
* @brief Construct frequency value from a string.
*
* @param num string to convert to frequency.
*/
frequency(const string &num)
{
uint32_t input_freq = 0;
// Verify input is an integer.
try
{
input_freq = stol(num);
}
catch (const invalid_argument &e)
{
throw invalid_argument("Invalid frequency argument. Expected a number.");
}
catch (const out_of_range &e)
{
throw out_of_range("Frequency input is out of range for 'std::stol'.");
}
// Verify frequency is in audible range.
if (input_freq < 20 || input_freq > 20000)
{
throw out_of_range("Frequency outside audible range (20 Hz, 20000 Hz). \n");
}
f = input_freq;
}
/**
* @brief Construct a frequency value from a number.
*
* @param num number to convert to frequency.
*/
frequency(uint32_t &num)
{
// Verify frequency is in audible range.
if (num < 20 || num > 20000)
{
throw out_of_range("Frequency outside audible range (20 Hz, 20000 Hz) \n");
}
f = num;
}
// =======================
// Public member functions
// =======================
/**
* @brief Get the frequency value.
*
* @return uint32_t frequency (Hz).
*/
uint32_t get_frequency()
{
return f;
}
private:
// ============
// Private data
// ============
/**
* @brief frequency in Hz.
*
*/
uint32_t f;
};
// End class frequency //
// ============================================================================================= //
// ============================================================================================= //
// Begin class fft //
/**
* @brief Fast Fourier transform class.
*
*/
class fft
{
public:
// ===========
// Constructor
// ===========
/**
* @brief Construct a new fft object.
*
* @param dat vector of complex data to perform FFT on.
*/
fft(vector<complex<double>> &dat)
{
x = cooley_tukey(dat);
}
// =======================
// Public member functions
// =======================
/**
* @brief Cooley-Tukey radix-2 FFT algorithm.
*
* @param dat data to perform FFT on.
* @return vector<complex<double>> FFT bins.
*/
vector<complex<double>> cooley_tukey(vector<complex<double>> &dat)
{
const double pi = acos(-1.0);
// Get size of input vector.
uint64_t N = dat.size();
if (N == 1)
{
// Do nothing.
}
else
{
// Divide N by 2.
double N_2 = (double)N / 2;
// Initialize to store DFTs for even and odd indices.
vector<complex<double>> even;
vector<complex<double>> odd;
// Separate input vector into even and odd indices.
for (uint64_t i = 0; i < (uint64_t)N_2; i++)
{
even.push_back(dat[2 * i]);
odd.push_back(dat[2 * i + 1]);
}
// Recursively compute even and odd vectors.
cooley_tukey(even);
cooley_tukey(odd);
complex<double> q = 0;
for (uint64_t k = 0; k < (uint64_t)N_2; k++)
{
// Twiddle factor times odd values.
q = polar(1.0, (-2.0 * pi * (double)k) / (double)(N)) * odd[k];
// Update k-th DFT.
dat[k] = even[k] + q;
dat[k + (uint64_t)N_2] = even[k] - q;
}
}
return dat;
}
/**
* @brief Get the output from the FFT.
*
* @return vector<complex<double>> FFT bins.
*/
vector<complex<double>> get_data()
{
return x;
}
/**
* @brief Get the index of the FFT bins at a given frequency.
*
* @param f frequency.
* @param f_samp sampling rate of signal.
* @return uint32_t index of FFT bin.
*/
uint32_t get_index(frequency &f, uint32_t f_samp)
{
// Size of FFT chunk.
uint64_t N = x.size();
// Frequency value.
uint32_t freq = f.get_frequency();
// Comput index of FFT bin at specified frequency.
double i = round((double)freq * (double)N) / ((double)f_samp);
uint32_t index = (uint32_t)i;
return index;
}
private:
// ============
// Private data
// ============
/**
* @brief values from output of FFT (FFT bins).
*
*/
vector<complex<double>> x;
};
// End class fft //
// ============================================================================================= //
// ============================================================================================= //
// Begin class i_fft //
/**
* @brief Inverse Fast Fourier transform class.
*
*/
class i_fft
{
public:
// ===========
// Constructor
// ===========
/**
* @brief Construct a new inverse fft object.
*
* @param dft values to perform inverse FFT on.
*/
i_fft(vector<complex<double>> &dft)
{
y = inverse(dft);
}
// =======================
// Public member functions
// =======================
/**
* @brief Inverse Cooley-Tukey radix-2 FFT.
*
* @param freq_domain frequency domain values to perform inverse FFT on.
* @return vector<complex<double>> inverse FFT values.
*/
vector<complex<double>> inverse(vector<complex<double>> &freq_domain)
{
// Compute complex conjugate of data in freqency domain.
for (uint64_t i = 0; i < freq_domain.size(); i++)
{
freq_domain[i] = conj(freq_domain[i]);
}
// Compute forward FFT.
fft out(freq_domain);
freq_domain = out.get_data();
uint64_t N = freq_domain.size();
// Compute complex conjugate and scale output by N.
for (uint64_t i = 0; i < freq_domain.size(); i++)
{
freq_domain[i] = conj(freq_domain[i]) / (double)N;
}
return freq_domain;
}
/**
* @brief Get the inverse FFT values.
*
* @return vector<complex<double>> values from the output of the inverse FFT.
*/
vector<complex<double>> get_data()
{
return y;
}
private:
// ============
// Private data
// ============
/**
* @brief Values from the output of the inverse FFT.
*
*/
vector<complex<double>>
y;
};
// End class i_fft //
// ============================================================================================= //
// ============================================================================================= //
// Begin class filter //
/**
* @brief Digital filter class for signal processing.
*
*/
class filter
{
public:
// ===========
// Constructor
// ===========
/**
* @brief Construct a new filter object with one index to apply to FFT bins.
*
* @param index index of frequency value used in filter.
* @param fft_values FFT bins to filter.
*/
filter(uint32_t &index, vector<complex<double>> &fft_values)
{
// Check index is not larger than length of FFT bins.
if (index > fft_values.size())
{
throw out_of_range("Filter index value is larger than FFT vector");
}
threshold_one = index;
bins = fft_values;
n = (uint32_t)fft_values.size();
}
/**
* @brief Construct a new filter object with two indicdes to apply to FFT bins.
*
* @param index_one index of frequency value used in filter.
* @param index_two second index of frequency value used in filter.
* @param fft_values FFT bins to filter.
*/
filter(uint32_t &index_one, uint32_t &index_two, vector<complex<double>> &fft_values)
{
// Check index is not larger than length of FFT bins.
if ((index_one > fft_values.size()) && (index_two > fft_values.size()))
{
throw out_of_range("Filter index value is larger than FFT vector");
}
threshold_one = index_one;
threshold_two = index_two;
bins = fft_values;
n = (uint32_t)fft_values.size();
}
// =======================
// Public member functions
// =======================
/**
* @brief Low-pass sharp-cut digital filter. Frequencies above threshold will be removed.
*
* @return vector<complex<double>> filtered FFT values.
*/
vector<complex<double>> low_pass()
{
// Remove frequency domain outside of threshold
for (uint32_t i = threshold_one; i < (n - threshold_one); i++)
{
bins[i] = 0;
}
return bins;
}
/**
* @brief High-pass sharp-cut digital filter. Frequencies below threshold will be removed.
*
* @return vector<complex<double>> filtered FFT values.
*/
vector<complex<double>> high_pass()
{
// Remove frequency domain outside of threshold
for (uint32_t i = 0; i < threshold_one; i++)
{
bins[i] = 0;
}
for (uint32_t i = (n - threshold_one); i < n; i++)
{
bins[i] = 0;
}
return bins;
}
/**
* @brief Band-pass sharp-cut digital filter. Frequencies above and below both thresholds will be removed.
*
* @return vector<complex<double>> filtered FFT values.
*/
vector<complex<double>> band_pass()
{
// Remove frequency domain outside of both thresholds.
for (uint32_t i = 0; i < threshold_one; i++)
{
bins[i] = 0;
}
for (uint32_t i = threshold_two; i < (n / 2 + threshold_two); i++)
{
bins[i] = 0;
}
for (uint32_t i = (n - threshold_one); i < n; i++)
{
bins[i] = 0;
}
return bins;
}
private:
// ============
// Private data
// ============
/**
* @brief Index of first frequency value in filter.
*
*/
uint32_t threshold_one;
/**
* @brief Index of second frequency value in filter.
*
*/
uint32_t threshold_two;
/**
* @brief Filtered FFT bins.
*
*/
vector<complex<double>> bins;
/**
* @brief Length of FFT bins.
*
*/
uint32_t n;
};
// End class filter //
// ============================================================================================= //
// ============================================================================================= //
// Begin class equalize //
/**
* @brief Equalizer class to perform decibel attenuation and boost to signal.
*
*/
class equalize
{
public:
// ===========
// Constructor
// ===========
/**
* @brief Construct a new equalize object with default values.
*
*/
equalize()
{
modify.assign({0, 0, 0, 0, 0, 0, 0, 0, 0, 0});
bands = get_bands();
}
/**
* @brief Construct a new equalize object given ten input decibel changes to apply to the ten frequency bands.
*
* @param one decibel change to apply to band one.
* @param two decibel change to apply to band two.
* @param three decibel change to apply to band three.
* @param four decibel change to apply to band four.
* @param five decibel change to apply to band five.
* @param six decibel change to apply to band six.
* @param seven decibel change to apply to band seven.
* @param eight decibel change to apply to band eight.
* @param nine decibel change to apply to band nine.
* @param ten decibel change to apply to band ten.
*/
equalize(char *one, char *two, char *three, char *four, char *five, char *six, char *seven, char *eight, char *nine, char *ten)
{
// Put input decibel changes in a vector.
vector<string> input_vec = {one, two, three, four, five, six, seven, eight, nine, ten};
int32_t input_dec;
for (uint32_t i = 0; i < input_vec.size(); i++)
{
// Verify decibel change is an integer.
try
{
input_dec = stol(input_vec[i]);
}
catch (const invalid_argument &e)
{
throw invalid_argument("Invalid decibel argument. Expected a number. \n");
}
catch (const out_of_range &e)
{
throw out_of_range("Decibel scaler is out of range for 'std::stol'. \n");
}
// Verify decibel change is betwen -24 and 24.
if (input_dec < -24 || input_dec > 24)
{
throw out_of_range("Decibel scaler is outside valid range. Valid rand is (-24dB, 24dB)\n");
}
modify.push_back(input_dec);
}
// Bands are set to ten frequency ranges.
bands = get_bands();
}
// =======================
// Public member functions
// =======================
/**
* @brief Flat band equalizer to apply decibel changes across entire band.
*
* @param fft FFT object to apply equalizing.
* @param fs sampling rate of signal.
* @return vector<complex<double>> Equalized FFT values
*/
vector<complex<double>> flat_band(fft &fft, uint32_t &fs)
{
vector<complex<double>> fft_data;
vector<uint32_t> indices;
// Convert decibel change to gain.
double gain;
fft_data = fft.get_data();
// Get frequency index bound of each band.
for (uint32_t i = 0; i < bands.size(); i++)
{
indices.push_back(fft.get_index(bands[i], fs));
}
// Apply gain across entire band.
for (uint32_t i = 0; i < (bands.size() - 1); i++)
{
gain = pow(10.0, ((double)modify[i] / 20.0));
for (uint32_t k = indices[i]; k < indices[i + 1]; k++)
{
fft_data[k] = fft_data[k] * gain;
}
}
return fft_data;
}
/**
* @brief Get the preset ten frequency bands.
*
* @return vector<frequency> vector of frequency bands.
*/
vector<frequency> get_bands()
{
uint32_t n1 = 23;
uint32_t n2 = 45;
uint32_t n3 = 89;
uint32_t n4 = 177;
uint32_t n5 = 354;
uint32_t n6 = 707;
uint32_t n7 = 1414;
uint32_t n8 = 2828;
uint32_t n9 = 5657;
uint32_t n10 = 11314;
uint32_t n11 = 20000;
frequency f1(n1);
frequency f2(n2);
frequency f3(n3);
frequency f4(n4);
frequency f5(n5);
frequency f6(n6);
frequency f7(n7);
frequency f8(n8);
frequency f9(n9);
frequency f10(n10);
frequency f11(n11);
bands.assign({f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11});
return bands;
}
private:
// ============
// Private data
// ============
/**
* @brief Modifications to be made to frequency band in decibel changes.
*
*/
vector<int32_t> modify;
/**
* @brief Preset ten frequency bands.
*
*/
vector<frequency> bands;
};
// End class equalize //
// ============================================================================================= //
// ============================================================================================= //
// Begin class class periodogram //
/**
* @brief Class to compute periodogram, frequency versus power spectrum.
*
*/
class periodogram
{
public:
// ===========
// Constructor
// ===========
/**
* @brief Construct a periodogram object given an FFT object and the sampling rate of the signal.
*
* @param fft_object FFT object.
* @param f_samp sampling rate of signal.
*/
periodogram(fft &fft_object, uint32_t &f_samp)
{
// Get FFT bins.
vector<complex<double>> fft_data = fft_object.get_data();
uint32_t freq;
for (uint32_t i = 0; i < fft_data.size(); i++)
{
// Compute modulus of complex FFT bins.
magnitude.push_back(abs(fft_data[i]));
// Get frequency value for each FFT bins.
freq = (uint32_t)round((double)(i * f_samp) / (double)fft_data.size());
// For small and large values, round to audible range.
if (freq < 20)
{