Bela
|
Playback WAV files
This sketch shows how to playback audio samples from a buffer.
An audio file is loaded into a buffer SampleData
as gSampleData
. This is accessed with a read pointer that is incremented at audio rate within the render function: out += gSampleData.samples[gReadPtr++]
.
Note that the read pointer is stopped from incrementing past the length of the gSampleData
. This is achieved by comparing the read pointer value against the sample length which we can access as follows: gSampleData.sampleLen
.
The sample is triggered by keyboard input: (a) starts sample playback, (s) stops sample playback. The triggering is treated as a lower priority task than the audio. You can see this at the bottom of the render function: Bela_scheduleAuxiliaryTask(gTriggerSamplesTask)
;
Generated on Sun Dec 22 2024 06:28:13 for Bela by 1.8.11