Mercurial > hg > decimation
comparison qm-dsp-decimate/decimate.cpp @ 28:69ee50c19c0c tip
Add decimate-b
author | Chris Cannam |
---|---|
date | Tue, 22 Oct 2013 08:59:42 +0100 |
parents | f8efad075df0 |
children |
comparison
equal
deleted
inserted
replaced
27:ece2031120c9 | 28:69ee50c19c0c |
---|---|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ | 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ |
2 | 2 |
3 #ifdef DECIMATE_B | |
4 #include "qm-dsp/dsp/rateconversion/DecimatorB.h" | |
5 #else | |
3 #include "qm-dsp/dsp/rateconversion/Decimator.h" | 6 #include "qm-dsp/dsp/rateconversion/Decimator.h" |
7 #endif | |
8 | |
4 #include "qm-dsp/maths/MathUtilities.h" | 9 #include "qm-dsp/maths/MathUtilities.h" |
5 | 10 |
6 #include <iostream> | 11 #include <iostream> |
7 #include <sndfile.h> | 12 #include <sndfile.h> |
8 #include <time.h> | 13 #include <time.h> |
60 | 65 |
61 if (!MathUtilities::isPowerOfTwo(factor)) { | 66 if (!MathUtilities::isPowerOfTwo(factor)) { |
62 cerr << "ERROR: Factor must be a power of two" << endl; | 67 cerr << "ERROR: Factor must be a power of two" << endl; |
63 return 1; | 68 return 1; |
64 } | 69 } |
70 #ifdef DECIMATE_B | |
71 if (factor < 2) { | |
72 cerr << "ERROR: Factor must be at least 2" << endl; | |
73 return 1; | |
74 } | |
75 #else | |
65 if (factor < 2 || factor > Decimator::getHighestSupportedFactor()) { | 76 if (factor < 2 || factor > Decimator::getHighestSupportedFactor()) { |
66 cerr << "ERROR: Only factors between 2 and " | 77 cerr << "ERROR: Only factors between 2 and " |
67 << Decimator::getHighestSupportedFactor() | 78 << Decimator::getHighestSupportedFactor() |
68 << " inclusive are supported" <<endl; | 79 << " inclusive are supported" <<endl; |
69 return 1; | 80 return 1; |
70 } | 81 } |
82 #endif | |
71 | 83 |
72 timeval tv; | 84 timeval tv; |
73 (void)gettimeofday(&tv, 0); | 85 (void)gettimeofday(&tv, 0); |
74 | 86 |
75 char *fileName = strdup(argv[optind++]); | 87 char *fileName = strdup(argv[optind++]); |
113 << sf_strerror(sndfileOut) << endl; | 125 << sf_strerror(sndfileOut) << endl; |
114 return 1; | 126 return 1; |
115 } | 127 } |
116 | 128 |
117 int channels = sfinfo.channels; | 129 int channels = sfinfo.channels; |
118 vector<Decimator *> decimators; // one per channel | |
119 | |
120 int ibs = 1024; | 130 int ibs = 1024; |
121 int obs = ibs / factor; | 131 int obs = ibs / factor; |
122 | 132 |
133 #ifdef DECIMATE_B | |
134 vector<DecimatorB *> decimators; // one per channel | |
135 for (int c = 0; c < channels; ++c) { | |
136 decimators.push_back(new DecimatorB(ibs, factor)); | |
137 } | |
138 #else | |
139 vector<Decimator *> decimators; // one per channel | |
123 for (int c = 0; c < channels; ++c) { | 140 for (int c = 0; c < channels; ++c) { |
124 decimators.push_back(new Decimator(ibs, factor)); | 141 decimators.push_back(new Decimator(ibs, factor)); |
125 } | 142 } |
143 #endif | |
126 | 144 |
127 float *ibuf = new float[channels * ibs]; | 145 float *ibuf = new float[channels * ibs]; |
128 float *obuf = new float[channels * obs]; | 146 float *obuf = new float[channels * obs]; |
129 | 147 |
130 double **prebuf = new double*[channels]; | 148 double **prebuf = new double*[channels]; |