Chris@39: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@39: Chris@42: /* Chris@42: Tipic Chris@42: Chris@42: Centre for Digital Music, Queen Mary, University of London. Chris@42: Chris@42: This program is free software; you can redistribute it and/or Chris@42: modify it under the terms of the GNU General Public License as Chris@42: published by the Free Software Foundation; either version 2 of the Chris@42: License, or (at your option) any later version. See the file Chris@42: COPYING included with this distribution for more information. Chris@42: */ Chris@42: Chris@39: #ifndef QUANTIZE_H Chris@39: #define QUANTIZE_H Chris@39: Chris@39: #include Chris@39: #include Chris@39: Chris@39: class Quantize Chris@39: { Chris@39: public: Chris@39: class Parameters { Chris@39: public: Chris@39: std::vector steps; Chris@39: std::vector weights; Chris@39: Parameters() : Chris@39: steps({ 0.4, 0.2, 0.1, 0.05 }), Chris@39: weights({ 0.25, 0.25, 0.25, 0.25 }) { } Chris@39: }; Chris@39: Chris@39: Quantize(Parameters params) : m_params(params) { Chris@39: if (params.steps.empty()) { Chris@39: throw std::invalid_argument("Quantize steps must not be empty"); Chris@39: } Chris@39: if (params.steps.size() != params.weights.size()) { Chris@39: throw std::invalid_argument("Must have same number of quantize steps and weights"); Chris@39: } Chris@39: } Chris@39: ~Quantize() { } Chris@39: Chris@39: std::vector process(const std::vector &in) { Chris@39: int n = in.size(); Chris@39: int m = m_params.steps.size(); Chris@39: std::vector out(n, 0.0); Chris@39: for (int i = 0; i < n; ++i) { Chris@39: for (int j = 0; j < m; ++j) { Chris@39: if (in[i] > m_params.steps[j]) { Chris@39: out[i] += m_params.weights[j]; Chris@39: } Chris@39: } Chris@39: } Chris@39: return out; Chris@39: } Chris@39: Chris@39: private: Chris@39: Parameters m_params; Chris@39: }; Chris@39: Chris@39: #endif