ddf.minim.ugens
Class WavetableGenerator

java.lang.Object
  extended by ddf.minim.ugens.WavetableGenerator

public abstract class WavetableGenerator
extends java.lang.Object

WavetableGenerator is a helper class for generating Wavetables. The method names are likely to change in a future release to be a bit more descriptive.

Author:
Mark Godfrey

Constructor Summary
WavetableGenerator()
           
 
Method Summary
static Wavetable gen10(int size, float[] amp)
          Generate a Wavetable given a list of amplitudes for successive partials (harmonics).
static Wavetable gen7(int size, float[] val, int[] dist)
          Generate a piecewise linear waveform given an array of sample values and the distances between them.
static Wavetable gen9(int size, float[] partial, float[] amp, float[] phase)
          Generates a Wavetable from a list of partials with matching amplitudes and phases.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WavetableGenerator

public WavetableGenerator()
Method Detail

gen7

public static Wavetable gen7(int size,
                             float[] val,
                             int[] dist)
Generate a piecewise linear waveform given an array of sample values and the distances between them. The dist array should contain one value less than the val array. The values in the dist array should also add up to size. For instance, a call like this:

Wavetable table = WavetableGenerator.gen7( 4096, new float[] { 1.0, -1.0, 1.0 }, new int[] { 2048, 2048 } );

Would generate a Wavetable that was 4096 samples long and the values of those samples would start at 1.0, linearly decrease to -1.0 over 2048 samples, and then increase to 1.0 over the next 2048 samples.

If you wanted to generate a triangle wavetable with 4096 samples, you'd do this:

Wavetable table = WavetableGenerator.gen7( 4069, new float[] { 0.0, 1.0, 0.0, -1.0, 0.0 }, new int[] { 1024, 1024, 1024, 1024 } );

Parameters:
size - the size of the Wavetable that you want generate
val - the sample values used as control points for generating the waveform
dist - the sample distances between control points in val

gen9

public static Wavetable gen9(int size,
                             float[] partial,
                             float[] amp,
                             float[] phase)
Generates a Wavetable from a list of partials with matching amplitudes and phases. Partial, here, refers to a particular sine wave in the harmonic series (see: http://en.wikipedia.org/wiki/Harmonic_series_%28music%29#Harmonic_vs._partial). If you want to generate a single sine wave, suitable for playing a single tone of a particular frequency in an Oscil, you could use this code:

Wavetable sine = WavetableGenerator.gen9(4096, new float[] { 1 }, new float[] { 1 }, new float[] { 0 });

But what this method lets you do, is create a Wavetable that contains several different partials, each with a particular amplitude or phase shift. For instance, you could create a Wavetable that plays two pitches an octave apart like this:

Wavetable octave = WavetableGenerator.gen9(4096, new float[] { 1, 2 }, new float[] { 1, 1 }, new float[] { 0, 0 });

If this is something you want a particular instrument you write to do, then creating a Wavetable that already contains the octave and using that in an Oscil will be less computationally expensive than creating two Oscils and setting their frequencies an octave apart.

Parameters:
size - how many samples the Wavetable should contain
partial - a list of partials to generate
amp - the amplitude of each partial
phase - the phase of each partial

gen10

public static Wavetable gen10(int size,
                              float[] amp)
Generate a Wavetable given a list of amplitudes for successive partials (harmonics). These two method calls are equivalent:

Wavetable table = WavetableGenerator.gen9(4096, new float[] { 1, 2, 3 }, new float[] { 1, 0.5, 0.2 }, new float[] { 0, 0, 0 });

Wavetable table = WavetableGenerator.gen10(4096, new float[] { 1, 0.5, 0.2 });

Parameters:
size - the number of samples the Wavetable should contain
amp - the amplitude of each successive partial, beginning with partial 1.
See Also:
gen9(int, float[], float[], float[])