121 lines
2.5 KiB
C
121 lines
2.5 KiB
C
////////////////////////////////////////////////////////////
|
|
//~ Track types
|
|
|
|
Enum(MIX_TrackFlag)
|
|
{
|
|
MIX_TrackFlag_None = 0,
|
|
MIX_TrackFlag_Spatialize = (1 << 0)
|
|
};
|
|
|
|
Struct(MIX_Handle)
|
|
{
|
|
u64 gen;
|
|
void *data;
|
|
};
|
|
|
|
Struct(MIX_TrackDesc)
|
|
{
|
|
MIX_TrackFlag flags;
|
|
f32 volume; // 0 -> 1.0+
|
|
f32 speed; // 0 -> 1.0+
|
|
b32 looping;
|
|
|
|
Vec2 pos;
|
|
};
|
|
#define MIX_TRACKDESC(...) ((MIX_TrackDesc) { \
|
|
.flags = 0, \
|
|
.volume = 1.0, \
|
|
.speed = 1.0, \
|
|
.looping = 0, \
|
|
.pos = VEC2(0, 0), \
|
|
__VA_ARGS__ \
|
|
})
|
|
|
|
////////////////////////////////////////////////////////////
|
|
//~ Mix types
|
|
|
|
// Stereo mix of 32 bit float samples
|
|
Struct(MIX_PcmF32)
|
|
{
|
|
u64 count;
|
|
f32 *samples;
|
|
};
|
|
|
|
Struct(MIX_EffectData)
|
|
{
|
|
// Spatialization
|
|
f32 spatial_volume;
|
|
f32 spatial_pan;
|
|
};
|
|
|
|
Struct(MIX_MixData)
|
|
{
|
|
MIX_Handle track_handle;
|
|
b32 track_finished;
|
|
|
|
MIX_TrackDesc desc;
|
|
MIX_EffectData effect_data;
|
|
SND_Sound *source;
|
|
u64 source_pos;
|
|
};
|
|
|
|
Struct(MIX_Track){
|
|
u64 gen;
|
|
|
|
// Controlled via interface
|
|
SND_Sound *sound;
|
|
MIX_TrackDesc desc;
|
|
|
|
// Internal
|
|
MIX_MixData mix;
|
|
|
|
MIX_Track *next;
|
|
MIX_Track *prev;
|
|
};
|
|
|
|
////////////////////////////////////////////////////////////
|
|
//~ State types
|
|
|
|
Struct(MIX_Ctx)
|
|
{
|
|
Mutex mutex;
|
|
|
|
// Listener
|
|
Vec2 listener_pos;
|
|
Vec2 listener_dir;
|
|
|
|
// Track list
|
|
Arena *track_arena;
|
|
MIX_Track *track_first_playing;
|
|
MIX_Track *track_last_playing;
|
|
u64 track_playing_count;
|
|
MIX_Track *track_first_free;
|
|
};
|
|
|
|
extern MIX_Ctx MIX;
|
|
|
|
////////////////////////////////////////////////////////////
|
|
//~ Bootstrap
|
|
|
|
void MIX_Bootstrap(void);
|
|
|
|
////////////////////////////////////////////////////////////
|
|
//~ Track
|
|
|
|
MIX_Handle MIX_HandleFromTrack(MIX_Track *track);
|
|
MIX_Track *MIX_TrackFromHandle(MIX_Handle handle);
|
|
MIX_Track *MIX_AcquireTrackLocked(Lock *lock, SND_Sound *sound);
|
|
void MIX_ReleaseTrackLocked(Lock *lock, MIX_Track *track);
|
|
|
|
MIX_Handle MIX_PlaySound(SND_Sound *sound);
|
|
MIX_Handle MIX_PlaySoundEx(SND_Sound *sound, MIX_TrackDesc desc);
|
|
MIX_TrackDesc MIX_TrackDescFromHandle(MIX_Handle handle);
|
|
void MIX_UpdateTrack(MIX_Handle handle, MIX_TrackDesc desc);
|
|
void MIX_UpdateListener(Vec2 pos, Vec2 dir);
|
|
|
|
////////////////////////////////////////////////////////////
|
|
//~ Mix
|
|
|
|
i16 MIX_SampleSound(SND_Sound *sound, u64 sample_pos, b32 wrap);
|
|
MIX_PcmF32 MIX_MixAllTracks(Arena *arena, u64 frame_count);
|