#include "vg_audio_vorbis.h"
#include "common_maths.h"
#include "vg_async.h"
+#include "vg_camera.h"
+#include "vg_graphics.h"
+#include "console_system.h"
+#include "vg_engine.h"
#include <unistd.h>
v_l *= v_s * (1.0-v_p);
v_r *= v_s * (1.0+v_p);
}
+ else
+ {
+ f64 v_p = (f64)state->pan / (f64)AUDIO_PAN_RIGHT_100;
+ v_l *= f32_min( 1.0f, (1.0-v_p) );
+ v_r *= f32_min( 1.0f, (1.0+v_p) );
+ }
f32 s_l, s_r;
if( frame_sample_rate != 1.0f )
_audio.working = 0;
#endif
}
+
+void _audio_gui(void)
+{
+ if( _cvar_vg_audio == 0 )
+ return;
+
+ _audio_lock();
+ i16 panel[4] = {0,0,_engine.w,_engine.h};
+
+ /* Draw audio stack */
+ for( i32 id=1; id<=AUDIO_CHANNELS; id ++ )
+ {
+ struct audio_channel *channel = get_audio_channel( id );
+
+ i16 row[4];
+ rect_split( panel, 0, 18, 1, row, panel );
+
+ if( channel->stage == k_channel_stage_none )
+ {
+ _graphics_fill_rect( row, (union colour){{ 0x33,0x33,0x33,0x50 }} );
+ }
+ else if( channel->stage == k_channel_stage_allocation )
+ {
+ _graphics_fill_rect( row, (union colour){{ 0x33,0x33,0xff,0x50 }} );
+ }
+ else if( channel->stage == k_channel_stage_active )
+ {
+ char buf[256];
+ struct stream string;
+ stream_open_buffer_write( &string, buf, sizeof(buf), k_stream_null_terminate );
+
+ $v_string( &string, $signed(id) );
+
+ if( channel->group )
+ {
+ $v_string( &string, {" grp"}, $unsigned( channel->group ) );
+ }
+ else
+ {
+ $v_string( &string, {" "} );
+ }
+
+ $v_string( &string, {" flags:"} );
+ u32 flags = get_audio_channel_controls( id )->flags;
+ string_append_c8( &string, (flags & AUDIO_FLAG_RELINQUISHED)? 'R': '_' );
+ string_append_c8( &string, (flags & AUDIO_FLAG_SPACIAL_3D)? 'S': '_' );
+ string_append_c8( &string, (flags & AUDIO_FLAG_WORLD)? 'W': '_' );
+ string_append_c8( &string, (flags & AUDIO_FLAG_NO_DOPPLER)? '_':'D' );
+ string_append_c8( &string, (flags & AUDIO_FLAG_NO_DSP)? '_':'E' );
+ string_append_c8( &string, (flags & AUDIO_FLAG_LOOP)? 'L':'_' );
+
+ const c8 *formats[] =
+ {
+ " mono ",
+ " stereo ",
+ " vorbis ",
+ " none0 ",
+ " none1 ",
+ " none2 ",
+ " none3 ",
+ " none4 ",
+ "synth:bird",
+ " none5 ",
+ " none6 ",
+ " none7 ",
+ " none8 ",
+ " none9 ",
+ " none10 ",
+ " none11 ",
+ };
+
+ u32 format_index = (channel->clip->flags & AUDIO_FLAG_FORMAT)>>9;
+ string_append( &string, " format:", 0 );
+ string_append( &string, formats[format_index], 0 );
+
+ const c8 *activties[] =
+ {
+ "wake ",
+ "play ",
+ "pause",
+ "end ",
+ "error"
+ };
+ $v_string( &string, {" "}, {activties[channel->ui_activity]}, {" "} );
+
+ f32 volume = (f32)channel->ui_volume / (f32)AUDIO_VOLUME_100;
+ $v_string( &string, $signed( volume * 100.0f ), {"% "}, {channel->ui_name} );
+
+ i16 row_l[4], row_r[4];
+ rect_split( row, 1, 32, 2, row_l, row_r );
+
+ i16 indicator_l[4], indicator_r[4];
+ rect_split_ratio( row_l, 1, 0.5f, 1, indicator_l, indicator_r );
+
+ _graphics_fill_rect( indicator_l, (union colour){{0,0,0,255}} );
+ if( volume > 0.01f )
+ {
+ f32 h = volume * (f32)indicator_l[3];
+ i16 vol_bar[4] = { indicator_l[0], indicator_l[1] + indicator_l[3] - h, indicator_l[2], h };
+ _graphics_fill_rect( vol_bar, (union colour){{ 0,255,0, 255 }} );
+ if( flags & AUDIO_FLAG_SPACIAL_3D )
+ {
+ f32 h = ((f32)channel->ui_spacial_volume / (f32)AUDIO_VOLUME_100) * (f32)indicator_l[3];
+ i16 space_bar[4] = { indicator_l[0], indicator_l[1] + indicator_l[3] - h, indicator_l[2], 1 };
+ _graphics_fill_rect( space_bar, (union colour){{ 255,255,255,255 }} );
+ }
+ }
+
+ f32 pan = (f32)channel->ui_pan / (f32)AUDIO_PAN_RIGHT_100;
+ _graphics_fill_rect( indicator_r, (union colour){{ 0x11,0x11,0x11,255 }} );
+ f32 midpoint = (f32)indicator_r[0] + (f32)indicator_r[2] * 0.5f;
+
+ f32 pan_abs = fabsf(pan);
+ if( pan_abs > 0.01f )
+ {
+ i16 bar[4] = { midpoint,indicator_r[1], pan_abs * (f32)indicator_r[2] * 0.5f, indicator_r[3] };
+ if( pan < 0.0f )
+ bar[0] -= (f32)bar[2];
+ _graphics_fill_rect( bar, (union colour){{ 0xff, 0xaa, 0x00, 0xff }} );
+ }
+
+ if( flags & AUDIO_FLAG_SPACIAL_3D )
+ {
+ f32 w = ((f32)channel->ui_spacial_pan / (f32)AUDIO_PAN_RIGHT_100) * (f32)indicator_r[2] * 0.5f;
+ i16 space_bar[4] = { midpoint+w, indicator_r[1], 1, indicator_r[3] };
+ _graphics_fill_rect( space_bar, (union colour){{ 0xff,0xff,0xff,0xff }} );
+ }
+
+ _graphics_fill_rect( row_r, (union colour){ .word = 0xa0000000 | channel->ui_colour } );
+ _ui_text( row_r, string_get( &string ), k_ui_align_y_center, (union colour){{0xff,0xff,0xff,0xff}} );
+ }
+ }
+
+#if 0
+#ifdef VG_3D
+ if( vd->view_3d && (ch->flags & AUDIO_FLAG_SPACIAL_3D) )
+ {
+ v4f wpos;
+ v3_copy( ch->spacial_falloff, wpos );
+
+ wpos[3] = 1.0f;
+ m4x4_mulv( vg.pv, wpos, wpos );
+
+ if( wpos[3] > 0.0f )
+ {
+ v2_muls( wpos, (1.0f/wpos[3]) * 0.5f, wpos );
+ v2_add( wpos, (v2f){ 0.5f, 0.5f }, wpos );
+
+ ui_rect wr;
+ wr[0] = vg_clampf(wpos[0] * vg.window_x, -32000.0f,32000.0f);
+ wr[1] = vg_clampf((1.0f-wpos[1]) * vg.window_y,-32000.0f,32000.0f);
+ wr[2] = 1000;
+ wr[3] = 17;
+
+ for( int j=0; j<12; j++ )
+ {
+ int collide = 0;
+ for( int k=0; k<overlap_length; k++ )
+ {
+ ui_px *wk = overlap_buffer[k];
+ if( ((wr[0] <= wk[0]+wk[2]) && (wr[0]+wr[2] >= wk[0])) &&
+ ((wr[1] <= wk[1]+wk[3]) && (wr[1]+wr[3] >= wk[1])) )
+ {
+ collide = 1;
+ break;
+ }
+ }
+
+ if( !collide )
+ break;
+ else
+ wr[1] += 18;
+ }
+
+ ui_text( ctx, wr, perf, 1, k_ui_align_middle_left, 0 );
+ rect_copy( wr, overlap_buffer[ overlap_length ++ ] );
+ }
+ }
+#endif
+#endif
+
+ _audio_unlock();
+}