231 lines
3.8 KiB
C
231 lines
3.8 KiB
C
/* date = April 15th 2023 2:40 pm */
|
|
|
|
#ifndef VIDEO_RENDER_H
|
|
#define VIDEO_RENDER_H
|
|
|
|
////////////////////////////////
|
|
// NOTE(allen): Audio Processing
|
|
|
|
// types
|
|
struct Track{
|
|
F32 *channels[2];
|
|
U32 sample_count;
|
|
};
|
|
|
|
struct SpeakerMarker{
|
|
U32 frame_idx;
|
|
U32 speaker_idx;
|
|
B32 begin;
|
|
};
|
|
|
|
struct SpeakerMarkerNode{
|
|
SpeakerMarkerNode *next;
|
|
SpeakerMarker marker;
|
|
};
|
|
|
|
struct SpeakerMarkerList{
|
|
SpeakerMarkerNode *first;
|
|
SpeakerMarkerNode *last;
|
|
U64 count;
|
|
};
|
|
|
|
struct SpeakerMarkerArray{
|
|
SpeakerMarker *markers;
|
|
U64 count;
|
|
};
|
|
|
|
struct SortRange{
|
|
SortRange *next;
|
|
U64 first;
|
|
U64 opl;
|
|
};
|
|
|
|
struct Array_F32{
|
|
F32 *v;
|
|
U64 count;
|
|
};
|
|
|
|
// functions
|
|
function String8
|
|
bop_f32_from_s16(M_Arena *arena, String8 in);
|
|
|
|
function Track
|
|
track_from_file_path(M_Arena *arena, String8 full_path);
|
|
|
|
function F32
|
|
decibel_from_linear(F32 r);
|
|
|
|
function Array_F32
|
|
db_per_frame_from_samples(M_Arena *arena,
|
|
F32 *samples, U32 sample_count,
|
|
U32 sample_frequency);
|
|
|
|
function void
|
|
speaker_marker_push(M_Arena *arena, SpeakerMarkerList *list,
|
|
U32 frame_idx, U32 speaker_idx, B32 begin);
|
|
|
|
function SpeakerMarkerArray
|
|
speaker_marker_array_from_list(M_Arena *arena, SpeakerMarkerList *list);
|
|
|
|
function void
|
|
speaker_marker_array_sort_in_place(SpeakerMarker *markers, U64 count);
|
|
|
|
////////////////////////////////
|
|
// NOTE(allen): Main Types
|
|
|
|
// data table
|
|
global F32
|
|
master_band_frequencies_hz[] = {
|
|
23.8f,
|
|
28.3f,
|
|
33.6f,
|
|
40.0f,
|
|
47.6f,
|
|
56.6f,
|
|
67.3f,
|
|
80.0f,
|
|
95.1f,
|
|
113.1f,
|
|
134.6f,
|
|
160.0f,
|
|
190.3f,
|
|
226.3f,
|
|
269.1f,
|
|
320.0f,
|
|
380.6f,
|
|
452.6f,
|
|
538.2f,
|
|
640.0f,
|
|
761.1f,
|
|
905.1f,
|
|
1076.4f,
|
|
1280.0f,
|
|
1522.2f,
|
|
1810.2f,
|
|
2152.7f,
|
|
2560.0f,
|
|
3044.4f,
|
|
3620.4f,
|
|
4305.4f,
|
|
5120.0f,
|
|
6088.7f,
|
|
7240.8f,
|
|
8610.8f,
|
|
10240.0f,
|
|
12177.5f,
|
|
14481.6f,
|
|
17221.6f,
|
|
};
|
|
|
|
global F32
|
|
avatar_band_frequencies_hz[] = {
|
|
40.f,
|
|
80.f,
|
|
160.f,
|
|
320.f,
|
|
640.f,
|
|
1280.f,
|
|
2560.f,
|
|
5120.f,
|
|
};
|
|
|
|
#define MASTER_BAND_COUNT (ArrayCount(master_band_frequencies_hz) - 1)
|
|
#define AVATAR_BAND_COUNT (ArrayCount(avatar_band_frequencies_hz) - 1)
|
|
|
|
#define MAX_BAND_COUNT Max(MASTER_BAND_COUNT, AVATAR_BAND_COUNT)
|
|
|
|
// types
|
|
struct Speaker{
|
|
String8 avatar_path;
|
|
String8 audio_path;
|
|
};
|
|
|
|
struct ProcessedTrack{
|
|
U32 frame_count;
|
|
F32 *max_level_db_per_frame;
|
|
F32 *band_level_db_per_frame[MAX_BAND_COUNT];
|
|
U32 band_count;
|
|
};
|
|
|
|
struct SpeakerState{
|
|
F32 is_speaking_level;
|
|
F32 freq_wiggles[MAX_BAND_COUNT];
|
|
};
|
|
|
|
// functions
|
|
function ProcessedTrack
|
|
processed_track_from_samples(M_Arena *arena,
|
|
F32 *samples, U32 sample_count,
|
|
U32 sample_frequency,
|
|
F32 *band_freq_hz, U32 band_count);
|
|
|
|
////////////////////////////////
|
|
// NOTE(allen): Graphics Types
|
|
|
|
// types
|
|
struct Vertex{
|
|
// primitive shape
|
|
V2F32 p;
|
|
|
|
// color
|
|
U32 color;
|
|
|
|
// rectangle
|
|
I2F32 rect;
|
|
|
|
// uv
|
|
V2F32 uv;
|
|
|
|
// sat,val
|
|
F32 s_mul;
|
|
F32 v_mul;
|
|
F32 over;
|
|
};
|
|
|
|
struct RectNode{
|
|
RectNode *next;
|
|
I2F32 rect;
|
|
V4F32 top_color;
|
|
V4F32 bot_color;
|
|
};
|
|
|
|
struct RectList{
|
|
RectNode *first;
|
|
RectNode *last;
|
|
U64 count;
|
|
};
|
|
|
|
struct AvatarParams{
|
|
U32 frame_counter;
|
|
F32 radius;
|
|
F32 sat_mul;
|
|
F32 val_mul;
|
|
F32 freq_wiggles[MAX_BAND_COUNT];
|
|
U32 band_count;
|
|
};
|
|
|
|
// functions
|
|
function void
|
|
setup_opengl_state(void);
|
|
|
|
function GLuint
|
|
avatar_gpu_texture_from_file_path(String8 full_path);
|
|
|
|
function void
|
|
draw_geometry_vert(Vertex *v, U32 count, GLuint tex, V2F32 windim);
|
|
|
|
function void
|
|
draw_geometry_rect(Vertex *v, U32 count, V2F32 windim);
|
|
|
|
function void
|
|
draw_avatar(V2F32 center, GLuint texture, AvatarParams *params, V2F32 windim);
|
|
|
|
function void
|
|
rectangle_push(M_Arena *arena, RectList *list,
|
|
I2F32 rect, V4F32 top_color, V4F32 bot_color);
|
|
|
|
function void
|
|
draw_rectangle_list(RectList *list, V2F32 windim);
|
|
|
|
#endif //VIDEO_RENDER_H
|