Skip to content

Commit

Permalink
replaced oscillators, broke sound
Browse files Browse the repository at this point in the history
  • Loading branch information
hsetlik committed Jun 4, 2021
1 parent 18803a5 commit 86f9a8a
Show file tree
Hide file tree
Showing 10 changed files with 362 additions and 234 deletions.
Binary file modified .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions HexFm.jucer
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
file="Source/LfoGroupComponent.h"/>
</GROUP>
<GROUP id="{7E985CFD-2F8E-2A87-C0F5-C64EED65ED45}" name="Synthesis">
<FILE id="DgL1HF" name="FFT.h" compile="0" resource="0" file="Source/FFT.h"/>
<FILE id="D5olNn" name="WavetableData.h" compile="0" resource="0" file="Source/WavetableData.h"/>
<FILE id="DsuaAU" name="WavetableProcessor.cpp" compile="1" resource="0"
file="Source/WavetableProcessor.cpp"/>
Expand Down
85 changes: 85 additions & 0 deletions Source/FFT.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
==============================================================================
FFT.h
Created: 30 Apr 2021 2:18:00pm
Author: Hayden Setlik
==============================================================================
*/

#pragma once
#include <JuceHeader.h>
struct FFT {
static void runFloat(int N, float *ar, float *ai)
/*
in-place complex fft
After Cooley, Lewis, and Welch; from Rabiner & Gold (1975)
program adapted from FORTRAN
by K. Steiglitz ([email protected])
Computer Science Dept.
Princeton University 08544 */
{
int i, j, k, L; /* indexes */
int M, TEMP, LE, LE1, ip; /* M = log N */
int NV2, NM1;
double t; /* temp */
float Ur, Ui, Wr, Wi, Tr, Ti;
float Ur_old;
// if ((N > 1) && !(N & (N - 1))) // make sure we have a power of 2
NV2 = N >> 1;
NM1 = N - 1;
TEMP = N; /* get M = log N */
M = 0;
while (TEMP >>= 1)
++M;
/* shuffle */
j = 1;
for (i = 1; i <= NM1; i++)
{
if(i<j)
{ /* swap a[i] and a[j] */
t = ar[j-1];
ar[j-1] = ar[i-1];
ar[i-1] = t;
t = ai[j-1];
ai[j-1] = ai[i-1];
ai[i-1] = t;
}
k = NV2; /* bit-reversed counter */
while(k < j)
{
j -= k;
k /= 2;
}
j += k;
}
LE = 1.0f;
for (L = 1; L <= M; L++) { // stage L
LE1 = LE; // (LE1 = LE/2)
LE *= 2; // (LE = 2^L)
Ur = 1.0f;
Ui = 0.0f;
Wr = cos(M_PI/(float)LE1);
Wi = -sin(M_PI/(float)LE1); // Cooley, Lewis, and Welch have "+" here
for (j = 1; j <= LE1; j++)
{
for (i = j; i <= N; i += LE)
{ // butterfly
ip = i+LE1;
Tr = ar[ip-1] * Ur - ai[ip-1] * Ui;
Ti = ar[ip-1] * Ui + ai[ip-1] * Ur;
ar[ip-1] = ar[i-1] - Tr;
ai[ip-1] = ai[i-1] - Ti;
ar[i-1] = ar[i-1] + Tr;
ai[i-1] = ai[i-1] + Ti;
}
Ur_old = Ur;
Ur = Ur_old * Wr - Ui * Wi;
Ui = Ur_old * Wi + Ui * Wr;
}
}
}
};
8 changes: 5 additions & 3 deletions Source/FmVoice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@



FmVoice::FmVoice(int numOperators, int index, juce::AudioProcessorValueTreeState* t) : tree(t), voiceIndex(index), operatorCount(numOperators), fundamental(1.0f)
FmVoice::FmVoice(int numOperators, int index, juce::AudioProcessorValueTreeState* t) : tree(t), voiceIndex(index), numLoudSamples(0), operatorCount(numOperators), fundamental(1.0f)
{
lfoMax = std::numeric_limits<float>::min();
lfoMin = std::numeric_limits<float>::max();
Expand Down Expand Up @@ -87,8 +87,10 @@ void FmVoice::renderNextBlock(juce::AudioBuffer<float> &outputBuffer, int startS
}
++op1Index;
}
outputBuffer.addSample(0, i, sumL);
outputBuffer.addSample(1, i, sumR);
if(fabs(sumL) > 0.3f)
++numLoudSamples;
outputBuffer.setSample(0, i, sumL);
outputBuffer.setSample(1, i, sumR);

if(fabs(opSum - lastOpSample) > 0.2f)
++numJumps;
Expand Down
7 changes: 4 additions & 3 deletions Source/FmVoice.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ class FmSound : public juce::SynthesiserSound
class FmVoice : public juce::SynthesiserVoice
{
public:
juce::AudioProcessorValueTreeState* tree;
juce::AudioProcessorValueTreeState* const tree;
FmVoice(int numOperators, int index, juce::AudioProcessorValueTreeState* t);
~FmVoice()
{
//printf("Voice #: %d -- %d total jumps\n", voiceIndex, numJumps);
printf("%ld loud samples\n", numLoudSamples);
}
bool canPlaySound(juce::SynthesiserSound* sound) override
{
Expand Down Expand Up @@ -99,6 +99,7 @@ class FmVoice : public juce::SynthesiserVoice
}
void updateParams();
int voiceIndex;
long numLoudSamples;
int numJumps;
int operatorCount;
float fundamental;
Expand All @@ -125,7 +126,7 @@ class FmVoice : public juce::SynthesiserVoice
class FmSynth : public juce::Synthesiser
{
public:
juce::AudioProcessorValueTreeState* tree;
juce::AudioProcessorValueTreeState* const tree;
FmSynth(int operators, int lfos, int nVoices, juce::AudioProcessorValueTreeState* t) : juce::Synthesiser(), tree(t), numOperators(operators), numLfos(lfos), numVoices(nVoices)
{
for(int i = 0; i < numVoices; ++i)
Expand Down
4 changes: 2 additions & 2 deletions Source/OperatorProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
float Operator::sample(float fund)
{
fundamental = fund;
rawSample = wtOsc.getSample((fund * workingRatio) + (modOffset * modIndex)) * level;
lastOutputSample = envelope.process(rawSample) * ( 1.0f - amplitudeMod);
rawSample = wtOsc.getSample((fund * workingRatio) + (modOffset * modIndex));
lastOutputSample = envelope.process(rawSample) * ( 1.0f - amplitudeMod) * level;
updatePan();
return lastOutputSample;
}
Expand Down
9 changes: 8 additions & 1 deletion Source/OperatorProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,14 @@ class Operator
{
public:
juce::AudioProcessorValueTreeState* tree;
Operator(int opIndex, int voiceIndex, juce::AudioProcessorValueTreeState* t) : tree(t), lastOutputSample(0.0f), envelope(opIndex, tree), voice(voiceIndex), baseRatio(1.0f), index(opIndex)
Operator(int opIndex, int voiceIndex, juce::AudioProcessorValueTreeState* t) :
tree(t),
lastOutputSample(0.0f),
envelope(opIndex, tree),
voice(voiceIndex),
modOffset(0.0f),
index(opIndex),
baseRatio(1.0f)
{
auto iStr = juce::String(opIndex);
panId = "panParam" + iStr;
Expand Down
Loading

0 comments on commit 86f9a8a

Please sign in to comment.