annotate data/model/test/MockWaveModel.cpp @ 1143:d649818fc249

Update JAMS output to JAMS v0.2.0. We now (for the first time?!) write actual JAMS schema-compliant output when possible, though it isn't possible for many types of plugin. The output for all tested combinations of transforms is valid JSON even where it isn't schema-compliant.
author Chris Cannam
date Wed, 04 Nov 2015 10:07:29 +0000
parents 6d550a16f7d6
children 1309b66eff53
rev   line source
Chris@1086 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@1086 2
Chris@1086 3 /*
Chris@1086 4 Sonic Visualiser
Chris@1086 5 An audio file viewer and annotation editor.
Chris@1086 6 Centre for Digital Music, Queen Mary, University of London.
Chris@1086 7 This file copyright 2006 Chris Cannam.
Chris@1086 8
Chris@1086 9 This program is free software; you can redistribute it and/or
Chris@1086 10 modify it under the terms of the GNU General Public License as
Chris@1086 11 published by the Free Software Foundation; either version 2 of the
Chris@1086 12 License, or (at your option) any later version. See the file
Chris@1086 13 COPYING included with this distribution for more information.
Chris@1086 14 */
Chris@1086 15
Chris@1086 16 #include "MockWaveModel.h"
Chris@1086 17
Chris@1137 18 #include <cmath>
Chris@1137 19
Chris@1086 20 using namespace std;
Chris@1086 21
Chris@1088 22 MockWaveModel::MockWaveModel(vector<Sort> sorts, int length, int pad)
Chris@1086 23 {
Chris@1086 24 for (auto sort: sorts) {
Chris@1088 25 m_data.push_back(generate(sort, length, pad));
Chris@1086 26 }
Chris@1086 27 }
Chris@1086 28
Chris@1086 29 sv_frame_t
Chris@1086 30 MockWaveModel::getData(int channel, sv_frame_t start, sv_frame_t count,
Chris@1086 31 float *buffer) const
Chris@1086 32 {
Chris@1086 33 sv_frame_t i = 0;
Chris@1086 34
Chris@1086 35 cerr << "MockWaveModel::getData(" << channel << "," << start << "," << count << "): ";
Chris@1086 36
Chris@1086 37 while (i < count) {
Chris@1086 38 sv_frame_t idx = start + i;
Chris@1086 39 if (!in_range_for(m_data[channel], idx)) break;
Chris@1086 40 buffer[i] = m_data[channel][idx];
Chris@1086 41 cerr << buffer[i] << " ";
Chris@1086 42 ++i;
Chris@1086 43 }
Chris@1086 44
Chris@1086 45 cerr << endl;
Chris@1086 46
Chris@1086 47 return i;
Chris@1086 48 }
Chris@1086 49
Chris@1086 50 sv_frame_t
Chris@1086 51 MockWaveModel::getMultiChannelData(int fromchannel, int tochannel,
Chris@1086 52 sv_frame_t start, sv_frame_t count,
Chris@1086 53 float **buffers) const
Chris@1086 54 {
Chris@1086 55 sv_frame_t min = count;
Chris@1086 56
Chris@1086 57 for (int c = fromchannel; c <= tochannel; ++c) {
Chris@1086 58 sv_frame_t n = getData(c, start, count, buffers[c]);
Chris@1086 59 if (n < min) min = n;
Chris@1086 60 }
Chris@1086 61
Chris@1086 62 return min;
Chris@1086 63 }
Chris@1086 64
Chris@1086 65 vector<float>
Chris@1088 66 MockWaveModel::generate(Sort sort, int length, int pad) const
Chris@1086 67 {
Chris@1086 68 vector<float> data;
Chris@1086 69
Chris@1088 70 for (int i = 0; i < pad; ++i) {
Chris@1088 71 data.push_back(0.f);
Chris@1088 72 }
Chris@1088 73
Chris@1086 74 for (int i = 0; i < length; ++i) {
Chris@1086 75
Chris@1087 76 double v = 0.0;
Chris@1086 77
Chris@1086 78 switch (sort) {
Chris@1087 79 case DC: v = 1.0; break;
Chris@1087 80 case Sine: v = sin((2.0 * M_PI / 8.0) * i); break;
Chris@1087 81 case Cosine: v = cos((2.0 * M_PI / 8.0) * i); break;
Chris@1086 82 case Nyquist: v = (i % 2) * 2 - 1; break;
Chris@1087 83 case Dirac: v = (i == 0) ? 1.0 : 0.0; break;
Chris@1086 84 }
Chris@1086 85
Chris@1087 86 data.push_back(float(v));
Chris@1086 87 }
Chris@1086 88
Chris@1088 89 for (int i = 0; i < pad; ++i) {
Chris@1088 90 data.push_back(0.f);
Chris@1088 91 }
Chris@1088 92
Chris@1086 93 return data;
Chris@1086 94 }
Chris@1086 95