ExtensionAn SNSampler lets you record sequences of sound up to a specified length. When you instantiate a new SNSampler an array of consecutive empty buffers of equal length will be created. The length of these buffers determines how long the sequences can be. The actual sampling is started be executing the -sample method with a boolean argument true. Again executing the same method with an argument false. The length of the recorde sound will be stored in a variable -loopLengths which stores the lengths of of all currently recorded sequences in values between 0 and 1 (1 represents the longest possible sequence).
Create a new SNSampler instance.
| name |
Optional - a String or a Symbol denoting the name for the new instance. If not given this will default to |
| numBuffers |
Optional - a Integer denoting the number of consecutive buffers to be allocated. If not given this will default to |
| bufLength |
Optional - the lengths of the allocated (audio) Buffers in seconds. If not given this will default to |
| numChannels |
Optional - the number of channels for each buffer. If not given this will default to |
| server |
Optional - the Server on which to allocate the audio buffers. If not given this buffers will be allocated on |
| touchOSC |
Optional - a NetAddr under which an installation of the popular TouchOSC OSC controller is running. NOTE: The address will be used to send feedback to TouchOSC, so you must provide the port under which TouchOSC expects to receive OSC messages! Also, some of the widgets in CVCenter will automatically be connected, based on the IP address provided with the NetAddress. For this to work properly all elements in the TouchOSC interface (provided as layout file with SNSampler) need to be normalized, i.e. their output range must be 0.0-1.0. |
| touchOSCPanel |
Optional - TouchOSC's user interface can be organized in a number of panels. Panels are numbered, beginning from 1. This is also reflected in TouchOSC's commandname structure. E.g. |
an SNSampler
an Event, holding all current SNSampler instances.
Before you can actually use the SNSampler instance you must specify the input bus and (probably) a procedure to be executed when sampling is done. Usually you will want to play the buffer that you've just recorded. This procedure should go into doneAction.
| in |
An Integer, denoting the input bus. If not given this will default to |
| doneAction |
A Function denoting the action that should be taken after sampling has been finished. |
Set the buffer number for the next sample or get the current one (respectively, the one used for the last recording). Incoming sound will be recorded to the buffer denoted by this value. It usually should not be necessary to set the buffer number explicitly - the sampler knows which buffers audio has already been written to and will, as long as empty buffers are still available, automatically choose an empty buffer.
| bufnum |
An Integer denoting the bufnum. |
Set or get the input bus for the sampler. This expects an Integer or a whole-numbered Float.
| in |
An Integer, denoting the bus from which to read incoming audio. |
Start or stop sampling. The buffer to which the sampled audio will be written to is either determined by -setBufnum or, if that method has not been called in advance, the next buffer number. Sampling will usually start at the lowest buffer number in the array of consecutive buffers that have been allocated in -setupSampler or, if -randomBufferSelect has been set to true, at a random buffer number.
sample(false) will automatically advance the buffer number for the next recording. Hence, if you want to play back the recorded audio after calling sample(false), rather use -lastBufnum than -recBufnum. (see example at the bottom for a minimal playback setup).| bool |
A Boolean determining whether sampling should be started or stopped. |
| bufnum |
A Integer, denoting the bufnum to which audio shall be recorded. If not provided the sampler will either write to the next available bufnum or use a random bufnum if -randomBufferSelect has been set to |
Open a Stethoscope, displaying the currently recorded audio. This method will be called automatically when calling -setupSampler but can be called anytime to recreate the stethoscope e.g. if it has been closed accidently.
Reset one or all buffers. Recorded audio will be reset to zero, the -loopLengths will be reset and, if given, doneAction will be executed.
| index |
An Integer, denoting the buffer number that should be reset. |
| doneAction |
A Function that will be executed upon reseting the buffer(s) |
Quit the sampler and free all resources except CVWidgets. After calling this method a new SNSampler of the same name can be initialized. CVWidgets created for the old SNSampler will still work with the new one.
An action to be executed immediately after recording audio has been finished. This could e.g. be some synth that plays back the recorded audio but can be anything. The doneAction must be given as a Function.
Set the NetAddr under which an installation of TouchOSC will be communicating with the sampler.
TouchOSC's graphical user interface is typically organized in panels. A toggle button on the first panel may be addressed through the following command name: /1/toggle1. The touchOSCPanel should allow you to specify the panel under which buttons connected to the SNSampler live.
A page in a TouchOSC GUI that is used select pre-recorded soundfiles. Default: 4
Determine whether the next buffer for audio recording should be selected randomly. Even if this is set to true SNSampler will always try to select a buffer that has not yet been used for recording (only if all buffers have already been filled it will start overwriting already recorded audio).
As already described buffers within SNSampler have a fixed maximum length. That means, if you write audio to them, buffers will likely not be filled completely. However SNSampler keeps track of the actual length of audio data within each buffer. A length of 0 means no audio has been written to the buffer (the whole buffer is filled with zeros) whereas 1 means the buffer is filled completely. 0.5 means exactly half of the buffer is filled (starting at the beginning of the buffer). The value is simply the ratio of the total buffer length by the length of the recorded audio.
The buffers that have already been written audio to.
an Array of integers, denoting the buffer numbers that already contain recorded audio data
When recording is stopped by calling -sample(false) bufnum will automatically be advanced to the next usable bufnum. The variable lastBufnum will automatically return the last used bufnum, so the buffer can be played back easily (see example at the bottom).
The number of channels for each Buffer allocated when initializing a new SNSampler. Allocating the buffers is done by calling Buffer: *allocConsecutive which only allows setting the same number of channels for all allocated buffers. By default this will be 1.
Returns the array of consecutive buffers, allocated when the SNSampler was initialized.
In an SNSamplePlayer not only sounds sampled live within SNSampler can be used but also prerecorded soundfiles. If a prerecorded sound is used a buffer in the -buffers array will be replaced by that sound. The replaced buffer will be backed up in backupBuffers along with the length of the actually recorded audio in seconds under the same index as in the buffers array. Contrary to the buffers array, backupBuffers is an array of events:
Keeping the extra information on the length of the recorded audio allows for recreating the correct specs again, if the backed up buffer is used again.
The name of the SNSampler. By default this will be 'Sampler'.
Either true or false, depending on whether the sampler is currently recording audio.
The length of each buffer in the array of consecutive buffers in seconds.
The Server on which the biffer have been allocated.
Return whether the sampler has been fully set up.
The input of the sampler may be sent through a comressor before recording it - probably not necessary in many cases but it may help amplifying a very low level signal. Note that this may also create noising. The arguments follow the arguments to a Compander ugen, except for in, control, mul, add which are omitted here.
| thresh |
Ampplitude threshold. Default: |
| slopeBelow |
Slope of applied amplitude curve if control signal amplitude is below thresh. If > 1.0, the amplitude drops off more quickly the softer the control signal gets; when the control signal is close to 0 amplitude, the output should be exactly zero -- hence, noise gating. Values < 1.0 are possible, but it means that a very low-level control signal will cause the input signal to be amplified, which would raise the noise floor. Default: |
| slopeAbove |
Slope of applied amplitude curve if control signal amplitude is above thresh. Values < 1.0 achieve compression (louder signals are attenuated) whereas values > 1.0 expand (louder signals are made even louder). A value of 1/3 achieves a 3:1 compression. Default: |
| clampTime |
Time (in seconds) it takes for the amplitude adjustment to kick in fully after the control signal is above thresh. Usually a small value around 10ms (0.01), often set as low as 2ms (0.002). Default: |
| relaxTime |
Time (in seconds) for the amplitude adjustment to be released (control signal below thresh). Usually longer than clampTime; depending on the input and control signal, setting both times too short results in (possibly unwanted) artifacts. Default: |
For a more complex example have a look at SNSamplePlayer.