Skip to content

Commit

Permalink
bristol: Expand BLO object and declare it with external linkage
Browse files Browse the repository at this point in the history
  • Loading branch information
nomadbyte committed May 11, 2021
1 parent e4e2e66 commit 3d9a322
Show file tree
Hide file tree
Showing 11 changed files with 94 additions and 82 deletions.
6 changes: 3 additions & 3 deletions bristol/arpdco.c
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ fillWave(float *mem, int count, int type)
if (blo.flags & BRISTOL_BLO)
{
for (i = 0; i < count; i++)
mem[i] = blosquare[i];
mem[i] = blo.square[i];
return;
}
for (i = 0; i < count / 2; i++)
Expand Down Expand Up @@ -822,7 +822,7 @@ fillWave(float *mem, int count, int type)
if (blo.flags & BRISTOL_BLO)
{
for (i = 0; i < count; i++)
mem[i] = bloramp[i];
mem[i] = blo.ramp[i];
return;
}
fillPDsine(mem, count, 5);
Expand All @@ -835,7 +835,7 @@ fillWave(float *mem, int count, int type)
if (blo.flags & BRISTOL_BLO)
{
for (i = 0; i < count; i++)
mem[i] = blotriangle[i];
mem[i] = blo.triangle[i];
return;
}
for (i = 0; i < count / 2; i++)
Expand Down
6 changes: 3 additions & 3 deletions bristol/bit1osc.c
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,7 @@ fillWave(register float *mem, register int count, int type)
int i;

for (i = 0; i < count; i++)
mem[i] = bloramp[i];
mem[i] = blo.ramp[i];
return;
}
fillPDwave(mem, count, 20.0);
Expand All @@ -769,7 +769,7 @@ fillWave(register float *mem, register int count, int type)
if (blo.flags & BRISTOL_BLO)
{
for (i = 0; i < count; i++)
mem[i] = blosquare[i];
mem[i] = blo.square[i];
return;
}
for (i = 0; i < count / 2; i++)
Expand All @@ -786,7 +786,7 @@ fillWave(register float *mem, register int count, int type)
if (blo.flags & BRISTOL_BLO)
{
for (i = 0; i < count; i++)
mem[i] = blotriangle[i];
mem[i] = blo.triangle[i];
return;
}
for (i = 0; i < count / 2; i++)
Expand Down
92 changes: 51 additions & 41 deletions bristol/blo.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,17 @@

#include "bristolblo.h"

bristolBLO blo;

static int init = 1;

float blosine[BRISTOL_BLO_SIZE];
float blocosine[BRISTOL_BLO_SIZE];
float blosquare[BRISTOL_BLO_SIZE];
float bloramp[BRISTOL_BLO_SIZE];
float blosaw[BRISTOL_BLO_SIZE];
float blotriangle[BRISTOL_BLO_SIZE];
float blopulse[BRISTOL_BLO_SIZE];
static float blosine[BRISTOL_BLO_SIZE];
static float blocosine[BRISTOL_BLO_SIZE];
static float blosquare[BRISTOL_BLO_SIZE];
static float bloramp[BRISTOL_BLO_SIZE];
static float blosaw[BRISTOL_BLO_SIZE];
static float blotriangle[BRISTOL_BLO_SIZE];
static float blopulse[BRISTOL_BLO_SIZE];

/*
* Generate the waveforms to the given harmonic reference size. The code could
Expand All @@ -61,6 +63,14 @@ float fraction, int samplerate)
blo.samplerate = samplerate;
blo.fraction = fraction * 1024;

blo.sine = blosine;
blo.cosine = blocosine;
blo.square = blosquare;
blo.ramp = bloramp;
blo.saw = blosaw;
blo.triangle = blotriangle;
blo.pulse = blopulse;

printf("generate bandlimited waveforms(%i, %2.0f, %i, %1.2f, %1.2f, %i)\n",
harmonics, gn, cutin, cutoff, fraction, samplerate);

Expand All @@ -78,18 +88,18 @@ float fraction, int samplerate)

for (i = 0; i < BRISTOL_BLO_SIZE; i++)
{
blosine[i] = sinf(2 * M_PI * ((float) i) / BRISTOL_BLO_SIZE) * gn;
blocosine[i] = cosf(2 * M_PI * ((float) i) / BRISTOL_BLO_SIZE) * gn;
blo.sine[i] = sinf(2 * M_PI * ((float) i) / BRISTOL_BLO_SIZE) * gn;
blo.cosine[i] = cosf(2 * M_PI * ((float) i) / BRISTOL_BLO_SIZE) * gn;
}
}

/*
memset(blosquare, 0, BRISTOL_BLO_SIZE * sizeof(float));
memset(bloramp, 0, BRISTOL_BLO_SIZE * sizeof(float));
memset(blotriangle, 0, BRISTOL_BLO_SIZE * sizeof(float));
memset(blo.square, 0, BRISTOL_BLO_SIZE * sizeof(float));
memset(blo.ramp, 0, BRISTOL_BLO_SIZE * sizeof(float));
memset(blo.triangle, 0, BRISTOL_BLO_SIZE * sizeof(float));
*/
for (i = 0; i < BRISTOL_BLO_SIZE; i++)
blosquare[i] = bloramp[i] = blotriangle[i] = 0;
blo.square[i] = blo.ramp[i] = blo.triangle[i] = 0;

/*
* The square wave:
Expand All @@ -104,7 +114,7 @@ float fraction, int samplerate)

for (i = 0; i < BRISTOL_BLO_SIZE; i++)
{
blosquare[i] += blosine[k] * gain;
blo.square[i] += blo.sine[k] * gain;
if ((k += j) >= BRISTOL_BLO_SIZE)
k -= BRISTOL_BLO_SIZE;
}
Expand All @@ -118,14 +128,14 @@ float fraction, int samplerate)
{
for (i = 0; i < BRISTOL_BLO_SIZE; i++)
{
blopulse[i] += (blosine[k] - blosine[(k + 256) & 1023]) * gain;
blo.pulse[i] += (blo.sine[k] - blo.sine[(k + 256) & 1023]) * gain;
if ((k += j) >= BRISTOL_BLO_SIZE)
k -= BRISTOL_BLO_SIZE;
}
} else {
for (i = 0; i < BRISTOL_BLO_SIZE; i++)
{
blopulse[i] -= (blosine[k] + blosine[(k + 256) & 1023]) * gain;
blo.pulse[i] -= (blo.sine[k] + blo.sine[(k + 256) & 1023]) * gain;
if ((k += j) >= BRISTOL_BLO_SIZE)
k -= BRISTOL_BLO_SIZE;
}
Expand All @@ -146,14 +156,14 @@ float fraction, int samplerate)
{
for (i = 0; i < BRISTOL_BLO_SIZE; i++)
{
blosaw[i] += blosine[k] * gain;
blo.saw[i] += blo.sine[k] * gain;
if ((k += j) >= BRISTOL_BLO_SIZE)
k -= BRISTOL_BLO_SIZE;
}
} else {
for (i = 0; i < BRISTOL_BLO_SIZE; i++)
{
blosaw[i] -= blosine[k] * gain;
blo.saw[i] -= blo.sine[k] * gain;
if ((k += j) >= BRISTOL_BLO_SIZE)
k -= BRISTOL_BLO_SIZE;
}
Expand All @@ -162,15 +172,15 @@ float fraction, int samplerate)

/* Invert this for the ramp */
for (i = 0; i < BRISTOL_BLO_SIZE; i++)
bloramp[i] = -blosaw[i];
blo.ramp[i] = -blo.saw[i];

/*
* Tri:
* Sum odd cosine harmonics, gain is reciprocal of square of harmonic
*/
k = 0; gain = 1.0;
for (i = 0; i < BRISTOL_BLO_SIZE; i++)
blotriangle[i] = blosine[i];
blo.triangle[i] = blo.sine[i];

for (j = 3; j <= harmonics; j+=2)
{
Expand All @@ -179,7 +189,7 @@ float fraction, int samplerate)

for (i = 0; i < BRISTOL_BLO_SIZE; i++)
{
blotriangle[i] += blocosine[k] * gain;
blo.triangle[i] += blo.cosine[k] * gain;
if ((k += j) >= BRISTOL_BLO_SIZE)
k -= BRISTOL_BLO_SIZE;
}
Expand Down Expand Up @@ -228,15 +238,15 @@ generateBLOwaveformF(float step, float *dst, int wf)
for (i = 0; i < BRISTOL_BLO_SIZE; i++)
{
dst[i] +=
(blosine[k] - blosine[(k + 256) & 1023]) * gain;
(blo.sine[k] - blo.sine[(k + 256) & 1023]) * gain;
if ((k += j) >= BRISTOL_BLO_SIZE)
k -= BRISTOL_BLO_SIZE;
}
} else {
for (i = 0; i < BRISTOL_BLO_SIZE; i++)
{
dst[i] -=
(blosine[k] + blosine[(k + 256) & 1023]) * gain;
(blo.sine[k] + blo.sine[(k + 256) & 1023]) * gain;
if ((k += j) >= BRISTOL_BLO_SIZE)
k -= BRISTOL_BLO_SIZE;
}
Expand All @@ -259,7 +269,7 @@ generateBLOwaveformF(float step, float *dst, int wf)

for (i = 0; i < BRISTOL_BLO_SIZE; i++)
{
dst[i] += blosine[k] * gain;
dst[i] += blo.sine[k] * gain;
if ((k += j) >= BRISTOL_BLO_SIZE)
k -= BRISTOL_BLO_SIZE;
}
Expand All @@ -282,14 +292,14 @@ generateBLOwaveformF(float step, float *dst, int wf)
{
for (i = 0; i < BRISTOL_BLO_SIZE; i++)
{
dst[i] += blosine[k] * gain;
dst[i] += blo.sine[k] * gain;
if ((k += j) >= BRISTOL_BLO_SIZE)
k -= BRISTOL_BLO_SIZE;
}
} else {
for (i = 0; i < BRISTOL_BLO_SIZE; i++)
{
dst[i] -= blosine[k] * gain;
dst[i] -= blo.sine[k] * gain;
if ((k += j) >= BRISTOL_BLO_SIZE)
k -= BRISTOL_BLO_SIZE;
}
Expand All @@ -306,14 +316,14 @@ generateBLOwaveformF(float step, float *dst, int wf)
{
for (i = 0; i < BRISTOL_BLO_SIZE; i++)
{
dst[i] += blosine[k] * gain;
dst[i] += blo.sine[k] * gain;
if ((k += j) >= BRISTOL_BLO_SIZE)
k -= BRISTOL_BLO_SIZE;
}
} else {
for (i = 0; i < BRISTOL_BLO_SIZE; i++)
{
dst[i] -= blosine[k] * gain;
dst[i] -= blo.sine[k] * gain;
if ((k += j) >= BRISTOL_BLO_SIZE)
k -= BRISTOL_BLO_SIZE;
}
Expand All @@ -327,7 +337,7 @@ generateBLOwaveformF(float step, float *dst, int wf)
*/
k = 0; gain = 1.0;
for (i = 0; i < BRISTOL_BLO_SIZE; i++)
dst[i] = blosine[i];
dst[i] = blo.sine[i];

for (j = 3; j <= harmonics; j+=2)
{
Expand All @@ -337,7 +347,7 @@ generateBLOwaveformF(float step, float *dst, int wf)

for (i = 0; i < BRISTOL_BLO_SIZE; i++)
{
dst[i] += blocosine[k] * gain;
dst[i] += blo.cosine[k] * gain;
if ((k += j) >= BRISTOL_BLO_SIZE)
k -= BRISTOL_BLO_SIZE;
}
Expand All @@ -346,12 +356,12 @@ generateBLOwaveformF(float step, float *dst, int wf)
case BLO_SINE:
gain = 1.0;
for (i = 0; i < BRISTOL_BLO_SIZE; i++)
dst[i] += blosine[i] * gain;
dst[i] += blo.sine[i] * gain;
return;
case BLO_COSINE:
gain = 1.0;
for (i = 0; i < BRISTOL_BLO_SIZE; i++)
dst[i] += blocosine[i] * gain;
dst[i] += blo.cosine[i] * gain;
return;
}
}
Expand Down Expand Up @@ -407,7 +417,7 @@ generateBLOwaveformZ(int key, float *dst, float gn, int wf)

for (i = 0; i < BRISTOL_BLO_SIZE; i++)
{
dst[i] += blosine[k] * gain;
dst[i] += blo.sine[k] * gain;
if ((k += j) >= BRISTOL_BLO_SIZE)
k -= BRISTOL_BLO_SIZE;
}
Expand All @@ -429,14 +439,14 @@ generateBLOwaveformZ(int key, float *dst, float gn, int wf)
{
for (i = 0; i < BRISTOL_BLO_SIZE; i++)
{
dst[i] += blosine[k] * gain;
dst[i] += blo.sine[k] * gain;
if ((k += j) >= BRISTOL_BLO_SIZE)
k -= BRISTOL_BLO_SIZE;
}
} else {
for (i = 0; i < BRISTOL_BLO_SIZE; i++)
{
dst[i] -= blosine[k] * gain;
dst[i] -= blo.sine[k] * gain;
if ((k += j) >= BRISTOL_BLO_SIZE)
k -= BRISTOL_BLO_SIZE;
}
Expand All @@ -452,14 +462,14 @@ generateBLOwaveformZ(int key, float *dst, float gn, int wf)
{
for (i = 0; i < BRISTOL_BLO_SIZE; i++)
{
dst[i] += blosine[k] * gain;
dst[i] += blo.sine[k] * gain;
if ((k += j) >= BRISTOL_BLO_SIZE)
k -= BRISTOL_BLO_SIZE;
}
} else {
for (i = 0; i < BRISTOL_BLO_SIZE; i++)
{
dst[i] -= blosine[k] * gain;
dst[i] -= blo.sine[k] * gain;
if ((k += j) >= BRISTOL_BLO_SIZE)
k -= BRISTOL_BLO_SIZE;
}
Expand All @@ -473,7 +483,7 @@ generateBLOwaveformZ(int key, float *dst, float gn, int wf)
*/
k = 0; gain = 1.0;
for (i = 0; i < BRISTOL_BLO_SIZE; i++)
dst[i] = blosine[i];
dst[i] = blo.sine[i];

for (j = 3; j <= harmonics; j+=2)
{
Expand All @@ -482,7 +492,7 @@ generateBLOwaveformZ(int key, float *dst, float gn, int wf)

for (i = 0; i < BRISTOL_BLO_SIZE; i++)
{
dst[i] += blocosine[k] * gain;
dst[i] += blo.cosine[k] * gain;
if ((k += j) >= BRISTOL_BLO_SIZE)
k -= BRISTOL_BLO_SIZE;
}
Expand All @@ -491,12 +501,12 @@ generateBLOwaveformZ(int key, float *dst, float gn, int wf)
case BLO_SINE:
gain = 1.0;
for (i = 0; i < BRISTOL_BLO_SIZE; i++)
dst[i] += blosine[i] * gain;
dst[i] += blo.sine[i] * gain;
return;
case BLO_COSINE:
gain = 1.0;
for (i = 0; i < BRISTOL_BLO_SIZE; i++)
dst[i] += blocosine[i] * gain;
dst[i] += blo.cosine[i] * gain;
return;
}
}
Expand Down
8 changes: 4 additions & 4 deletions bristol/cs80osc.c
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ fillWave(register float *mem, register int count, int type)
int i;

for (i = 0; i < count; i++)
mem[i] = blosine[i];
mem[i] = blo.sine[i];
return;
}
fillPDwave(mem, count, 1.0);
Expand All @@ -695,7 +695,7 @@ fillWave(register float *mem, register int count, int type)
int i;

for (i = 0; i < count; i++)
mem[i] = bloramp[i];
mem[i] = blo.ramp[i];
return;
}
fillPDwave(mem, count, 20.0);
Expand All @@ -711,7 +711,7 @@ fillWave(register float *mem, register int count, int type)
if (blo.flags & BRISTOL_BLO)
{
for (i = 0; i < count; i++)
mem[i] = blosquare[i];
mem[i] = blo.square[i];
return;
}
for (i = 0; i < count / 2; i++)
Expand All @@ -728,7 +728,7 @@ fillWave(register float *mem, register int count, int type)
if (blo.flags & BRISTOL_BLO)
{
for (i = 0; i < count; i++)
mem[i] = blotriangle[i];
mem[i] = blo.triangle[i];
return;
}

Expand Down
Loading

0 comments on commit 3d9a322

Please sign in to comment.