sfplay~
Play audio file from disk
Description
Use the sfplay~ object to play audio files from disk. Supported formats include AIFF, WAVE, MP3, OGG, FLAC, M4A, CAF, WF64, WAVE64, and Raw Data.
Discussion
To play a file, you send sfplay~ the message, then send it a to start and a to stop. takes an argument to specify a filename in the search path. You can also create additional cues with the message. These can reference other files, all of which are simultaneously accessible. The message sets the "current" file: the one that plays back from the beginning when is sent and is used as the default for the message. sfplay~ can also connect to the cues defined in an sflist~ object. Since multiple sfplay~ objects can reference the same sflist~, this allows you to store a global list of cues.
Arguments
sflist-object-name[symbol]
optional
number-of-output-channels[int]
optional
Sets the number of output channels, which determines the number of signal outlets that the sfplay~ object will have. The maximum number of channels is 64. The default is 1. If the audio file being played has more output channels than the sfplay~ object, higher-numbered channels will not be played. If the audio file has fewer channels, the signals coming from the extra outlets of sfplay~ will be 0.
buffer-size[int]
optional
An additional optional argument can be used to specify the disk buffer size in samples. The default disk buffer size is 120960, and disk buffer sizes must be specified as multiples of 20160. If this argument has a value of 0, the default disk buffer size will be used.
position-outlet-flag[int]
optional
An additional optional argument can be used to create outlets to the sfplay~ object which display positioning information. Specifying a final argument of
Like all MSP audio signals, this playback position is a 32-bit single precision floating-point signal. If greater precision is desired, specifying a final argument of 2 creates a second outlet which outputs a second 32-bit single precision floating-point signal containing the single precision roundoff error. Together these signals provide near double precision floating-point accuracy. (Note: after several minutes a single precision floating-point value is no longer sample accurate) Using the two signals together with objects such as the unsupported Max/ MSP high resolution signal processing objects like hr.+~ , one may perform sample-accurate calculations based on file position
object-reference-name[symbol]
optional
If the last argument is a symbol, it specifies a name by which other objects can refer to the sfplay~ object to access its contents.
Attributes
audiofile[symbol]
7.0.0
Specifies the name/pathname of an audio file to be loaded by the sfplay~ object.
basictuning[int]
7.0.0
Sets a tuning standard based on a frequency for A for pitch correction operations (440 = default, range is 400 - 500)
followglobaltempo[int]
7.0.0
When followgobaltempo is enabled, sfplay~ will calculate the current tempo out of the ratio between originaltempo and global tempo and adapt to global tempo changes.
formant[float]: 1.
7.0.0
The word
, followed by floating point value, sets the amount of formant scaling when pitchshifting is performed.
formantcorrection[int]
7.0.0
The word
, followed by a zero or one, disables/enables formant correction when pitch correction is performed.
loop[int]
Turn looping on or off.
mode[int]
7.0.0
Sets the timestretching mode to be used. Each mode is optimized for handling different kinds of audio material. All modes are zero latency.
Possible values:
'basic'
(
Default mode of operation
)
This is the default mode of operation.
'monophonic'
(
Monophonic sources (voice, flute)
)
This mode is best for monophonic instruments (e.g. solo voice, flute, etc.)
'rhythmic'
(
Optimizes for transient preservation
)
This mode is for time stretched percussion. It provides optimal transient preservation.
'general'
(
Balance spectral integrity with transient preservaton
)
This mode balances spectral integrity and transient preservation for general cases.
'extremestretch'
(
For stretch ratios greater than 2.0
)
This mode is intended for stretch ratios greater 2.0, a more artistic effect is intended.
'efficient'
(
Good CPU performance
)
This mode is intended for a good CPU performance/quality tradeoff.
name[symbol]
Name
originallength[Time Value]
7.0.0
The original length of the the audio file in beats. Used by
to calculate the speed in relation to the global transport speed. Setting the will calculate the .
originaltempo[float]
7.0.0
The original tempo of the the audio file. Used by
to calculate the speed in relation to the global transport speed. Setting the will calculate the .
pitchcorrection[int]
7.0.0
The word retune~ object.
, followed by a zero or one, enable/disables the formant-corrected chromatic intonation correction. For more extensive real-time intonation correction, use the
pitchshift[float]: 1.
7.0.0
Specify pitchshift as a factor of the original pitch (i.e. 2.0 = doubling of pitch, .5 = halving of the original pitch, etc.).
pitchshiftcent[int]: 0
7.0.0
Specify pitchshift as positive or negative cent values (i.e. 100 = semitone up, -1200 = octave down). Cents may be specified as ints or floats.
quality[symbol]
7.0.0
Choose the quality for timestretching output.
Possible values:
'basic'
(
Basic quality (the default)
)
'good'
(
Good quality
)
'better'
(
Better quality
)
'best'
(
Highest quality
)
slurtime[float]: 0.
7.0.0
Set the time it takes for the correction to reach the full correction amount. Typically, notes are a bit unstable at the beginning, because the attack phase of a sound has a higher amount of noise, and because singers gradually adjust their tuning after the onset of the note. The slur time makes the pitch correction sound natural because it models this effect. Higher values will yield a slower adaptation time and it will take longer for the correction to produce the corrected pitch. However, longer slur times will also preserve vibrato better.
speed[float]
Playback speed
timestretch[int]
7.0.0
The word
, followed by a zero or one, disables/enables timestretching.Common Box Attributes
annotation[symbol]
Sets the text that will be displayed in the Clue window when the user moves the mouse over the object.
background[int]: 0
Adds or removes the object from the patcher's background layer.
adds the object to the background layer, removes it. Objects in the background layer are shown behind all objects in the default foreground layer.
color[4 floats]
Sets the color for the object box outline.
fontface[int]
Sets the type style used by the object. The options are:
plain
bold
italic
bold italic
Possible values:
0 = 'regular'
1 = 'bold'
2 = 'italic'
3 = 'bold italic'
fontname[symbol]
Sets the object's font.
fontsize[float]
Sets the object's font size (in points).
Possible values:
'8'
'9'
'10'
'11'
'12'
'13'
'14'
'16'
'18'
'20'
'24'
'30'
'36'
'48'
'64'
'72'
hint[symbol]
Sets the text that will be displayed in as a pop-up hint when the user moves the mouse over the object in a locked patcher.
ignoreclick[int]: 0
Toggles whether an object ignores mouse clicks in a locked patcher.
jspainterfile[symbol]
You can override the default appearance of a user interface object by assigning a JavaScript file with code for painting the object. The file must be in the search path.
patching_rect[4 floats]: 0. 0. 100. 0.
Sets the position and size of the object in the patcher window.
position[2 floats]
write-only
Sets the object's x and y position in both patching and presentation modes (if the object belongs to its patcher's presentation), leaving its size unchanged.
presentation[int]: 0
Sets whether an object belongs to the patcher's presentation.
presentation_rect[4 floats]: 0. 0. 0. 0.
Sets the x and y position and width and height of the object in the patcher's presentation, leaving its patching position unchanged.
rect[4 floats]
write-only
Sets the x and y position and width and height of the object in both patching and presentation modes (if the object belongs to its patcher's presentation).
size[2 floats]
write-only
Sets the object's width and height in both patching and presentation modes (if the object belongs to its patcher's presentation), leaving its position unchanged.
textcolor[4 floats]
Sets the color for the object's text in RGBA format.
textjustification[int]
Sets the justification for the object's text.
Possible values:
0 = 'left'
1 = 'center'
2 = 'right'
varname[symbol]
Sets the patcher's scripting name, which can be used to address the object by name in pattr, scripting messages to thispatcher, and the js object.
Messages
int
In left inlet: If a file has been opened with the sfplay~ object. When the file is played, the audio data in the file is sent out the signal outlets according to the number of channels the object has. When the cue is completed or sfplay~ is stopped with a , a is sent out the right outlet. If the object is currently assigned to an sflist~ object (using the message or with a typed-in argument), an will trigger cues stored in the sflist~ object rather than inside the sfplay~. To reset sfplay~ to use its own cues, send it the message with no arguments.
message, begins playback (of the most recently opened file), and stops playback. Numbers greater than 1 trigger cues that have been defined with the message, or that were defined based on the saved state of the- start/stop-playback-of-cue-number
[int]
float
In right inlet: Defines the playback rate of an audio file. A value of 1.0 plays the audio file at normal speed. A playback rate of -1 plays the audio file backwards at normal speed. A playback rate of 2 plays the audio file at twice the normal speed. A playback rate of .5 plays the audio file at half the normal speed. The playback rate cannot be changed when playback is off.
To initiate starting from a cue point with a negative speed, bidirectional cues must be used.
- playback-rate
[float]
list
In left inlet: Gives a set of cues for sfplay~ to play, one after the other. The maximum number of cues is in a list is 128. Cue numbers (set using the message) can be any integer greater than or equal to 2.If a cue number in a list has not been defined, it is skipped and the next cue, if any, is tried. If the object is currently assigned to an sflist~ object, a list uses cues stored in the sflist~ object. Otherwise, cues stored inside the sfplay~ object are used.
- cues
[list]
anything
(drag)
When an audio file is dragged from the Max File Browser to an sfplay~ object, the file will be loaded.
clear
In left inlet: The word sfplay~ object's cue list. requires the DSP chain to be off.
with no arguments clears all defined cues. After a message is received, only the number will play anything (assuming there's an open file). The word followed by one or more cue numbers removes them from the- cue-numbers
[list]
dictionary
7.0.0
Use a dictionary to define more complex time stretching. Define a point in time (sourcetime) and define where this point should be transformed to (desttime). For example, the dictionary below will
- create marker01 which will stretch the whole sample (“end”) to be twice as long
{ "marker01" : { "sourcetime" : “end”, "desttime" : “*2”, } }
- dictionary-name
[symbol]
embed
In left inlet: The message sfplay~ to save all of its defined cues and the name of the current open file when the patcher file is saved. The message keeps sfplay~ from saving this information when the patcher is saved. By default, the current file name and the cue information is not saved in sfplay~ when the patcher is saved. If an sfplay~ object is saved with stored cues, they will all be preloaded when the patcher containing the object is loaded.
, followed by any non-zero integer, causes- saving-preference-flag (0 or nonzero)
[int]
fclose
In left inlet: The word
, followed by the name of an open file, closes the file and removes all cues associated with it. The word by itself closes the current file.- filename
[symbol]
loopone
In left inlet: The word
, followed by a cue-number, will set only the cue specified to loop.- cue-number
[int]
modout
In left inlet: The word sfplay~ object will reduplicate the audio file's channels across all of sfplay~ object's outputs (rather than outputting zero) if modulo output is enabled. For example, a mono audio file loaded into an sfplay~ object with two outputs will be played with the mono channel sent out both outputs of the object if modulo output is enabled. Similarly a stereo audio file will be played on an sfplay~ object with four outlets with the left channel played on outputs 1 and 3, while the right will be played on outputs 2 and 4. The message disables this feature.
, followed by 1, turns on modulo output. If the number of channels in a audio file is less than the number of outputs for the sfplay~ object, the- modulo-output-flag
[int]
offset
In left inlet: The word
, followed by a number, specifies the sample start offset in bytes. The default value is 0. This value useful for aligning samples and avoiding playback of header information.- sample-start-offset (bytes)
[int]
open
In left inlet: followed by the name of an AIFF, WAVE, MP3, OGG, FLAC, M4A, CAF, WF64, WAVE64, or Raw format audio file or CD-audio track, opens the file for playback and makes it the current file. The word sfplay~ the message . When the message is received, the previous current file, if any, remains open and can be referred to by name when defining a cue with the message. If any cues were defined that used the previous current file, they are still valid even if the file is no longer current.
, followed by a filename, opens the file if it exists in Max's search path. Without a filename, brings up a standard open file dialog allowing you to choose a file. When a file is opened, its beginning is read into memory, and until another file is opened, you can play the file from the beginning by sending- filename
[symbol]
openraw
In left inlet: The
message functions exactly like , but allows you to open any type of file for playback and make it the current file. The message assumes that the file being opened is a 16-bit stereo file sampled at a rate of 44100 Hz, and assumes that there is no header information to ignore (i.e., an offset of 0). The file types can be explicitly specified using the , , , and messages.- filename
[symbol]
pause
In left inlet: The
message causes the audio file playback to pause at its current playback position. Playback can be restarted with the message.
preload
In left inlet: Defines a cue - an integer greater than or equal to 2 - to refer to a specific region of a file. When that cue number is subsequently received, sfplay~ plays that region of that file. Cue number 1 is always the beginning of the current file - the file last opened with the message - and cannot be modified with the message.
There are a number of forms for the message. The word is followed by an obligatory cue number between 2 and 32767. If the cue number is followed by a filename of a file in Max's search path, or a full file pathname, that cue number will play the specified file. Note that a file need not have been explicitly opened with the message in order to be used in a cue. If no filename is specified, the currently open file is used.
After the optional filename, an optional start time in milliseconds can be specified. If no start time is specified, the beginning of the file is used as the cue start point. After the start time, an end time in milliseconds can be specified. If no end time is specified, or the end time is , the cue will play to the end of the file. If the end time is less than the start time, the cue is defined but will not play. Eventually it may be possible to define cues that play in reverse.
After the start and/or end time arguments, a optional directional buffer flag is used to enable reverse playback of stored cues. Setting this flag to 1 enables reverse cue playback. The default setting is (bidirectional buffering off).
A final optional argument is used to set the playback speed. A float value sets the sfplay~ object's playback speed relative to the object's global playback speed -- set by either the message or the sfplay~ object's right inlet. The default value is .
Each cue that is defined requires approximately 40K of memory per sfplay~ channel at the default buffer size (40320), with bidirectional buffering turned off. With bidirectional buffering turned on, the amount of memory per cue is doubled.
The message is always deferred to low priority. The , , and messages are not. If you have problems with these messages arriving before you want them to in overdrive mode (i.e., before you've preloaded the most recent cue), use the defer object.
- cue-number
[int]
- filename
[symbol]
- start-time
[number]
- end-time
[number]
- directional-flag
[int]
- playback-speed
[float]
preloadn
7.0.0
The
message works in precisely the same manner as the message, but normalized values in the range 0. - 1.0 are to specify start and end times for the cue.- cue-number
[int]
- filename
[symbol]
- start-time
[float]
- end-time
[float]
- directional-flag
[int]
- playback-speed
[float]
print
In left inlet: Prints information about the state of the object, plus a list of all the currently defined cues.
resume
In left inlet: If playback was paused, playback resumes from the paused point in the file.
samptype
In left inlet: The word
The following types of sample data are supported:
: 8-bit integer
: 16-bit integer
: 24-bit integer
: 32-bit integer
: 32-bit floating-point
: 64-bit floating-point
: 8-bit "mu"-law encoding
: 8-bit a-law encoding
- sample-type
[symbol]
- bit-depth
[int]
seek
In left inlet: The word
NOTE: The message is always deferred to low priority. If you have problems with these messages arriving before you want them to in overdrive mode (i.e. before you've finished seeking to a new location), then use the defer object.
- start-time
[number]
- end-time
[number]
set
signal
In left inlet: An input signal may be used for the sample-accurate triggering of prestored cues. When a signal value is received in the left inlet, the integer portion of the signal value is monitored. When the integer portion of the input signal changes to a value equal to the index of a prestored cue, that cue is triggered. Negative values are ignored.
srate
In left inlet: The word
, followed by a number, specifies the sampling rate (Hertz) at which to interpret the audio file's sample data (thus overriding the audio file's actual sampling rate). This is sometimes called "header munging." When reading files in response to the openraw message, the assumed sampling rate is 44,100 Hz. Modifications using make no changes to the file on disk.- sample-rate
[float]
srcchans
In left inlet: The word
, followed by a number, specifies the number of channels in which to interpret the audio file's sample data (thus overriding the audio file's actual number of channels). This is sometimes called "header munging." When reading files in response to the message, the assumed number of channels is 2. Modifications using make no changes to the file on disk.- number-of-channels
[int]
Output
bang
Out right outlet: When the file is done playing, or when playback is stopped with a
message, a is sent out.signal
There is one signal outlet for each of the sfplay~ object's specified output channels (set by or as an argument to the sfplay~ object) that sends out the audio data of the corresponding channel of the audio file when a cue number is received in the inlet. (The left outlet plays channel 1, and so on.)
If the optional output position argument is specified, there will be one or two signal outputs following the channel outputs whose signal outputs display positioning information. If the argument is , a single outlet to the left of the rightmost "bang on finish or halt" outputs a signal containing the current playback position in milliseconds. Specifying a final argument of creates a second outlet which outputs a signal containing the playback position single precision roundoff error in milliseconds (see Arguments for a more detailed description of the sfplay~ object's position outlets).
See Also
Name | Description |
---|---|
buffer~ | Store audio samples |
groove~ | Variable-rate looping sample playback |
mc.sfplay~ | Play audio file from disk (multi-channel) |
play~ | Position-based sample playback |
sfinfo~ | Report audio file information |
sflist~ | Store audio file cues |
sfrecord~ | Record to audio file on disk |
mc.sfrecord~ | Record to audio file on disk (multi-channel) |