Home
Main website
Display Sidebar
Hide Ads
Recent Changes
View Source:
SDL_OpenAudio(3)
Edit
PageHistory
Diff
Info
LikePages
SDL_!OpenAudio !!!SDL_!OpenAudio NAME SYNOPSIS DESCRIPTION EXAMPLES SEE ALSO ---- !!NAME SDL_!OpenAudio- Opens the audio device with the desired parameters. !!SYNOPSIS __#include __ __int SDL_!OpenAudio__(__SDL_!AudioSpec *desired, SDL_!AudioSpec *obtained__); !!DESCRIPTION This function opens the audio device with the __desired__ parameters, and returns 0 if successful, placing the actual hardware parameters in the structure pointed to by __obtained__. If __obtained__ is NULL, the audio data passed to the callback function will be guaranteed to be in the requested format, and will be automatically converted to the hardware audio format if necessary. This function returns -1 if it failed to open the audio device, or couldn't set up the audio thread. To open the audio device a __desired SDL_!AudioSpec__ must be created. SDL_!AudioSpec *desired; . . desired=(SDL_!AudioSpec *)malloc(sizeof(SDL_!AudioSpec)); You must then fill this structure with your desired audio specifications. __desired__-__freq__ __desired__-__format__ __desired__-__samples__ __desired__-__callback__ void callback(void *userdata, Uint8 *stream, int len); __userdata__ is the pointer stored in __userdata__ field of the __SDL_!AudioSpec__. __stream__ is a pointer to the audio buffer you want to fill with information and __len__ is the length of the audio buffer in bytes. __desired__-__userdata__ __SDL_!OpenAudio__ reads these fields from the __desired SDL_!AudioSpec__ structure pass to the function and attempts to find an audio configuration matching your __desired__. As mentioned above, if the __obtained__ parameter is __NULL__ then SDL with convert from your __desired__ audio settings to the hardware settings as it plays. If __obtained__ is __NULL__ then the __desired SDL_!AudioSpec__ is your working specification, otherwise the __obtained SDL_!AudioSpec__ becomes the working specification and the __desirec__ specification can be deleted. The data in the working specification is used when building __SDL_AudioCVT__'s for converting loaded data to the hardware format. __SDL_!OpenAudio__ calculates the __size__ and __silence__ fields for both the __desired__ and __obtained__ specifications. The __size__ field stores the total size of the audio buffer in bytes, while the __silence__ stores the value used to represent silence in the audio buffer The audio device starts out playing __silence__ when it's opened, and should be enabled for playing by calling __SDL_!PauseAudio__''(''__0__) when you are ready for your audio __callback__ function to be called. Since the audio driver may modify the requested __size__ of the audio buffer, you should allocate any local mixing buffers after you open the audio device. !!EXAMPLES /* Prototype of our callback function */ void my_audio_callback(void *userdata, Uint8 *stream, int len); /* Open the audio device */ SDL_!AudioSpec *desired, *obtained; SDL_!AudioSpec *hardware_spec; /* Allocate a desired SDL_!AudioSpec */ desired=(SDL_!AudioSpec *)malloc(sizeof(SDL_!AudioSpec)); /* Allocate space for the obtained SDL_!AudioSpec */ obtained=(SDL_!AudioSpec *)malloc(sizeof(SDL_!AudioSpec)); /* 22050Hz - FM Radio quality */ desired- !!SEE ALSO __SDL_!AudioSpec__, __SDL_!LockAudio__, __SDL_!UnlockAudio__, __SDL_!PauseAudio__ ----
One page links to
SDL_OpenAudio(3)
:
SDLManPages
This page is a man page (or other imported legacy content). We are unable to automatically determine the license status of this page.