Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash when changing wavetable too quickly #106

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions src/main/java/ddf/minim/ugens/Wavetable.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,22 +128,26 @@ public float get(int i)
*/
public float value(float at)
{
float whichSample = lengthForValue * at;
// create local waveform for thread safe
float[] wave = this.waveform;
if(wave.length==0) return 0;

float whichSample = wave.length * (((at%1)+1)%1);

// linearly interpolate between the two samples we want.
int lowSamp = (int)whichSample;
int hiSamp = lowSamp + 1;
int lowSamp = ((int)whichSample)%wave.length;
int hiSamp = (lowSamp + 1)%wave.length;
// lowSamp might be the last sample in the waveform
// we need to make sure we wrap.
if ( hiSamp >= waveform.length )
if ( hiSamp >= wave.length )
{
hiSamp -= waveform.length;
hiSamp -= wave.length;
}

float rem = whichSample - lowSamp;

return waveform[lowSamp] + rem
* ( waveform[hiSamp] - waveform[lowSamp] );
return wave[lowSamp] + rem
* ( wave[hiSamp] - wave[lowSamp] );

// This was here for testing.
// Causes non-interpolation, but adds max # of oscillators
Expand Down