jass.generators
Class GranularConstantLoopBuffer

java.lang.Object
  extended by jass.engine.Out
      extended by jass.generators.ConstantLoopBuffer
          extended by jass.generators.GranularConstantLoopBuffer
All Implemented Interfaces:
Source

public class GranularConstantLoopBuffer
extends ConstantLoopBuffer

Jump through a buffer, loaded from an audio file or provided by caller. No speed or volume control is provided. Sample is divided into segments with segmentation array segs[]. seg[k] is start of segment k, except last element of segs[], which denotes the end of the last segment (in order not to run into the artificial buffer end). Playback starts at segment i, then makes transition to setgment k, with transition probability tprob[i][k] (user provided matrix). Generally you must define first the segments, then the transition matrix.

Author:
Kees van den Doel (kvdoel@cs.ubc.ca)

Field Summary
protected  int currentSegIndex
          Current segment index
protected  float fadeTime
          Fade-in time for grains
protected  int[] isSeg
          array telling you segment index of sample k in loopBuffer[].
protected  float linearBias
          If 1 will have linear wavetable playback, 0 total random
protected  int[] segs
          Locations of segments in samples.
protected  double[][] tprob
          Transition probabilities.
protected  float volume
          volume
 
Fields inherited from class jass.generators.ConstantLoopBuffer
ix, loopBuffer, loopBufferLength, srate
 
Fields inherited from class jass.engine.Out
buf, bufferSize, bufOld, lock
 
Constructor Summary
GranularConstantLoopBuffer(float srate, int bufferSize, float[] loopBuffer)
          Construct from provided buffer
GranularConstantLoopBuffer(float srate, int bufferSize, java.lang.String fn)
          Construct from named file.
GranularConstantLoopBuffer(float srate, int bufferSize, java.net.URL url)
          Construct from url.
 
Method Summary
 void computeBuffer()
          Compute the next buffer.
 void initRandom(int n, float linearBias)
          Random initialization with n segments (not counting last unused one)
 void setFadeTime(float dur)
          Set duration of fade-in at the grain boundaries This method only works if the segments are ordered sequentually in time.
 void setLinearBias(float val)
          Set probability that InitRandom() generated random transition matrix will favour sequential playback
 void setSegments(float[] segs)
          Define segments as float array of times.
 void setSegments(int n)
          Define n segments randomly
 void setTransitionMatrix()
          Define random transition matrix.
 void setTransitionMatrix(double[][] t)
          Define transition matrix
 void setVolume(float vol)
          Set volume
 
Methods inherited from class jass.generators.ConstantLoopBuffer
getLoopBuffer, getSamplingRate
 
Methods inherited from class jass.engine.Out
clearBuffer, copyToOld, getBuffer, getBuffer, getBufferSize, getTime, peekAtBuffer, resetTime, setBufferSize, setTime, setTimeAndNotify
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

segs

protected int[] segs
Locations of segments in samples. Last entry marks end only


tprob

protected double[][] tprob
Transition probabilities. Last segment start not transited to


currentSegIndex

protected int currentSegIndex
Current segment index


isSeg

protected int[] isSeg
array telling you segment index of sample k in loopBuffer[]. This includes last unheard segment


fadeTime

protected float fadeTime
Fade-in time for grains


linearBias

protected float linearBias
If 1 will have linear wavetable playback, 0 total random


volume

protected float volume
volume

Constructor Detail

GranularConstantLoopBuffer

public GranularConstantLoopBuffer(float srate,
                                  int bufferSize,
                                  java.lang.String fn)
Construct from named file.

Parameters:
srate - sampling rate in Hertz.
bufferSize - bufferSize of this Out
fn - Audio file name.

GranularConstantLoopBuffer

public GranularConstantLoopBuffer(float srate,
                                  int bufferSize,
                                  java.net.URL url)
Construct from url.

Parameters:
srate - sampling rate in Hertz.
bufferSize - bufferSize of this Out
url - Audio file url.

GranularConstantLoopBuffer

public GranularConstantLoopBuffer(float srate,
                                  int bufferSize,
                                  float[] loopBuffer)
Construct from provided buffer

Parameters:
srate - sampling rate in Hertz.
bufferSize - bufferSize of this Out.
loopBuffer - looping buffer.
Method Detail

initRandom

public void initRandom(int n,
                       float linearBias)
Random initialization with n segments (not counting last unused one)

Parameters:
n - number of segments
linearBias - how likely a linear playback is (1 will give looping, 0 total randomness)

setFadeTime

public void setFadeTime(float dur)
Set duration of fade-in at the grain boundaries This method only works if the segments are ordered sequentually in time.

Parameters:
fadeTime - fade-in time in seconds

setLinearBias

public void setLinearBias(float val)
Set probability that InitRandom() generated random transition matrix will favour sequential playback

Parameters:
val - probability for linear order

setSegments

public void setSegments(float[] segs)
Define segments as float array of times.

Parameters:
segs - segments. Last segment is unused, but used to make end of prev.

setSegments

public void setSegments(int n)
Define n segments randomly

Parameters:
n - number of segments (not including last one)

setTransitionMatrix

public void setTransitionMatrix(double[][] t)
Define transition matrix

Parameters:
t - transition matrix of size (segs.length-1)*(segs.length-1)

setTransitionMatrix

public void setTransitionMatrix()
Define random transition matrix. Muse have segments defined before use.

Parameters:
n - transition matrix of size (segs.length-1)*(segs.length-1)

setVolume

public void setVolume(float vol)
Set volume

Parameters:
vol - volume

computeBuffer

public void computeBuffer()
Compute the next buffer.

Overrides:
computeBuffer in class ConstantLoopBuffer