comparison data/model/FFTModel.cpp @ 1450:a12fd0456f0c streaming-csv-writer

Merge from default branch
author Chris Cannam
date Tue, 17 Apr 2018 10:35:42 +0100
parents 48e9f538e6e9
children 0925b37a3ed1
comparison
equal deleted inserted replaced
1449:deabf9fd3d28 1450:a12fd0456f0c
17 #include "DenseTimeValueModel.h" 17 #include "DenseTimeValueModel.h"
18 18
19 #include "base/Profiler.h" 19 #include "base/Profiler.h"
20 #include "base/Pitch.h" 20 #include "base/Pitch.h"
21 #include "base/HitCount.h" 21 #include "base/HitCount.h"
22 #include "base/Debug.h"
22 23
23 #include <algorithm> 24 #include <algorithm>
24 25
25 #include <cassert> 26 #include <cassert>
26 #include <deque> 27 #include <deque>
50 while (m_cached.size() < m_cacheSize) { 51 while (m_cached.size() < m_cacheSize) {
51 m_cached.push_back({ -1, cvec(m_fftSize / 2 + 1) }); 52 m_cached.push_back({ -1, cvec(m_fftSize / 2 + 1) });
52 } 53 }
53 54
54 if (m_windowSize > m_fftSize) { 55 if (m_windowSize > m_fftSize) {
55 cerr << "ERROR: FFTModel::FFTModel: window size (" << m_windowSize 56 SVCERR << "ERROR: FFTModel::FFTModel: window size (" << m_windowSize
56 << ") must be at least FFT size (" << m_fftSize << ")" << endl; 57 << ") must be at least FFT size (" << m_fftSize << ")" << endl;
57 throw invalid_argument("FFTModel window size must be at least FFT size"); 58 throw invalid_argument("FFTModel window size must be at least FFT size");
58 } 59 }
59 60
60 m_fft.initFloat(); 61 m_fft.initFloat();
61 62
70 71
71 void 72 void
72 FFTModel::sourceModelAboutToBeDeleted() 73 FFTModel::sourceModelAboutToBeDeleted()
73 { 74 {
74 if (m_model) { 75 if (m_model) {
75 cerr << "FFTModel[" << this << "]::sourceModelAboutToBeDeleted(" << m_model << ")" << endl; 76 SVDEBUG << "FFTModel[" << this << "]::sourceModelAboutToBeDeleted(" << m_model << ")" << endl;
76 m_model = 0; 77 m_model = 0;
77 } 78 }
78 } 79 }
79 80
80 int 81 int
285 vector<float> pad(pfx, 0.f); 286 vector<float> pad(pfx, 0.f);
286 data.insert(data.begin(), pad.begin(), pad.end()); 287 data.insert(data.begin(), pad.begin(), pad.end());
287 } 288 }
288 289
289 if (m_channel == -1) { 290 if (m_channel == -1) {
290 int channels = m_model->getChannelCount(); 291 int channels = m_model->getChannelCount();
291 if (channels > 1) { 292 if (channels > 1) {
292 int n = int(data.size()); 293 int n = int(data.size());
293 float factor = 1.f / float(channels); 294 float factor = 1.f / float(channels);
294 // use mean instead of sum for fft model input 295 // use mean instead of sum for fft model input
295 for (int i = 0; i < n; ++i) { 296 for (int i = 0; i < n; ++i) {
296 data[i] *= factor; 297 data[i] *= factor;
297 } 298 }
298 } 299 }
299 } 300 }
300 301
301 return data; 302 return data;
302 } 303 }
303 304