comparison data/model/test/MockWaveModel.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 bdebff3265ae
children bead35921256
comparison
equal deleted inserted replaced
1095:b66734b5f806 1096:4d9816ba0ebe
22 for (auto sort: sorts) { 22 for (auto sort: sorts) {
23 m_data.push_back(generate(sort, length, pad)); 23 m_data.push_back(generate(sort, length, pad));
24 } 24 }
25 } 25 }
26 26
27 sv_frame_t 27 vector<float>
28 MockWaveModel::getData(int channel, sv_frame_t start, sv_frame_t count, 28 MockWaveModel::getData(int channel, sv_frame_t start, sv_frame_t count) const
29 float *buffer) const
30 { 29 {
31 sv_frame_t i = 0; 30 sv_frame_t i = 0;
32 31
33 // cerr << "MockWaveModel::getData(" << channel << "," << start << "," << count << "): "; 32 // cerr << "MockWaveModel::getData(" << channel << "," << start << "," << count << "): ";
34 33
34 vector<float> data;
35
35 while (i < count) { 36 while (i < count) {
36 sv_frame_t idx = start + i; 37 sv_frame_t idx = start + i;
37 if (!in_range_for(m_data[channel], idx)) break; 38 if (!in_range_for(m_data[channel], idx)) break;
38 buffer[i] = m_data[channel][idx]; 39 data.push_back(m_data[channel][idx]);
39 // cerr << buffer[i] << " "; 40 // cerr << data[i] << " ";
40 ++i; 41 ++i;
41 } 42 }
42 43
43 // cerr << endl; 44 // cerr << endl;
44 45
45 return i; 46 return data;
46 } 47 }
47 48
48 sv_frame_t 49 vector<vector<float>>
49 MockWaveModel::getMultiChannelData(int fromchannel, int tochannel, 50 MockWaveModel::getMultiChannelData(int fromchannel, int tochannel,
50 sv_frame_t start, sv_frame_t count, 51 sv_frame_t start, sv_frame_t count) const
51 float **buffers) const
52 { 52 {
53 sv_frame_t min = count; 53 vector<vector<float>> data(tochannel - fromchannel + 1);
54 54
55 for (int c = fromchannel; c <= tochannel; ++c) { 55 for (int c = fromchannel; c <= tochannel; ++c) {
56 sv_frame_t n = getData(c, start, count, buffers[c]); 56 data.push_back(getData(c, start, count));
57 if (n < min) min = n;
58 } 57 }
59 58
60 return min; 59 return data;
61 } 60 }
62 61
63 vector<float> 62 vector<float>
64 MockWaveModel::generate(Sort sort, int length, int pad) const 63 MockWaveModel::generate(Sort sort, int length, int pad) const
65 { 64 {