The core elements we want to use to build a sampler are:

  • it has to make one-shot sounds
  • it has to be able to create continuous sounds
  • it has to be able to give a shape to sounds

Alongside these three essentials, two other core aspects need development:

  • how to select the sound to play and how to trigger it: the performance aspect
  • how to process the sounds to create interesting original new timbres: the sound processing aspect
One-shot sounds

The basic sampler module should be made of one of the sample playback objects (for example play~)

and implement some code for allowing the user to play them to trigger single shot sounds.

Two methods for triggering sounds. Left: a simple button; Right: an automatic random system

In the examples above a small portion of the buffer is used for playback (0-250 ms) and sometimes is read backwards or at double the speed (respectively middle and rightmost play~ in the automatic random method).

Give a shape to the sound

Although the one-shot sound has a specific duration, you might still want to add a shape to it. Planning a clever signal routeing to your patcher would help to achieve this.

In this picture, you can see that the two one-shot playback methods (in the green and blue panels) are sending their raw sound signal to the yellow panel where the signal is further processed by an envelope.

Here is interesting to note that a send trigger object has been added to connect the button to the envelope. When you want to trigger a sound you might need to make sure its envelope starts in sync with the sound. There are many options for syncing the envelope with the sound-triggers in particular if you want to use the automatic random system. I have just given here an example of the simple method.

Please note: Panels here are used to illustrate specific sections in the code, for the sake of this explanation. When using a Max project for example you can place each of these sections in a dedicated patch.

Continuous sound

The second important element of the sampler is that it should also create continuous sounds. The basic continuous sound is created with a suitable playback object (e.g. groove~) and then sent to the envelop panel as well.

When deciding how to setup code for performing the continuous sound, the options for customisation exponentially expand, depending on the musical idea. In this case, I have created a slider to scroll through the sample in chunks of 100 ms.

The slider size takes the total length of the sample buffer (an information retrieved from the buffer~ itself using the object info~): this is used to select in the waveform~ display the starting point for groove~ to loop from. To this position in time 100 ms are added. This will allow me to change the sample area to be played back while groove~ continuously loops over 100 ms range. Then a simple button would trigger the envelope for releasing the sound.

The overall picture then is the following

in which the green, blue, and purple panels are three methods for playing back sound (two one-shot, one continuous) and the yellow is to control the shape of the sound and the master volume.

User interface

Connecting the user to the sound playback is the next aspect that is core to this exercise. The more subtle and sophisticated this section would be, the smoother the musical result.

Making use of buttons, sliders, and other interfaces to directly interact with the objects as well as for activating the various automatic systems is essential. It will dramatically improve your the ability to create interesting sounds, allowing nuances and subtle effects. The key object can be used to translate keyboard keys input into max messages, or ctrl object for connecting external faders or devices.

Actions can be used too (with line, line~), to setup control with progression, or at certain moments in time; use threshold operators (=>, ==, != …) and listener objects (timer, peakamp~) to smooth out the interaction.

Sound processing

In this example,  I have shown how to route signal data to the yellow panel for simple envelope control. Similarly,  you can think of creating other sections for further sound processing before the final output. Delay effects can be used, but not only. Any signal in max can be delayed, but also recorded and be played back automatically with envelopes applied to it, and this nesting could create incredible effects.