comparison data/model/AggregateWaveModel.cpp @ 300:5877d68815c7

* Change WaveFileModel API from getValues(start,end) to getData(start,count). It's much less error-prone to pass in frame counts instead of start/end locations. Should have done this ages ago. This closes #1794563. * Add option to apply a transform to only the selection region, instead of the whole audio. * (to make the above work properly) Add start frame offset to wave models
author Chris Cannam
date Mon, 01 Oct 2007 13:48:38 +0000
parents c022976d18e8
children 70a232b1f12a
comparison
equal deleted inserted replaced
299:576be0d0d218 300:5877d68815c7
95 { 95 {
96 return new AggregateWaveModel(m_components); 96 return new AggregateWaveModel(m_components);
97 } 97 }
98 98
99 size_t 99 size_t
100 AggregateWaveModel::getValues(int channel, size_t start, size_t end, 100 AggregateWaveModel::getData(int channel, size_t start, size_t count,
101 float *buffer) const 101 float *buffer) const
102 { 102 {
103 int ch0 = channel, ch1 = channel; 103 int ch0 = channel, ch1 = channel;
104 bool mixing = false; 104 bool mixing = false;
105 if (channel == -1) { 105 if (channel == -1) {
106 ch0 = 0; 106 ch0 = 0;
108 mixing = true; 108 mixing = true;
109 } 109 }
110 110
111 float *readbuf = buffer; 111 float *readbuf = buffer;
112 if (mixing) { 112 if (mixing) {
113 readbuf = new float[end - start]; 113 readbuf = new float[count];
114 for (size_t i = 0; i < end - start; ++i) { 114 for (size_t i = 0; i < count; ++i) {
115 buffer[i] = 0.f; 115 buffer[i] = 0.f;
116 } 116 }
117 } 117 }
118 118
119 size_t sz = end - start; 119 size_t sz = count;
120 120
121 for (int c = ch0; c <= ch1; ++c) { 121 for (int c = ch0; c <= ch1; ++c) {
122 size_t szHere = 122 size_t szHere =
123 m_components[c].model->getValues(m_components[c].channel, 123 m_components[c].model->getData(m_components[c].channel,
124 start, end, 124 start, count,
125 readbuf); 125 readbuf);
126 if (szHere < sz) sz = szHere; 126 if (szHere < sz) sz = szHere;
127 if (mixing) { 127 if (mixing) {
128 for (size_t i = 0; i < end - start; ++i) { 128 for (size_t i = 0; i < count; ++i) {
129 buffer[i] += readbuf[i]; 129 buffer[i] += readbuf[i];
130 } 130 }
131 } 131 }
132 } 132 }
133 133
134 if (mixing) delete[] readbuf; 134 if (mixing) delete[] readbuf;
135 return sz; 135 return sz;
136 } 136 }
137 137
138 size_t 138 size_t
139 AggregateWaveModel::getValues(int channel, size_t start, size_t end, 139 AggregateWaveModel::getData(int channel, size_t start, size_t count,
140 double *buffer) const 140 double *buffer) const
141 { 141 {
142 int ch0 = channel, ch1 = channel; 142 int ch0 = channel, ch1 = channel;
143 bool mixing = false; 143 bool mixing = false;
144 if (channel == -1) { 144 if (channel == -1) {
145 ch0 = 0; 145 ch0 = 0;
147 mixing = true; 147 mixing = true;
148 } 148 }
149 149
150 double *readbuf = buffer; 150 double *readbuf = buffer;
151 if (mixing) { 151 if (mixing) {
152 readbuf = new double[end - start]; 152 readbuf = new double[count];
153 for (size_t i = 0; i < end - start; ++i) { 153 for (size_t i = 0; i < count; ++i) {
154 buffer[i] = 0.f; 154 buffer[i] = 0.0;
155 } 155 }
156 } 156 }
157 157
158 size_t sz = end - start; 158 size_t sz = count;
159 159
160 for (int c = ch0; c <= ch1; ++c) { 160 for (int c = ch0; c <= ch1; ++c) {
161 size_t szHere = 161 size_t szHere =
162 m_components[c].model->getValues(m_components[c].channel, 162 m_components[c].model->getData(m_components[c].channel,
163 start, end, 163 start, count,
164 readbuf); 164 readbuf);
165 if (szHere < sz) sz = szHere; 165 if (szHere < sz) sz = szHere;
166 if (mixing) { 166 if (mixing) {
167 for (size_t i = 0; i < end - start; ++i) { 167 for (size_t i = 0; i < count; ++i) {
168 buffer[i] += readbuf[i]; 168 buffer[i] += readbuf[i];
169 } 169 }
170 } 170 }
171 } 171 }
172 172
173 if (mixing) delete[] readbuf; 173 if (mixing) delete[] readbuf;
174 return sz; 174 return sz;
175 } 175 }
176 176
177 void 177 void
178 AggregateWaveModel::getRanges(size_t channel, size_t start, size_t end, 178 AggregateWaveModel::getSummaries(size_t channel, size_t start, size_t count,
179 RangeBlock &ranges, size_t &blockSize) const 179 RangeBlock &ranges, size_t &blockSize) const
180 { 180 {
181 //!!! complete 181 //!!! complete
182 } 182 }
183 183
184 AggregateWaveModel::Range 184 AggregateWaveModel::Range
185 AggregateWaveModel::getRange(size_t channel, size_t start, size_t end) const 185 AggregateWaveModel::getSummary(size_t channel, size_t start, size_t count) const
186 { 186 {
187 //!!! complete 187 //!!! complete
188 return Range(); 188 return Range();
189 } 189 }
190 190