comparison layer/WaveformLayer.cpp @ 1339:b0555b434575 zoom

Add custom waveform oversampler method
author Chris Cannam
date Wed, 26 Sep 2018 11:54:25 +0100
parents 6d091348e4e9
children fc3c9971a43a
comparison
equal deleted inserted replaced
1338:6d091348e4e9 1339:b0555b434575
21 #include "base/RangeMapper.h" 21 #include "base/RangeMapper.h"
22 #include "base/Strings.h" 22 #include "base/Strings.h"
23 23
24 #include "ColourDatabase.h" 24 #include "ColourDatabase.h"
25 #include "PaintAssistant.h" 25 #include "PaintAssistant.h"
26 #include "WaveformOversampler.h"
26 27
27 #include <QPainter> 28 #include <QPainter>
28 #include <QPixmap> 29 #include <QPixmap>
29 #include <QTextStream> 30 #include <QTextStream>
30 31
49 m_channelMode(SeparateChannels), 50 m_channelMode(SeparateChannels),
50 m_channel(-1), 51 m_channel(-1),
51 m_scale(LinearScale), 52 m_scale(LinearScale),
52 m_middleLineHeight(0.5), 53 m_middleLineHeight(0.5),
53 m_aggressive(false), 54 m_aggressive(false),
54 m_oversampler(0),
55 m_cache(0), 55 m_cache(0),
56 m_cacheValid(false) 56 m_cacheValid(false)
57 { 57 {
58 } 58 }
59 59
60 WaveformLayer::~WaveformLayer() 60 WaveformLayer::~WaveformLayer()
61 { 61 {
62 delete m_cache; 62 delete m_cache;
63 delete m_oversampler;
64 } 63 }
65 64
66 void 65 void
67 WaveformLayer::setModel(const RangeSummarisableTimeValueModel *model) 66 WaveformLayer::setModel(const RangeSummarisableTimeValueModel *model)
68 { 67 {
82 81
83 m_model = model; 82 m_model = model;
84 m_cacheValid = false; 83 m_cacheValid = false;
85 if (!m_model || !m_model->isOK()) return; 84 if (!m_model || !m_model->isOK()) return;
86 85
87 delete m_oversampler;
88 breakfastquay::Resampler::Parameters params;
89 params.initialSampleRate = m_model->getSampleRate();
90 // Oversampler is initialised with 1 channel: we resample the
91 // channels individually for practical reasons (because channel
92 // configuration may vary)
93 m_oversampler = new breakfastquay::Resampler(params, 1);
94
95 connectSignals(m_model); 86 connectSignals(m_model);
96 87
97 emit modelReplaced(); 88 emit modelReplaced();
98 89
99 if (channelsChanged) emit layerParametersChanged(); 90 if (channelsChanged) emit layerParametersChanged();
707 << rf0 << ")" << endl; 698 << rf0 << ")" << endl;
708 return; 699 return;
709 } 700 }
710 701
711 for (int ch = minChannel; ch <= maxChannel; ++ch) { 702 for (int ch = minChannel; ch <= maxChannel; ++ch) {
712 floatvec_t raw = m_model->getData(ch, rf0, rf1 - rf0); 703 floatvec_t oversampled = WaveformOversampler::getOversampledData
713 floatvec_t oversampled(oversampleBy * (frame1 - frame0 + 2 * tail), 704 (m_model, ch, frame0, frame1 - frame0, oversampleBy);
714 0.f);
715 //!!! return value, err etc
716 m_oversampler->reset();
717 m_oversampler->resampleInterleaved(oversampled.data(),
718 oversampled.size(),
719 raw.data(),
720 raw.size(),
721 oversampleBy,
722 true);
723 RangeSummarisableTimeValueModel::RangeBlock rr; 705 RangeSummarisableTimeValueModel::RangeBlock rr;
724 for (sv_frame_t ix = leftTail * oversampleBy; 706 for (float v: oversampled) {
725 in_range_for(oversampled, ix + (rightTail * oversampleBy));
726 ++ix) {
727 RangeSummarisableTimeValueModel::Range r; 707 RangeSummarisableTimeValueModel::Range r;
728 r.sample(oversampled[ix]); 708 r.sample(v);
729 rr.push_back(r); 709 rr.push_back(r);
730 } 710 }
731 ranges.push_back(rr); 711 ranges.push_back(rr);
732 712
733 #ifdef DEBUG_WAVEFORM_PAINT 713 #ifdef DEBUG_WAVEFORM_PAINT