Optimize control point interpolation.

This commit is contained in:
Jonathan Moore Liles 2008-04-28 21:21:17 -05:00
parent f168b90e07
commit 1fae0b89d7
3 changed files with 24 additions and 36 deletions

View File

@ -319,7 +319,8 @@ Control_Sequence::handle ( int m )
static inline float static inline float
linear_interpolate ( float y1, float y2, float mu ) linear_interpolate ( float y1, float y2, float mu )
{ {
return y1 + mu * ( y2 - y1 ); // return y1 + mu * ( y2 - y1 );
return y1 * ( 1.0f - mu ) + y2 * mu;
} }
static inline float static inline float
@ -328,23 +329,6 @@ sigmoid_interpolate ( float y1, float y2, float mu )
return linear_interpolate( y1, y2, ( 1 - cos( mu * M_PI ) ) / 2 ); return linear_interpolate( y1, y2, ( 1 - cos( mu * M_PI ) ) / 2 );
} }
static inline float
quadratic_interpolate ( float y1, float y2, float mu )
{
return ( y1 * y1 ) * ( mu * mu ) + ( 2.0f * y1 * y2 ) * mu * ( y1 * y1 );
}
/* static inline float */
/* quadratic_interpolate ( float y1, float y2, float mu ) */
/* { */
/* } */
/* static inline float */
/* exponential_interpolate ( float y1, float y2, float mu ) */
/* { */
/* // return y1 * pow( y2 / y1, mu ); */
/* } */
/* THREAD: ?? */ /* THREAD: ?? */
/** fill buf with /nframes/ of interpolated control curve values /** fill buf with /nframes/ of interpolated control curve values
* starting at /frame/ */ * starting at /frame/ */
@ -363,22 +347,25 @@ Control_Sequence::play ( sample_t *buf, nframes_t frame, nframes_t nframes )
if ( p2->when() < frame ) if ( p2->when() < frame )
continue; continue;
nframes_t d = p2->when() - p1->when(); /* do incremental linear interpolation */
for ( nframes_t i = frame - p1->when(); i < d; ++i ) const nframes_t len = p2->when() - p1->when();
{
// *(buf++) = 1.0f - ( 2 * sigmoid_interpolate( p1->control(), p2->control(), i / (float)d ) );
*(buf++) = 1.0f - ( 2 * linear_interpolate( p1->control(), p2->control(), i / (float)d ) );
// *(buf++) = 1.0f - ( 2 * quadratic_interpolate( p1->control(), p2->control(), i / (float)d ) );
if ( ! n-- ) /* scale to -1.0 to 1.0 */
return nframes; const float y1 = 1.0f - ( 2.0f * p1->control() );
const float y2 = 1.0f - ( 2.0f * p2->control() );
const nframes_t start = frame - p1->when();
const float incr = ( y2 - y1 ) / (float)len;
float v = y1 + start * incr;
for ( nframes_t i = start; i < len && n--; ++i, v += incr )
*(buf++) = v;
frame++;
}
} }
return frame; return nframes - n;
} }

View File

@ -50,7 +50,7 @@
/* TODO: read/write data from/to disk in larger chunks to avoid /* TODO: read/write data from/to disk in larger chunks to avoid
* excessive seeking. 256k is supposedly the sweetspot. */ * excessive seeking. 256k is supposedly the sweetspot. */
//float Disk_Stream::seconds_to_buffer = 5.0f; // float Disk_Stream::seconds_to_buffer = 5.0f;
float Disk_Stream::seconds_to_buffer = 2.0f; float Disk_Stream::seconds_to_buffer = 2.0f;
// size_t Disk_Stream::disk_block_frames = 2048; // size_t Disk_Stream::disk_block_frames = 2048;

View File

@ -142,12 +142,13 @@ Playback_DS::disk_thread ( void )
for ( int i = channels(); i--; ) for ( int i = channels(); i--; )
{ {
while ( jack_ringbuffer_write_space( _rb[ i ] ) < block_size )
{ /* while ( jack_ringbuffer_write_space( _rb[ i ] ) < block_size ) */
printf( "IO: disk buffer overrun!\n" ); /* { */
/* FIXME: is this *really* the right thing to do? */ /* printf( "IO: disk buffer overrun!\n" ); */
usleep( 2000 ); /* /\* FIXME: is this *really* the right thing to do? *\/ */
} /* usleep( 2000 ); */
/* } */
/* deinterleave direcectly into the ringbuffer to avoid /* deinterleave direcectly into the ringbuffer to avoid
* unnecessary copying */ * unnecessary copying */