A newer version of Max is available. Click here to access the latest version of the Max documentation

Sample-Accurate Scheduling

Sample-Accurate Scheduling

Max 8.3 introduces the ability for events to affect certain audio objects sample accurately.
To enable sample-accurate scheduling, the Overdrive and Scheduler in Audio Interrupt settings must be enabled in the Audio Status window. Then events sent to signal objects must be high-priority events, i.e. scheduled. Examples of scheduled events include events generated from a MIDI controller or the output of a metro object. Examples of low-priority, i.e. non-scheduled, events include events generated by a screen action (clicking on a button) or by a computer keyboard. As a further example, if you click on a button, the output of the button is not a scheduled event. But if you connect the button to a delay object, the bang output of the delay will be scheduled.
When Scheduler in Audio Interrupt is enabled, the Max scheduler processes all events that will affect the next signal vector's worth of audio imediately before that audio vector is processed. For example, when the signal vector size is 256 samples, the scheduler will execute all the events within the next 5.8 milliseconds (equivalent to 256 samples at 44.1 kHz). Said another way, the scheduler and audio processing alternate in lock step: first the scheduler generates events, then the audio is processed reflecting any changes that occurred when the scheduler ran.

Sample-Accurate Events to Audio

As an example, consider the sig~ object which converts events (incoming numbers) to audio. When a scheduled event is sent to sig~, the sample-accurate mode determines the precise offset within the signal vector represented by the current scheduler time. The incoming number will be put into the signal vector at this offset.
If sig~ is not operating sample-accurately, any incoming events will be reflected starting at the first sample of the next signal vector to be processed.
Sample accuracy has another advantage: you can send multiple events to sig~ in the time of one signal vector. Without sample accuracy, only the most recently received event will be in the output signal.

Objects That Support Sample-Accurate Events to Audio

  • sig~ will convert events to audio signals sample-accurately
  • click~ will start an impulse sample-accurately when it receives a scheduled bang
  • line~ and curve~ will start a function sample-accurately
  • vst~ receives MIDI events sample-accurately

Sample-Accurate Audio to Events

The snapshot~ object generates events from samples in its audio input. When Scheduler in Audio Interrupt is enabled, snapshot~ outputs sample values at the precise millisecond interval you specify. When Scheduler in Audio Interrupt is disabled, snapshot~ will use the first sample in each audio vector and its resolution cannot be better than the signal vector size. As an example, consider a signal vector size of 256 and a snapshot~ interval of 1ms. At 44.1kHz sampling rate, snapshot~ will output at least five sample values exactly 1ms apart for every signal vector when Scheduler in Audio Interrupt is enabled. But when Scheduler in Audio Interrupt is disabled, even though you wanted an interval of 1 millisecond, the effective resolution is closer to 6 milliseconds.
In Scheduler in Audio Interrupt, the scheduler for the vector of audio that snapshot~ sampled runs before the audio vector is processed. This means the events generated by snapshot~ will be delayed by exactly one signal vector's worth of real time.

Objects That Support Sample-Accurate Audio to Events

  • snapshot~ will sample incoming audio and generate events sample-accurately
  • peakamp~ will record peaks in the incoming signal and generate events sample-accurately
  • edge~ outputs the zero-to-non-zero signal transitions sample-accurately
  • line~ and curve~ output their "done" bang event sample-accurately
  • spike~ outputs the time between audio events sample-accurately
  • what~ outputs detected signal values sample-accurately
  • subdiv~ outputs step values sample-accurately