Skip to content

Instantly share code, notes, and snippets.

@jpcima
Created June 7, 2021 23:23
Show Gist options
  • Save jpcima/cb01cf62a5ddb3a344b7dee4e260f915 to your computer and use it in GitHub Desktop.
Save jpcima/cb01cf62a5ddb3a344b7dee4e260f915 to your computer and use it in GitHub Desktop.
#include <SDL2/SDL.h>
#include <stdio.h>
/*
--- Want
Rate : 44444
Channels : 2
Samples : 4096
Size : 0
Format : 0x008120
--- Have
Rate : 44444
Channels : 2
Samples : 4096
Size : 32768
Format : 0x008120
*/
static void SDLCALL MyAudioCallback (void *userdata, Uint8 * stream, int len)
{
}
void printAudioSpec(const SDL_AudioSpec &spec)
{
printf("Rate : %d\n", spec.freq);
printf("Channels : %d\n", spec.channels);
printf("Samples : %d\n", spec.samples);
printf("Size : %d\n", spec.size);
printf("Format : %#08x\n", spec.format);
}
int main()
{
SDL_Init(SDL_INIT_EVERYTHING);
SDL_AudioSpec want, have;
SDL_AudioDeviceID dev;
SDL_memset(&want, 0, sizeof(want));
SDL_memset(&have, 0, sizeof(have));
want.freq = 44444;
want.format = AUDIO_F32;
want.channels = 2;
want.samples = 4096;
want.callback = MyAudioCallback;
dev = SDL_OpenAudioDevice(NULL, 0, &want, &have, SDL_AUDIO_ALLOW_FORMAT_CHANGE|SDL_AUDIO_ALLOW_FREQUENCY_CHANGE);
if (!dev)
return 1;
printf("--- Want\n");
printAudioSpec(want);
printf("--- Have\n");
printAudioSpec(have);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment