Oversampler special cases 2x 4x
This commit is contained in:
parent
781f2167ad
commit
ff359df5cd
2 changed files with 86 additions and 86 deletions
|
|
@ -199,7 +199,14 @@ static void generate_cpp_upsampler(const Stage *stages, int num_stages)
|
||||||
|
|
||||||
printf("\t" "static int recommendedBuffer(int factor, int spl)\n");
|
printf("\t" "static int recommendedBuffer(int factor, int spl)\n");
|
||||||
printf("\t" "{\n");
|
printf("\t" "{\n");
|
||||||
printf("\t\t" "return factor * spl;\n");
|
printf("\t\t" "switch (factor) {\n");
|
||||||
|
printf("\t\t" "case 2:\n");
|
||||||
|
printf("\t\t\t" "return 0;\n");
|
||||||
|
printf("\t\t" "case 4:\n");
|
||||||
|
printf("\t\t\t" "return 2 * spl;\n");
|
||||||
|
printf("\t\t" "default:\n");
|
||||||
|
printf("\t\t\t" "return factor * spl;\n");
|
||||||
|
printf("\t\t" "}\n");
|
||||||
printf("\t" "}\n");
|
printf("\t" "}\n");
|
||||||
|
|
||||||
printf("\t" "static bool canProcess(int factor)\n");
|
printf("\t" "static bool canProcess(int factor)\n");
|
||||||
|
|
@ -235,14 +242,25 @@ static void generate_cpp_upsampler(const Stage *stages, int num_stages)
|
||||||
printf("\t" "}\n");
|
printf("\t" "}\n");
|
||||||
|
|
||||||
for (int n = 1; n <= num_stages; ++n) {
|
for (int n = 1; n <= num_stages; ++n) {
|
||||||
|
// special case factor=2, buffer not required
|
||||||
|
if (stages[n - 1].factor == 2) {
|
||||||
|
printf("\t" "void process2x(const float *in, float *out, int spl, float * = nullptr, int = 0)\n");
|
||||||
|
printf("\t" "{\n");
|
||||||
|
printf("\t\t" "up2_.process_block(out, in, spl);\n");
|
||||||
|
printf("\t" "}\n");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
printf("\t" "void process%dx(const float *in, float *out, int spl, float *temp, int ntemp)\n", stages[n - 1].factor);
|
printf("\t" "void process%dx(const float *in, float *out, int spl, float *temp, int ntemp)\n", stages[n - 1].factor);
|
||||||
printf("\t" "{\n");
|
printf("\t" "{\n");
|
||||||
printf("\t\t" "int maxspl = ntemp / %d;\n", stages[n - 1].factor);
|
// special case factor=4, only 1 buffer required
|
||||||
printf("\t\t" "ASSERT(maxspl >= 0);\n");
|
if (stages[n - 1].factor > 4)
|
||||||
|
printf("\t\t" "int maxspl = ntemp / %d;\n", stages[n - 1].factor);
|
||||||
|
else
|
||||||
|
printf("\t\t" "int maxspl = ntemp / %d;\n", stages[n - 1].factor / 2);
|
||||||
|
printf("\t\t" "ASSERT(maxspl > 0);\n");
|
||||||
printf("\t\t" "float *t1 = temp;\n");
|
printf("\t\t" "float *t1 = temp;\n");
|
||||||
printf("\t\t" "float *t2 = temp + %d * maxspl;\n", stages[n - 1].factor / 2);
|
if (stages[n - 1].factor > 4)
|
||||||
printf("\t\t" "(void)t1;\n");
|
printf("\t\t" "float *t2 = temp + %d * maxspl;\n", stages[n - 1].factor / 2);
|
||||||
printf("\t\t" "(void)t2;\n");
|
|
||||||
printf("\t\t" "while (spl > 0) {\n");
|
printf("\t\t" "while (spl > 0) {\n");
|
||||||
printf("\t\t\t" "int curspl = (spl < maxspl) ? spl : maxspl;\n");
|
printf("\t\t\t" "int curspl = (spl < maxspl) ? spl : maxspl;\n");
|
||||||
for (int i = 0; i < n; ++i) {
|
for (int i = 0; i < n; ++i) {
|
||||||
|
|
@ -294,7 +312,14 @@ static void generate_cpp_downsampler(const Stage *stages, int num_stages)
|
||||||
|
|
||||||
printf("\t" "static int recommendedBuffer(int factor, int spl)\n");
|
printf("\t" "static int recommendedBuffer(int factor, int spl)\n");
|
||||||
printf("\t" "{\n");
|
printf("\t" "{\n");
|
||||||
printf("\t\t" "return factor * spl;\n");
|
printf("\t\t" "switch (factor) {\n");
|
||||||
|
printf("\t\t" "case 2:\n");
|
||||||
|
printf("\t\t\t" "return 0;\n");
|
||||||
|
printf("\t\t" "case 4:\n");
|
||||||
|
printf("\t\t\t" "return 2 * spl;\n");
|
||||||
|
printf("\t\t" "default:\n");
|
||||||
|
printf("\t\t\t" "return factor * spl;\n");
|
||||||
|
printf("\t\t" "}\n");
|
||||||
printf("\t" "}\n");
|
printf("\t" "}\n");
|
||||||
|
|
||||||
printf("\t" "static bool canProcess(int factor)\n");
|
printf("\t" "static bool canProcess(int factor)\n");
|
||||||
|
|
@ -330,14 +355,25 @@ static void generate_cpp_downsampler(const Stage *stages, int num_stages)
|
||||||
printf("\t" "}\n");
|
printf("\t" "}\n");
|
||||||
|
|
||||||
for (int n = 1; n <= num_stages; ++n) {
|
for (int n = 1; n <= num_stages; ++n) {
|
||||||
|
// special case factor=2, buffer not required
|
||||||
|
if (stages[n - 1].factor == 2) {
|
||||||
|
printf("\t" "void process2x(const float *in, float *out, int spl, float * = nullptr, int = 0)\n");
|
||||||
|
printf("\t" "{\n");
|
||||||
|
printf("\t\t" "down2_.process_block(out, in, spl);\n");
|
||||||
|
printf("\t" "}\n");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
printf("\t" "void process%dx(const float *in, float *out, int spl, float *temp, int ntemp)\n", stages[n - 1].factor);
|
printf("\t" "void process%dx(const float *in, float *out, int spl, float *temp, int ntemp)\n", stages[n - 1].factor);
|
||||||
printf("\t" "{\n");
|
printf("\t" "{\n");
|
||||||
printf("\t\t" "int maxspl = ntemp / %d;\n", stages[n - 1].factor);
|
// special case factor=4, only 1 buffer required
|
||||||
printf("\t\t" "ASSERT(maxspl >= 0);\n");
|
if (stages[n - 1].factor > 4)
|
||||||
|
printf("\t\t" "int maxspl = ntemp / %d;\n", stages[n - 1].factor);
|
||||||
|
else
|
||||||
|
printf("\t\t" "int maxspl = ntemp / %d;\n", stages[n - 1].factor / 2);
|
||||||
|
printf("\t\t" "ASSERT(maxspl > 0);\n");
|
||||||
printf("\t\t" "float *t1 = temp;\n");
|
printf("\t\t" "float *t1 = temp;\n");
|
||||||
printf("\t\t" "float *t2 = temp + %d * maxspl;\n", stages[n - 1].factor / 2);
|
if (stages[n - 1].factor > 4)
|
||||||
printf("\t\t" "(void)t1;\n");
|
printf("\t\t" "float *t2 = temp + %d * maxspl;\n", stages[n - 1].factor / 2);
|
||||||
printf("\t\t" "(void)t2;\n");
|
|
||||||
printf("\t\t" "while (spl > 0) {\n");
|
printf("\t\t" "while (spl > 0) {\n");
|
||||||
printf("\t\t\t" "int curspl = (spl < maxspl) ? spl : maxspl;\n");
|
printf("\t\t\t" "int curspl = (spl < maxspl) ? spl : maxspl;\n");
|
||||||
for (int i = 0; i < n; ++i) {
|
for (int i = 0; i < n; ++i) {
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
// 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
|
|
||||||
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// This is generated by the Sfizz HIIR designer
|
// This is generated by the Sfizz HIIR designer
|
||||||
|
|
@ -85,7 +85,14 @@ public:
|
||||||
}
|
}
|
||||||
static int recommendedBuffer(int factor, int spl)
|
static int recommendedBuffer(int factor, int spl)
|
||||||
{
|
{
|
||||||
return factor * spl;
|
switch (factor) {
|
||||||
|
case 2:
|
||||||
|
return 0;
|
||||||
|
case 4:
|
||||||
|
return 2 * spl;
|
||||||
|
default:
|
||||||
|
return factor * spl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
static bool canProcess(int factor)
|
static bool canProcess(int factor)
|
||||||
{
|
{
|
||||||
|
|
@ -135,30 +142,15 @@ public:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void process2x(const float *in, float *out, int spl, float *temp, int ntemp)
|
void process2x(const float *in, float *out, int spl, float * = nullptr, int = 0)
|
||||||
{
|
{
|
||||||
int maxspl = ntemp / 2;
|
up2_.process_block(out, in, spl);
|
||||||
ASSERT(maxspl >= 0);
|
|
||||||
float *t1 = temp;
|
|
||||||
float *t2 = temp + 1 * maxspl;
|
|
||||||
(void)t1;
|
|
||||||
(void)t2;
|
|
||||||
while (spl > 0) {
|
|
||||||
int curspl = (spl < maxspl) ? spl : maxspl;
|
|
||||||
up2_.process_block(out, in, 1 * curspl);
|
|
||||||
in += curspl;
|
|
||||||
out += curspl;
|
|
||||||
spl -= curspl;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
void process4x(const float *in, float *out, int spl, float *temp, int ntemp)
|
void process4x(const float *in, float *out, int spl, float *temp, int ntemp)
|
||||||
{
|
{
|
||||||
int maxspl = ntemp / 4;
|
int maxspl = ntemp / 2;
|
||||||
ASSERT(maxspl >= 0);
|
ASSERT(maxspl > 0);
|
||||||
float *t1 = temp;
|
float *t1 = temp;
|
||||||
float *t2 = temp + 2 * maxspl;
|
|
||||||
(void)t1;
|
|
||||||
(void)t2;
|
|
||||||
while (spl > 0) {
|
while (spl > 0) {
|
||||||
int curspl = (spl < maxspl) ? spl : maxspl;
|
int curspl = (spl < maxspl) ? spl : maxspl;
|
||||||
up2_.process_block(t1, in, 1 * curspl);
|
up2_.process_block(t1, in, 1 * curspl);
|
||||||
|
|
@ -171,11 +163,9 @@ public:
|
||||||
void process8x(const float *in, float *out, int spl, float *temp, int ntemp)
|
void process8x(const float *in, float *out, int spl, float *temp, int ntemp)
|
||||||
{
|
{
|
||||||
int maxspl = ntemp / 8;
|
int maxspl = ntemp / 8;
|
||||||
ASSERT(maxspl >= 0);
|
ASSERT(maxspl > 0);
|
||||||
float *t1 = temp;
|
float *t1 = temp;
|
||||||
float *t2 = temp + 4 * maxspl;
|
float *t2 = temp + 4 * maxspl;
|
||||||
(void)t1;
|
|
||||||
(void)t2;
|
|
||||||
while (spl > 0) {
|
while (spl > 0) {
|
||||||
int curspl = (spl < maxspl) ? spl : maxspl;
|
int curspl = (spl < maxspl) ? spl : maxspl;
|
||||||
up2_.process_block(t1, in, 1 * curspl);
|
up2_.process_block(t1, in, 1 * curspl);
|
||||||
|
|
@ -189,11 +179,9 @@ public:
|
||||||
void process16x(const float *in, float *out, int spl, float *temp, int ntemp)
|
void process16x(const float *in, float *out, int spl, float *temp, int ntemp)
|
||||||
{
|
{
|
||||||
int maxspl = ntemp / 16;
|
int maxspl = ntemp / 16;
|
||||||
ASSERT(maxspl >= 0);
|
ASSERT(maxspl > 0);
|
||||||
float *t1 = temp;
|
float *t1 = temp;
|
||||||
float *t2 = temp + 8 * maxspl;
|
float *t2 = temp + 8 * maxspl;
|
||||||
(void)t1;
|
|
||||||
(void)t2;
|
|
||||||
while (spl > 0) {
|
while (spl > 0) {
|
||||||
int curspl = (spl < maxspl) ? spl : maxspl;
|
int curspl = (spl < maxspl) ? spl : maxspl;
|
||||||
up2_.process_block(t1, in, 1 * curspl);
|
up2_.process_block(t1, in, 1 * curspl);
|
||||||
|
|
@ -208,11 +196,9 @@ public:
|
||||||
void process32x(const float *in, float *out, int spl, float *temp, int ntemp)
|
void process32x(const float *in, float *out, int spl, float *temp, int ntemp)
|
||||||
{
|
{
|
||||||
int maxspl = ntemp / 32;
|
int maxspl = ntemp / 32;
|
||||||
ASSERT(maxspl >= 0);
|
ASSERT(maxspl > 0);
|
||||||
float *t1 = temp;
|
float *t1 = temp;
|
||||||
float *t2 = temp + 16 * maxspl;
|
float *t2 = temp + 16 * maxspl;
|
||||||
(void)t1;
|
|
||||||
(void)t2;
|
|
||||||
while (spl > 0) {
|
while (spl > 0) {
|
||||||
int curspl = (spl < maxspl) ? spl : maxspl;
|
int curspl = (spl < maxspl) ? spl : maxspl;
|
||||||
up2_.process_block(t1, in, 1 * curspl);
|
up2_.process_block(t1, in, 1 * curspl);
|
||||||
|
|
@ -228,11 +214,9 @@ public:
|
||||||
void process64x(const float *in, float *out, int spl, float *temp, int ntemp)
|
void process64x(const float *in, float *out, int spl, float *temp, int ntemp)
|
||||||
{
|
{
|
||||||
int maxspl = ntemp / 64;
|
int maxspl = ntemp / 64;
|
||||||
ASSERT(maxspl >= 0);
|
ASSERT(maxspl > 0);
|
||||||
float *t1 = temp;
|
float *t1 = temp;
|
||||||
float *t2 = temp + 32 * maxspl;
|
float *t2 = temp + 32 * maxspl;
|
||||||
(void)t1;
|
|
||||||
(void)t2;
|
|
||||||
while (spl > 0) {
|
while (spl > 0) {
|
||||||
int curspl = (spl < maxspl) ? spl : maxspl;
|
int curspl = (spl < maxspl) ? spl : maxspl;
|
||||||
up2_.process_block(t1, in, 1 * curspl);
|
up2_.process_block(t1, in, 1 * curspl);
|
||||||
|
|
@ -249,11 +233,9 @@ public:
|
||||||
void process128x(const float *in, float *out, int spl, float *temp, int ntemp)
|
void process128x(const float *in, float *out, int spl, float *temp, int ntemp)
|
||||||
{
|
{
|
||||||
int maxspl = ntemp / 128;
|
int maxspl = ntemp / 128;
|
||||||
ASSERT(maxspl >= 0);
|
ASSERT(maxspl > 0);
|
||||||
float *t1 = temp;
|
float *t1 = temp;
|
||||||
float *t2 = temp + 64 * maxspl;
|
float *t2 = temp + 64 * maxspl;
|
||||||
(void)t1;
|
|
||||||
(void)t2;
|
|
||||||
while (spl > 0) {
|
while (spl > 0) {
|
||||||
int curspl = (spl < maxspl) ? spl : maxspl;
|
int curspl = (spl < maxspl) ? spl : maxspl;
|
||||||
up2_.process_block(t1, in, 1 * curspl);
|
up2_.process_block(t1, in, 1 * curspl);
|
||||||
|
|
@ -302,7 +284,14 @@ public:
|
||||||
}
|
}
|
||||||
static int recommendedBuffer(int factor, int spl)
|
static int recommendedBuffer(int factor, int spl)
|
||||||
{
|
{
|
||||||
return factor * spl;
|
switch (factor) {
|
||||||
|
case 2:
|
||||||
|
return 0;
|
||||||
|
case 4:
|
||||||
|
return 2 * spl;
|
||||||
|
default:
|
||||||
|
return factor * spl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
static bool canProcess(int factor)
|
static bool canProcess(int factor)
|
||||||
{
|
{
|
||||||
|
|
@ -352,30 +341,15 @@ public:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void process2x(const float *in, float *out, int spl, float *temp, int ntemp)
|
void process2x(const float *in, float *out, int spl, float * = nullptr, int = 0)
|
||||||
{
|
{
|
||||||
int maxspl = ntemp / 2;
|
down2_.process_block(out, in, spl);
|
||||||
ASSERT(maxspl >= 0);
|
|
||||||
float *t1 = temp;
|
|
||||||
float *t2 = temp + 1 * maxspl;
|
|
||||||
(void)t1;
|
|
||||||
(void)t2;
|
|
||||||
while (spl > 0) {
|
|
||||||
int curspl = (spl < maxspl) ? spl : maxspl;
|
|
||||||
down2_.process_block(out, in, 1 * curspl);
|
|
||||||
in += curspl;
|
|
||||||
out += curspl;
|
|
||||||
spl -= curspl;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
void process4x(const float *in, float *out, int spl, float *temp, int ntemp)
|
void process4x(const float *in, float *out, int spl, float *temp, int ntemp)
|
||||||
{
|
{
|
||||||
int maxspl = ntemp / 4;
|
int maxspl = ntemp / 2;
|
||||||
ASSERT(maxspl >= 0);
|
ASSERT(maxspl > 0);
|
||||||
float *t1 = temp;
|
float *t1 = temp;
|
||||||
float *t2 = temp + 2 * maxspl;
|
|
||||||
(void)t1;
|
|
||||||
(void)t2;
|
|
||||||
while (spl > 0) {
|
while (spl > 0) {
|
||||||
int curspl = (spl < maxspl) ? spl : maxspl;
|
int curspl = (spl < maxspl) ? spl : maxspl;
|
||||||
down4_.process_block(t1, in, 2 * curspl);
|
down4_.process_block(t1, in, 2 * curspl);
|
||||||
|
|
@ -388,11 +362,9 @@ public:
|
||||||
void process8x(const float *in, float *out, int spl, float *temp, int ntemp)
|
void process8x(const float *in, float *out, int spl, float *temp, int ntemp)
|
||||||
{
|
{
|
||||||
int maxspl = ntemp / 8;
|
int maxspl = ntemp / 8;
|
||||||
ASSERT(maxspl >= 0);
|
ASSERT(maxspl > 0);
|
||||||
float *t1 = temp;
|
float *t1 = temp;
|
||||||
float *t2 = temp + 4 * maxspl;
|
float *t2 = temp + 4 * maxspl;
|
||||||
(void)t1;
|
|
||||||
(void)t2;
|
|
||||||
while (spl > 0) {
|
while (spl > 0) {
|
||||||
int curspl = (spl < maxspl) ? spl : maxspl;
|
int curspl = (spl < maxspl) ? spl : maxspl;
|
||||||
down8_.process_block(t1, in, 4 * curspl);
|
down8_.process_block(t1, in, 4 * curspl);
|
||||||
|
|
@ -406,11 +378,9 @@ public:
|
||||||
void process16x(const float *in, float *out, int spl, float *temp, int ntemp)
|
void process16x(const float *in, float *out, int spl, float *temp, int ntemp)
|
||||||
{
|
{
|
||||||
int maxspl = ntemp / 16;
|
int maxspl = ntemp / 16;
|
||||||
ASSERT(maxspl >= 0);
|
ASSERT(maxspl > 0);
|
||||||
float *t1 = temp;
|
float *t1 = temp;
|
||||||
float *t2 = temp + 8 * maxspl;
|
float *t2 = temp + 8 * maxspl;
|
||||||
(void)t1;
|
|
||||||
(void)t2;
|
|
||||||
while (spl > 0) {
|
while (spl > 0) {
|
||||||
int curspl = (spl < maxspl) ? spl : maxspl;
|
int curspl = (spl < maxspl) ? spl : maxspl;
|
||||||
down16_.process_block(t1, in, 8 * curspl);
|
down16_.process_block(t1, in, 8 * curspl);
|
||||||
|
|
@ -425,11 +395,9 @@ public:
|
||||||
void process32x(const float *in, float *out, int spl, float *temp, int ntemp)
|
void process32x(const float *in, float *out, int spl, float *temp, int ntemp)
|
||||||
{
|
{
|
||||||
int maxspl = ntemp / 32;
|
int maxspl = ntemp / 32;
|
||||||
ASSERT(maxspl >= 0);
|
ASSERT(maxspl > 0);
|
||||||
float *t1 = temp;
|
float *t1 = temp;
|
||||||
float *t2 = temp + 16 * maxspl;
|
float *t2 = temp + 16 * maxspl;
|
||||||
(void)t1;
|
|
||||||
(void)t2;
|
|
||||||
while (spl > 0) {
|
while (spl > 0) {
|
||||||
int curspl = (spl < maxspl) ? spl : maxspl;
|
int curspl = (spl < maxspl) ? spl : maxspl;
|
||||||
down32_.process_block(t1, in, 16 * curspl);
|
down32_.process_block(t1, in, 16 * curspl);
|
||||||
|
|
@ -445,11 +413,9 @@ public:
|
||||||
void process64x(const float *in, float *out, int spl, float *temp, int ntemp)
|
void process64x(const float *in, float *out, int spl, float *temp, int ntemp)
|
||||||
{
|
{
|
||||||
int maxspl = ntemp / 64;
|
int maxspl = ntemp / 64;
|
||||||
ASSERT(maxspl >= 0);
|
ASSERT(maxspl > 0);
|
||||||
float *t1 = temp;
|
float *t1 = temp;
|
||||||
float *t2 = temp + 32 * maxspl;
|
float *t2 = temp + 32 * maxspl;
|
||||||
(void)t1;
|
|
||||||
(void)t2;
|
|
||||||
while (spl > 0) {
|
while (spl > 0) {
|
||||||
int curspl = (spl < maxspl) ? spl : maxspl;
|
int curspl = (spl < maxspl) ? spl : maxspl;
|
||||||
down64_.process_block(t1, in, 32 * curspl);
|
down64_.process_block(t1, in, 32 * curspl);
|
||||||
|
|
@ -466,11 +432,9 @@ public:
|
||||||
void process128x(const float *in, float *out, int spl, float *temp, int ntemp)
|
void process128x(const float *in, float *out, int spl, float *temp, int ntemp)
|
||||||
{
|
{
|
||||||
int maxspl = ntemp / 128;
|
int maxspl = ntemp / 128;
|
||||||
ASSERT(maxspl >= 0);
|
ASSERT(maxspl > 0);
|
||||||
float *t1 = temp;
|
float *t1 = temp;
|
||||||
float *t2 = temp + 64 * maxspl;
|
float *t2 = temp + 64 * maxspl;
|
||||||
(void)t1;
|
|
||||||
(void)t2;
|
|
||||||
while (spl > 0) {
|
while (spl > 0) {
|
||||||
int curspl = (spl < maxspl) ? spl : maxspl;
|
int curspl = (spl < maxspl) ? spl : maxspl;
|
||||||
down128_.process_block(t1, in, 64 * curspl);
|
down128_.process_block(t1, in, 64 * curspl);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue