X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=vg_audio.h;h=39f494ffa0b843e501c28aaab94db4cfa7dd443e;hb=76d234b7dc5e6500e8a54009b367e7620f11ef97;hp=4d203bf9c1aafae550af5dc158bac615b108ba7c;hpb=4f4aba081a05f72ad1bbc7844ca4060cd1f43fe6;p=vg.git diff --git a/vg_audio.h b/vg_audio.h index 4d203bf..39f494f 100644 --- a/vg_audio.h +++ b/vg_audio.h @@ -10,7 +10,6 @@ #include "vg/vg_platform.h" #include "vg/vg_io.h" #include "vg/vg_m.h" -#include "vg/vg_ui.h" #include "vg/vg_console.h" #include "vg/vg_store.h" #include "vg/vg_profiler.h" @@ -94,7 +93,7 @@ struct audio_clip{ }; }; -static struct vg_audio_system{ +struct vg_audio_system{ SDL_AudioDeviceID sdl_output_device; void *audio_pool, @@ -205,7 +204,7 @@ static struct vg_audio_system{ float internal_global_volume, external_global_volume; } -vg_audio = { .external_global_volume = 1.0f }; +static vg_audio = { .external_global_volume = 1.0f }; #include "vg/vg_audio_dsp.h" @@ -224,7 +223,7 @@ static struct vg_profile * These functions are called from the main thread and used to prevent bad * access. TODO: They should be no-ops in release builds. */ -VG_STATIC int audio_lock_checker_load(void) +static int audio_lock_checker_load(void) { int value; SDL_AtomicLock( &vg_audio.sl_checker ); @@ -233,14 +232,14 @@ VG_STATIC int audio_lock_checker_load(void) return value; } -VG_STATIC void audio_lock_checker_store( int value ) +static void audio_lock_checker_store( int value ) { SDL_AtomicLock( &vg_audio.sl_checker ); vg_audio.sync_locked = value; SDL_AtomicUnlock( &vg_audio.sl_checker ); } -VG_STATIC void audio_require_lock(void) +static void audio_require_lock(void) { if( audio_lock_checker_load() ) return; @@ -249,20 +248,20 @@ VG_STATIC void audio_require_lock(void) abort(); } -VG_STATIC void audio_lock(void) +static void audio_lock(void) { SDL_AtomicLock( &vg_audio.sl_sync ); audio_lock_checker_store(1); } -VG_STATIC void audio_unlock(void) +static void audio_unlock(void) { audio_lock_checker_store(0); SDL_AtomicUnlock( &vg_audio.sl_sync ); } -VG_STATIC void audio_mixer_callback( void *user, u8 *stream, int frame_count ); -VG_STATIC void vg_audio_init(void) +static void audio_mixer_callback( void *user, u8 *stream, int frame_count ); +static void vg_audio_init(void) { /* TODO: Move here? */ vg_console_reg_var( "debug_audio", &vg_audio.debug_ui, @@ -311,7 +310,7 @@ VG_STATIC void vg_audio_init(void) } } -VG_STATIC void vg_audio_free(void) +static void vg_audio_free(void) { vg_dsp_free(); SDL_CloseAudioDevice( vg_audio.sdl_output_device ); @@ -624,7 +623,7 @@ static int audio_channel_load_source( audio_channel *ch ) return 1; } -VG_STATIC void audio_decode_uncompressed_mono( i16 *src, u32 count, float *dst ) +static void audio_decode_uncompressed_mono( i16 *src, u32 count, float *dst ) { for( u32 i=0; istereo */ -VG_STATIC int +static int stb_vorbis_get_samples_float_interleaved_stereo( stb_vorbis *f, float *buffer, int len ) { @@ -669,7 +668,7 @@ stb_vorbis_get_samples_float_interleaved_stereo( stb_vorbis *f, float *buffer, /* * ........ more wrecked code sorry! */ -VG_STATIC int +static int stb_vorbis_get_samples_i16_downmixed( stb_vorbis *f, i16 *buffer, int len ) { int n = 0, @@ -850,10 +849,25 @@ static void audio_channel_mix( audio_channel *ch, float *buffer ) } } - if( !vg_validf( framevol_l ) ) vg_fatal_error( "NaN left channel" ); - if( !vg_validf( framevol_r ) ) vg_fatal_error( "NaN right channel" ); - if( !vg_validf( frame_samplerate ) ) - vg_fatal_error( "NaN sample rate" ); + if( !vg_validf( framevol_l ) || + !vg_validf( framevol_r ) || + !vg_validf( frame_samplerate ) ){ + vg_fatal_error( "Invalid sampling conditions.\n" + "This crash is to protect your ears.\n" + " channel: %p (%s)\n" + " sample_rate: %f\n" + " volume: L%f R%f\n" + " listener: %.2f %.2f %.2f [%.2f %.2f %.2f]\n", + ch, ch->name, frame_samplerate, + framevol_l, framevol_r, + vg_audio.internal_listener_pos[0], + vg_audio.internal_listener_pos[1], + vg_audio.internal_listener_pos[2], + vg_audio.internal_listener_ears[0], + vg_audio.internal_listener_ears[1], + vg_audio.internal_listener_ears[2] + ); + } } u32 buffer_length = AUDIO_MIX_FRAME_SIZE; @@ -921,7 +935,7 @@ static void audio_channel_mix( audio_channel *ch, float *buffer ) vg_profile_end( &_vg_prof_audio_mix ); } -VG_STATIC void audio_mixer_callback( void *user, u8 *stream, int byte_count ) +static void audio_mixer_callback( void *user, u8 *stream, int byte_count ) { /* * Copy data and move edit flags to commit flags @@ -1139,7 +1153,7 @@ VG_STATIC void audio_mixer_callback( void *user, u8 *stream, int byte_count ) audio_unlock(); } -VG_STATIC void audio_clip_load( audio_clip *clip, void *lin_alloc ) +static void audio_clip_load( audio_clip *clip, void *lin_alloc ) { if( lin_alloc == NULL ) lin_alloc = vg_audio.audio_pool; @@ -1232,19 +1246,21 @@ VG_STATIC void audio_clip_load( audio_clip *clip, void *lin_alloc ) if( read_samples != length_samples ) vg_fatal_error( "Decode error" ); +#if 0 float mb = (float)(data_size) / (1024.0f*1024.0f); vg_info( "Loaded audio clip '%s' (%.1fmb) %u samples\n", clip->path, mb, length_samples ); +#endif } } -VG_STATIC void audio_clip_loadn( audio_clip *arr, int count, void *lin_alloc ) +static void audio_clip_loadn( audio_clip *arr, int count, void *lin_alloc ) { for( int i=0; idata && clip->size ) return; @@ -1257,7 +1273,7 @@ VG_STATIC void audio_require_clip_loaded( audio_clip *clip ) * Debugging */ -VG_STATIC void audio_debug_ui( m4x4f mtx_pv ) +static void audio_debug_ui( m4x4f mtx_pv ) { if( !vg_audio.debug_ui ) return; @@ -1275,13 +1291,11 @@ VG_STATIC void audio_debug_ui( m4x4f mtx_pv ) */ float budget = ((double)vg_audio.samples_last / 44100.0) * 1000.0; -#if 0 vg_profile_drawn( (struct vg_profile *[]){ &vg_prof_audio_decode, &vg_prof_audio_mix, &vg_prof_audio_dsp}, 3, budget, (ui_rect){ 4, VG_PROFILE_SAMPLE_COUNT*2 + 8, 512, 0 }, 3 ); -#endif char perf[128];