Final Platform Layer 0.9.8-beta
Loading...
Searching...
No Matches
Writing audio samples

Overview

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
++result;
}
}
} else {
// ... handle other formats here
}
return result;
}
@ fplAudioFormatType_S16
Signed 16-bit integer PCM.
A structure containing audio device format runtime properties, such as type, samplerate,...
fplAudioFormatType type
Format.
uint32_t channels
Number of channels.

Notes

  • 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!