For time-delayed audio, we need to create what's called a "circular buffer" or a "ring buffer", an array of samples to which we record continuously in a loop, and which we can then use always to access the most recently recorded sound from the past.
Timing is very important in music. The fundamental way to ensure precise timing of events is to use a scheduler. A schedule is a list of time-tagged events to be executed at specific times in the future. That schedule must be consulted constantly at regular intervals (as often as possible, e.g., every millisecond) to see if any item on the list has a time tag that is less than or equal to the current time; if so, that event should be enacted.
In Max, the message bang is used as an all-purpose triggering message, to cause some event to happen. Most Max objects understand the message bang to mean "do whatever you do". In other words, the message bang is used to cause some event (such as playback of a sound file) to occur.
This patch shows how to play a loaded movie file in short chunks.
This patch will choose a new 1 second segment of a video to play every second.
This patch will send out a MIDI command to play middle C (60) when the "c" key on the computer keyboard is pressed.
The tapin~ and tapout~ objects work together to delay sound. The tapin~ creates a place in memory for storing a circular buffer of the most recently received signal. Its argument specifies how many milliseconds of audio it should store. Any connected tapout~ object accesses that memory to get the recent past of an audio signal.
This example shows how to create a “theremin” where the mouse position controls pitch and amplitude of a cycle~ with the x and y position respectively.
This patch demonstrates a method of storing and recalling sound in RAM using the buffer~ object and the various objects that can access a buffer.