Skip to content

Audio Samples Writing

Finalspace edited this page May 29, 2026 · 2 revisions

Table of Contents

Overview

To write audio samples in the audio client callback, you have to know the following parameters:

  • Target format (S16, S24, F32, etc.)
  • Target number of channels (1 = Mono, 2 = Stereo, 4 = Quad or Surround, 6 = 5.1 etc.)
  • Target sample rate (22050, 44100 Hz, 48000 Hz, etc.)
  • Number of audio frames required
  • If your sound device uses more than two channels, you have to call fplGetAudioChannelMap() to get the channel mapping for each audio channel.

All this information is provided by the fpl_audio_client_read_callback callback function.

The required format is stored as an argument to your call, see fplAudioFormat or 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  *nativeFormat, const uint32_t frameCount, void *outputSamples, void *userData) {
    uint32_t result = 0;
    if (nativeFormat-> == ) {
        int16_t *outSamples = (int16_t *)outputSamples;
        for (uint32_t frameIndex = 0; frameIndex < frameCount; ++frameIndex) {
            for (uint32_t channelIndex = 0; channelIndex < nativeFormat->; ++channelIndex) {
                 *outSamples++ = // ... Getting a sample for the current frame/channel
                ++result;
            }
        }
    } else {
        // ... handle other formats here
    }
    return result;
}

Important Notes

Note: 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!

Respect the audio channel map, otherwise samples may be played back on the wrong speaker!

Final Platform Layer

Pages

Topics

Data Structures

Clone this wiki locally