SDL_SETAUDIOSTREAMFREQUENCYRATIO(3)

πŸ’– SDL_SetAudioStreamFrequencyRatio πŸ’–

okay bestie, welcome to the SDL3 FUNCTIONS corner of the manual, and today's main character is SDL_SetAudioStreamFrequencyRatio β€” the lil function that changes the frequency ratio of an audio stream. yes it's a mouthful, no you don't have to say it out loud. πŸŽ€


✨ NAME ✨

SDL_SetAudioStreamFrequencyRatio β€” change the frequency ratio of an audio stream.


🌸 SYNOPSIS 🌸

#include <SDL3/SDL_audio.h>

bool SDL_SetAudioStreamFrequencyRatio(SDL_AudioStream *stream, float ratio);

πŸ¦‹ DESCRIPTION πŸ¦‹

so here's the vibe: the frequency ratio is what adjusts the rate at which input data is consumed. change it and you're literally changing the speed and the pitch of the audio. it's giving DJ, it's giving chipmunk, it's giving slow-mo dramatic montage. πŸ’…

  • a value greater than 1.0f plays the audio faster, and at a higher pitch 🐿️
  • a value less than 1.0f plays the audio slower, and at a lower pitch 🐒
  • 1.0f means play at normal speed, aka the default reality, aka no notes ✨

this gets applied during SDL_GetAudioStreamData, and you can continuously change it to create various effects. obsessed. keep messing with it mid-stream, the audio does not mind. πŸ”₯


πŸ’… FUNCTION PARAMETERS πŸ’…

  • stream β€” the stream on which the frequency ratio is being changed. yes, the one you're doing this to. that stream. 🫢
  • ratio β€” the frequency ratio. 1.0 is normal speed. Must be between 0.01 and 100. like, genuinely must. no cap.

πŸ‘‘ RETURN VALUE πŸ‘‘

returns true on success or false on failure. and if it fails, bestie, go call SDL_GetError() for more information β€” it will tell you what went wrong, fr fr. 😭


πŸ”’ THREAD SAFETY πŸ”’

it is safe to call this function from any thread, because it holds a stream-specific mutex while running. multitask away, she's protected. πŸ’œ


🌈 AVAILABILITY 🌈

this function has been available since SDL 3.2.0. if you're on something older... not the vibe, upgrade. ⭐


πŸŽ€ SEE ALSO πŸŽ€


and that's the whole page, bestie, you ate it. πŸ“ this iconic lil doc is brought to you by Simple Directmedia Layer β€” SDL 3.4.18 β€” mwah, slay, periodt. πŸ’–βœ¨πŸ§š

πŸ“¦ where this page comes from