diff options
author | erdgeist <> | 2013-03-30 02:47:28 +0000 |
---|---|---|
committer | erdgeist <> | 2013-03-30 02:47:28 +0000 |
commit | 287d0f897567fa7db30f6a6efa163bff1bc66124 (patch) | |
tree | 52094083bf81abefed91bed680f0bcfd057580db | |
parent | 626486a3916b5276dc6b5b6c8b63db87e73278d2 (diff) |
Add an option to allow seamless connection after last processed frame
-rw-r--r-- | timestretch.c | 11 |
1 files 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 ) { | |||
34 | free( g_overlap_buffer ); | 34 | free( g_overlap_buffer ); |
35 | g_overlap_buffer = malloc( sizeof(short) * g_overlap ); | 35 | g_overlap_buffer = malloc( sizeof(short) * g_overlap ); |
36 | g_firstframe = 1; | 36 | g_firstframe = 1; |
37 | g_offset = 0; | ||
37 | 38 | ||
38 | g_output_length = (sample_rate * OUTPUT_LEN ) / 1000; | 39 | g_output_length = (sample_rate * OUTPUT_LEN ) / 1000; |
39 | if ( g_output_length < g_overlap) | 40 | if ( g_output_length < g_overlap) |
@@ -87,7 +88,7 @@ static unsigned int find_corr_max(const short *input, const short *mixbuf) { | |||
87 | } | 88 | } |
88 | 89 | ||
89 | // Returns the amount of samples that can be discarded from begin of the input buffer | 90 | // Returns the amount of samples that can be discarded from begin of the input buffer |
90 | size_t process_frame( short *input, short *output, short *overlap ) { | 91 | size_t process_frame( short *input, short *output, short *overlap, int lastframe ) { |
91 | int i, i_ = (int)g_overlap; | 92 | int i, i_ = (int)g_overlap; |
92 | unsigned int offset = 0; | 93 | unsigned int offset = 0; |
93 | 94 | ||
@@ -107,6 +108,10 @@ size_t process_frame( short *input, short *output, short *overlap ) { | |||
107 | sampcpy( output + g_overlap, input + offset + g_overlap, g_output_length - g_overlap ); | 108 | sampcpy( output + g_overlap, input + offset + g_overlap, g_output_length - g_overlap ); |
108 | } | 109 | } |
109 | 110 | ||
111 | // On the last frame help connect the next frame from input seamlessly | ||
112 | if( lastframe ) | ||
113 | return offset + g_output_length; | ||
114 | |||
110 | // Remember end of this frame for next frame | 115 | // Remember end of this frame for next frame |
111 | sampcpy( overlap, input + offset + g_output_length, g_overlap ); | 116 | sampcpy( overlap, input + offset + g_output_length, g_overlap ); |
112 | 117 | ||
@@ -122,7 +127,7 @@ int main( int args, char **argv ) { | |||
122 | short outbuf[ g_output_length ]; | 127 | short outbuf[ g_output_length ]; |
123 | short inbuf [ g_input_length ]; | 128 | short inbuf [ g_input_length ]; |
124 | 129 | ||
125 | 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 ); | 130 | // 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 ); |
126 | 131 | ||
127 | int fd_in = open( "in.raw", O_RDONLY ); | 132 | int fd_in = open( "in.raw", O_RDONLY ); |
128 | int fd_out = open( "out.raw", O_CREAT | O_WRONLY | O_TRUNC ); | 133 | int fd_out = open( "out.raw", O_CREAT | O_WRONLY | O_TRUNC ); |
@@ -143,7 +148,7 @@ int main( int args, char **argv ) { | |||
143 | } | 148 | } |
144 | 149 | ||
145 | // Do one cycle of processing and outputting | 150 | // Do one cycle of processing and outputting |
146 | processed = process_frame( inbuf, outbuf, g_overlap_buffer ); | 151 | processed = process_frame( inbuf, outbuf, g_overlap_buffer, 0 ); |
147 | write( fd_out, outbuf, g_output_length * sizeof(short) ); | 152 | write( fd_out, outbuf, g_output_length * sizeof(short) ); |
148 | 153 | ||
149 | memmove( inbuf, inbuf + processed, ( in_fill - processed ) * sizeof(short) ); | 154 | memmove( inbuf, inbuf + processed, ( in_fill - processed ) * sizeof(short) ); |