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;
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[] =
float reflection_variance = 0.1f;
- for( int i=0; i<8; i++ )
- {
+ 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 );
float diffusions[] = { 187.0f, 159.0f, 143.0f, 121.0f,
79.0f, 57.0f, 27.0f, 11.0f };
- for( int i=0; i<8; i++ )
- {
+ for( int i=0; i<8; i++ ){
dsp_init_schroeder( __diffusion_chain+i, diffusions[i]/1000.0f, 0.7f );
}
}
float in_total = (stereo_in[0]+stereo_in[1])*0.5f;
float recieved = 0.0f;
- for( int i=0; i<8; i++ )
- {
+ for( int i=0; i<8; i++ ){
float echo;
dsp_read_delay( __echos+i, &echo );
dsp_write_lpf( __echos_lpf+i, &echo );
float diffused = recieved;
- for( int i=0; i<8; i++ )
- {
+ for( int i=0; i<8; i++ ){
dsp_process_schroeder( __diffusion_chain+i, &diffused, &diffused );
}
{
float sizes[] =
{ 2.0f, 4.0f, 8.0f, 16.0f, 32.0f, 64.0f, 128.0f, 256.0f };
+ float volumes[] =
+ { 0.2f, 0.3f, 0.5f, 0.7f, 0.8f, 0.9f, 1.0f, 1.0f };
float avg_distance = 0.0f;
for( int i=0; i<8; i++ )
vg_dsp.echo_tunings[i] = 0.5f;
- for( int j=0; j<14; j++ )
- {
+ for( int j=0; j<14; j++ ){
float d = vg_dsp.echo_distances[j];
- for( int i=0; i<7; i++ )
- {
- if( d < sizes[i+1] )
- {
+ for( int i=0; i<7; i++ ){
+ if( d < sizes[i+1] ){
float range = sizes[i+1]-sizes[i];
float t = vg_clampf( (d - sizes[i])/range, 0.0f, 1.0f );
for( int i=0; i<8; i++ )
total += vg_dsp.echo_tunings[i];
- if( total > 0.0f )
- {
+ if( total > 0.0f ){
float inverse = 1.0f/total;
- for( int i=0;i<8; i++ )
- {
+ for( int i=0;i<8; i++ ){
vg_dsp.echo_tunings[i] *= inverse;
}
}
- for( int i=0; i<8; i++ )
- {
+ for( int i=0; i<8; i++ ){
float freq = vg_lerpf( 200.0f, 500.0f, vg_dsp.echo_tunings[i] );
dsp_update_lpf( &__echos_lpf[i], freq );
}
+
+ for( int i=0;i<8; i++ ){
+ vg_dsp.echo_tunings[i] *= volumes[i];
+ }
}
static void vg_dsp_free( void )
static void vg_dsp_update_texture( void )
{
- for( int i=0; i<512*512; i++ )
- {
+ for( int i=0; i<512*512; i++ ){
float v = vg_clampf( vg_dsp.buffer[i] * 0.5f + 0.5f, 0.0f, 1.0f );
vg_dsp.view_texture_buffer[i] = v * 255.0f;
}