annotate data/model/AggregateWaveModel.cpp @ 1136:e94719f941ba tony-2.0-integration

Return maximum through getNormalizedMagnitudesAt to avoid having to make more than one call
author Chris Cannam
date Tue, 20 Oct 2015 12:54:06 +0100
parents 5cbf71022679
children 54af1e21705c
rev   line source
Chris@297 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@297 2
Chris@297 3 /*
Chris@297 4 Sonic Visualiser
Chris@297 5 An audio file viewer and annotation editor.
Chris@297 6 Centre for Digital Music, Queen Mary, University of London.
Chris@297 7 This file copyright 2007 QMUL.
Chris@297 8
Chris@297 9 This program is free software; you can redistribute it and/or
Chris@297 10 modify it under the terms of the GNU General Public License as
Chris@297 11 published by the Free Software Foundation; either version 2 of the
Chris@297 12 License, or (at your option) any later version. See the file
Chris@297 13 COPYING included with this distribution for more information.
Chris@297 14 */
Chris@297 15
Chris@297 16 #include "AggregateWaveModel.h"
Chris@297 17
Chris@297 18 #include <iostream>
Chris@297 19
Chris@314 20 #include <QTextStream>
Chris@314 21
Chris@1096 22 using namespace std;
Chris@1096 23
Chris@297 24 PowerOfSqrtTwoZoomConstraint
Chris@297 25 AggregateWaveModel::m_zoomConstraint;
Chris@297 26
Chris@297 27 AggregateWaveModel::AggregateWaveModel(ChannelSpecList channelSpecs) :
Chris@297 28 m_components(channelSpecs)
Chris@297 29 {
Chris@297 30 for (ChannelSpecList::const_iterator i = channelSpecs.begin();
Chris@297 31 i != channelSpecs.end(); ++i) {
Chris@297 32 if (i->model->getSampleRate() !=
Chris@297 33 channelSpecs.begin()->model->getSampleRate()) {
Chris@690 34 SVDEBUG << "AggregateWaveModel::AggregateWaveModel: WARNING: Component models do not all have the same sample rate" << endl;
Chris@297 35 break;
Chris@297 36 }
Chris@297 37 }
Chris@297 38 }
Chris@297 39
Chris@297 40 AggregateWaveModel::~AggregateWaveModel()
Chris@297 41 {
Chris@297 42 }
Chris@297 43
Chris@297 44 bool
Chris@297 45 AggregateWaveModel::isOK() const
Chris@297 46 {
Chris@297 47 for (ChannelSpecList::const_iterator i = m_components.begin();
Chris@297 48 i != m_components.end(); ++i) {
Chris@297 49 if (!i->model->isOK()) return false;
Chris@297 50 }
Chris@297 51 return true;
Chris@297 52 }
Chris@297 53
Chris@297 54 bool
Chris@297 55 AggregateWaveModel::isReady(int *completion) const
Chris@297 56 {
Chris@297 57 if (completion) *completion = 100;
Chris@297 58 bool ready = true;
Chris@297 59 for (ChannelSpecList::const_iterator i = m_components.begin();
Chris@297 60 i != m_components.end(); ++i) {
Chris@297 61 int completionHere = 100;
Chris@297 62 if (!i->model->isReady(&completionHere)) ready = false;
Chris@297 63 if (completion && completionHere < *completion) {
Chris@297 64 *completion = completionHere;
Chris@297 65 }
Chris@297 66 }
Chris@297 67 return ready;
Chris@297 68 }
Chris@297 69
Chris@1038 70 sv_frame_t
Chris@297 71 AggregateWaveModel::getFrameCount() const
Chris@297 72 {
Chris@1038 73 sv_frame_t count = 0;
Chris@297 74
Chris@297 75 for (ChannelSpecList::const_iterator i = m_components.begin();
Chris@297 76 i != m_components.end(); ++i) {
Chris@1038 77 sv_frame_t thisCount = i->model->getEndFrame() - i->model->getStartFrame();
Chris@297 78 if (thisCount > count) count = thisCount;
Chris@297 79 }
Chris@297 80
Chris@297 81 return count;
Chris@297 82 }
Chris@297 83
Chris@929 84 int
Chris@297 85 AggregateWaveModel::getChannelCount() const
Chris@297 86 {
Chris@1038 87 return int(m_components.size());
Chris@297 88 }
Chris@297 89
Chris@1040 90 sv_samplerate_t
Chris@297 91 AggregateWaveModel::getSampleRate() const
Chris@297 92 {
Chris@297 93 if (m_components.empty()) return 0;
Chris@297 94 return m_components.begin()->model->getSampleRate();
Chris@297 95 }
Chris@297 96
Chris@1096 97 vector<float>
Chris@1096 98 AggregateWaveModel::getData(int channel, sv_frame_t start, sv_frame_t count) const
Chris@297 99 {
Chris@297 100 int ch0 = channel, ch1 = channel;
Chris@297 101 if (channel == -1) {
Chris@297 102 ch0 = 0;
Chris@297 103 ch1 = getChannelCount()-1;
Chris@297 104 }
Chris@297 105
Chris@1096 106 vector<float> result(count, 0.f);
Chris@297 107
Chris@1038 108 sv_frame_t longest = 0;
Chris@1008 109
Chris@297 110 for (int c = ch0; c <= ch1; ++c) {
Chris@1096 111
Chris@1096 112 auto here = m_components[c].model->getData(m_components[c].channel,
Chris@1096 113 start, count);
Chris@1100 114 if (sv_frame_t(here.size()) > longest) {
Chris@1100 115 longest = sv_frame_t(here.size());
Chris@1008 116 }
Chris@1096 117 for (sv_frame_t i = 0; in_range_for(here, i); ++i) {
Chris@1096 118 result[i] += here[i];
Chris@297 119 }
Chris@297 120 }
Chris@297 121
Chris@1096 122 result.resize(longest);
Chris@1096 123 return result;
Chris@297 124 }
Chris@363 125
Chris@1096 126 vector<vector<float>>
Chris@1086 127 AggregateWaveModel::getMultiChannelData(int fromchannel, int tochannel,
Chris@1096 128 sv_frame_t start, sv_frame_t count) const
Chris@363 129 {
Chris@1038 130 sv_frame_t min = count;
Chris@363 131
Chris@1096 132 vector<vector<float>> result;
Chris@1096 133
Chris@929 134 for (int c = fromchannel; c <= tochannel; ++c) {
Chris@1096 135 auto here = getData(c, start, count);
Chris@1100 136 if (sv_frame_t(here.size()) < min) {
Chris@1100 137 min = sv_frame_t(here.size());
Chris@1100 138 }
Chris@1096 139 result.push_back(here);
Chris@1096 140 }
Chris@1096 141
Chris@1096 142 if (min < count) {
Chris@1096 143 for (auto &v : result) v.resize(min);
Chris@363 144 }
Chris@363 145
Chris@1096 146 return result;
Chris@363 147 }
Chris@377 148
Chris@929 149 int
Chris@929 150 AggregateWaveModel::getSummaryBlockSize(int desired) const
Chris@377 151 {
Chris@377 152 //!!! complete
Chris@377 153 return desired;
Chris@377 154 }
Chris@297 155
Chris@297 156 void
Chris@1038 157 AggregateWaveModel::getSummaries(int, sv_frame_t, sv_frame_t,
Chris@929 158 RangeBlock &, int &) const
Chris@297 159 {
Chris@297 160 //!!! complete
Chris@297 161 }
Chris@297 162
Chris@297 163 AggregateWaveModel::Range
Chris@1038 164 AggregateWaveModel::getSummary(int, sv_frame_t, sv_frame_t) const
Chris@297 165 {
Chris@297 166 //!!! complete
Chris@297 167 return Range();
Chris@297 168 }
Chris@297 169
Chris@929 170 int
Chris@297 171 AggregateWaveModel::getComponentCount() const
Chris@297 172 {
Chris@1038 173 return int(m_components.size());
Chris@297 174 }
Chris@297 175
Chris@297 176 AggregateWaveModel::ModelChannelSpec
Chris@929 177 AggregateWaveModel::getComponent(int c) const
Chris@297 178 {
Chris@297 179 return m_components[c];
Chris@297 180 }
Chris@297 181
Chris@297 182 void
Chris@297 183 AggregateWaveModel::componentModelChanged()
Chris@297 184 {
Chris@297 185 emit modelChanged();
Chris@297 186 }
Chris@297 187
Chris@297 188 void
Chris@1038 189 AggregateWaveModel::componentModelChangedWithin(sv_frame_t start, sv_frame_t end)
Chris@297 190 {
Chris@947 191 emit modelChangedWithin(start, end);
Chris@297 192 }
Chris@297 193
Chris@297 194 void
Chris@297 195 AggregateWaveModel::componentModelCompletionChanged()
Chris@297 196 {
Chris@297 197 emit completionChanged();
Chris@297 198 }
Chris@297 199
Chris@297 200 void
Chris@929 201 AggregateWaveModel::toXml(QTextStream &,
Chris@929 202 QString ,
Chris@929 203 QString ) const
Chris@297 204 {
Chris@297 205 //!!! complete
Chris@297 206 }
Chris@297 207