Mercurial > hg > decimation
diff garage-resampler/resample.cpp @ 16:66abf86c864d
Add bandwidth, snr parameters
author | Chris Cannam |
---|---|
date | Fri, 18 Oct 2013 14:57:48 +0100 |
parents | 8c87484e6d79 |
children |
line wrap: on
line diff
--- a/garage-resampler/resample.cpp Fri Oct 18 13:08:00 2013 +0100 +++ b/garage-resampler/resample.cpp Fri Oct 18 14:57:48 2013 +0100 @@ -20,6 +20,8 @@ int targetRate = 0; bool version = false; bool help = false; + double snr = 100; + double bandwidth = 0.02; int c = 0; while (1) { @@ -29,11 +31,13 @@ { "help", 0, 0, 'h' }, { "version", 0, 0, 'V' }, { "to", 1, 0, 't' }, + { "snr", 1, 0, 's' }, + { "bandwidth", 1, 0, 'b' }, { 0, 0, 0, 0 } }; c = getopt_long(argc, argv, - "t:hV", + "t:hVs:b:", longOpts, &optionIndex); if (c == -1) break; @@ -41,6 +45,8 @@ case 'h': help = true; break; case 'V': version = true; break; case 't': targetRate = atoi(optarg); break; + case 's': snr = atof(optarg); break; + case 'b': bandwidth = atof(optarg); break; default: help = true; break; } } @@ -52,7 +58,7 @@ if (help || targetRate == 0 || optind + 2 != argc) { cerr << endl; - cerr << "usage: " << argv[0] << " --to <rate> <infile.wav> <outfile.wav>" << endl; + cerr << "usage: " << argv[0] << " --to <rate> [--snr <s>] [--bandwidth <b>] <infile.wav> <outfile.wav>" << endl; cerr << endl; return 2; } @@ -96,8 +102,13 @@ int channels = sfinfo.channels; vector<Resampler *> resamplers; // one per channel + cerr << "Resampling from " << sourceRate << " to " << targetRate + << " Hz [with snr " << snr << ", bandwidth " << bandwidth << "]" + << endl; + for (int c = 0; c < channels; ++c) { - resamplers.push_back(new Resampler(sourceRate, targetRate)); + resamplers.push_back + (new Resampler(sourceRate, targetRate, snr, bandwidth)); } int outputLatency = resamplers[0]->getLatency(); @@ -199,7 +210,11 @@ etv.tv_usec -= tv.tv_usec; double sec = double(etv.tv_sec) + (double(etv.tv_usec) / 1000000.0); - cerr << "elapsed time: " << sec << " sec, in frames/sec: " << sfinfo.frames/sec << ", out frames/sec: " << n/sec << endl; + cerr << sfinfo.frames << " frames in, " << n << " frames out" + << ", nominal ratio " << double(targetRate)/double(sourceRate) + << ", actual " << double(n)/double(sfinfo.frames) + << endl << "Elapsed time: " << sec << " sec, in frames/sec: " + << int(sfinfo.frames/sec) << ", out frames/sec: " << int(n/sec) << endl; return 0; }