33 lines
854 B
C
33 lines
854 B
C
#include <audio.h>
|
|
#include <stdio.h>
|
|
|
|
int audioInit(AudioContext *aud) {
|
|
SDL_AudioSpec spec;
|
|
spec.freq = 41700;
|
|
spec.format = SDL_AUDIO_S16;
|
|
spec.channels = 2;
|
|
|
|
aud->stream = SDL_OpenAudioDeviceStream(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &spec, NULL, NULL);
|
|
aud->paused = true;
|
|
if (!aud->stream) {
|
|
fprintf(stderr, "could not open audio device stream: %s\n", SDL_GetError());
|
|
return -1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
int audioUpdate(AudioContext *aud, void *data, uint32_t bytes) {
|
|
if (!aud->stream) return -1;
|
|
|
|
if (!SDL_PutAudioStreamData(aud->stream, data, bytes)) {
|
|
fprintf(stderr, "could not write audio: %s\n", SDL_GetError());
|
|
return -1;
|
|
}
|
|
|
|
if (aud->paused) {
|
|
SDL_ResumeAudioDevice(SDL_GetAudioStreamDevice(aud->stream));
|
|
aud->paused = false;
|
|
}
|
|
|
|
return 0;
|
|
} |