#include #include #include "Arguments.h" extern char _binary_usage_txt_start; extern char _binary_usage_txt_end; using std::string; static void coefficients_bass(int intensity, double *b0, double *b1, double *b2, double *a1, double *a2); static void coefficients_treble(int intensity, double *b0, double *b1, double *b2, double *a1, double *a2); Arguments::Arguments(int argc, char** argv) { while(1) { switch(getopt(argc, argv, "p:b:t:h")) { case 'p': { this->max_threads = atoi(optarg); continue; } case 'b': { this->gain_bass = atoi(optarg); continue; } case 't': { this->gain_treble = atoi(optarg); continue; } case 'h': { char* s = &_binary_usage_txt_start; int len = &_binary_usage_txt_end - &_binary_usage_txt_start + 1; printf("%.*s", len, s); exit(0); continue; } case -1: break; } if (optind + 2 > argc) { printf("please provide an input and output file\n"); exit(1); } this->file_input = string(argv[optind++]); this->file_output = string(argv[optind++]); break; } calculate_coefficients(); } void Arguments::calculate_coefficients() { coefficients_bass(this->gain_bass, &this->bass.b0, &this->bass.b1, &this->bass.b2, &this->bass.a1, &this->bass.a2); coefficients_treble(this->gain_treble, &this->treble.b0, &this->treble.b1, &this->treble.b2, &this->treble.a1, &this->treble.a2); } static void coefficients_bass(int intensity, double *b0, double *b1, double *b2, double *a1, double *a2) { double frequency = 330; double qFactor = 0.5; double gain = intensity; double sampleRate = 44100; double pi = 4.0 * atan(1); double a = pow(10.0, gain / 40); double w0 = 2 * pi * frequency / sampleRate; double alpha = sin(w0) / (2.0 * qFactor); double a0 = (a + 1) + (a - 1) * cos(w0) + 2.0 * sqrt(a) * alpha; *a1 = -(-2.0 * ((a - 1) + (a + 1) * cos(w0))) / a0; *a2 = -((a + 1) + (a - 1) * cos(w0) - 2.0 * sqrt(a) * alpha) / a0; *b0 = (a * ((a + 1) - (a - 1) * cos(w0) + 2.0 * sqrt(a) * alpha)) / a0; *b1 = (2 * a * ((a - 1) - (a + 1) * cos(w0))) / a0; *b2 = (a * ((a + 1) - (a - 1) * cos(w0) - 2.0 * sqrt(a) * alpha)) / a0; } static void coefficients_treble(int intensity, double *b0, double *b1, double *b2, double *a1, double *a2) { double frequency = 3300; double qFactor = 0.5; double gain = intensity; double sampleRate = 44100; double pi = 4.0 * atan(1); double a = pow(10.0, gain / 40); double w0 = 2 * pi * frequency / sampleRate; double alpha = sin(w0) / (2.0 * qFactor); double a0 = (a + 1) - (a - 1) * cos(w0) + 2.0 * sqrt(a) * alpha; *a1 = -(2.0 * ((a - 1) - (a + 1) * cos(w0))) / a0; *a2 = -((a + 1) - (a - 1) * cos(w0) - 2.0 * sqrt(a) * alpha) / a0; *b0 = (a * ((a + 1) + (a - 1) * cos(w0) + 2.0 * sqrt(a) * alpha)) / a0; *b1 = (-2.0 * a * ((a - 1) + (a + 1) * cos(w0))) / a0; *b2 = (a * ((a + 1) + (a - 1) * cos(w0) - 2.0 * sqrt(a) * alpha)) / a0; }