lib/minim/src/ddf/minim/ugens/GranulateRandom.java
// Make the samples.  Must make the samples
Make the samples.  Must make the samples
Make the samples . Must make the samples
@Override
	protected void uGenerate( float[] channels ) 
	{
		if ( insideGrain )  
		{	
			float amp = maxAmp;
			if ( timeSinceGrainStart < fadeLength )  
			{
				amp *= timeSinceGrainStart/fadeLength;
			}
			else if ( timeSinceGrainStart > ( grainLength - fadeLength ) )  
			{
				amp *= ( grainLength - timeSinceGrainStart )/fadeLength;
			}
			for(int i = 0; i < channels.length; i++)
			{
				channels[i] = amp*audio.getLastValues()[i];
			}
			timeSinceGrainStart += timeStep;
			if ( timeSinceGrainStart > grainLength )  
			{
				timeSinceGrainStop = 0.0f;
				insideGrain = false;
				spaceLengthMin = spaceLenMin.getLastValue();
				spaceLengthMax = spaceLenMax.getLastValue();
				spaceLength = randomBetween( spaceLengthMin, spaceLengthMax );
			}
		}
		else  
		{
			for(int i = 0; i < channels.length; i++)
			{
				channels[i] = minAmp;
			}
			timeSinceGrainStop += timeStep;
			if (timeSinceGrainStop > spaceLength)  
			{
				timeSinceGrainStart = 0.0f;
				insideGrain = true;
				grainLengthMin = grainLenMin.getLastValue();
			  grainLengthMax = grainLenMax.getLastValue();
				grainLength = randomBetween( grainLengthMin, grainLengthMax );
				fadeLengthMin = fadeLenMin.getLastValue();
				fadeLengthMax = fadeLenMax.getLastValue();
				fadeLength = randomBetween( fadeLengthMin, fadeLengthMax );
				checkFadeLength();
			}
		}
	}
@ Override protected void uGenerate ( float [ ] channels ) { if ( insideGrain ) { float amp = maxAmp ; if ( timeSinceGrainStart < fadeLength ) { amp *= timeSinceGrainStart / fadeLength ; } else if ( timeSinceGrainStart > ( grainLength - fadeLength ) ) { amp *= ( grainLength - timeSinceGrainStart ) / fadeLength ; } for ( int i = 0 ; i < channels . length ; i ++ ) { channels [ i ] = amp * audio . getLastValues ( ) [ i ] ; } timeSinceGrainStart += timeStep ; if ( timeSinceGrainStart > grainLength ) { timeSinceGrainStop = 0.0f ; insideGrain = false ; spaceLengthMin = spaceLenMin . getLastValue ( ) ; spaceLengthMax = spaceLenMax . getLastValue ( ) ; spaceLength = randomBetween ( spaceLengthMin , spaceLengthMax ) ; } } else { for ( int i = 0 ; i < channels . length ; i ++ ) { channels [ i ] = minAmp ; } timeSinceGrainStop += timeStep ; if ( timeSinceGrainStop > spaceLength ) { timeSinceGrainStart = 0.0f ; insideGrain = true ; grainLengthMin = grainLenMin . getLastValue ( ) ; grainLengthMax = grainLenMax . getLastValue ( ) ; grainLength = randomBetween ( grainLengthMin , grainLengthMax ) ; fadeLengthMin = fadeLenMin . getLastValue ( ) ; fadeLengthMax = fadeLenMax . getLastValue ( ) ; fadeLength = randomBetween ( fadeLengthMin , fadeLengthMax ) ; checkFadeLength ( ) ; } } }
Make the samples.
Make the samples .
// inside a grain // start with an amplitude at maxAmp // inside the rise  // linear fade in // inside the decay // linear fade out // generate the sample // increment time // just after a grain  // stop the grain // set a new spaceLength // outside a grain // increment time // just inside a grain again // start the grain // set a new grain length // set a new fade length // make sure the fade length is correct