Play audio file from disk
Name | Type | Opt | Description |
---|---|---|---|
sflist-object-name | symbol | opt | If the first argument is a sflist~ that the sfplay~ object will use for playing cues. If no symbol argument is given, sfplay~ plays its own internally defined cues. | , it names an
number-of-output-channels | int | opt | 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 28. 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. An additional optional argument can be used to specify the disk buffer size in samples. If this argument has a value of 0, the default disk buffer size will be used. An additional optional argument can be used to create outlets to the sfplay~ object which display positioning information. Specifying a final argument of creates a single outlet to the left of the rightmost "bang on finish or halt" outlet which outputs a signal value which corresponds to the current playback position in milliseconds. 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 | opt | 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. |
int | start/stop-playback-of-cue-number [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
float | playback-rate [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. |
list | cues [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. |
anything | sflist-object-name and cue-number [list] |
In left inlet: If the name of an sflist~ object is sent to sfplay~, followed by a number, the numbered cue from the sflist~ is played if it exists. |
(mouse) | Double-clicking on buffer~ opens a display window where you can view the contents of the buffer~. object that the sfplay~ object references. | |
(drag) | When an audio file is dragged from the Max 5 File Browser to an sfplay~ object, the file will be loaded. | |
clear | cue-numbers [list] |
In left inlet: The word sfplay~ object's cue list. | 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
fclose | filename [symbol] |
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.
embed | saving-preference-flag (0 or nonzero) [int] |
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
loop | looping-flag (0 or 1) [int] |
In left inlet: The word | , followed by 1, turns on looping. turns off looping. By default, looping is off.
loopone | cue-number [int] |
In left inlet: The word | , followed by a cue-number, will set only the cue specified to loop.
offset | sample-start-offset (bytes) [int] |
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.
open | filename [symbol] |
In left inlet: followed by the name of an AIFF, WAV, NeXT/Sun, 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
openraw | filename [symbol] |
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.
name | object-reference-name [symbol] |
The word sfinfo~ can refer to the sfplay~ object. Objects that were referring to the sfplay~ under its old name lose their connection to it. Every sfplay~ object should be given a unique name; if you give an sfplay~ object a name that already belongs to another sfplay~ object, that name will no longer be associated with the sfplay~ object that first had it. | , followed by a , changes the name by which other objects such as
modout | modulo-output-flag (0 or 1) [int] |
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
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 | cue-number filename start-time end-time directional-flag playback-speed [list] |
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 - a file that is currently open or one that is in Max's search path - that cue number will henceforth 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 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. |
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 |
sample-type [symbol] bit-depth [int] |
In left inlet: The word The following types of sample data are supported: 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 |
, followed by a symbol, specifies the sample type to use when interpreting the audio file's sample data (thus overriding the audio file's actual sample type). This is sometimes called "header munging." When reading files in response to the message, the assumed sample type is 16-bit integer. Modifications using make no changes to the file on disk.
seek |
start-time (milliseconds) [float] end-time (milliseconds) [float] |
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. |
, followed by a start time in milliseconds, moves to the specified position in the current file and begins playing. After the start time, an optional end time can be specified, which will set a point for playback to stop. The message is intended to allow you to preview and adjust the start and end points of a cue.
set | sflist-object-name [symbol] |
In left inlet: The message sflist~ object, will cause sfplay~ to play cues stored in the sflist~ when it receives an or . The message with no arguments resets sfplay~ to use its own internally defined cues when receiving an or . | , followed by a name of an
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. | |
speed | playback-rate [float] |
In left inlet: The word | , followed by a number, sets an overall multiplier on the playback rate of all cues played by the object. A value of 1.0 (the default) plays all cues at normal speed. A playback rate of -1 plays all cues backward at normal speed. A playback rate of 2 plays the cues at twice their defined speed. A playback rate of 0.5 plays cues at half their defined speed. For example, if a cue has a playback rate of 2, and the speed is set to 3, the cue will play back at 6 times the normal speed.
srate | sampling-rate (Hz) [float] |
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.
srcchans | number-of-channels [int] |
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.
Name | Type | g/s | Description |
---|---|---|---|
audiofile | symbol | Specifies the name/pathname of an audio file to be loaded by the sfplay~ object. |
Name | Description |
---|---|
buffer~ | Store audio samples |
groove~ | Variable-rate looping sample playback |
play~ | Position-based sample playback |
sfinfo~ | Report audio file information |
sflist~ | Store audio file cues |
sfrecord~ | Record to audio file on disk |
MSP Tutorial 16: Record and Play Audio Files | MSP Tutorial 16: Record and Play Audio Files |