Clarify documentation for audio callback migration
parent
6cf84e2c5b
commit
14980b25a8
|
@ -62,7 +62,7 @@ In SDL2, you might have done something like this to play audio...
|
|||
```c
|
||||
void SDLCALL MyAudioCallback(void *userdata, Uint8 * stream, int len)
|
||||
{
|
||||
/* calculate a little more audio here, maybe using `userdata`, write it to `stream` */
|
||||
/* Calculate a little more audio here, maybe using `userdata`, write it to `stream` */
|
||||
}
|
||||
|
||||
/* ...somewhere near startup... */
|
||||
|
@ -81,15 +81,25 @@ In SDL2, you might have done something like this to play audio...
|
|||
...in SDL3, you can do this...
|
||||
|
||||
```c
|
||||
void SDLCALL MyAudioCallback(SDL_AudioStream *stream, int len, void *userdata)
|
||||
void SDLCALL MyAudioCallback3(void *userdata, SDL_AudioStream *stream, int additional_amount, int total_amount)
|
||||
{
|
||||
/* calculate a little more audio here, maybe using `userdata`, write it to `stream` */
|
||||
SDL_PutAudioStreamData(stream, newdata, len);
|
||||
/* Calculate a little more audio here, maybe using `userdata`, write it to `stream`
|
||||
*
|
||||
* If you want to reuse the original callback, you could do something like this:
|
||||
*/
|
||||
if (additional_amount > 0) {
|
||||
Uint16 *data = SDL_stack_alloc(Uint16, additional_amount / sizeof(Uint16));
|
||||
if (data) {
|
||||
MyAudioCallback(userdata, data, additional_amount);
|
||||
SDL_PutAudioStreamData(stream, data, additional_amount);
|
||||
SDL_stack_free(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ...somewhere near startup... */
|
||||
const SDL_AudioSpec spec = { SDL_AUDIO_S16, 2, 44100 };
|
||||
SDL_AudioStream *stream = SDL_OpenAudioDeviceStream(SDL_AUDIO_DEVICE_DEFAULT_OUTPUT, &spec, MyAudioCallback, &my_audio_callback_user_data);
|
||||
SDL_AudioStream *stream = SDL_OpenAudioDeviceStream(SDL_AUDIO_DEVICE_DEFAULT_OUTPUT, &spec, MyAudioCallback3, &my_audio_callback_user_data);
|
||||
SDL_ResumeAudioDevice(SDL_GetAudioStreamDevice(stream));
|
||||
```
|
||||
|
||||
|
|
Loading…
Reference in New Issue