annotate data/model/AggregateWaveModel.cpp @ 1068:135c5899a71f tonioni

Revert to -Werror in debug only
author Chris Cannam
date Mon, 13 Apr 2015 13:52:05 +0100
parents 0fd3661bcfff
children 9f4505ac9072
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@297 22 PowerOfSqrtTwoZoomConstraint
Chris@297 23 AggregateWaveModel::m_zoomConstraint;
Chris@297 24
Chris@297 25 AggregateWaveModel::AggregateWaveModel(ChannelSpecList channelSpecs) :
Chris@297 26 m_components(channelSpecs)
Chris@297 27 {
Chris@297 28 for (ChannelSpecList::const_iterator i = channelSpecs.begin();
Chris@297 29 i != channelSpecs.end(); ++i) {
Chris@297 30 if (i->model->getSampleRate() !=
Chris@297 31 channelSpecs.begin()->model->getSampleRate()) {
Chris@690 32 SVDEBUG << "AggregateWaveModel::AggregateWaveModel: WARNING: Component models do not all have the same sample rate" << endl;
Chris@297 33 break;
Chris@297 34 }
Chris@297 35 }
Chris@297 36 }
Chris@297 37
Chris@297 38 AggregateWaveModel::~AggregateWaveModel()
Chris@297 39 {
Chris@297 40 }
Chris@297 41
Chris@297 42 bool
Chris@297 43 AggregateWaveModel::isOK() const
Chris@297 44 {
Chris@297 45 for (ChannelSpecList::const_iterator i = m_components.begin();
Chris@297 46 i != m_components.end(); ++i) {
Chris@297 47 if (!i->model->isOK()) return false;
Chris@297 48 }
Chris@297 49 return true;
Chris@297 50 }
Chris@297 51
Chris@297 52 bool
Chris@297 53 AggregateWaveModel::isReady(int *completion) const
Chris@297 54 {
Chris@297 55 if (completion) *completion = 100;
Chris@297 56 bool ready = true;
Chris@297 57 for (ChannelSpecList::const_iterator i = m_components.begin();
Chris@297 58 i != m_components.end(); ++i) {
Chris@297 59 int completionHere = 100;
Chris@297 60 if (!i->model->isReady(&completionHere)) ready = false;
Chris@297 61 if (completion && completionHere < *completion) {
Chris@297 62 *completion = completionHere;
Chris@297 63 }
Chris@297 64 }
Chris@297 65 return ready;
Chris@297 66 }
Chris@297 67
Chris@1038 68 sv_frame_t
Chris@297 69 AggregateWaveModel::getFrameCount() const
Chris@297 70 {
Chris@1038 71 sv_frame_t count = 0;
Chris@297 72
Chris@297 73 for (ChannelSpecList::const_iterator i = m_components.begin();
Chris@297 74 i != m_components.end(); ++i) {
Chris@1038 75 sv_frame_t thisCount = i->model->getEndFrame() - i->model->getStartFrame();
Chris@297 76 if (thisCount > count) count = thisCount;
Chris@297 77 }
Chris@297 78
Chris@297 79 return count;
Chris@297 80 }
Chris@297 81
Chris@929 82 int
Chris@297 83 AggregateWaveModel::getChannelCount() const
Chris@297 84 {
Chris@1038 85 return int(m_components.size());
Chris@297 86 }
Chris@297 87
Chris@1040 88 sv_samplerate_t
Chris@297 89 AggregateWaveModel::getSampleRate() const
Chris@297 90 {
Chris@297 91 if (m_components.empty()) return 0;
Chris@297 92 return m_components.begin()->model->getSampleRate();
Chris@297 93 }
Chris@297 94
Chris@1038 95 sv_frame_t
Chris@1038 96 AggregateWaveModel::getData(int channel, sv_frame_t start, sv_frame_t count,
Chris@300 97 float *buffer) const
Chris@297 98 {
Chris@297 99 int ch0 = channel, ch1 = channel;
Chris@297 100 bool mixing = false;
Chris@297 101 if (channel == -1) {
Chris@297 102 ch0 = 0;
Chris@297 103 ch1 = getChannelCount()-1;
Chris@297 104 mixing = true;
Chris@297 105 }
Chris@297 106
Chris@297 107 float *readbuf = buffer;
Chris@297 108 if (mixing) {
Chris@300 109 readbuf = new float[count];
Chris@1038 110 for (sv_frame_t i = 0; i < count; ++i) {
Chris@297 111 buffer[i] = 0.f;
Chris@297 112 }
Chris@297 113 }
Chris@297 114
Chris@1038 115 sv_frame_t longest = 0;
Chris@1008 116
Chris@297 117 for (int c = ch0; c <= ch1; ++c) {
Chris@1038 118 sv_frame_t here =
Chris@300 119 m_components[c].model->getData(m_components[c].channel,
Chris@300 120 start, count,
Chris@300 121 readbuf);
Chris@1008 122 if (here > longest) {
Chris@1008 123 longest = here;
Chris@1008 124 }
Chris@1008 125 if (here < count) {
Chris@1038 126 for (sv_frame_t i = here; i < count; ++i) {
Chris@1008 127 readbuf[i] = 0.f;
Chris@1008 128 }
Chris@1008 129 }
Chris@297 130 if (mixing) {
Chris@1038 131 for (sv_frame_t i = 0; i < count; ++i) {
Chris@297 132 buffer[i] += readbuf[i];
Chris@297 133 }
Chris@297 134 }
Chris@297 135 }
Chris@297 136
Chris@297 137 if (mixing) delete[] readbuf;
Chris@1008 138 return longest;
Chris@297 139 }
Chris@297 140
Chris@1038 141 sv_frame_t
Chris@1038 142 AggregateWaveModel::getData(int channel, sv_frame_t start, sv_frame_t count,
Chris@300 143 double *buffer) const
Chris@297 144 {
Chris@297 145 int ch0 = channel, ch1 = channel;
Chris@297 146 bool mixing = false;
Chris@297 147 if (channel == -1) {
Chris@297 148 ch0 = 0;
Chris@297 149 ch1 = getChannelCount()-1;
Chris@297 150 mixing = true;
Chris@297 151 }
Chris@297 152
Chris@297 153 double *readbuf = buffer;
Chris@297 154 if (mixing) {
Chris@300 155 readbuf = new double[count];
Chris@1038 156 for (sv_frame_t i = 0; i < count; ++i) {
Chris@300 157 buffer[i] = 0.0;
Chris@297 158 }
Chris@297 159 }
Chris@297 160
Chris@1038 161 sv_frame_t longest = 0;
Chris@297 162
Chris@297 163 for (int c = ch0; c <= ch1; ++c) {
Chris@1038 164 sv_frame_t here =
Chris@300 165 m_components[c].model->getData(m_components[c].channel,
Chris@300 166 start, count,
Chris@300 167 readbuf);
Chris@1008 168 if (here > longest) {
Chris@1008 169 longest = here;
Chris@1008 170 }
Chris@1008 171 if (here < count) {
Chris@1038 172 for (sv_frame_t i = here; i < count; ++i) {
Chris@1008 173 readbuf[i] = 0.;
Chris@1008 174 }
Chris@1008 175 }
Chris@297 176 if (mixing) {
Chris@1038 177 for (sv_frame_t i = 0; i < count; ++i) {
Chris@297 178 buffer[i] += readbuf[i];
Chris@297 179 }
Chris@297 180 }
Chris@297 181 }
Chris@297 182
Chris@297 183 if (mixing) delete[] readbuf;
Chris@1008 184 return longest;
Chris@297 185 }
Chris@363 186
Chris@1038 187 sv_frame_t
Chris@929 188 AggregateWaveModel::getData(int fromchannel, int tochannel,
Chris@1038 189 sv_frame_t start, sv_frame_t count,
Chris@363 190 float **buffer) const
Chris@363 191 {
Chris@1038 192 sv_frame_t min = count;
Chris@363 193
Chris@929 194 for (int c = fromchannel; c <= tochannel; ++c) {
Chris@1038 195 sv_frame_t here = getData(c, start, count, buffer[c - fromchannel]);
Chris@363 196 if (here < min) min = here;
Chris@363 197 }
Chris@363 198
Chris@363 199 return min;
Chris@363 200 }
Chris@377 201
Chris@929 202 int
Chris@929 203 AggregateWaveModel::getSummaryBlockSize(int desired) const
Chris@377 204 {
Chris@377 205 //!!! complete
Chris@377 206 return desired;
Chris@377 207 }
Chris@297 208
Chris@297 209 void
Chris@1038 210 AggregateWaveModel::getSummaries(int, sv_frame_t, sv_frame_t,
Chris@929 211 RangeBlock &, int &) const
Chris@297 212 {
Chris@297 213 //!!! complete
Chris@297 214 }
Chris@297 215
Chris@297 216 AggregateWaveModel::Range
Chris@1038 217 AggregateWaveModel::getSummary(int, sv_frame_t, sv_frame_t) const
Chris@297 218 {
Chris@297 219 //!!! complete
Chris@297 220 return Range();
Chris@297 221 }
Chris@297 222
Chris@929 223 int
Chris@297 224 AggregateWaveModel::getComponentCount() const
Chris@297 225 {
Chris@1038 226 return int(m_components.size());
Chris@297 227 }
Chris@297 228
Chris@297 229 AggregateWaveModel::ModelChannelSpec
Chris@929 230 AggregateWaveModel::getComponent(int c) const
Chris@297 231 {
Chris@297 232 return m_components[c];
Chris@297 233 }
Chris@297 234
Chris@297 235 void
Chris@297 236 AggregateWaveModel::componentModelChanged()
Chris@297 237 {
Chris@297 238 emit modelChanged();
Chris@297 239 }
Chris@297 240
Chris@297 241 void
Chris@1038 242 AggregateWaveModel::componentModelChangedWithin(sv_frame_t start, sv_frame_t end)
Chris@297 243 {
Chris@947 244 emit modelChangedWithin(start, end);
Chris@297 245 }
Chris@297 246
Chris@297 247 void
Chris@297 248 AggregateWaveModel::componentModelCompletionChanged()
Chris@297 249 {
Chris@297 250 emit completionChanged();
Chris@297 251 }
Chris@297 252
Chris@297 253 void
Chris@929 254 AggregateWaveModel::toXml(QTextStream &,
Chris@929 255 QString ,
Chris@929 256 QString ) const
Chris@297 257 {
Chris@297 258 //!!! complete
Chris@297 259 }
Chris@297 260