Mercurial > hg > svcore
comparison data/model/test/MockWaveModel.cpp @ 1086:9f4505ac9072
Tidy dense time-value model API a bit; add first simple unit test for FFT model
author | Chris Cannam |
---|---|
date | Wed, 10 Jun 2015 17:06:02 +0100 |
parents | |
children | dcf54a6964d0 |
comparison
equal
deleted
inserted
replaced
1085:bf6f64dabe73 | 1086:9f4505ac9072 |
---|---|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ | |
2 | |
3 /* | |
4 Sonic Visualiser | |
5 An audio file viewer and annotation editor. | |
6 Centre for Digital Music, Queen Mary, University of London. | |
7 This file copyright 2006 Chris Cannam. | |
8 | |
9 This program is free software; you can redistribute it and/or | |
10 modify it under the terms of the GNU General Public License as | |
11 published by the Free Software Foundation; either version 2 of the | |
12 License, or (at your option) any later version. See the file | |
13 COPYING included with this distribution for more information. | |
14 */ | |
15 | |
16 #include "MockWaveModel.h" | |
17 | |
18 using namespace std; | |
19 | |
20 MockWaveModel::MockWaveModel(vector<Sort> sorts, int length) | |
21 { | |
22 for (auto sort: sorts) { | |
23 m_data.push_back(generate(sort, length)); | |
24 } | |
25 } | |
26 | |
27 sv_frame_t | |
28 MockWaveModel::getData(int channel, sv_frame_t start, sv_frame_t count, | |
29 float *buffer) const | |
30 { | |
31 sv_frame_t i = 0; | |
32 | |
33 cerr << "MockWaveModel::getData(" << channel << "," << start << "," << count << "): "; | |
34 | |
35 while (i < count) { | |
36 sv_frame_t idx = start + i; | |
37 if (!in_range_for(m_data[channel], idx)) break; | |
38 buffer[i] = m_data[channel][idx]; | |
39 cerr << buffer[i] << " "; | |
40 ++i; | |
41 } | |
42 | |
43 cerr << endl; | |
44 | |
45 return i; | |
46 } | |
47 | |
48 sv_frame_t | |
49 MockWaveModel::getMultiChannelData(int fromchannel, int tochannel, | |
50 sv_frame_t start, sv_frame_t count, | |
51 float **buffers) const | |
52 { | |
53 sv_frame_t min = count; | |
54 | |
55 for (int c = fromchannel; c <= tochannel; ++c) { | |
56 sv_frame_t n = getData(c, start, count, buffers[c]); | |
57 if (n < min) min = n; | |
58 } | |
59 | |
60 return min; | |
61 } | |
62 | |
63 vector<float> | |
64 MockWaveModel::generate(Sort sort, int length) const | |
65 { | |
66 vector<float> data; | |
67 | |
68 for (int i = 0; i < length; ++i) { | |
69 | |
70 float v = 0.f; | |
71 | |
72 switch (sort) { | |
73 case DC: v = 1.f; break; | |
74 case Sine: v = (float)sin((2.0 * M_PI / 8.0) * i); break; | |
75 case Cosine: v = (float)cos((2.0 * M_PI / 8.0) * i); break; | |
76 case Nyquist: v = (i % 2) * 2 - 1; break; | |
77 case Dirac: v = (i == 0) ? 1.f : 0.f; break; | |
78 } | |
79 | |
80 data.push_back(v); | |
81 } | |
82 | |
83 return data; | |
84 } | |
85 |