power_play/src/mixer.h
2024-03-28 08:51:06 -05:00

55 lines
1.2 KiB
C

#ifndef MIXER_H
#define MIXER_H
struct sound;
#define MIXER_FLAG_NONE 0x0
#define MIXER_FLAG_SPATIALIZE 0x1
#define MIXER_DESC(...) ((struct mixer_desc) { \
.flags = 0, \
\
.volume = 1.0, \
.speed = 1.0, \
.looping = false, \
\
.pos = V2(0, 0), \
\
__VA_ARGS__ \
})
struct mixer_desc {
u32 flags;
f32 volume; /* 0 -> 1.0+ */
f32 speed; /* 0 -> 1.0+ */
b32 looping;
/* MIXER_FLAG_SPATIALIZE */
struct v2 pos;
};
struct mixer_track_handle {
u64 gen;
void *data;
};
/* Stereo mix of 32 bit float samples */
struct mixed_pcm_f32 {
u64 count;
f32 *samples;
};
void mixer_startup(void);
/* Interface */
struct mixer_track_handle mixer_play(struct sound *sound);
struct mixer_track_handle mixer_play_ex(struct sound *sound, struct mixer_desc desc);
struct mixer_desc mixer_track_get(struct mixer_track_handle handle);
void mixer_track_set(struct mixer_track_handle handle, struct mixer_desc desc);
void mixer_set_listener(struct v2 pos, struct v2 dir);
/* Mixing */
struct mixed_pcm_f32 mixer_update(struct arena *arena, u64 frame_request_count);
void mixer_advance(u64 frames_written_count);
#endif