Skip to main content

ezsampler

ezsampler(
@pitch 6000
@duration 2000
@velocity 64
@keymap null
@resample 1
@useseed 0
@usecache 1
) -> llll

Generates a buffer that best matches a target pitch, duration, and velocity value, given an optional llll representing a sampler keymap.

A keymap is a llll of key-value pairs, where the each key is a numeric pitch value, in midicents, that maps to one or more audio file paths corresponding to that pitch, or to a list of key-value pairs with velocity values, between 0 and 127, as keys, and audio file paths as values.

When multiple file paths are provided for a given pitch or velocity key, one of them is chosen at random. If no keymap is provided, the function defaults to a basic, built-in key map. The generated buffer will be one that best approximates the specified pitch, duration, and velocity values.

Here are some examples of how flexibily one can structure keymaps to be used by ezsampler:

  • One-to-one pitch mapping.

    [ <pitch1> <file1> ]
    [ <pitch2> <file2> ]
    ...
    [ <pitchN> <fileN> ]
  • One-to-many pitch mapping.

    [ <pitch1> <file1a> <file1b> ]
    [ <pitch2> <file2a> ]
    ...
    [ <pitchN> <fileNa> ... <fileNz> ]
  • One-to-many pitch-velocity mapping.

    [ <pitch1>
    [ <velocity1> <file1> ]
    ...
    [ <velocityN> <fileNa> ... <fileNb> ]
    ]
    [ <pitch2> <file2a> ]
    ...
    [ <pitchN>
    [ <velocity1> <file1a> ... <file1z>]
    ...
    [ <velocityN> <fileN> ]
    ]

Arguments

  • @pitch [int/float]: Target pitch in midicents. (default: 6000).
  • @duration [int/float]: Target duration in milliseconds. Set to null to get the sample's max. duration. (default: 2000).
  • @velocity [int/float]: Target velocity, from 0 to 127. Used only when keymap has velocity-based options. (default: 64).
  • @keymap [llll]: Key mapping, with pitch in midicents as key and file path as value (default: null).
  • @resample [int]: Resample buffer to match target pitch. (default: 1).
    • 0: Off
    • 1: On
  • @useseed [int]: Use seed-based random selection function. (default: 0).
    • 0: Off
    • 1: On
  • @usecache [int]: Use buffer cache to optimize memory usage. (default: 1).
    • 0: Off
    • 1: On

Output

Buffer [llll]


Usage

$chord = c5 e5 g5 b5;
$keymap = [6900 'viola.wav'];
for $pitch in $chord do (
ezsampler(
@pitch $pitch
@keymap $keymap
@duration 6500
).transcribe()
);
render(@play 1)