Created
August 9, 2023 07:04
-
-
Save fredrb/9eec7f6249ee5a5333deff32eb6ce19c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const int SAMPLE_RATE = 44100; | |
const int BUFFER_SIZE = 4096; | |
void callback(void *userdata, Uint8 *stream, int len) { | |
for (int i = 0; i < len; i++) { | |
stream[i] = /* ADD SAMPLE HERE */ ; | |
} | |
} | |
int main() { | |
if (SDL_Init(SDL_INIT_AUDIO | SDL_INIT_EVENTS) < 0) { | |
printf("Failed to initialize SDL: %s\n", SDL_GetError()); | |
return 1; | |
} | |
SDL_AudioSpec spec = { | |
.format = AUDIO_F32, | |
.channels = 1, | |
.freq = SAMPLE_RATE, | |
.samples = BUFFER_SIZE, | |
.callback = callback, | |
}; | |
if (SDL_OpenAudio(&spec, NULL) < 0) { | |
printf("Failed to open Audio Device: %s\n", SDL_GetError()); | |
return 1; | |
} | |
SDL_PauseAudio(0); | |
while (true) { | |
SDL_Event e; | |
while (SDL_PollEvent(&e)) { | |
switch (e.type) { | |
case SDL_QUIT: | |
return 0; | |
} | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment