6 #ifndef MONOREPO_JSTRACESKI_CLIP_H
7 #define MONOREPO_JSTRACESKI_CLIP_H
29 static std::vector<Ref<Clip>>
sounds;
38 fmt.format = AUDIO_S16;
42 fmt.userdata =
nullptr;
45 if ( SDL_OpenAudio(&fmt,
nullptr) < 0 ){
46 fprintf(stderr,
"Couldn't open audio: %s\n", SDL_GetError());
70 static void callback(
void *userdata, Uint8 *stream,
int len) {
71 memset(stream, 0, len);
73 for (
const auto& s :
sounds) {
75 if (s->trackPos + len >= s->clipLen) {
76 Uint32 last = s->clipLen - s->trackPos;
77 SDL_MixAudio(stream, &s->data[s->trackPos], last, SDL_MIX_MAXVOLUME);
80 Uint32 extra = len - last;
81 SDL_MixAudio(&stream[last], &s->data[0], extra, SDL_MIX_MAXVOLUME);
88 SDL_MixAudio(stream, &s->data[s->trackPos], len, SDL_MIX_MAXVOLUME);
117 #endif //MONOREPO_JSTRACESKI_CLIP_H