Final Platform Layer  0.9.6-beta
Writing audio samples


To write audio samples in the audio client callback, you have to know at least four things:

  • Target format (S16, S24, F32, etc.)
  • Target number of channels (1 = Mono, 2 = Stereo, etc.)
  • Target sample rate (44 kHz, 48 kHz, etc.)
  • Number of frames required

All these informations are provided by the fpl_audio_client_read_callback callback function.

Call fplGetAudioHardwareFormat(), to get this information before the audio playback is started.

Useful functions

To help with sample computation there are several functions available:

Writing 16-bit signed integer samples

static uint32_t MyAudioPlaybackCallback(const fplAudioDeviceFormat *nativeFormat, const uint32_t frameCount, void *outputSamples, void *userData) {
uint32_t result = 0;
if (nativeFormat->type == fplAudioFormatType_S16) {
int16_t *outSamples = (int16_t *)outputSamples;
for (uint32_t frameIndex = 0; frameIndex < frameCount; ++frameIndex) {
for (uint32_t channelIndex = 0; channelIndex < nativeFormat->channels; ++channelIndex) {
*outSamples++ = // ... Getting a sample for the current frame/channel
} else {
// ... handle other formats here
return result;


  • FPL does not provide any functionality for doing any kind of DSP or format conversion!
  • You are responsible for filling out the samples in the correct format your audio device expects!
uint32_t channels
Number of channels.
Definition: final_platform_layer.h:3655
A structure containing audio device format runtime properties, such as type, samplerate,...
Definition: final_platform_layer.h:3649
Signed 16-bit integer PCM.
Definition: final_platform_layer.h:3604
fplAudioFormatType type
Definition: final_platform_layer.h:3659