Move the wavetables to a "WavetablePool"Matching the other resources management type

This commit is contained in:
Paul Fd 2020-03-15 19:12:49 +01:00
parent 1c80c65ae0
commit b33ce4a3ad
7 changed files with 41 additions and 71 deletions

View file

@ -18,7 +18,6 @@ set (SFIZZ_SOURCES
sfizz/SfzFilter.cpp
sfizz/Curve.cpp
sfizz/Wavetables.cpp
sfizz/Resources.cpp
sfizz/Effects.cpp
sfizz/effects/Nothing.cpp
sfizz/effects/Filter.cpp

View file

@ -73,6 +73,12 @@ namespace config {
Limit of how many "fxN" buses are accepted (in SFZv2, maximum is 4)
*/
constexpr int maxEffectBuses { 256 };
// Wavetable constants; amplitude values are matched to reference
static constexpr unsigned tableSize = 1024;
static constexpr double amplitudeSine = 0.625;
static constexpr double amplitudeTriangle = 0.625;
static constexpr double amplitudeSaw = 0.515;
static constexpr double amplitudeSquare = 0.515;
} // namespace config
// Enable or disable SIMD accelerators by default

View file

@ -1,58 +0,0 @@
// SPDX-License-Identifier: BSD-2-Clause
// This code is part of the sfizz library and is licensed under a BSD 2-clause
// license. You should have receive a LICENSE.md file along with the code.
// If not, contact the sfizz maintainers at https://github.com/sfztools/sfizz
#include "Resources.h"
#include "Wavetables.h"
namespace sfz
{
static constexpr unsigned kTableSize = 1024;
// amplitude values are matched to reference
static constexpr double kAmplitudeSine = 0.625;
static constexpr double kAmplitudeTriangle = 0.625;
static constexpr double kAmplitudeSaw = 0.515;
static constexpr double kAmplitudeSquare = 0.515;
static const WavetableMulti* getWaveSin()
{
static auto wave = WavetableMulti::createForHarmonicProfile(
HarmonicProfile::getSine(), kAmplitudeSine, kTableSize);
return &wave;
}
static const WavetableMulti* getWaveTriangle()
{
static auto wave = WavetableMulti::createForHarmonicProfile(
HarmonicProfile::getTriangle(), kAmplitudeTriangle, kTableSize);
return &wave;
}
static const WavetableMulti* getWaveSaw()
{
static auto wave = WavetableMulti::createForHarmonicProfile(
HarmonicProfile::getSaw(), kAmplitudeSaw, kTableSize);
return &wave;
}
static const WavetableMulti* getWaveSquare()
{
static auto wave = WavetableMulti::createForHarmonicProfile(
HarmonicProfile::getSquare(), kAmplitudeSquare, kTableSize);
return &wave;
}
Resources::Resources()
: waveSin(getWaveSin()),
waveTriangle(getWaveTriangle()),
waveSaw(getWaveSaw()),
waveSquare(getWaveSquare())
{
}
}

View file

@ -9,6 +9,7 @@
#include "FilterPool.h"
#include "EQPool.h"
#include "Logger.h"
#include "Wavetables.h"
namespace sfz
{
@ -21,12 +22,6 @@ struct Resources
FilePool filePool { logger };
FilterPool filterPool { midiState };
EQPool eqPool { midiState };
const WavetableMulti* waveSin { nullptr };
const WavetableMulti* waveTriangle { nullptr };
const WavetableMulti* waveSaw { nullptr };
const WavetableMulti* waveSquare { nullptr };
Resources();
WavetablePool wavePool;
};
}

View file

@ -44,17 +44,17 @@ void sfz::Voice::startVoice(Region* region, int delay, int number, uint8_t value
case hash("*silence"):
break;
case hash("*sine"):
wave = resources.waveSin;
wave = resources.wavePool.getWaveSin();
break;
case hash("*triangle"): // fallthrough
case hash("*tri"):
wave = resources.waveTriangle;
wave = resources.wavePool.getWaveTriangle();
break;
case hash("*square"):
wave = resources.waveSquare;
wave = resources.wavePool.getWaveSquare();
break;
case hash("*saw"):
wave = resources.waveSaw;
wave = resources.wavePool.getWaveSaw();
break;
}
waveOscillator.setWavetable(wave);

View file

@ -273,4 +273,13 @@ void WavetableMulti::fillExtra()
}
}
WavetablePool::WavetablePool()
: waveSin(WavetableMulti::createForHarmonicProfile(HarmonicProfile::getSine(), config::amplitudeSine))
, waveTriangle(WavetableMulti::createForHarmonicProfile(HarmonicProfile::getTriangle(), config::amplitudeTriangle))
, waveSaw(WavetableMulti::createForHarmonicProfile(HarmonicProfile::getSaw(), config::amplitudeSaw))
, waveSquare(WavetableMulti::createForHarmonicProfile(HarmonicProfile::getSquare(), config::amplitudeSquare))
{ }
} // namespace sfz

View file

@ -5,6 +5,7 @@
// If not, contact the sfizz maintainers at https://github.com/sfztools/sfizz
#pragma once
#include "Config.h"
#include <absl/types/span.h>
#include <memory>
#include <complex>
@ -146,7 +147,7 @@ public:
// the reference sample rate is the minimum value accepted by the DSP
// system (most defavorable wrt. aliasing)
static WavetableMulti createForHarmonicProfile(
const HarmonicProfile& hp, double amplitude, unsigned tableSize, double refSampleRate = 44100.0);
const HarmonicProfile& hp, double amplitude, unsigned tableSize = config::tableSize, double refSampleRate = 44100.0);
// create the tiniest wavetable with null content for use with oscillators
static WavetableMulti createSilence();
@ -174,4 +175,22 @@ private:
std::unique_ptr<float[]> _multiData;
};
/**
* @brief Holds predefined wavetables.
*
*/
class WavetablePool {
public:
WavetablePool();
const WavetableMulti* getWaveSin() const { return &waveSin; }
const WavetableMulti* getWaveTriangle() const { return &waveTriangle; }
const WavetableMulti* getWaveSaw() const { return &waveSaw; }
const WavetableMulti* getWaveSquare() const { return &waveSquare; };
private:
const WavetableMulti waveSin;
const WavetableMulti waveTriangle;
const WavetableMulti waveSaw;
const WavetableMulti waveSquare;
};
} // namespace sfz