OscillatorConstants.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * OscillatorConstants.h - declaration of constants used in Oscillator and SampleBuffer
  3. * for band limited wave tables
  4. *
  5. * Copyright (c) 2018 Dave French <dave/dot/french3/at/googlemail/dot/com>
  6. *
  7. * This file is part of LMMS - https://lmms.io
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public
  11. * License as published by the Free Software Foundation; either
  12. * version 2 of the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public
  20. * License along with this program (see COPYING); if not, write to the
  21. * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  22. * Boston, MA 02110-1301 USA.
  23. *
  24. */
  25. #ifndef OSCILLATORCONSTANTS_H
  26. #define OSCILLATORCONSTANTS_H
  27. #include <array>
  28. #include "lmms_basics.h"
  29. namespace OscillatorConstants
  30. {
  31. // Limit wavetables to the audible audio spectrum
  32. const int MAX_FREQ = 20000;
  33. // Minimum size of table to have all audible bands for midi note 1 (i.e. 20 000 Hz / 8.176 Hz)
  34. constexpr int WAVETABLE_LENGTH = static_cast<int>(MAX_FREQ / 8.176);
  35. //SEMITONES_PER_TABLE, the smaller the value the smoother the harmonics change on frequency sweeps
  36. // with the trade off of increased memory requirements to store the wave tables
  37. // require memory = NumberOfWaveShapes*WAVETABLE_LENGTH*(MidiNoteCount/SEMITONES_PER_TABLE)*BytePerSample_t
  38. // 7*2446*(128/1)*4 = 8766464 bytes
  39. const int SEMITONES_PER_TABLE = 1;
  40. const int WAVE_TABLES_PER_WAVEFORM_COUNT = 128 / SEMITONES_PER_TABLE;
  41. // There is some ambiguity around the use of "wavetable", "wavetable synthesis" or related terms.
  42. // The following meanings and definitions were selected for use in the Oscillator class:
  43. // - wave shape: abstract and precise definition of the graph associated with a given type of wave;
  44. // - waveform: digital representations the wave shape, a set of waves optimized for use at varying pitches;
  45. // - wavetable: a table containing one period of a wave, with frequency content optimized for a specific pitch.
  46. typedef std::array<sample_t, WAVETABLE_LENGTH> wavetable_t;
  47. typedef std::array<wavetable_t, WAVE_TABLES_PER_WAVEFORM_COUNT> waveform_t;
  48. };
  49. #endif // OSCILLATORCONSTANTS_H