formatting
This commit is contained in:
parent
5b07284d02
commit
52c613263d
@ -240,7 +240,7 @@ void P_AppStartup(String args_str)
|
|||||||
TTF_StartupReceipt ttf_sr = TTF_Startup();
|
TTF_StartupReceipt ttf_sr = TTF_Startup();
|
||||||
F_StartupReceipt font_sr = F_Startup(&asset_cache_sr, &ttf_sr);
|
F_StartupReceipt font_sr = F_Startup(&asset_cache_sr, &ttf_sr);
|
||||||
S_StartupReceipt sprite_sr = sprite_startup();
|
S_StartupReceipt sprite_sr = sprite_startup();
|
||||||
M_StartupReceipt mixer_sr = M_Startup();
|
MIX_StartupReceipt mixer_sr = MIX_Startup();
|
||||||
SND_StartupReceipt sound_sr = SND_Startup(&asset_cache_sr);
|
SND_StartupReceipt sound_sr = SND_Startup(&asset_cache_sr);
|
||||||
D_StartupReceipt draw_sr = D_Startup(&font_sr);
|
D_StartupReceipt draw_sr = D_Startup(&font_sr);
|
||||||
SimStartupReceipt sim_sr = sim_startup();
|
SimStartupReceipt sim_sr = sim_startup();
|
||||||
|
|||||||
@ -14,35 +14,35 @@
|
|||||||
* - 2 32 bit float samples output by mixer and consumed by playback API, one sample for each audio channel
|
* - 2 32 bit float samples output by mixer and consumed by playback API, one sample for each audio channel
|
||||||
*/
|
*/
|
||||||
|
|
||||||
M_SharedState M_shared_state = ZI;
|
MIX_SharedState M_shared_state = ZI;
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ Startup
|
//~ Startup
|
||||||
|
|
||||||
M_StartupReceipt M_Startup(void)
|
MIX_StartupReceipt MIX_Startup(void)
|
||||||
{
|
{
|
||||||
__prof;
|
__prof;
|
||||||
M_SharedState *g = &M_shared_state;
|
MIX_SharedState *g = &M_shared_state;
|
||||||
g->track_arena = AllocArena(Gibi(64));
|
g->track_arena = AllocArena(Gibi(64));
|
||||||
g->listener_pos = VEC2(0, 0);
|
g->listener_pos = VEC2(0, 0);
|
||||||
g->listener_dir = VEC2(0, -1);
|
g->listener_dir = VEC2(0, -1);
|
||||||
return (M_StartupReceipt) { 0 };
|
return (MIX_StartupReceipt) { 0 };
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ Track
|
//~ Track
|
||||||
|
|
||||||
M_Handle M_HandleFromTrack(M_Track *track)
|
MIX_Handle MIX_HandleFromTrack(MIX_Track *track)
|
||||||
{
|
{
|
||||||
M_Handle result = ZI;
|
MIX_Handle result = ZI;
|
||||||
result.gen = track->gen;
|
result.gen = track->gen;
|
||||||
result.data = track;
|
result.data = track;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
M_Track *M_TrackFromHandle(M_Handle handle)
|
MIX_Track *MIX_TrackFromHandle(MIX_Handle handle)
|
||||||
{
|
{
|
||||||
M_Track *track = (M_Track *)handle.data;
|
MIX_Track *track = (MIX_Track *)handle.data;
|
||||||
if (track && track->gen == handle.gen)
|
if (track && track->gen == handle.gen)
|
||||||
{
|
{
|
||||||
return track;
|
return track;
|
||||||
@ -53,38 +53,38 @@ M_Track *M_TrackFromHandle(M_Handle handle)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
M_Track *M_AllocTrackLocked(P_Lock *lock, SND_Sound *sound)
|
MIX_Track *MIX_AllocTrackLocked(P_Lock *lock, SND_Sound *sound)
|
||||||
{
|
{
|
||||||
M_SharedState *g = &M_shared_state;
|
MIX_SharedState *g = &M_shared_state;
|
||||||
P_AssertLockedE(lock, &g->mutex);
|
P_AssertLockedE(lock, &g->mutex);
|
||||||
(UNUSED)lock;
|
(UNUSED)lock;
|
||||||
|
|
||||||
M_Track *track = 0;
|
MIX_Track *track = 0;
|
||||||
if (g->track_first_free)
|
if (g->track_first_free)
|
||||||
{
|
{
|
||||||
/* Take from free list */
|
/* Take from free list */
|
||||||
track = g->track_first_free;
|
track = g->track_first_free;
|
||||||
M_Track *next_free = track->next;
|
MIX_Track *next_free = track->next;
|
||||||
g->track_first_free = next_free;
|
g->track_first_free = next_free;
|
||||||
if (next_free)
|
if (next_free)
|
||||||
{
|
{
|
||||||
next_free->prev = 0;
|
next_free->prev = 0;
|
||||||
}
|
}
|
||||||
*track = (M_Track) { .gen = track->gen + 1 };
|
*track = (MIX_Track) { .gen = track->gen + 1 };
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Allocate new */
|
/* Allocate new */
|
||||||
track = PushStruct(g->track_arena, M_Track);
|
track = PushStruct(g->track_arena, MIX_Track);
|
||||||
track->gen = 1;
|
track->gen = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
track->sound = sound;
|
track->sound = sound;
|
||||||
track->mix.source = sound;
|
track->mix.source = sound;
|
||||||
track->mix.track_handle = M_HandleFromTrack(track);
|
track->mix.track_handle = MIX_HandleFromTrack(track);
|
||||||
|
|
||||||
/* Append to playing list */
|
/* Append to playing list */
|
||||||
M_Track *prev = g->track_last_playing;
|
MIX_Track *prev = g->track_last_playing;
|
||||||
if (prev)
|
if (prev)
|
||||||
{
|
{
|
||||||
prev->next = track;
|
prev->next = track;
|
||||||
@ -100,15 +100,15 @@ M_Track *M_AllocTrackLocked(P_Lock *lock, SND_Sound *sound)
|
|||||||
return track;
|
return track;
|
||||||
}
|
}
|
||||||
|
|
||||||
void M_ReleaseTrackLocked(P_Lock *lock, M_Track *track)
|
void MIX_ReleaseTrackLocked(P_Lock *lock, MIX_Track *track)
|
||||||
{
|
{
|
||||||
M_SharedState *g = &M_shared_state;
|
MIX_SharedState *g = &M_shared_state;
|
||||||
P_AssertLockedE(lock, &g->mutex);
|
P_AssertLockedE(lock, &g->mutex);
|
||||||
(UNUSED)lock;
|
(UNUSED)lock;
|
||||||
|
|
||||||
/* Remove from playing list */
|
/* Remove from playing list */
|
||||||
M_Track *prev = track->prev;
|
MIX_Track *prev = track->prev;
|
||||||
M_Track *next = track->next;
|
MIX_Track *next = track->next;
|
||||||
if (prev)
|
if (prev)
|
||||||
{
|
{
|
||||||
prev->next = next;
|
prev->next = next;
|
||||||
@ -145,40 +145,40 @@ void M_ReleaseTrackLocked(P_Lock *lock, M_Track *track)
|
|||||||
|
|
||||||
/* TODO: Rework interface to be command based instead of directly modifying tracks. */
|
/* TODO: Rework interface to be command based instead of directly modifying tracks. */
|
||||||
|
|
||||||
M_Handle M_PlaySound(SND_Sound *sound)
|
MIX_Handle MIX_PlaySound(SND_Sound *sound)
|
||||||
{
|
{
|
||||||
return M_PlaySoundEx(sound, M_TRACKDESC());
|
return MIX_PlaySoundEx(sound, M_TRACKDESC());
|
||||||
}
|
}
|
||||||
|
|
||||||
M_Handle M_PlaySoundEx(SND_Sound *sound, M_TrackDesc desc)
|
MIX_Handle MIX_PlaySoundEx(SND_Sound *sound, MIX_TrackDesc desc)
|
||||||
{
|
{
|
||||||
M_SharedState *g = &M_shared_state;
|
MIX_SharedState *g = &M_shared_state;
|
||||||
M_Track *track;
|
MIX_Track *track;
|
||||||
{
|
{
|
||||||
P_Lock lock = P_LockE(&g->mutex);
|
P_Lock lock = P_LockE(&g->mutex);
|
||||||
{
|
{
|
||||||
track = M_AllocTrackLocked(&lock, sound);
|
track = MIX_AllocTrackLocked(&lock, sound);
|
||||||
track->desc = desc;
|
track->desc = desc;
|
||||||
}
|
}
|
||||||
P_Unlock(&lock);
|
P_Unlock(&lock);
|
||||||
}
|
}
|
||||||
return M_HandleFromTrack(track);
|
return MIX_HandleFromTrack(track);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* NOTE: This is quite inefficient. */
|
/* NOTE: This is quite inefficient. */
|
||||||
M_TrackDesc M_TrackDescFromHandle(M_Handle handle)
|
MIX_TrackDesc MIX_TrackDescFromHandle(MIX_Handle handle)
|
||||||
{
|
{
|
||||||
M_SharedState *g = &M_shared_state;
|
MIX_SharedState *g = &M_shared_state;
|
||||||
M_TrackDesc result = ZI;
|
MIX_TrackDesc result = ZI;
|
||||||
|
|
||||||
M_Track *track = M_TrackFromHandle(handle);
|
MIX_Track *track = MIX_TrackFromHandle(handle);
|
||||||
if (track)
|
if (track)
|
||||||
{
|
{
|
||||||
/* TODO: Only lock mutex on track itself or something */
|
/* TODO: Only lock mutex on track itself or something */
|
||||||
P_Lock lock = P_LockE(&g->mutex);
|
P_Lock lock = P_LockE(&g->mutex);
|
||||||
{
|
{
|
||||||
/* Confirm handle is still valid now that we're locked */
|
/* Confirm handle is still valid now that we're locked */
|
||||||
track = M_TrackFromHandle(handle);
|
track = MIX_TrackFromHandle(handle);
|
||||||
if (track)
|
if (track)
|
||||||
{
|
{
|
||||||
result = track->desc;
|
result = track->desc;
|
||||||
@ -191,17 +191,17 @@ M_TrackDesc M_TrackDescFromHandle(M_Handle handle)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* NOTE: This is quite inefficient. */
|
/* NOTE: This is quite inefficient. */
|
||||||
void M_UpdateTrack(M_Handle handle, M_TrackDesc desc)
|
void MIX_UpdateTrack(MIX_Handle handle, MIX_TrackDesc desc)
|
||||||
{
|
{
|
||||||
M_SharedState *g = &M_shared_state;
|
MIX_SharedState *g = &M_shared_state;
|
||||||
M_Track *track = M_TrackFromHandle(handle);
|
MIX_Track *track = MIX_TrackFromHandle(handle);
|
||||||
if (track)
|
if (track)
|
||||||
{
|
{
|
||||||
/* TODO: Only lock mutex on track itself or something */
|
/* TODO: Only lock mutex on track itself or something */
|
||||||
P_Lock lock = P_LockE(&g->mutex);
|
P_Lock lock = P_LockE(&g->mutex);
|
||||||
{
|
{
|
||||||
/* Confirm handle is still valid now that we're locked */
|
/* Confirm handle is still valid now that we're locked */
|
||||||
track = M_TrackFromHandle(handle);
|
track = MIX_TrackFromHandle(handle);
|
||||||
if (track)
|
if (track)
|
||||||
{
|
{
|
||||||
track->desc = desc;
|
track->desc = desc;
|
||||||
@ -211,9 +211,9 @@ void M_UpdateTrack(M_Handle handle, M_TrackDesc desc)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void M_UpdateListener(Vec2 pos, Vec2 dir)
|
void MIX_UpdateListener(Vec2 pos, Vec2 dir)
|
||||||
{
|
{
|
||||||
M_SharedState *g = &M_shared_state;
|
MIX_SharedState *g = &M_shared_state;
|
||||||
P_Lock lock = P_LockE(&g->mutex);
|
P_Lock lock = P_LockE(&g->mutex);
|
||||||
{
|
{
|
||||||
g->listener_pos = pos;
|
g->listener_pos = pos;
|
||||||
@ -225,7 +225,7 @@ void M_UpdateListener(Vec2 pos, Vec2 dir)
|
|||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ Mix
|
//~ Mix
|
||||||
|
|
||||||
i16 M_SampleSound(SND_Sound *sound, u64 sample_pos, b32 wrap)
|
i16 MIX_SampleSound(SND_Sound *sound, u64 sample_pos, b32 wrap)
|
||||||
{
|
{
|
||||||
if (wrap)
|
if (wrap)
|
||||||
{
|
{
|
||||||
@ -242,13 +242,13 @@ i16 M_SampleSound(SND_Sound *sound, u64 sample_pos, b32 wrap)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* To be called once per audio playback interval */
|
/* To be called once per audio playback interval */
|
||||||
M_PcmF32 M_MixAllTracks(Arena *arena, u64 frame_count)
|
MIX_PcmF32 MIX_MixAllTracks(Arena *arena, u64 frame_count)
|
||||||
{
|
{
|
||||||
__prof;
|
__prof;
|
||||||
TempArena scratch = BeginScratch(arena);
|
TempArena scratch = BeginScratch(arena);
|
||||||
M_SharedState *g = &M_shared_state;
|
MIX_SharedState *g = &M_shared_state;
|
||||||
|
|
||||||
M_PcmF32 result = ZI;
|
MIX_PcmF32 result = ZI;
|
||||||
result.count = frame_count * 2;
|
result.count = frame_count * 2;
|
||||||
result.samples = PushStructs(arena, f32, result.count);
|
result.samples = PushStructs(arena, f32, result.count);
|
||||||
|
|
||||||
@ -257,7 +257,7 @@ M_PcmF32 M_MixAllTracks(Arena *arena, u64 frame_count)
|
|||||||
|
|
||||||
//- Create temp mix array
|
//- Create temp mix array
|
||||||
|
|
||||||
M_MixData **mixes = 0;
|
MIX_MixData **mixes = 0;
|
||||||
u64 mixes_count = 0;
|
u64 mixes_count = 0;
|
||||||
{
|
{
|
||||||
P_Lock lock = P_LockE(&g->mutex);
|
P_Lock lock = P_LockE(&g->mutex);
|
||||||
@ -267,11 +267,11 @@ M_PcmF32 M_MixAllTracks(Arena *arena, u64 frame_count)
|
|||||||
listener_dir = g->listener_dir;
|
listener_dir = g->listener_dir;
|
||||||
|
|
||||||
/* Update & read mixes */
|
/* Update & read mixes */
|
||||||
mixes = PushStructsNoZero(scratch.arena, M_MixData *, g->track_playing_count);
|
mixes = PushStructsNoZero(scratch.arena, MIX_MixData *, g->track_playing_count);
|
||||||
for (M_Track *track = g->track_first_playing; track; track = track->next)
|
for (MIX_Track *track = g->track_first_playing; track; track = track->next)
|
||||||
{
|
{
|
||||||
__profn("Prepare track");
|
__profn("Prepare track");
|
||||||
M_MixData *mix = &track->mix;
|
MIX_MixData *mix = &track->mix;
|
||||||
mix->desc = track->desc;
|
mix->desc = track->desc;
|
||||||
mixes[mixes_count++] = mix;
|
mixes[mixes_count++] = mix;
|
||||||
}
|
}
|
||||||
@ -284,7 +284,7 @@ M_PcmF32 M_MixAllTracks(Arena *arena, u64 frame_count)
|
|||||||
for (u64 mix_index = 0; mix_index < mixes_count; ++mix_index)
|
for (u64 mix_index = 0; mix_index < mixes_count; ++mix_index)
|
||||||
{
|
{
|
||||||
__profn("Mix track");
|
__profn("Mix track");
|
||||||
M_MixData *mix = mixes[mix_index];
|
MIX_MixData *mix = mixes[mix_index];
|
||||||
|
|
||||||
if (mix->source->samples_count <= 0)
|
if (mix->source->samples_count <= 0)
|
||||||
{
|
{
|
||||||
@ -293,8 +293,8 @@ M_PcmF32 M_MixAllTracks(Arena *arena, u64 frame_count)
|
|||||||
}
|
}
|
||||||
|
|
||||||
SND_Sound *source = mix->source;
|
SND_Sound *source = mix->source;
|
||||||
M_TrackDesc desc = mix->desc;
|
MIX_TrackDesc desc = mix->desc;
|
||||||
M_EffectData *effect_data = &mix->effect_data;
|
MIX_EffectData *effect_data = &mix->effect_data;
|
||||||
b32 source_is_stereo = source->flags & SND_SoundFlag_Stereo;
|
b32 source_is_stereo = source->flags & SND_SoundFlag_Stereo;
|
||||||
f32 speed = MaxF32(0, desc.speed);
|
f32 speed = MaxF32(0, desc.speed);
|
||||||
|
|
||||||
@ -333,7 +333,7 @@ M_PcmF32 M_MixAllTracks(Arena *arena, u64 frame_count)
|
|||||||
|
|
||||||
mix->source_pos = source_sample_pos_end;
|
mix->source_pos = source_sample_pos_end;
|
||||||
|
|
||||||
M_PcmF32 mix_pcm = {
|
MIX_PcmF32 mix_pcm = {
|
||||||
.count = result.count,
|
.count = result.count,
|
||||||
.samples = PushStructs(scratch.arena, f32, result.count)
|
.samples = PushStructs(scratch.arena, f32, result.count)
|
||||||
};
|
};
|
||||||
@ -358,10 +358,10 @@ M_PcmF32 M_MixAllTracks(Arena *arena, u64 frame_count)
|
|||||||
u32 in_frame_pos_next = CeilF32ToI32(in_frame_pos_exact);
|
u32 in_frame_pos_next = CeilF32ToI32(in_frame_pos_exact);
|
||||||
|
|
||||||
/* Sample source */
|
/* Sample source */
|
||||||
f32 sample1_prev = M_SampleSound(source, (in_frame_pos_prev * 2) + 0, desc.looping) * (1.f / 32768.f);
|
f32 sample1_prev = MIX_SampleSound(source, (in_frame_pos_prev * 2) + 0, desc.looping) * (1.f / 32768.f);
|
||||||
f32 sample1_next = M_SampleSound(source, (in_frame_pos_next * 2) + 0, desc.looping) * (1.f / 32768.f);
|
f32 sample1_next = MIX_SampleSound(source, (in_frame_pos_next * 2) + 0, desc.looping) * (1.f / 32768.f);
|
||||||
f32 sample2_prev = M_SampleSound(source, (in_frame_pos_prev * 2) + 1, desc.looping) * (1.f / 32768.f);
|
f32 sample2_prev = MIX_SampleSound(source, (in_frame_pos_prev * 2) + 1, desc.looping) * (1.f / 32768.f);
|
||||||
f32 sample2_next = M_SampleSound(source, (in_frame_pos_next * 2) + 1, desc.looping) * (1.f / 32768.f);
|
f32 sample2_next = MIX_SampleSound(source, (in_frame_pos_next * 2) + 1, desc.looping) * (1.f / 32768.f);
|
||||||
|
|
||||||
/* Lerp */
|
/* Lerp */
|
||||||
f32 t = in_frame_pos_exact - (f32)in_frame_pos_prev;
|
f32 t = in_frame_pos_exact - (f32)in_frame_pos_prev;
|
||||||
@ -382,8 +382,8 @@ M_PcmF32 M_MixAllTracks(Arena *arena, u64 frame_count)
|
|||||||
u32 in_frame_pos_next = CeilF32ToI32(in_frame_pos_exact);
|
u32 in_frame_pos_next = CeilF32ToI32(in_frame_pos_exact);
|
||||||
|
|
||||||
/* Sample source */
|
/* Sample source */
|
||||||
f32 sample_prev = M_SampleSound(source, in_frame_pos_prev, desc.looping) * (1.f / 32768.f);
|
f32 sample_prev = MIX_SampleSound(source, in_frame_pos_prev, desc.looping) * (1.f / 32768.f);
|
||||||
f32 sample_next = M_SampleSound(source, in_frame_pos_next, desc.looping) * (1.f / 32768.f);
|
f32 sample_next = MIX_SampleSound(source, in_frame_pos_next, desc.looping) * (1.f / 32768.f);
|
||||||
|
|
||||||
/* Lerp */
|
/* Lerp */
|
||||||
f32 t = (f32)in_frame_pos_exact - in_frame_pos_prev;
|
f32 t = (f32)in_frame_pos_exact - in_frame_pos_prev;
|
||||||
@ -396,7 +396,7 @@ M_PcmF32 M_MixAllTracks(Arena *arena, u64 frame_count)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//- Spatialize
|
//- Spatialize
|
||||||
if (desc.flags & M_TrackFlag_Spatialize)
|
if (desc.flags & MIX_TrackFlag_Spatialize)
|
||||||
{
|
{
|
||||||
__profn("Spatialize");
|
__profn("Spatialize");
|
||||||
|
|
||||||
@ -464,14 +464,14 @@ M_PcmF32 M_MixAllTracks(Arena *arena, u64 frame_count)
|
|||||||
P_Lock lock = P_LockE(&g->mutex);
|
P_Lock lock = P_LockE(&g->mutex);
|
||||||
for (u64 i = 0; i < mixes_count; ++i)
|
for (u64 i = 0; i < mixes_count; ++i)
|
||||||
{
|
{
|
||||||
M_MixData *mix = mixes[i];
|
MIX_MixData *mix = mixes[i];
|
||||||
M_Track *track = M_TrackFromHandle(mix->track_handle);
|
MIX_Track *track = MIX_TrackFromHandle(mix->track_handle);
|
||||||
if (track)
|
if (track)
|
||||||
{
|
{
|
||||||
if (mix->track_finished)
|
if (mix->track_finished)
|
||||||
{
|
{
|
||||||
/* Release finished tracks */
|
/* Release finished tracks */
|
||||||
M_ReleaseTrackLocked(&lock, track);
|
MIX_ReleaseTrackLocked(&lock, track);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,29 +1,29 @@
|
|||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ Track types
|
//~ Track types
|
||||||
|
|
||||||
typedef u32 M_TrackFlag; enum
|
typedef u32 MIX_TrackFlag; enum
|
||||||
{
|
{
|
||||||
M_TrackFlag_None = 0,
|
MIX_TrackFlag_None = 0,
|
||||||
M_TrackFlag_Spatialize = (1 << 0)
|
MIX_TrackFlag_Spatialize = (1 << 0)
|
||||||
};
|
};
|
||||||
|
|
||||||
Struct(M_Handle)
|
Struct(MIX_Handle)
|
||||||
{
|
{
|
||||||
u64 gen;
|
u64 gen;
|
||||||
void *data;
|
void *data;
|
||||||
};
|
};
|
||||||
|
|
||||||
Struct(M_TrackDesc)
|
Struct(MIX_TrackDesc)
|
||||||
{
|
{
|
||||||
M_TrackFlag flags;
|
MIX_TrackFlag flags;
|
||||||
f32 volume; /* 0 -> 1.0+ */
|
f32 volume; /* 0 -> 1.0+ */
|
||||||
f32 speed; /* 0 -> 1.0+ */
|
f32 speed; /* 0 -> 1.0+ */
|
||||||
b32 looping;
|
b32 looping;
|
||||||
|
|
||||||
/* M_TrackFlag_Spatialize */
|
/* MIX_TrackFlag_Spatialize */
|
||||||
Vec2 pos;
|
Vec2 pos;
|
||||||
};
|
};
|
||||||
#define M_TRACKDESC(...) ((M_TrackDesc) { \
|
#define M_TRACKDESC(...) ((MIX_TrackDesc) { \
|
||||||
.flags = 0, \
|
.flags = 0, \
|
||||||
.volume = 1.0, \
|
.volume = 1.0, \
|
||||||
.speed = 1.0, \
|
.speed = 1.0, \
|
||||||
@ -36,48 +36,48 @@ Struct(M_TrackDesc)
|
|||||||
//~ Mix types
|
//~ Mix types
|
||||||
|
|
||||||
/* Stereo mix of 32 bit float samples */
|
/* Stereo mix of 32 bit float samples */
|
||||||
Struct(M_PcmF32)
|
Struct(MIX_PcmF32)
|
||||||
{
|
{
|
||||||
u64 count;
|
u64 count;
|
||||||
f32 *samples;
|
f32 *samples;
|
||||||
};
|
};
|
||||||
|
|
||||||
Struct(M_EffectData)
|
Struct(MIX_EffectData)
|
||||||
{
|
{
|
||||||
/* Spatialization */
|
/* Spatialization */
|
||||||
f32 spatial_volume;
|
f32 spatial_volume;
|
||||||
f32 spatial_pan;
|
f32 spatial_pan;
|
||||||
};
|
};
|
||||||
|
|
||||||
Struct(M_MixData)
|
Struct(MIX_MixData)
|
||||||
{
|
{
|
||||||
M_Handle track_handle;
|
MIX_Handle track_handle;
|
||||||
b32 track_finished;
|
b32 track_finished;
|
||||||
|
|
||||||
M_TrackDesc desc;
|
MIX_TrackDesc desc;
|
||||||
M_EffectData effect_data;
|
MIX_EffectData effect_data;
|
||||||
SND_Sound *source;
|
SND_Sound *source;
|
||||||
u64 source_pos;
|
u64 source_pos;
|
||||||
};
|
};
|
||||||
|
|
||||||
Struct(M_Track)
|
Struct(MIX_Track){
|
||||||
{
|
|
||||||
u64 gen;
|
u64 gen;
|
||||||
|
|
||||||
/* Controlled via interface */
|
/* Controlled via interface */
|
||||||
SND_Sound *sound;
|
SND_Sound *sound;
|
||||||
M_TrackDesc desc;
|
MIX_TrackDesc desc;
|
||||||
|
|
||||||
/* Internal */
|
/* Internal */
|
||||||
M_MixData mix;
|
MIX_MixData mix;
|
||||||
|
|
||||||
M_Track *next;
|
MIX_Track *next;
|
||||||
M_Track *prev;
|
MIX_Track *prev;
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ Shared state
|
//~ Shared state
|
||||||
|
|
||||||
Struct(M_SharedState)
|
Struct(MIX_SharedState)
|
||||||
{
|
{
|
||||||
P_Mutex mutex;
|
P_Mutex mutex;
|
||||||
|
|
||||||
@ -87,39 +87,39 @@ Struct(M_SharedState)
|
|||||||
|
|
||||||
/* Track list */
|
/* Track list */
|
||||||
Arena *track_arena;
|
Arena *track_arena;
|
||||||
M_Track *track_first_playing;
|
MIX_Track *track_first_playing;
|
||||||
M_Track *track_last_playing;
|
MIX_Track *track_last_playing;
|
||||||
u64 track_playing_count;
|
u64 track_playing_count;
|
||||||
M_Track *track_first_free;
|
MIX_Track *track_first_free;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern M_SharedState M_shared_state;
|
extern MIX_SharedState M_shared_state;
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ Startup
|
//~ Startup
|
||||||
|
|
||||||
Struct(M_StartupReceipt) { i32 _; };
|
Struct(MIX_StartupReceipt) { i32 _; };
|
||||||
M_StartupReceipt M_Startup(void);
|
MIX_StartupReceipt MIX_Startup(void);
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ Track operations
|
//~ Track operations
|
||||||
|
|
||||||
M_Handle M_HandleFromTrack(M_Track *track);
|
MIX_Handle MIX_HandleFromTrack(MIX_Track *track);
|
||||||
M_Track *M_TrackFromHandle(M_Handle handle);
|
MIX_Track *MIX_TrackFromHandle(MIX_Handle handle);
|
||||||
M_Track *M_AllocTrackLocked(P_Lock *lock, SND_Sound *sound);
|
MIX_Track *MIX_AllocTrackLocked(P_Lock *lock, SND_Sound *sound);
|
||||||
void M_ReleaseTrackLocked(P_Lock *lock, M_Track *track);
|
void MIX_ReleaseTrackLocked(P_Lock *lock, MIX_Track *track);
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ Mixer state operations
|
//~ Mixer state operations
|
||||||
|
|
||||||
M_Handle M_PlaySound(SND_Sound *sound);
|
MIX_Handle MIX_PlaySound(SND_Sound *sound);
|
||||||
M_Handle M_PlaySoundEx(SND_Sound *sound, M_TrackDesc desc);
|
MIX_Handle MIX_PlaySoundEx(SND_Sound *sound, MIX_TrackDesc desc);
|
||||||
M_TrackDesc M_TrackDescFromHandle(M_Handle handle);
|
MIX_TrackDesc MIX_TrackDescFromHandle(MIX_Handle handle);
|
||||||
void M_UpdateTrack(M_Handle handle, M_TrackDesc desc);
|
void MIX_UpdateTrack(MIX_Handle handle, MIX_TrackDesc desc);
|
||||||
void M_UpdateListener(Vec2 pos, Vec2 dir);
|
void MIX_UpdateListener(Vec2 pos, Vec2 dir);
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ Mixer update
|
//~ Mixer update
|
||||||
|
|
||||||
i16 M_SampleSound(SND_Sound *sound, u64 sample_pos, b32 wrap);
|
i16 MIX_SampleSound(SND_Sound *sound, u64 sample_pos, b32 wrap);
|
||||||
M_PcmF32 M_MixAllTracks(Arena *arena, u64 frame_count);
|
MIX_PcmF32 MIX_MixAllTracks(Arena *arena, u64 frame_count);
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
#define PB_SampleRate 48000
|
#define PB_SampleRate 48000
|
||||||
|
|
||||||
Struct(PB_StartupReceipt) { i32 _; };
|
Struct(PB_StartupReceipt) { i32 _; };
|
||||||
PB_StartupReceipt PB_Startup(M_StartupReceipt *mixer_sr);
|
PB_StartupReceipt PB_Startup(MIX_StartupReceipt *mixer_sr);
|
||||||
|
|||||||
@ -9,7 +9,7 @@ PB_WSP_SharedState PB_WSP_shared_state = ZI;
|
|||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ Startup
|
//~ Startup
|
||||||
|
|
||||||
PB_StartupReceipt PB_Startup(M_StartupReceipt *mixer_sr)
|
PB_StartupReceipt PB_Startup(MIX_StartupReceipt *mixer_sr)
|
||||||
{
|
{
|
||||||
__prof;
|
__prof;
|
||||||
PB_WSP_SharedState *g = &PB_WSP_shared_state;
|
PB_WSP_SharedState *g = &PB_WSP_shared_state;
|
||||||
@ -147,7 +147,7 @@ PB_WSP_Buff PB_WSP_BeginUpdate(void)
|
|||||||
return wspbuf;
|
return wspbuf;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PB_WSP_EndUpdate(PB_WSP_Buff *wspbuf, M_PcmF32 src)
|
void PB_WSP_EndUpdate(PB_WSP_Buff *wspbuf, MIX_PcmF32 src)
|
||||||
{
|
{
|
||||||
__prof;
|
__prof;
|
||||||
PB_WSP_SharedState *g = &PB_WSP_shared_state;
|
PB_WSP_SharedState *g = &PB_WSP_shared_state;
|
||||||
@ -202,7 +202,7 @@ P_JobDef(PB_WSP_PlaybackJob, _)
|
|||||||
{
|
{
|
||||||
__profn("Fill sample buffer");
|
__profn("Fill sample buffer");
|
||||||
PB_WSP_Buff wspbuf = PB_WSP_BeginUpdate();
|
PB_WSP_Buff wspbuf = PB_WSP_BeginUpdate();
|
||||||
M_PcmF32 pcm = M_MixAllTracks(scratch.arena, wspbuf.frames_count);
|
MIX_PcmF32 pcm = MIX_MixAllTracks(scratch.arena, wspbuf.frames_count);
|
||||||
PB_WSP_EndUpdate(&wspbuf, pcm);
|
PB_WSP_EndUpdate(&wspbuf, pcm);
|
||||||
}
|
}
|
||||||
EndScratch(scratch);
|
EndScratch(scratch);
|
||||||
|
|||||||
@ -56,7 +56,7 @@ P_ExitFuncDef(PB_WSP_Shutdown);
|
|||||||
//~ Playback update
|
//~ Playback update
|
||||||
|
|
||||||
PB_WSP_Buff PB_WSP_BeginUpdate(void);
|
PB_WSP_Buff PB_WSP_BeginUpdate(void);
|
||||||
void PB_WSP_EndUpdate(PB_WSP_Buff *wspbuf, M_PcmF32 src);
|
void PB_WSP_EndUpdate(PB_WSP_Buff *wspbuf, MIX_PcmF32 src);
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ Playback job
|
//~ Playback job
|
||||||
|
|||||||
@ -373,8 +373,8 @@ Struct(Ent) {
|
|||||||
|
|
||||||
/* SEPROP_TEST_SOUND_EMITTER */
|
/* SEPROP_TEST_SOUND_EMITTER */
|
||||||
String sound_name;
|
String sound_name;
|
||||||
M_TrackDesc sound_desc;
|
MIX_TrackDesc sound_desc;
|
||||||
M_Handle sound_handle;
|
MIX_Handle sound_handle;
|
||||||
|
|
||||||
/* ====================================================================== */
|
/* ====================================================================== */
|
||||||
/* Camera */
|
/* Camera */
|
||||||
|
|||||||
@ -183,7 +183,7 @@ struct user_startup_receipt user_startup(F_StartupReceipt *font_sr,
|
|||||||
D_StartupReceipt *draw_sr,
|
D_StartupReceipt *draw_sr,
|
||||||
AC_StartupReceipt *asset_cache_sr,
|
AC_StartupReceipt *asset_cache_sr,
|
||||||
SND_StartupReceipt *sound_sr,
|
SND_StartupReceipt *sound_sr,
|
||||||
M_StartupReceipt *mixer_sr,
|
MIX_StartupReceipt *mixer_sr,
|
||||||
SimStartupReceipt *sim_sr,
|
SimStartupReceipt *sim_sr,
|
||||||
String connect_address_str)
|
String connect_address_str)
|
||||||
{
|
{
|
||||||
@ -1012,7 +1012,7 @@ internal void user_update(P_Window *window)
|
|||||||
Vec2 ui_center = MulVec2(G.ui_size, 0.5f);
|
Vec2 ui_center = MulVec2(G.ui_size, 0.5f);
|
||||||
Vec2 listener_pos = InvertXformMulV2(G.world_to_ui_xf, ui_center);
|
Vec2 listener_pos = InvertXformMulV2(G.world_to_ui_xf, ui_center);
|
||||||
Vec2 listener_dir = NormVec2(InvertXformBasisMulV2(G.world_to_ui_xf, up));
|
Vec2 listener_dir = NormVec2(InvertXformBasisMulV2(G.world_to_ui_xf, up));
|
||||||
M_UpdateListener(listener_pos, listener_dir);
|
MIX_UpdateListener(listener_pos, listener_dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ========================== *
|
/* ========================== *
|
||||||
|
|||||||
@ -53,6 +53,6 @@ struct user_startup_receipt user_startup(F_StartupReceipt *font_sr,
|
|||||||
D_StartupReceipt *draw_sr,
|
D_StartupReceipt *draw_sr,
|
||||||
AC_StartupReceipt *asset_cache_sr,
|
AC_StartupReceipt *asset_cache_sr,
|
||||||
SND_StartupReceipt *sound_sr,
|
SND_StartupReceipt *sound_sr,
|
||||||
M_StartupReceipt *mixer_sr,
|
MIX_StartupReceipt *mixer_sr,
|
||||||
SimStartupReceipt *sim_sr,
|
SimStartupReceipt *sim_sr,
|
||||||
String connect_address_str);
|
String connect_address_str);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user