comparison data/model/AggregateWaveModel.cpp @ 1096:4d9816ba0ebe simple-fft-model

Rework audio file reader API to prefer using std containers
author Chris Cannam
date Mon, 15 Jun 2015 12:19:47 +0100
parents 9f4505ac9072
children 5cbf71022679
comparison
equal deleted inserted replaced
1095:b66734b5f806 1096:4d9816ba0ebe
17 17
18 #include <iostream> 18 #include <iostream>
19 19
20 #include <QTextStream> 20 #include <QTextStream>
21 21
22 using namespace std;
23
22 PowerOfSqrtTwoZoomConstraint 24 PowerOfSqrtTwoZoomConstraint
23 AggregateWaveModel::m_zoomConstraint; 25 AggregateWaveModel::m_zoomConstraint;
24 26
25 AggregateWaveModel::AggregateWaveModel(ChannelSpecList channelSpecs) : 27 AggregateWaveModel::AggregateWaveModel(ChannelSpecList channelSpecs) :
26 m_components(channelSpecs) 28 m_components(channelSpecs)
90 { 92 {
91 if (m_components.empty()) return 0; 93 if (m_components.empty()) return 0;
92 return m_components.begin()->model->getSampleRate(); 94 return m_components.begin()->model->getSampleRate();
93 } 95 }
94 96
95 sv_frame_t 97 vector<float>
96 AggregateWaveModel::getData(int channel, sv_frame_t start, sv_frame_t count, 98 AggregateWaveModel::getData(int channel, sv_frame_t start, sv_frame_t count) const
97 float *buffer) const
98 { 99 {
99 int ch0 = channel, ch1 = channel; 100 int ch0 = channel, ch1 = channel;
100 bool mixing = false;
101 if (channel == -1) { 101 if (channel == -1) {
102 ch0 = 0; 102 ch0 = 0;
103 ch1 = getChannelCount()-1; 103 ch1 = getChannelCount()-1;
104 mixing = true; 104 }
105 } 105
106 106 vector<float> result(count, 0.f);
107 float *readbuf = buffer;
108 if (mixing) {
109 readbuf = new float[count];
110 for (sv_frame_t i = 0; i < count; ++i) {
111 buffer[i] = 0.f;
112 }
113 }
114 107
115 sv_frame_t longest = 0; 108 sv_frame_t longest = 0;
116 109
117 for (int c = ch0; c <= ch1; ++c) { 110 for (int c = ch0; c <= ch1; ++c) {
118 sv_frame_t here = 111
119 m_components[c].model->getData(m_components[c].channel, 112 auto here = m_components[c].model->getData(m_components[c].channel,
120 start, count, 113 start, count);
121 readbuf); 114 if (here.size() > longest) {
122 if (here > longest) { 115 longest = here.size();
123 longest = here; 116 }
124 } 117 for (sv_frame_t i = 0; in_range_for(here, i); ++i) {
125 if (here < count) { 118 result[i] += here[i];
126 for (sv_frame_t i = here; i < count; ++i) { 119 }
127 readbuf[i] = 0.f; 120 }
128 } 121
129 } 122 result.resize(longest);
130 if (mixing) { 123 return result;
131 for (sv_frame_t i = 0; i < count; ++i) { 124 }
132 buffer[i] += readbuf[i]; 125
133 } 126 vector<vector<float>>
134 }
135 }
136
137 if (mixing) delete[] readbuf;
138 return longest;
139 }
140
141 sv_frame_t
142 AggregateWaveModel::getMultiChannelData(int fromchannel, int tochannel, 127 AggregateWaveModel::getMultiChannelData(int fromchannel, int tochannel,
143 sv_frame_t start, sv_frame_t count, 128 sv_frame_t start, sv_frame_t count) const
144 float **buffer) const
145 { 129 {
146 sv_frame_t min = count; 130 sv_frame_t min = count;
147 131
132 vector<vector<float>> result;
133
148 for (int c = fromchannel; c <= tochannel; ++c) { 134 for (int c = fromchannel; c <= tochannel; ++c) {
149 sv_frame_t here = getData(c, start, count, buffer[c - fromchannel]); 135 auto here = getData(c, start, count);
150 if (here < min) min = here; 136 if (here.size() < min) min = here.size();
137 result.push_back(here);
138 }
139
140 if (min < count) {
141 for (auto &v : result) v.resize(min);
151 } 142 }
152 143
153 return min; 144 return result;
154 } 145 }
155 146
156 int 147 int
157 AggregateWaveModel::getSummaryBlockSize(int desired) const 148 AggregateWaveModel::getSummaryBlockSize(int desired) const
158 { 149 {