-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
14 changed files
with
4,873 additions
and
3,400 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
"slug": "TinyTricks", | ||
"name": "Tiny Tricks", | ||
"brand": "Tiny Tricks", | ||
"version": "1.3.0", | ||
"version": "1.4.0", | ||
"license": "MIT", | ||
"author": "Thomas René Sidor", | ||
"authorEmail": "[email protected]", | ||
|
@@ -200,5 +200,14 @@ | |
"oscillator" | ||
] | ||
} | ||
, | ||
{ | ||
"slug": "WAVE", | ||
"name": "Wavetable Oscillator", | ||
"description": "A wavetable oscillator where you can record your own waves.", | ||
"tags": [ | ||
"oscillator" | ||
] | ||
} | ||
] | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
struct WaveTableOscillator{ | ||
|
||
static const int WAVEFORM_COUNT = 3; | ||
static const int MAX_SAMPLE_COUNT = 2048; | ||
int TABLE_END = MAX_SAMPLE_COUNT; | ||
float lookuptables[WAVEFORM_COUNT][MAX_SAMPLE_COUNT] = {0}; | ||
|
||
float currentIndex = 0.f; | ||
float tableDelta = 0.f; | ||
|
||
bool isStepEOC = false; | ||
|
||
bool mirror = false; | ||
bool reverse = false; | ||
|
||
float prevPitch = 90000.f; | ||
|
||
float phase = 0.f; | ||
float freq = 0.f; | ||
|
||
WaveTableOscillator(){ | ||
|
||
} | ||
|
||
void step(){ | ||
isStepEOC = false; | ||
|
||
if(mirror){ | ||
if(!reverse){ | ||
currentIndex += tableDelta; | ||
if (currentIndex >= TABLE_END/2.f) | ||
reverse = true; | ||
} | ||
else{ | ||
currentIndex -= tableDelta; | ||
if(currentIndex < 0.f){ | ||
reverse = false; | ||
currentIndex = 0.f; | ||
isStepEOC = true; | ||
} | ||
} | ||
} | ||
else{ | ||
currentIndex += tableDelta; | ||
if (currentIndex >= TABLE_END){ | ||
currentIndex -= TABLE_END; | ||
isStepEOC = true; | ||
} | ||
} | ||
} | ||
|
||
bool isEOC(){ | ||
return isStepEOC; | ||
} | ||
|
||
float getSample(float y){ | ||
|
||
//Getting indexes for current place in table | ||
int index0 = (int) currentIndex; | ||
int index1 = index0 == (TABLE_END - 1) ? (int) 0 : index0 + 1; | ||
|
||
// How far are we from the index | ||
float indexFrac = currentIndex - (float) index0; | ||
|
||
//Getting indexes for the levels based on y | ||
float frac = y * (WAVEFORM_COUNT-1); | ||
int level0 = floor(frac); | ||
int level1 = ceil(frac); | ||
float levelFrac = frac - (float) level0; | ||
|
||
//Getting the four samples in the table | ||
float Level0Value0 = lookuptables[level0][index0]; | ||
float Level0Value1 = lookuptables[level0][index1]; | ||
|
||
float Level1Value0 = lookuptables[level1][index0]; | ||
float Level1Value1 = lookuptables[level1][index1]; | ||
|
||
//Interpolating between the two | ||
float interpolatedValueForLevel0 = Level0Value0 + indexFrac * (Level0Value1 - Level0Value0); | ||
float interpolatedValueForLevel1 = Level1Value0 + indexFrac * (Level1Value1 - Level1Value0); | ||
|
||
float finalValue = interpolatedValueForLevel0 + levelFrac * (interpolatedValueForLevel1 - interpolatedValueForLevel0); | ||
|
||
return finalValue; | ||
} | ||
|
||
void addSampleToFrame(float sampleValue, float y){ | ||
lookuptables[yToLevel(y)][(int)currentIndex] = sampleValue; | ||
} | ||
|
||
unsigned int yToLevel(float y){ | ||
return floor(y*(WAVEFORM_COUNT-1)); | ||
} | ||
|
||
void endFrame(){ | ||
currentIndex = currentIndex + 1; | ||
} | ||
|
||
void startCapture(){ | ||
reset(); | ||
} | ||
|
||
void endCapture(){ | ||
TABLE_END = currentIndex; | ||
reset(); | ||
} | ||
|
||
void setPitch(float pitch, float sampleRate){ | ||
if(pitch != prevPitch){ | ||
float frequency = dsp::FREQ_C4 * powf(2.0f, pitch); | ||
auto tableSizeOverSampleRate = TABLE_END / sampleRate; | ||
tableDelta = frequency * tableSizeOverSampleRate; | ||
prevPitch = pitch; | ||
} | ||
} | ||
|
||
void setMirror(bool _mirror){ | ||
mirror = _mirror; | ||
reset(); | ||
} | ||
|
||
|
||
void reset(){ | ||
currentIndex = 0.f; | ||
} | ||
|
||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.