lib/minim/src/ddf/minim/ugens/WavetableGenerator.java
/** 
   * Generate a piecewise linear waveform given an array of sample values and the distances 
   * between them. The <code>dist</code> array should contain one value less than the <code>val</code>
   * array. The values in the <code>dist</code> array should also add up to <code>size</code>. For instance, a 
   * call like this:
   * <p>
   * <code>Wavetable table = WavetableGenerator.gen7( 4096, new float[] { 1.0, -1.0, 1.0 }, new int[] { 2048, 2048 } );</code>
   * <p>
   * 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.
   * <p>
   * If you wanted to generate a triangle wavetable with 4096 samples, you'd do this:
   * <p>
   * <code>Wavetable table = WavetableGenerator.gen7( 4069, new float[] { 0.0, 1.0, 0.0, -1.0, 0.0 }, new int[] { 1024, 1024, 1024, 1024 } );</code>
   * 
   * @shortdesc Generate a piecewise linear waveform given an array of sample values and the distances 
   * between them.
   * 
   * @param size 
   * 			int: the size of the Wavetable that you want generate
   * @param val 
   * 			float[]: the sample values used as control points for generating the waveform
   * @param dist 
   * 			int[]: the sample distances between control points in val
   * 
   * @return a Wavetable
   * 
   * @related Wavetable
   */
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.

@shortdesc Generate a piecewise linear waveform given an array of sample values and the distances
between them.

@param size
int: the size of the Wavetable that you want generate
@param val
float[]: the sample values used as control points for generating the waveform
@param dist
int[]: the sample distances between control points in val

@return a Wavetable

@related Wavetable
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 . @shortdesc Generate a piecewise linear waveform given an array of sample values and the distances between them . @param size int : the size of the Wavetable that you want generate @param val float [] : the sample values used as control points for generating the waveform @param dist int [] : the sample distances between control points in val @return a Wavetable @related Wavetable
public static Wavetable gen7(int size, float[] val, int[] dist)
	{
		float[] waveform = new float[size];
		if (val.length - 1 != dist.length)
		{
			System.out.println("Input arrays of invalid sizes!");
			return null;
		}
		int sum = 0;
		for (int i = 0; i < dist.length; i++)
		{
			sum += dist[i];
		}
		if (size != sum)
		{
			System.out.println("Distances do not sum to size!");
			return null;
		}
		int i = 0;
		for (int j = 1; j < val.length && i < waveform.length; j++)
		{
			waveform[i] = val[j - 1];
			float m = (val[j] - val[j - 1]) / (float)(dist[j - 1]);
			for (int k = i + 1; k < i + dist[j - 1]; k++)
			{
				waveform[k] = m * (k - i) + val[j - 1];
			}
			i += dist[j - 1];
		}
		waveform[waveform.length - 1] = val[val.length - 1];
		return new Wavetable(waveform);
	}
public static Wavetable gen7 ( int size , float [ ] val , int [ ] dist ) { float [ ] waveform = new float [ size ] ; if ( val . length - 1 != dist . length ) { System . out . println ( "Input arrays of invalid sizes!" ) ; return null ; } int sum = 0 ; for ( int i = 0 ; i < dist . length ; i ++ ) { sum += dist [ i ] ; } if ( size != sum ) { System . out . println ( "Distances do not sum to size!" ) ; return null ; } int i = 0 ; for ( int j = 1 ; j < val . length && i < waveform . length ; j ++ ) { waveform [ i ] = val [ j - 1 ] ; float m = ( val [ j ] - val [ j - 1 ] ) / ( float ) ( dist [ j - 1 ] ) ; for ( int k = i + 1 ; k < i + dist [ j - 1 ] ; k ++ ) { waveform [ k ] = m * ( k - i ) + val [ j - 1 ] ; } i += dist [ j - 1 ] ; } waveform [ waveform . length - 1 ] = val [ val . length - 1 ] ; return new Wavetable ( waveform ) ; }
Generate a piecewise linear waveform given an array of sample values and the distances
 between them.
Generate a piecewise linear waveform given an array of sample values and the distances between them .
//System.out.println("gen7: " + size + ", " + val + ", " + dist); // check lengths of arrays // check if size is sum of dists // waveform[0] = val[0]; // for(int n = 0; n < waveform.length; n++) // System.out.println(waveform[n]);