HRESULT TaudioFilterEQsuper::process(TfilterQueue::iterator it, TsampleFormat &fmt, void *samples, size_t numsamples, const TfilterSettingsAudio *cfg0) { const TeqSettings *cfg = (const TeqSettings*)cfg0; if (!eqs[0] || oldnchannels != fmt.nchannels || !cfg->equal(old)) { old = *cfg; oldnchannels = fmt.nchannels; float bands[supereq::NBANDS + 1]; for (unsigned int b = 0; b <= supereq::NBANDS; b++) { float db = (cfg->highdb - cfg->lowdb) * (&cfg->eq0)[b] / 200.0f + cfg->lowdb; bands[b] = db2value(db, 100); // pow(10.0,db/(100*20.0)); } for (unsigned int ch = 0; ch < fmt.nchannels; ch++) { if (eqs[ch]) { delete eqs[ch]; } eqs[ch] = new supereq; eqs[ch]->equ_makeTable(bands, (float)fmt.freq, &cfg->f0); } } float *in = (float*)init(cfg, fmt, samples, numsamples), *out = NULL; int samples_out = 0; for (unsigned int ch = 0; ch < fmt.nchannels; ch++) { eqs[ch]->write_samples(in + ch, (int)numsamples, fmt.nchannels); const float *eqout = eqs[ch]->get_output(&samples_out); if (!out) { out = (float*)alloc_buffer(fmt, samples_out, buf); } for (int i = 0; i < samples_out; i++) { out[ch + i * fmt.nchannels] = eqout[i]; } } return parent->deliverSamples(++it, fmt, out, samples_out); }
void TvolumePage::volTbr2cfg(int idc, int idff, int mult) { int x = tbrGet(idc); if (isdb) { x = mult * ff_round(db2value((double)x * mult) * 100); } cfgSet(idff, mult * x); }
void TvolumePage::TvolumeTbr::storeEditValue(const TffdshowParamInfo &info, int min, int max, const char_t *valS) { int x; self->eval(valS, min, max, &x, 1, true); if (isdb) { x = ff_round(db2value((double)x) * 100); } self->deci->putParam(info.id, x); }
void TvolumePage::applySettings(void) { HWND hed = GetDlgItem(m_hwnd, IDC_ED_VOLUME_NORMALIZE_MAX); if (isdb) { int db; if (eval(hed, 0, 30, &db)) { db = ff_round(db2value((double)db) * 100); cfgSet(IDFF_maxNormalization, db); } } else { eval(hed, 0, MAX_AMPLIFICATION, IDFF_maxNormalization); } }
void TaudioFilterEQ::Tequalizer::init(const TeqSettings *cfg, double freq) { reset(); static const double qmult = 1; for (int i = 0; i < AF_NCH; i++) for (int j = 0; j < KM; j++) { float db = (cfg->highdb - cfg->lowdb) * (&cfg->eq0)[j] / 200.0f + cfg->lowdb; g[i][j] = (float)(qmult * (db2value(db, 100)/* pow(10.0,db/(100*20.0))*/ - 1.0)); } K = KM; while (((&cfg->f0)[K - 1] / 100.0) > freq / 2.3) { K--; } for (int k = 0; k < K; k++) { bp2(a[k], b[k], ((&cfg->f0)[k] / 100.0) / freq, Q); } }
const FIRInstance * ParamFIR::make(int sample_rate) const { int i; ///////////////////////////////////////////////////////////////////////////// // Normalize double norm_factor = norm? 1.0: 1.0 / sample_rate; double f1_ = f1 * norm_factor; double f2_ = f2 * norm_factor; double df_ = df * norm_factor; ///////////////////////////////////////////////////////////////////////////// // Trivial cases if (f1_ < 0.0 || f2_ < 0.0 || df_ <= 0.0 || a < 0.0) return 0; if (a == 0.0) return new IdentityFIRInstance(sample_rate); switch (type) { case low_pass: if (f1_ >= 0.5) return new IdentityFIRInstance(sample_rate); if (f1_ == 0.0) return new GainFIRInstance(sample_rate, db2value(a)); break; case high_pass: if (f1_ >= 0.5) return new GainFIRInstance(sample_rate, db2value(a)); if (f1_ == 0.0) return new IdentityFIRInstance(sample_rate); break; case band_pass: if (f1_ >= 0.5) return new GainFIRInstance(sample_rate, db2value(a)); if (f2_ == 0.0) return new GainFIRInstance(sample_rate, db2value(a)); if (f1_ == 0.0 && f2_ >= 0.5) return new IdentityFIRInstance(sample_rate); break; case band_stop: if (f1_ >= 0.5) return new IdentityFIRInstance(sample_rate); if (f2_ == 0.0) return new IdentityFIRInstance(sample_rate); if (f1_ == 0.0 && f2_ >= 0.5) return new GainFIRInstance(sample_rate, db2value(a)); break; default: return 0; } ///////////////////////////////////////////////////////////////////////////// // Build the filter int n = kaiser_n(a, df_) | 1; // make odd (type 1 filter) int c = n / 2; DynamicFIRInstance *fir = new DynamicFIRInstance(sample_rate, n, c); double *filter = fir->buf; filter[0] = 1.0; double alpha = kaiser_alpha(a); switch (type) { case low_pass: for (i = 0; i < n; i++) filter[i] = (sample_t) (2 * f1_ * sinc((i - c) * 2 * M_PI * f1_) * kaiser_window(i - c, n, alpha)); return fir; case high_pass: for (i = 0; i < n; i++) filter[i] = (sample_t) (-2 * f1_ * sinc((i - c) * 2 * M_PI * f1_) * kaiser_window(i - c, n, alpha)); filter[c] = (sample_t) ((1 - 2 * f1_) * kaiser_window(0, n, alpha)); return fir; case band_pass: for (i = 0; i < n; i++) filter[i] = (sample_t) ((2 * f2_ * sinc((i - c) * 2 * M_PI * f2_) - 2 * f1_ * sinc((i - c) * 2 * M_PI * f1_)) * kaiser_window(i - c, n, alpha)); return fir; case band_stop: for (i = 0; i < n; i++) filter[i] = (sample_t) ((2 * f1_ * sinc((i - c) * 2 * M_PI * f1_) - 2 * f2_ * sinc((i - c) * 2 * M_PI * f2_)) * kaiser_window(i - c, n, alpha)); filter[c] = (sample_t) ((2 * f1_ + 1 - 2 * f2_) * kaiser_window(0, n, alpha)); return fir; }; // never be here assert(false); delete filter; return 0; }
int main(int argc, char **argv) { if (argc < 3) { printf( "Gain\n" "====\n" "Simple gain tool to amplify or attenuate an audio file.\n" "This utility is a part of AC3Filter project (http://ac3filter.net)\n" "Copyright (c) 2008-2009 by Alexander Vigovsky\n" "\n" "Usage:\n" " > gain input.wav output.wav [-g[ain]:n]\n" "\n" "Options:\n" " input.wav - file to process\n" " output.wav - file to write the result to\n" " -gain - gain to apply\n" "\n" "Example:\n" " > gain a.wav b.wav -gain:-10\n" " Attenuate by 10dB\n" ); return 0; } const char *input_filename = argv[1]; const char *output_filename = argv[2]; double gain = 1.0; ///////////////////////////////////////////////////////////////////////////// // Parse arguments for (int iarg = 3; iarg < argc; iarg++) { // -gain if (is_arg(argv[iarg], "gain", argt_num)) { gain = db2value(arg_num(argv[iarg])); continue; } printf("Error: unknown option: %s\n", argv[iarg]); return -1; } ///////////////////////////////////////////////////////////////////////////// // Open files WAVSource src(input_filename, block_size); if (!src.is_open()) { printf("Error: cannot open file: %s\n", input_filename); return -1; } WAVSink sink(output_filename); if (!sink.is_open()) { printf("Error: cannot open file: %s\n", output_filename); return -1; } Speakers spk = src.get_output(); ///////////////////////////////////////////////////////////////////////////// // Build the chain Converter iconv(block_size); Converter oconv(block_size); iconv.set_format(FORMAT_LINEAR); oconv.set_format(src.get_output().format); Gain gain_filter; AGC agc(1024); gain_filter.gain = gain; FilterChain chain; chain.add_back(&iconv, "Input converter"); chain.add_back(&gain_filter, "Gain"); chain.add_back(&agc, "AGC"); chain.add_back(&oconv, "Output converter"); if (!chain.set_input(spk)) { printf("Error: cannot start processing\n"); return -1; } ///////////////////////////////////////////////////////////////////////////// // Do the job Chunk chunk; printf("0%%\r"); vtime_t t = local_time() + 0.1; while (!src.is_empty()) { src.get_chunk(&chunk); if (!chain.process_to(&chunk, &sink)) { char buf[1024]; chain.chain_text(buf, array_size(buf)); printf("Processing error. Chain dump: %s\n", buf); return -1; } if (local_time() > t) { t += 0.1; double pos = double(src.pos()) * 100 / src.size(); printf("%i%%\r", (int)pos); } } printf("100%%\n"); return 0; }