comparison data/model/WaveformOversampler.cpp @ 1538:fa67fbbff8fc zoom

Oversampler fixes and further tests
author Chris Cannam
date Wed, 26 Sep 2018 15:11:26 +0100
parents eb10ed56d5a4
children ca43af0dcab7
comparison
equal deleted inserted replaced
1537:c5092ca1c6e5 1538:fa67fbbff8fc
36 36
37 for (int i = 0; i < targetCount; ++i) { 37 for (int i = 0; i < targetCount; ++i) {
38 double pos = (double(i) / oversampleBy) * m_filterRatio; 38 double pos = (double(i) / oversampleBy) * m_filterRatio;
39 double diff = pos - floor(pos); 39 double diff = pos - floor(pos);
40 int ix = int(floor(pos)); 40 int ix = int(floor(pos));
41 float interpolated = (1.0 - diff) * fixedRatio[ix]; 41 double interpolated = (1.0 - diff) * fixedRatio[ix];
42 if (in_range_for(fixedRatio, ix + 1)) { 42 if (in_range_for(fixedRatio, ix + 1)) {
43 interpolated += diff * fixedRatio[ix + 1]; 43 interpolated += diff * fixedRatio[ix + 1];
44 } 44 }
45 result[i] = interpolated; 45 result[i] = float(interpolated);
46 } 46 }
47 47
48 return result; 48 return result;
49 } 49 }
50 50
63 63
64 sv_frame_t targetFrameCount = sourceFrameCount * m_filterRatio; 64 sv_frame_t targetFrameCount = sourceFrameCount * m_filterRatio;
65 65
66 sv_frame_t filterLength = m_filter.size(); // NB this is known to be odd 66 sv_frame_t filterLength = m_filter.size(); // NB this is known to be odd
67 sv_frame_t filterTailOut = (filterLength - 1) / 2; 67 sv_frame_t filterTailOut = (filterLength - 1) / 2;
68 sv_frame_t filterTailIn = filterTailIn / m_filterRatio; 68 sv_frame_t filterTailIn = filterTailOut / m_filterRatio;
69 69
70 floatvec_t oversampled(targetFrameCount, 0.f); 70 floatvec_t oversampled(targetFrameCount, 0.f);
71 71
72 sv_frame_t i0 = sourceStartFrame - filterTailIn; 72 sv_frame_t i0 = sourceStartFrame - filterTailIn;
73 if (i0 < 0) { 73 if (i0 < 0) {
75 } 75 }
76 sv_frame_t i1 = sourceStartFrame + sourceFrameCount + filterTailIn; 76 sv_frame_t i1 = sourceStartFrame + sourceFrameCount + filterTailIn;
77 if (i1 > sourceLength) { 77 if (i1 > sourceLength) {
78 i1 = sourceLength; 78 i1 = sourceLength;
79 } 79 }
80 80
81 floatvec_t sourceData = source->getData(channel, i0, i1 - i0); 81 floatvec_t sourceData = source->getData(channel, i0, i1 - i0);
82 82
83 for (sv_frame_t i = i0; i < i1; ++i) { 83 for (sv_frame_t i = i0; i < i1; ++i) {
84 float v = sourceData[i - i0]; 84 float v = sourceData[i - i0];
85 sv_frame_t outOffset = 85 sv_frame_t outOffset =