Final Platform Layer 1.0.0
Loading...
Searching...
No Matches
Audio Samples Writing

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 fplAudioFormat *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.
Stores audio format properties, such as type, sample rate, channels, etc.
uint16_t channels
Number of channels (uses default when zero).
fplAudioFormatType type
Audio format (uses default when zero).

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!