Skip to main content

Audio Descriptors

One of the core features in bellplay~ is our ability to analyze buffers to extract relevant information. This is done via the analyze function which, similar to 'process', allows us to perform multiple operations. In the case of analyze, these operations are known as audio descriptors, which we generate through functions. These audio descriptors specify the different parameters for that specific operation, which analyze takes as arguments. As such, analyze outputs the analyze buffer with new keys, each associated with the specified descriptors.

This tutorial shows a simple use-case of audio analysis in bell:

  1. First, we analyze a buffer to extract onset positions (i.e., transient times).
  2. We use that information to compute the inter-onset durations — i.e., difference between consecutive onsets.
  3. Then we iterate through the onsets and durations to segment the original buffer, and analyze the loudness and spectral centroid of each segment.
  4. With this information, we generate sinusoidal oscillators that temporally coincide with transients in the initial buffer.

To learn about all available audio descriptors, please refer to the bellplay~ reference documentation.

audio_descriptors.bell
## generate buffer
$buff = importaudio('drums.wav');
## analyze buffer
$buff = $buff.analyze(
## use the onset detection descriptor
@descriptors onsets()
);
## extract onsets resulting from analysis
$onsets = $buff.getkey('onsets');
## compute inter-onset durations based on onsets
$durations = ($onsets $buff.getkey('source_end')).x2dx();
## iterate through onsets and durations
for $onset in $onsets, $dur in $durations do (
## create buffer segment
$seg = $buff.setkey('offset', $onset).setkey('duration', $dur);
## analyze buffer segment
$seg = $seg.analyze(
## descriptor for loudness analysis
larm()
## descriptor for spectral centroid (in Herz)
spectralcentroid()
);
## extract analysis information for loudness and centroid
$larm = $seg.getkey('larm');
$centroid = $seg.getkey('spectralcentroid');
## create gain envelope based on loudness feature
$env = [0 $larm 0] [1 0 -0.5];
## generate and transcribe oscillator
cycle(
## use centroid as frequency
@frequency $centroid
## use inter-onset duration
@duration $dur
).transcribe(
## match segment onset
@onset $onset
## apply gain envelope
@gain $env
)
);
## transcribe original buffer to check accuracy of the analysis
$buff.transcribe();
## trigger rendering and normalize output
render(
@play 1 @process normalize()
)