modal
[vg.git] / vg_audio_dsp.h
index 56d3b20c655cb8050999f87287531bf76cf59a41..0eaeb544ae6855da0687b106ad10eb8e0d4f3b15 100644 (file)
@@ -24,7 +24,7 @@ static float *dsp_allocate( u32 samples )
    samples = vg_align4( samples );
 
    if( vg_dsp.allocations + samples > (1024*1024)/4 )
-      vg_fatal_exit_loop( "too much dsp" );
+      vg_fatal_error( "too much dsp" );
 
    float *buf = &vg_dsp.buffer[ vg_dsp.allocations ];
    vg_dsp.allocations += samples;
@@ -139,23 +139,24 @@ static struct dsp_delay __echos[8];
 static struct dsp_lpf   __echos_lpf[8];
 static struct dsp_schroeder __diffusion_chain[8];
 
-static void vg_dsp_init( void )
+static void async_vg_dsp_alloc_texture( void *payload, u32 size )
 {
-   vg_dsp.buffer = vg_linear_alloc( vg_mem.rtmemory, 1024*1024*1 );
-   vg_dsp.view_texture_buffer = vg_linear_alloc( vg_mem.rtmemory, 512*512 );
-
-   vg_acquire_thread_sync();
    glGenTextures( 1, &vg_dsp.view_texture );
    glBindTexture( GL_TEXTURE_2D, vg_dsp.view_texture );
    glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, 
                  GL_RGBA, GL_UNSIGNED_BYTE, vg_dsp.view_texture_buffer );
-   vg_tex2d_nearest();
-   vg_release_thread_sync();
-
+   glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
+   glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
+}
 
-   /* temporary global design */
+static void vg_dsp_init( void )
+{
+   vg_dsp.buffer = vg_linear_alloc( vg_mem.rtmemory, 1024*1024*1 );
+   vg_dsp.view_texture_buffer = vg_linear_alloc( vg_mem.rtmemory, 512*512 );
 
+   vg_async_call( async_vg_dsp_alloc_texture, NULL, 0 );
 
+   /* temporary global design */
    dsp_init_lpf( &__lpf_mud_free, 125.0f );
 
    float sizes[] = 
@@ -166,7 +167,7 @@ static void vg_dsp_init( void )
    for( int i=0; i<8; i++ ){
       float reflection_time = ((sizes[i])/343.0f) * 1000.0f;
 
-      float var   = 1.0f + (vg_randf()*2.0f - 1.0f) * reflection_variance,
+      float var   = 1.0f + (vg_randf64()*2.0f - 1.0f) * reflection_variance,
             total = reflection_time * var;
 
       dsp_init_delay( &__echos[i], total / 1000.0f );