net.beadsproject.beads.ugens
Class RecordToSample

java.lang.Object
  extended by net.beadsproject.beads.core.Bead
      extended by net.beadsproject.beads.core.UGen
          extended by net.beadsproject.beads.ugens.RecordToSample

public class RecordToSample
extends UGen

RecordToSample records audio into a writeable Sample. RecordToSample has three different modes, which dictate how it behaves when the end of the sample is reached:

A recorder may not completely fill a sample. If you just want the recorded data then be sure to clip() the sample once done. Alternatively you can see how many frames were written.

Tip: Be sure to UGen.pause(boolean) the recorder when using INFINITE mode, otherwise it will keep recording and you may quickly run out of memory.

ADVANCED: When resizing a sample in INFINITE mode, the recorder uses a set of parameters that specify how it behaves. If necessary you can modify the parameters on a per-recorder basis. See setResizingParameters(double, double).


Nested Class Summary
static class RecordToSample.Mode
           
 
Nested classes/interfaces inherited from class net.beadsproject.beads.core.UGen
UGen.OutputInitializationRegime, UGen.OutputPauseRegime
 
Field Summary
 
Fields inherited from class net.beadsproject.beads.core.UGen
bufferSize, bufIn, bufOut, context, ins, outputInitializationRegime, outputPauseRegime, outs
 
Constructor Summary
RecordToSample(AudioContext context, int numChannels)
           
RecordToSample(AudioContext context, Sample sample)
          Instantiates a new RecordToSample.
RecordToSample(AudioContext context, Sample sample, RecordToSample.Mode mode)
          Instantiates a new RecordToSample.
 
Method Summary
 void calculateBuffer()
          Called by the signal chain to update this UGen's ouput data.
 void clip()
          Once you have finished writing into a sample this method clips the sample length to the recorded data.
 RecordToSample.Mode getMode()
           
 long getNumFramesRecorded()
           
 double getPosition()
          Gets the position.
 Sample getSample()
          Gets the Sample.
 boolean isLoopRecord()
          Deprecated. Use getMode() instead.
 void reset()
          Resets the Recorder to record into the beginning of the Sample.
 void setLoopRecord(boolean loopRecord)
          Deprecated. Use setMode(Mode) instead.
 void setMode(RecordToSample.Mode mode)
           
 void setPosition(double positionMs)
          Sets the position to record to in milliseconds.
 void setResizingParameters(double doubleUpTime, double constantResizeLength)
          Advanced: Change the parameters used when resizing samples in INFINITE recorder mode.
 void setSample(Sample sample)
          Sets the Sample.
 
Methods inherited from class net.beadsproject.beads.core.UGen
addDependent, addInput, addInput, clearDependents, clearInputConnections, containsInput, crossfadeInput, getConnectedInputs, getContext, getEnvelopes, getIns, getNumberOfConnectedUGens, getNumberOfDependents, getOutBuffer, getOuts, getTimeTakenLastUpdate, getValue, getValue, getValueDouble, getValueDouble, initializeOuts, isTimerMode, isUpdated, noInputs, pause, printInBuffers, printInputList, printOutBuffers, removeAllConnections, removeConnection, removeDependent, setOutsToPause, setTimerMode, setValue, update, zeroIns, zeroOuts
 
Methods inherited from class net.beadsproject.beads.core.Bead
getKillListener, getName, isDeleted, isPaused, kill, message, messageReceived, setKillListener, setName, start, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RecordToSample

public RecordToSample(AudioContext context,
                      Sample sample)
               throws java.lang.Exception
Instantiates a new RecordToSample.

Parameters:
context - the AudioContext.
sample - the Sample.
Throws:
java.lang.Exception - if sample is not writeable.

RecordToSample

public RecordToSample(AudioContext context,
                      Sample sample,
                      RecordToSample.Mode mode)
               throws java.lang.Exception
Instantiates a new RecordToSample.

Parameters:
context - the AudioContext.
sample - the Sample.
mode - the Recording Mode to use.
Throws:
java.lang.Exception - if sample is not writeable.

RecordToSample

public RecordToSample(AudioContext context,
                      int numChannels)
Method Detail

getSample

public Sample getSample()
Gets the Sample.

Returns:
the Sample.

setSample

public void setSample(Sample sample)
               throws java.lang.Exception
Sets the Sample.

Parameters:
sample - the new Sample.
Throws:
java.lang.Exception - if sample isn't writeable

reset

public void reset()
Resets the Recorder to record into the beginning of the Sample.


clip

public void clip()
Once you have finished writing into a sample this method clips the sample length to the recorded data.


setPosition

public void setPosition(double positionMs)
Sets the position to record to in milliseconds.

Parameters:
positionMs - the new position in milliseconds.

calculateBuffer

public void calculateBuffer()
Description copied from class: UGen
Called by the signal chain to update this UGen's ouput data. Subclassses of UGen should implement the UGen's DSP perform routine here. In general this involves grabbing data from UGen.bufIn and putting data into UGen.bufOut in some way. UGen.bufIn and UGen.bufOut are 2D arrays of floats of the form float[numChannels][bufferSize]. The length of the buffers is given by UGen.bufferSize, and the number of channels of the input and output buffers are given by UGen.ins and UGen.outs respectively.

Specified by:
calculateBuffer in class UGen

getPosition

public double getPosition()
Gets the position.

Returns:
the position

getNumFramesRecorded

public long getNumFramesRecorded()
Returns:
The number of frames recorded into the sample.

getMode

public RecordToSample.Mode getMode()
Returns:
The mode this recorder is operating in.

setMode

public void setMode(RecordToSample.Mode mode)
Parameters:
mode - Change the mode of this recorder. Can be changed while running.

setResizingParameters

public void setResizingParameters(double doubleUpTime,
                                  double constantResizeLength)
Advanced: Change the parameters used when resizing samples in INFINITE recorder mode. In INFINITE mode the recorder resizes the sample when it needs to write more data into it. Initially the recorder doubles the length of the sample, up to a particular length. Once the sample size is past this length the recorder stops doubling the length, and simply resizes the sample by a constant amount.

Parameters:
doubleUpTime - The time (in ms) up to which the sample size should be doubled.
constantResizeLength - The length (in ms) of the extra space appended to Sample.

isLoopRecord

public boolean isLoopRecord()
Deprecated. Use getMode() instead.

Checks if loop record mode is enabled.

Returns:
true if loop record mode is enabled.

setLoopRecord

public void setLoopRecord(boolean loopRecord)
Deprecated. Use setMode(Mode) instead.

Starts/stops loop record mode.

Parameters:
loopRecord - true to enable loop record mode.