Tutorial 14: Playback with Loops
Open the tutorial.
Playing samples with groove~
The groove~ object is the most versatile object for playing sound from a buffer~. You can specify the buffer~ to read, the starting point, the playback speed (either forward or backward), and starting and ending points for a repeating loop within the sample. As with other objects that read from a buffer~, groove~ accesses the buffer~ remotely, without patch cords, by sharing its name.
A standard configuration for the use of groove~
In the example above, the message loop 1 turns looping on, the start time of 0 ms indicates the beginning of the buffer~, the playback speed of 1 means to play forward at normal speed, and the loop start and end times mean that (because looping is turned on) when groove~ reaches a point 860 milliseconds into the buffer~ it will return to a point 572 ms into the buffer~ and continue playing from there. Notice that the start time must be received as a float (or int), and the playback speed must be received as a signal. This means the speed can be varied continuously by sending a time- varying signal in the left inlet.
Whenever a new start time is received, groove~ goes immediately to that time in the buffer~ and continues playing from there at the current speed. When groove~ receives the message loop 1 or startloop it goes to the beginning of the loop and begins playing at the current speed. (Note that loop points are ignored when groove~ is playing in reverse, so this does not work when the playback speed is negative.) groove~ stops when it reaches the end of the buffer~ (or the beginning if it's playing backward), or when it receives a speed of 0.

In the tutorial patch, three different buffer~ objects are loaded with AIFF files so that a single groove~ object can switch between various samples instantly (notice that each buffer~ object also contains two additional optional arguments that identify the length of the buffer and the number of channels). The message set, followed by the name of a buffer~, refers groove~ to that new buffer~ immediately. (If groove~ always referred to the same buffer~, and we used read messages to change the contents of the buffer~, some time would be needed to open and load each new file.)
Refer groove~ to a different buffer~ with a set message
• Click on the preset object to play the samples in different ways.
The first preset just functions as an ‘Off’ button. The next three presets play the three buffer~ objects at normal speed without looping. The rest of the presets demonstrate a variety of sound possibilities using different playback speeds on different excerpts of the buffered files, with or without looping.
• You may want to experiment with your own settings by changing the user interface objects directly.
You can control all aspects of the playback by changing the user interface object settings
If you want to create smooth undetectable loops with groove~, you can use the loopinterp message to enable crossfades between the end of a loop and the beginning of the next pass through the loop to smooth out the transition back to the start point (see the groove~ reference page for more information on this message). If the buffer~ contains an AIFF file that has its own loop points -- points established in a separate audio editing program -- there is a way to use those loop points to set the loop points of groove~.

The info~ object can report the loop points of an AIFF file contained in a buffer~, and you can send those loop start and end times directly into groove~. You can also use the the info~ object to find out the length (in milliseconds) of any file you load into a buffer.
Using info~ to get loop point information from an AIFF file
Summary
The groove~ object is the most versatile way to play sound from a buffer~. You can specify the buffer~ to read, the starting point, the playback speed (either forward or backward), and starting and ending points for a repeating loop within the sample. If the buffer~ contains an AIFF file that has its own pre-established loop points, you can use the info~ object to get those loop times and send them to groove~. The playback speed of groove~ is determined by the value of the signal coming in its left inlet. You can set the current buffer position of groove~ by sending a float time value in the left inlet.

See Also

Name Description
buffer~ Store audio samples
groove~ Variable-rate looping sample playback
sig~ Constant signal of a number