-
Notifications
You must be signed in to change notification settings - Fork 13
Audio Samples Writing
Finalspace edited this page May 29, 2026
·
2 revisions
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.
To help with sample computation there are several functions available:
- fplGetAudioHardwareFormat()
- fplGetAudioBufferSizeInFrames()
- fplGetAudioBufferSizeInMilliseconds()
- fplGetAudioBackendName()
- fplGetAudioFormatName()
- fplGetAudioSampleSizeInBytes()
- fplGetAudioFrameSizeInBytes()
- fplGetAudioBufferSizeInBytes()
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;
}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!
- Assertion & Debug
- Atomic operations
- Audio functions
- Clipboard functions
- Console functions
- Constants
- Display/Monitor functions
- Dynamic library loading
- Error Handling
- Files/IO functions
- Function macros
- Hardware Infos
- Input types and functions
- Localization functions
- Logging
- Memory Macros
- Memory functions
- Operating system Infos
- Path functions
- Platform functions
- Session Infos
- Settings & Configurations
- Storage class identifiers
- String functions
- Threading and synchronizations routines
- Timing functions
- Video functions
- Window events
- Window functions
- fplARMCPUCapabilities
- fplAudioChannelMap
- fplAudioDeviceID
- fplAudioDeviceInfo
- fplAudioFormat
- fplAudioSettings
- fplColor32
- fplConditionVariable
- fplConsoleSettings
- fplCPUCapabilities
- fplCPUIDLeaf
- fplDateTime
- fplDateTimeCreationResult
- fplDateTimeResult
- fplDisplayInfo
- fplDisplayMode
- fplDynamicLibraryHandle
- fplEndianess
- fplEvent
- fplFileEntry
- fplFileHandle
- fplFilePermissions
- fplFileTimeStamps
- fplGamepadButton
- fplGamepadData
- fplGamepadEvent
- fplGamepadInfo
- fplGamepadInputBinding
- fplGamepadMapping
- fplGamepadSettings
- fplGamepadState
- fplGamepadStates
- fplGraphicsApiSettings
- fplImageSource
- fplInputBackendMask
- fplInputBackendSupport
- fplInputDevice
- fplInputDeviceGuid
- fplInputSettings
- fplInternalConditionVariable
- fplInternalDynamicLibraryHandle
- fplInternalFileEntryHandle
- fplInternalFileHandle
- fplInternalFileRootInfo
- fplInternalMutexHandle
- fplInternalSemaphoreHandle
- fplInternalSignalHandle
- fplInternalThreadHandle
- fplKeyboardEvent
- fplKeyboardState
- fplLogSettings
- fplLogWriter
- fplLogWriterConsole
- fplLogWriterCustom
- fplMemoryAllocationSettings
- fplMemoryBlock
- fplMemoryInfos
- fplMemorySettings
- fplMouseEvent
- fplMouseState
- fplMutexHandle
- fplOpenGLSettings
- fplOSVersionInfos
- fplSemaphoreHandle
- fplSettings
- fplSignalHandle
- fplSpecificAudioSettings
- fplThreadHandle
- fplThreadParameters
- fplTimestamp
- fplVersionInfo
- fplVideoBackBuffer
- fplVideoRect
- fplVideoRequirements
- fplVideoRequirementsVulkan
- fplVideoSettings
- fplVideoSurface
- fplVideoSurfaceOpenGL
- fplVideoSurfaceVulkan
- fplVideoWindow
- fplVulkanSettings
- fplWindowCallbacks
- fplWindowDropFiles
- fplWindowEvent
- fplWindowPosition
- fplWindowSettings
- fplWindowSize
- fplX86CPUCapabilities