Rename multiSize
This commit is contained in:
parent
c596f6113c
commit
d27b7373fc
3 changed files with 12 additions and 11 deletions
|
|
@ -221,11 +221,11 @@ WavetableMulti WavetableMulti::createForHarmonicProfile(
|
||||||
const HarmonicProfile& hp, double amplitude, unsigned tableSize, double refSampleRate)
|
const HarmonicProfile& hp, double amplitude, unsigned tableSize, double refSampleRate)
|
||||||
{
|
{
|
||||||
WavetableMulti wm;
|
WavetableMulti wm;
|
||||||
constexpr unsigned multiSize = WavetableMulti::multiSize();
|
constexpr unsigned numTables = WavetableMulti::numTables();
|
||||||
|
|
||||||
wm.allocateStorage(tableSize);
|
wm.allocateStorage(tableSize);
|
||||||
|
|
||||||
for (unsigned m = 0; m < multiSize; ++m) {
|
for (unsigned m = 0; m < numTables; ++m) {
|
||||||
WavetableRange range = WavetableRange::getRangeForOctave(m);
|
WavetableRange range = WavetableRange::getRangeForOctave(m);
|
||||||
|
|
||||||
double freq = range.maxFrequency;
|
double freq = range.maxFrequency;
|
||||||
|
|
@ -256,7 +256,7 @@ WavetableMulti WavetableMulti::createSilence()
|
||||||
|
|
||||||
void WavetableMulti::allocateStorage(unsigned tableSize)
|
void WavetableMulti::allocateStorage(unsigned tableSize)
|
||||||
{
|
{
|
||||||
_multiData.reset(new float[(tableSize + _tableExtra) * multiSize()]());
|
_multiData.resize((tableSize + _tableExtra) * numTables());
|
||||||
_tableSize = tableSize;
|
_tableSize = tableSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -264,9 +264,9 @@ void WavetableMulti::fillExtra()
|
||||||
{
|
{
|
||||||
unsigned tableSize = _tableSize;
|
unsigned tableSize = _tableSize;
|
||||||
constexpr unsigned tableExtra = _tableExtra;
|
constexpr unsigned tableExtra = _tableExtra;
|
||||||
constexpr unsigned multiSize = WavetableMulti::multiSize();
|
constexpr unsigned numTables = WavetableMulti::numTables();
|
||||||
|
|
||||||
for (unsigned m = 0; m < multiSize; ++m) {
|
for (unsigned m = 0; m < numTables; ++m) {
|
||||||
float* ptr = const_cast<float*>(getTablePointer(m));
|
float* ptr = const_cast<float*>(getTablePointer(m));
|
||||||
for (unsigned i = 0; i < tableExtra; ++i)
|
for (unsigned i = 0; i < tableExtra; ++i)
|
||||||
ptr[tableSize + i] = ptr[i % tableSize];
|
ptr[tableSize + i] = ptr[i % tableSize];
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
#include "LeakDetector.h"
|
#include "LeakDetector.h"
|
||||||
|
#include "Buffer.h"
|
||||||
#include <absl/types/span.h>
|
#include <absl/types/span.h>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <complex>
|
#include <complex>
|
||||||
|
|
@ -131,7 +132,7 @@ public:
|
||||||
unsigned tableSize() const { return _tableSize; }
|
unsigned tableSize() const { return _tableSize; }
|
||||||
|
|
||||||
// number of tables in the multisample
|
// number of tables in the multisample
|
||||||
static constexpr unsigned multiSize() { return WavetableRange::countOctaves; }
|
static constexpr unsigned numTables() { return WavetableRange::countOctaves; }
|
||||||
|
|
||||||
// get the N-th table in the multisample
|
// get the N-th table in the multisample
|
||||||
absl::Span<const float> getTable(unsigned index) const
|
absl::Span<const float> getTable(unsigned index) const
|
||||||
|
|
@ -158,7 +159,7 @@ private:
|
||||||
// get a pointer to the beginning of the N-th table
|
// get a pointer to the beginning of the N-th table
|
||||||
const float* getTablePointer(unsigned index) const
|
const float* getTablePointer(unsigned index) const
|
||||||
{
|
{
|
||||||
return &_multiData[index * (_tableSize + _tableExtra)];
|
return _multiData.data() + index * (_tableSize + _tableExtra);
|
||||||
}
|
}
|
||||||
|
|
||||||
// allocate the internal data for tables of the given size
|
// allocate the internal data for tables of the given size
|
||||||
|
|
@ -174,7 +175,7 @@ private:
|
||||||
static constexpr unsigned _tableExtra = 4;
|
static constexpr unsigned _tableExtra = 4;
|
||||||
|
|
||||||
// internal storage, having `multiSize` rows and `tableSize` columns.
|
// internal storage, having `multiSize` rows and `tableSize` columns.
|
||||||
std::unique_ptr<float[]> _multiData;
|
sfz::Buffer<float> _multiData;
|
||||||
LEAK_DETECTOR(WavetableMulti);
|
LEAK_DETECTOR(WavetableMulti);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -68,11 +68,11 @@ int main(int argc, char* argv[])
|
||||||
} else {
|
} else {
|
||||||
sfz::WavetableMulti multi = sfz::WavetableMulti::createForHarmonicProfile(
|
sfz::WavetableMulti multi = sfz::WavetableMulti::createForHarmonicProfile(
|
||||||
*hp, 1.0, tableSize);
|
*hp, 1.0, tableSize);
|
||||||
unsigned multiSize = multi.multiSize();
|
unsigned numTables = multi.numTables();
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
// print all tables one after another
|
// print all tables one after another
|
||||||
for (unsigned m = 0; m < multiSize; ++m) {
|
for (unsigned m = 0; m < numTables; ++m) {
|
||||||
absl::Span<const float> table = multi.getTable(m);
|
absl::Span<const float> table = multi.getTable(m);
|
||||||
for (size_t i = 0; i < tableSize; ++i) {
|
for (size_t i = 0; i < tableSize; ++i) {
|
||||||
std::cout << ((i + m * tableSize) * (1.0 / tableSize))
|
std::cout << ((i + m * tableSize) * (1.0 / tableSize))
|
||||||
|
|
@ -83,7 +83,7 @@ int main(int argc, char* argv[])
|
||||||
// print all tables separately
|
// print all tables separately
|
||||||
for (size_t i = 0; i < tableSize; ++i) {
|
for (size_t i = 0; i < tableSize; ++i) {
|
||||||
std::cout << (i * (1.0 / tableSize));
|
std::cout << (i * (1.0 / tableSize));
|
||||||
for (unsigned m = 0; m < multiSize; ++m) {
|
for (unsigned m = 0; m < numTables; ++m) {
|
||||||
absl::Span<const float> table = multi.getTable(m);
|
absl::Span<const float> table = multi.getTable(m);
|
||||||
std::cout << ' ' << table[i];
|
std::cout << ' ' << table[i];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue