File indexing completed on 2024-04-28 15:08:07
0001 /* miniSynth - A Simple Software Synthesizer 0002 SPDX-FileCopyrightText: 2015 Ville Räisänen <vsr at vsr.name> 0003 0004 SPDX-License-Identifier: GPL-3.0-or-later 0005 */ 0006 0007 #ifndef WAVEFORM_H 0008 #define WAVEFORM_H 0009 0010 #include <qmath.h> 0011 #include <math.h> 0012 0013 // The Waveform class implements the necessary code for the generation of the 0014 // basic waveforms. The waveform is computed at the constructor stage and 0015 // assembled into a wavetable, which is evaluated with the eval(qreal t) 0016 // function. 0017 0018 class Waveform { 0019 public: 0020 explicit Waveform(unsigned int mode, unsigned int size=4096); 0021 ~Waveform(); 0022 0023 qreal eval(qreal t); 0024 0025 enum {MODE_SIN, MODE_SAW, MODE_SQU, MODE_SAW2}; 0026 private: 0027 qreal waveSin (qreal t); 0028 qreal waveSaw (qreal t); 0029 qreal waveSqu (qreal t); 0030 qreal waveSaw2(qreal t); 0031 0032 qreal *waveTable; 0033 unsigned int tableSize; 0034 0035 public: 0036 unsigned int mode; 0037 }; 0038 0039 #endif // WAVEFORM_H