fix swap profile
[vg.git] / vg_audio.h
index 2bba7ea09ec4e4ea31fa806cf3519523844a6750..59ad0574e88acf1ade05b94a422291375812a20f 100644 (file)
@@ -96,7 +96,7 @@ struct audio_clip{
 
 struct vg_audio_system{
    SDL_AudioDeviceID sdl_output_device;
-   char *force_device_name; /* NULL: using default */
+   vg_str device_choice; /* buffer is null? use default from OS */
 
    void             *audio_pool, 
                     *decode_buffer;
@@ -193,7 +193,7 @@ struct vg_audio_system{
    }
    channels[ AUDIO_CHANNELS ];
 
-   int               debug_ui, debug_ui_3d, debug_dsp;
+   int               debug_ui, debug_ui_3d, debug_dsp, dsp_enabled;
 
    v3f               internal_listener_pos,
                      internal_listener_ears,
@@ -206,7 +206,7 @@ struct vg_audio_system{
    float             internal_global_volume,
                      external_global_volume;
 }
-static vg_audio = { .external_global_volume = 1.0f };
+static vg_audio = { .external_global_volume = 1.0f, .dsp_enabled = 1 };
 
 #include "vg/vg_audio_dsp.h"
 
@@ -276,13 +276,13 @@ static void vg_audio_device_init(void){
    spec_desired.userdata = NULL;
 
    vg_audio.sdl_output_device = 
-      SDL_OpenAudioDevice( vg_audio.force_device_name, 0, 
+      SDL_OpenAudioDevice( vg_audio.device_choice.buffer, 0, 
                            &spec_desired, &spec_got,0 );
 
    vg_info( "Start audio device (%u, F32, %u) @%s\n", 
                spec_desired.freq,
                AUDIO_FRAME_SIZE,
-               vg_audio.force_device_name );
+               vg_audio.device_choice.buffer );
 
    if( vg_audio.sdl_output_device ){
       SDL_PauseAudioDevice( vg_audio.sdl_output_device, 0 );
@@ -298,15 +298,20 @@ static void vg_audio_device_init(void){
    }
 }
 
-
-static void vg_audio_init(void){
+static void vg_audio_register(void){
    vg_console_reg_var( "debug_audio", &vg_audio.debug_ui, 
                         k_var_dtype_i32, VG_VAR_CHEAT );
    vg_console_reg_var( "debug_dsp", &vg_audio.debug_dsp,
                         k_var_dtype_i32, VG_VAR_CHEAT );
    vg_console_reg_var( "volume", &vg_audio.external_global_volume,
                         k_var_dtype_f32, VG_VAR_PERSISTENT );
+   vg_console_reg_var( "vg_audio_device", &vg_audio.device_choice,
+                        k_var_dtype_str, VG_VAR_PERSISTENT );
+   vg_console_reg_var( "vg_dsp", &vg_audio.dsp_enabled,
+                        k_var_dtype_i32, VG_VAR_PERSISTENT );
+}
 
+static void vg_audio_init(void){
    /* allocate memory */
    /* 32mb fixed */
    vg_audio.audio_pool = 
@@ -975,12 +980,12 @@ static void audio_channel_mix( audio_channel *ch, float *buffer )
    vg_profile_end( &_vg_prof_audio_mix );
 }
 
-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
     * ------------------------------------------------------------- */
    audio_lock();
+   int use_dsp = vg_audio.dsp_enabled;
    
    v3_copy( vg_audio.external_listener_pos, vg_audio.internal_listener_pos );
    v3_copy( vg_audio.external_listener_ears, vg_audio.internal_listener_ears );
@@ -1160,12 +1165,12 @@ static void audio_mixer_callback( void *user, u8 *stream, int byte_count )
       }
    }
 
-   vg_profile_begin( &_vg_prof_dsp );
-
-   for( int i=0; i<frame_count; i++ )
-      vg_dsp_process( pOut32F + i*2, pOut32F + i*2 );
-
-   vg_profile_end( &_vg_prof_dsp );
+   if( use_dsp ){
+      vg_profile_begin( &_vg_prof_dsp );
+      for( int i=0; i<frame_count; i++ )
+         vg_dsp_process( pOut32F + i*2, pOut32F + i*2 );
+      vg_profile_end( &_vg_prof_dsp );
+   }
 
    audio_lock();