@@ -26,9 +26,9 @@ struct tsdr_context {
2626 void * ctx ;
2727 CircBuff_t circbuf ;
2828 double offset ;
29- double contributionfromlast ;
30- double max ;
31- double min ;
29+ float contributionfromlast ;
30+ float max ;
31+ float min ;
3232 } typedef tsdr_context_t ;
3333
3434int tsdr_setsamplerate (tsdr_lib_t * tsdr , uint32_t rate ) {
@@ -122,6 +122,7 @@ void process(float *buf, uint32_t len, void *ctx) {
122122 int outbufsize = context -> bufsize ;
123123
124124 const double post = context -> this -> pixeltimeoversampletime ;
125+ const double post1 = 1.0 / post ;
125126 const int pids = (int ) ((size - context -> offset ) / post );
126127
127128 // resize buffer so it fits
@@ -131,45 +132,47 @@ void process(float *buf, uint32_t len, void *ctx) {
131132 }
132133
133134 const double offset = context -> offset ;
134- double t = context -> offset ;
135- double contrib = context -> contributionfromlast ;
136- const double prev_max = context -> max ;
137- const double prev_min = context -> min ;
138- const double prev_span = (prev_min == prev_max ) ? (1 ) : (1.0f / (prev_max - prev_min ));
139- double max = -1 , min = 1 ;
135+ double t = context -> offset + post ;
136+ float contrib = context -> contributionfromlast ;
137+ const float prev_max = context -> max ;
138+ const float prev_min = context -> min ;
139+ const float prev_span = (prev_min == prev_max ) ? (1 ) : (1.0f / (prev_max - prev_min ));
140+ float max = -1 , min = 1 ;
140141
141142 int pid = 0 ;
142143 int i = 0 ;
143144 int id ;
144145 int j ;
145- for (id = 0 ; id < size ; id ++ ) {
146- const double I = buf [i ++ ];
147- const double Q = buf [i ++ ];
148146
149- const double val = sqrt (I * I + Q * Q );
147+ for (id = 1 ; id < size ; id ++ ) {
148+ const float I = buf [i ++ ];
149+ const float Q = buf [i ++ ];
150+
151+ const float val = sqrtf (I * I + Q * Q );
150152
151153 const int id1 = id + 1 ;
152154
153- while (t <= id1 - post ) {
154- const double pix = (t >= id ) ? (val ) : ((contrib + val * (t + post - id ))* post );
155+ while (t <= id1 ) {
156+ const float pix = (t >= id ) ? (val ) : ((contrib + val * (t - id ))* post1 );
155157 if (pix > max ) max = pix ; else if (pix < min ) min = pix ;
156158 outbuf [pid ++ ] = (pix - prev_min ) * prev_span ;
157- t = offset + pid * post ;
159+ t += post ;
158160 contrib = 0 ;
159161 }
160162
161- const double contrfract = id1 - t ;
162- contrib += (contrfract >= 1 ) ? (val ) : (contrfract * val );
163+ const float contrfract = id1 - t + post ;
164+ contrib += (contrfract < 0 ) ? (val ) : (contrfract * val );
163165 }
164166
165- if (pid != pids ) printf ("Pid %d is not pids %d" , pid , pids );
166-
167167 context -> bufsize = outbufsize ;
168168 context -> buffer = outbuf ;
169- context -> offset = t - size ;
169+ context -> offset = offset + pid * post - size ;
170170 context -> contributionfromlast = contrib ;
171- context -> max = (context -> max + max )/2.0f ;
172- context -> min = (context -> min + min )/2.0f ;
171+ context -> max = max ;
172+ context -> min = min ;
173+
174+ // if (pid != pids)
175+ // printf("Pid %d; pids %d; t %.4f, size %d, offset %.4f\n", pid, pids, t, size, context->offset);
173176
174177 cb_add (& context -> circbuf , outbuf , pid );
175178}
0 commit comments