More audio migration clarification
parent
14980b25a8
commit
ea02630143
|
@ -81,14 +81,14 @@ In SDL2, you might have done something like this to play audio...
|
|||
...in SDL3, you can do this...
|
||||
|
||||
```c
|
||||
void SDLCALL MyAudioCallback3(void *userdata, SDL_AudioStream *stream, int additional_amount, int total_amount)
|
||||
void SDLCALL MyNewAudioCallback(void *userdata, SDL_AudioStream *stream, int additional_amount, int total_amount)
|
||||
{
|
||||
/* 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 you want to use the original callback, you could do something like this:
|
||||
*/
|
||||
if (additional_amount > 0) {
|
||||
Uint16 *data = SDL_stack_alloc(Uint16, additional_amount / sizeof(Uint16));
|
||||
Uint8 *data = SDL_stack_alloc(Uint8, additional_amount);
|
||||
if (data) {
|
||||
MyAudioCallback(userdata, data, additional_amount);
|
||||
SDL_PutAudioStreamData(stream, data, additional_amount);
|
||||
|
@ -99,7 +99,7 @@ In SDL2, you might have done something like this to play audio...
|
|||
|
||||
/* ...somewhere near startup... */
|
||||
const SDL_AudioSpec spec = { SDL_AUDIO_S16, 2, 44100 };
|
||||
SDL_AudioStream *stream = SDL_OpenAudioDeviceStream(SDL_AUDIO_DEVICE_DEFAULT_OUTPUT, &spec, MyAudioCallback3, &my_audio_callback_user_data);
|
||||
SDL_AudioStream *stream = SDL_OpenAudioDeviceStream(SDL_AUDIO_DEVICE_DEFAULT_OUTPUT, &spec, MyNewAudioCallback, &my_audio_callback_user_data);
|
||||
SDL_ResumeAudioDevice(SDL_GetAudioStreamDevice(stream));
|
||||
```
|
||||
|
||||
|
|
Loading…
Reference in New Issue