Skip to main content

Inspecting buffers

An essential part of writing code is being able to debug unwanted or unexpected behaviors. This is particularly necessary when dealing with audio data—i.e., buffers. In bellplay~, we can use the view function to check the contents of any buffer we create. This function opens a pop-up window displaying useful information about the inspected buffers, once the code finished evaluation.

This tutorial shows a simple example where every buffer that is not rendered can still be visualized through the buffer inspector.

inspecting_buffers.bell
## import audio sample
$buff = importaudio('trumpet.wav');
## show original sample in viewer window (NOTE: label is optional)
view($buff @label 'pre-processing buffer');
## create envelope buffer, based on audio file duration
$env = envelope(
[0 4 0] [1 100 0.25] @duration $buff.getkey('duration')
);
## show envelope in viewer window
view($env, @label 'frequency envelope');
## create oscillator using envelope as frequency
$osc = cycle($env).process(plus(1));
## show oscillator in viewer window
view($osc @label 'frequency oscillator');
## process and transcribe buffer
$buff.process(
## use oscillator for amplitude modulation
multiply($osc)
).transcribe();
## trigger rendering
render(@play 1)

Result