memlog
[vg.git] / vg_audio.h
index 67cc3f100072d82a456c1ad89371bfb3245a17c0..f27c8592dac436d1844287671f4e939620e0c2b4 100644 (file)
 #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"
 #include "vg/vg_audio_synth_bird.h"
 
-#include <sys/time.h>
-#include <math.h>
-
 #ifdef __GNUC__
   #ifndef __clang__
     #pragma GCC push_options
@@ -83,13 +79,21 @@ typedef struct audio_channel audio_channel;
 typedef struct audio_lfo audio_lfo;
 
 struct audio_clip{
-   const char *path;
+   union {              /* TODO oof.. */
+      u64 _p64_;
+      const char *path;
+   };
+
    u32 flags;
    u32 size;
-   void *data;
+
+   union{ 
+      u64 _p64;
+      void *data;
+   };
 };
 
-static struct vg_audio_system{
+struct vg_audio_system{
    SDL_AudioDeviceID sdl_output_device;
 
    void             *audio_pool, 
@@ -200,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"
 
@@ -845,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;
@@ -1270,13 +1289,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];