Skip to main content

Music Information Retrieval (MIR)

Music Information Retrieval is the science of retrieving information from music. Among others, it allows the extraction of meaningful features from audio files, such as the pitch or the loudness of a sample. Kontakt comes with a collection of MIR functions, to assist or automate parts of the instrument creation process.

Single functions retrieve information from single files and take as argument an absolute filename (the full path to the sample file).

API Access

The MIR API is defined in the global table MIR, i.e. all constants and functions need to be prefixed with that name. For example:

kt = Kontakt
fs = Filesystem

print(MIR.detect_pitch(fs.join(kt.script_path, 'samples/Sine440_1sec.wav')))

Pitch Detection

The pitch detection tries to detect the fundamental frequency of a monophonic/single note sample. It corresponds to the MIDI scale (69 = 440 Hz) and ranges from semitone 15 (~20Hz) to semitone 120 (~8.4 kHz).

detect_pitch

detect_pitch(file: string) -> float?

Analyzes file and returns the detected MIDI pitch or nil if detection fails.

Peak, RMS & Loudness detection

Loudness, Peak, and RMS functions return a value in dB, with a maximum at 0dB.

The RMS and Loudness functions are calculated over small blocks of audio. The duration of those blocks is called frame size and is expressed in seconds. The process is repeated in intervals equal to the hop size (also expressed in seconds), until it reaches the end of the sample. The functions return the overall loudest/highest value of the different blocks.

If frame size and hop size are not indicated, the default values 0.4 (frame size in seconds) and 0.1 (hop size in seconds) are applied respectively.

detect_peak

detect_peak(file: string) -> float?

Analyzes file and returns the detected peak level or nil if detection fails.

detect_rms

detect_rms(file: string) -> float?
detect_rms(file: string, frame_size: float, hop_size: float) -> float?

Analyzes file and returns the detected RMS level or nil if detection fails.

detect_loudness

detect_loudness(file: string) -> float?
detect_loudness(file: string, frame_size: float, hop_size: float) -> float?

Analyzes file and returns the detected loudness level or nil if the detection fails.

Loop Detection

find_loop(file: string) -> start: integer?, end: integer?
find_loop(file: string, min_start: float, max_end: float, min_length: float) -> start: integer?, end: integer?

Analyzes file and returns the detected loop points or nil if detection fails.

Type Detection

Type detection is a means to determine which category a given audio sample belongs to. Currently, Kontakt Lua API supports detection of three distinct types: Sample Type, Drum Type, and Instrument Type. Sample Type is used to determine if a sample is either a drum or an instrument. Drum Type and Instrument Type both determine which drum or instrument category a sample belongs to.

sample_type

detect_sample_type(file: string) -> string

Returns the sample type of file. Returns one of the following types or nil if detection fails:

  • drum

  • instrument

detect_drum_type

detect_drum_type(file: string) -> string

Returns the drum type of file. Returns one of the following types or nil if detection failed.

  • kick

  • snare

  • hihat_closed

  • hihat_open

  • tom

  • cymbal

  • clap

  • shaker

  • percussion_drum

  • percussion_other

detect_instrument_type

detect_instrument_type(file: string) -> string

Returns the instrument type of file. Return one of the following types or nil if detection fails.

  • bass

  • bowed_string

  • brass

  • flute

  • guitar

  • keyboard

  • mallet

  • organ

  • plucked_string

  • reed

  • synth

  • vocal