From 287d0f897567fa7db30f6a6efa163bff1bc66124 Mon Sep 17 00:00:00 2001 From: erdgeist <> Date: Sat, 30 Mar 2013 02:47:28 +0000 Subject: Add an option to allow seamless connection after last processed frame --- timestretch.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/timestretch.c b/timestretch.c index 14ed732..b15bfe7 100644 --- a/timestretch.c +++ b/timestretch.c @@ -34,6 +34,7 @@ static size_t calc_convert_values( int sample_rate, float tempo ) { free( g_overlap_buffer ); g_overlap_buffer = malloc( sizeof(short) * g_overlap ); g_firstframe = 1; + g_offset = 0; g_output_length = (sample_rate * OUTPUT_LEN ) / 1000; if ( g_output_length < g_overlap) @@ -87,7 +88,7 @@ static unsigned int find_corr_max(const short *input, const short *mixbuf) { } // Returns the amount of samples that can be discarded from begin of the input buffer -size_t process_frame( short *input, short *output, short *overlap ) { +size_t process_frame( short *input, short *output, short *overlap, int lastframe ) { int i, i_ = (int)g_overlap; unsigned int offset = 0; @@ -107,6 +108,10 @@ size_t process_frame( short *input, short *output, short *overlap ) { sampcpy( output + g_overlap, input + offset + g_overlap, g_output_length - g_overlap ); } + // On the last frame help connect the next frame from input seamlessly + if( lastframe ) + return offset + g_output_length; + // Remember end of this frame for next frame sampcpy( overlap, input + offset + g_output_length, g_overlap ); @@ -122,7 +127,7 @@ int main( int args, char **argv ) { short outbuf[ g_output_length ]; short inbuf [ g_input_length ]; - printf( "DEBUG: OL: %zd SWL: %zd SL: %zd SK: %zd ICM: %zd\n", g_overlap, g_output_length, g_corr_length, g_skip / 65536, g_input_length ); +// printf( "DEBUG: OL: %zd SWL: %zd SL: %zd SK: %zd ICM: %zd\n", g_overlap, g_output_length, g_corr_length, g_skip / 65536, g_input_length ); int fd_in = open( "in.raw", O_RDONLY ); int fd_out = open( "out.raw", O_CREAT | O_WRONLY | O_TRUNC ); @@ -143,7 +148,7 @@ int main( int args, char **argv ) { } // Do one cycle of processing and outputting - processed = process_frame( inbuf, outbuf, g_overlap_buffer ); + processed = process_frame( inbuf, outbuf, g_overlap_buffer, 0 ); write( fd_out, outbuf, g_output_length * sizeof(short) ); memmove( inbuf, inbuf + processed, ( in_fill - processed ) * sizeof(short) ); -- cgit v1.2.3