ampler/audio.c

22 lines
579 B
C

// audio.c
int audio_frame(Ampler_state *state) {
int queued = SDL_GetQueuedAudioSize(state -> playdev);
queued /= sizeof s16; // queued is in bytes
if(queued > FRAME_SAMPLES * CHANNELS * 2) return 0;
// else puts("queued audio.");
s16 silence[FRAME_SAMPLES * CHANNELS] = { 0 };
for (int i = 0; i < FRAME_SAMPLES; i += CHANNELS) {
int vol = 10;
silence[i] = (i/2) * vol - FRAME_SAMPLES / 2;
silence[i + 1] = (i/2) * vol - FRAME_SAMPLES / 2;
}
if(SDL_QueueAudio(state -> playdev, silence, sizeof silence))
puts(SDL_GetError());
return 1; // audio was qued
}