Move the wavetables to a "WavetablePool"Matching the other resources management type
This commit is contained in:
parent
1c80c65ae0
commit
b33ce4a3ad
7 changed files with 41 additions and 71 deletions
|
|
@ -18,7 +18,6 @@ set (SFIZZ_SOURCES
|
||||||
sfizz/SfzFilter.cpp
|
sfizz/SfzFilter.cpp
|
||||||
sfizz/Curve.cpp
|
sfizz/Curve.cpp
|
||||||
sfizz/Wavetables.cpp
|
sfizz/Wavetables.cpp
|
||||||
sfizz/Resources.cpp
|
|
||||||
sfizz/Effects.cpp
|
sfizz/Effects.cpp
|
||||||
sfizz/effects/Nothing.cpp
|
sfizz/effects/Nothing.cpp
|
||||||
sfizz/effects/Filter.cpp
|
sfizz/effects/Filter.cpp
|
||||||
|
|
|
||||||
|
|
@ -73,6 +73,12 @@ namespace config {
|
||||||
Limit of how many "fxN" buses are accepted (in SFZv2, maximum is 4)
|
Limit of how many "fxN" buses are accepted (in SFZv2, maximum is 4)
|
||||||
*/
|
*/
|
||||||
constexpr int maxEffectBuses { 256 };
|
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
|
} // namespace config
|
||||||
|
|
||||||
// Enable or disable SIMD accelerators by default
|
// Enable or disable SIMD accelerators by default
|
||||||
|
|
|
||||||
|
|
@ -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())
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -9,6 +9,7 @@
|
||||||
#include "FilterPool.h"
|
#include "FilterPool.h"
|
||||||
#include "EQPool.h"
|
#include "EQPool.h"
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
|
#include "Wavetables.h"
|
||||||
|
|
||||||
namespace sfz
|
namespace sfz
|
||||||
{
|
{
|
||||||
|
|
@ -21,12 +22,6 @@ struct Resources
|
||||||
FilePool filePool { logger };
|
FilePool filePool { logger };
|
||||||
FilterPool filterPool { midiState };
|
FilterPool filterPool { midiState };
|
||||||
EQPool eqPool { midiState };
|
EQPool eqPool { midiState };
|
||||||
|
WavetablePool wavePool;
|
||||||
const WavetableMulti* waveSin { nullptr };
|
|
||||||
const WavetableMulti* waveTriangle { nullptr };
|
|
||||||
const WavetableMulti* waveSaw { nullptr };
|
|
||||||
const WavetableMulti* waveSquare { nullptr };
|
|
||||||
|
|
||||||
Resources();
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -44,17 +44,17 @@ void sfz::Voice::startVoice(Region* region, int delay, int number, uint8_t value
|
||||||
case hash("*silence"):
|
case hash("*silence"):
|
||||||
break;
|
break;
|
||||||
case hash("*sine"):
|
case hash("*sine"):
|
||||||
wave = resources.waveSin;
|
wave = resources.wavePool.getWaveSin();
|
||||||
break;
|
break;
|
||||||
case hash("*triangle"): // fallthrough
|
case hash("*triangle"): // fallthrough
|
||||||
case hash("*tri"):
|
case hash("*tri"):
|
||||||
wave = resources.waveTriangle;
|
wave = resources.wavePool.getWaveTriangle();
|
||||||
break;
|
break;
|
||||||
case hash("*square"):
|
case hash("*square"):
|
||||||
wave = resources.waveSquare;
|
wave = resources.wavePool.getWaveSquare();
|
||||||
break;
|
break;
|
||||||
case hash("*saw"):
|
case hash("*saw"):
|
||||||
wave = resources.waveSaw;
|
wave = resources.wavePool.getWaveSaw();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
waveOscillator.setWavetable(wave);
|
waveOscillator.setWavetable(wave);
|
||||||
|
|
|
||||||
|
|
@ -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
|
} // namespace sfz
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
// If not, contact the sfizz maintainers at https://github.com/sfztools/sfizz
|
// If not, contact the sfizz maintainers at https://github.com/sfztools/sfizz
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
#include "Config.h"
|
||||||
#include <absl/types/span.h>
|
#include <absl/types/span.h>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <complex>
|
#include <complex>
|
||||||
|
|
@ -146,7 +147,7 @@ public:
|
||||||
// the reference sample rate is the minimum value accepted by the DSP
|
// the reference sample rate is the minimum value accepted by the DSP
|
||||||
// system (most defavorable wrt. aliasing)
|
// system (most defavorable wrt. aliasing)
|
||||||
static WavetableMulti createForHarmonicProfile(
|
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
|
// create the tiniest wavetable with null content for use with oscillators
|
||||||
static WavetableMulti createSilence();
|
static WavetableMulti createSilence();
|
||||||
|
|
@ -174,4 +175,22 @@ private:
|
||||||
std::unique_ptr<float[]> _multiData;
|
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
|
} // namespace sfz
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue