Chris@1086: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
Chris@1086: 
Chris@1086: /*
Chris@1086:     Sonic Visualiser
Chris@1086:     An audio file viewer and annotation editor.
Chris@1086:     Centre for Digital Music, Queen Mary, University of London.
Chris@1086:     This file copyright 2006 Chris Cannam.
Chris@1086:     
Chris@1086:     This program is free software; you can redistribute it and/or
Chris@1086:     modify it under the terms of the GNU General Public License as
Chris@1086:     published by the Free Software Foundation; either version 2 of the
Chris@1086:     License, or (at your option) any later version.  See the file
Chris@1086:     COPYING included with this distribution for more information.
Chris@1086: */
Chris@1086: 
Chris@1086: #include "MockWaveModel.h"
Chris@1086: 
Chris@1107: #include <cmath>
Chris@1107: 
Chris@1086: using namespace std;
Chris@1086: 
Chris@1088: MockWaveModel::MockWaveModel(vector<Sort> sorts, int length, int pad)
Chris@1086: {
Chris@1086:     for (auto sort: sorts) {
Chris@1088: 	m_data.push_back(generate(sort, length, pad));
Chris@1086:     }
Chris@1086: }
Chris@1086: 
Chris@1096: vector<float>
Chris@1096: MockWaveModel::getData(int channel, sv_frame_t start, sv_frame_t count) const
Chris@1086: {
Chris@1086:     sv_frame_t i = 0;
Chris@1086: 
Chris@1091: //    cerr << "MockWaveModel::getData(" << channel << "," << start << "," << count << "): ";
Chris@1086: 
Chris@1096:     vector<float> data;
Chris@1096:     
Chris@1086:     while (i < count) {
Chris@1086: 	sv_frame_t idx = start + i;
Chris@1086: 	if (!in_range_for(m_data[channel], idx)) break;
Chris@1096: 	data.push_back(m_data[channel][idx]);
Chris@1096: //	cerr << data[i] << " ";
Chris@1086: 	++i;
Chris@1086:     }
Chris@1086: 
Chris@1091: //    cerr << endl;
Chris@1086:     
Chris@1096:     return data;
Chris@1086: }
Chris@1086: 
Chris@1096: vector<vector<float>>
Chris@1086: MockWaveModel::getMultiChannelData(int fromchannel, int tochannel,
Chris@1096: 				   sv_frame_t start, sv_frame_t count) const
Chris@1086: {
Chris@1096:     vector<vector<float>> data(tochannel - fromchannel + 1);
Chris@1096:     
Chris@1086:     for (int c = fromchannel; c <= tochannel; ++c) {
Chris@1096:         data.push_back(getData(c, start, count));
Chris@1086:     }
Chris@1086: 
Chris@1096:     return data;
Chris@1086: }
Chris@1086: 
Chris@1086: vector<float>
Chris@1088: MockWaveModel::generate(Sort sort, int length, int pad) const
Chris@1086: {
Chris@1086:     vector<float> data;
Chris@1086: 
Chris@1088:     for (int i = 0; i < pad; ++i) {
Chris@1088:         data.push_back(0.f);
Chris@1088:     }
Chris@1088:     
Chris@1086:     for (int i = 0; i < length; ++i) {
Chris@1086: 
Chris@1087: 	double v = 0.0;
Chris@1086: 	
Chris@1086: 	switch (sort) {
Chris@1087: 	case DC: v = 1.0; break;
Chris@1087: 	case Sine: v = sin((2.0 * M_PI / 8.0) * i); break;
Chris@1087: 	case Cosine: v = cos((2.0 * M_PI / 8.0) * i); break;
Chris@1086: 	case Nyquist: v = (i % 2) * 2 - 1; break;
Chris@1087: 	case Dirac: v = (i == 0) ? 1.0 : 0.0; break;
Chris@1086: 	}
Chris@1086: 
Chris@1087: 	data.push_back(float(v));
Chris@1086:     }
Chris@1086: 
Chris@1088:     for (int i = 0; i < pad; ++i) {
Chris@1088:         data.push_back(0.f);
Chris@1088:     }
Chris@1088: 
Chris@1086:     return data;
Chris@1086: }
Chris@1086: