* More work on framing, interpolation and scaling for longer window than FFT size.

This adds the --smoothing option to the command line tool and SmoothingOn/Off
  options to the API, introducing a double-length window with presum FFT and
  time-domain smoothing.  Behaviour elsewhere _should_ be unchanged.
This commit is contained in:
Chris Cannam
2010-05-29 22:07:54 +01:00
parent 49cf25d724
commit 99ba629361
10 changed files with 190 additions and 128 deletions

View File

@@ -45,16 +45,23 @@ public:
/**
* Construct a windower of the given type.
*/
Window(WindowType type, int size) : m_type(type), m_size(size) { encache(); }
Window(const Window &w) : m_type(w.m_type), m_size(w.m_size) { encache(); }
Window(WindowType type, int size) : m_type(type), m_size(size), m_cache(0) {
encache();
}
Window(const Window &w) : m_type(w.m_type), m_size(w.m_size), m_cache(0) {
encache();
}
Window &operator=(const Window &w) {
if (&w == this) return *this;
m_type = w.m_type;
m_size = w.m_size;
m_cache = 0;
encache();
return *this;
}
virtual ~Window() { delete[] m_cache; }
virtual ~Window() {
deallocate(m_cache);
}
inline void cut(T *const R__ block) const {
v_multiply(block, m_cache, m_size);
@@ -68,6 +75,16 @@ public:
v_add_with_gain(dst, m_cache, m_size, scale);
}
inline T getRMS() const {
T total = 0;
for (int i = 0; i < m_size; ++i) {
total += m_cache[i] * m_cache[i];
}
T rms = sqrt(total / m_size);
std::cerr << "rms = " << rms << std::endl;
return rms;
}
inline T getArea() const { return m_area; }
inline T getValue(int i) const { return m_cache[i]; }
@@ -87,41 +104,42 @@ protected:
template <typename T>
void Window<T>::encache()
{
if (!m_cache) m_cache = allocate<T>(m_size);
const int n = m_size;
T *mult = allocate<T>(n);
v_set(mult, T(1.0), n);
v_set(m_cache, T(1.0), n);
int i;
switch (m_type) {
case RectangularWindow:
for (i = 0; i < n; ++i) {
mult[i] *= 0.5;
m_cache[i] *= 0.5;
}
break;
case BartlettWindow:
for (i = 0; i < n/2; ++i) {
mult[i] *= (i / T(n/2));
mult[i + n/2] *= (1.0 - (i / T(n/2)));
m_cache[i] *= (i / T(n/2));
m_cache[i + n/2] *= (1.0 - (i / T(n/2)));
}
break;
case HammingWindow:
cosinewin(mult, 0.54, 0.46, 0.0, 0.0);
cosinewin(m_cache, 0.54, 0.46, 0.0, 0.0);
break;
case HanningWindow:
cosinewin(mult, 0.50, 0.50, 0.0, 0.0);
cosinewin(m_cache, 0.50, 0.50, 0.0, 0.0);
break;
case BlackmanWindow:
cosinewin(mult, 0.42, 0.50, 0.08, 0.0);
cosinewin(m_cache, 0.42, 0.50, 0.08, 0.0);
break;
case GaussianWindow:
for (i = 0; i < n; ++i) {
mult[i] *= pow(2, - pow((i - (n-1)/2.0) / ((n-1)/2.0 / 3), 2));
m_cache[i] *= pow(2, - pow((i - (n-1)/2.0) / ((n-1)/2.0 / 3), 2));
}
break;
@@ -130,29 +148,27 @@ void Window<T>::encache()
int N = n-1;
for (i = 0; i < N/4; ++i) {
T m = 2 * pow(1.0 - (T(N)/2 - i) / (T(N)/2), 3);
mult[i] *= m;
mult[N-i] *= m;
m_cache[i] *= m;
m_cache[N-i] *= m;
}
for (i = N/4; i <= N/2; ++i) {
int wn = i - N/2;
T m = 1.0 - 6 * pow(wn / (T(N)/2), 2) * (1.0 - abs(wn) / (T(N)/2));
mult[i] *= m;
mult[N-i] *= m;
m_cache[i] *= m;
m_cache[N-i] *= m;
}
break;
}
case NuttallWindow:
cosinewin(mult, 0.3635819, 0.4891775, 0.1365995, 0.0106411);
cosinewin(m_cache, 0.3635819, 0.4891775, 0.1365995, 0.0106411);
break;
case BlackmanHarrisWindow:
cosinewin(mult, 0.35875, 0.48829, 0.14128, 0.01168);
cosinewin(m_cache, 0.35875, 0.48829, 0.14128, 0.01168);
break;
}
m_cache = mult;
m_area = 0;
for (i = 0; i < n; ++i) {
m_area += m_cache[i];