@@ -113,6 +113,8 @@ void videodecodingthread(void * ctx) {
113113 mutex_signal ((mutex_t * ) context -> this -> mutex_video_stopped );
114114}
115115
116+
117+
116118void process (float * buf , uint32_t len , void * ctx ) {
117119 tsdr_context_t * context = (tsdr_context_t * ) ctx ;
118120
@@ -122,7 +124,7 @@ void process(float *buf, uint32_t len, void *ctx) {
122124 int outbufsize = context -> bufsize ;
123125
124126 const double post = context -> this -> pixeltimeoversampletime ;
125- const double post1 = 1.0 / post ;
127+ const double post1 = 1.0 / post ;
126128 const int pids = (int ) ((size - context -> offset ) / post );
127129
128130 // resize buffer so it fits
@@ -132,8 +134,8 @@ void process(float *buf, uint32_t len, void *ctx) {
132134 }
133135
134136 const double offset = context -> offset ;
135- double t = context -> offset + post ;
136- float contrib = context -> contributionfromlast ;
137+ double t = context -> offset ;
138+ double contrib = context -> contributionfromlast ;
137139 const float prev_max = context -> max ;
138140 const float prev_min = context -> min ;
139141 const float prev_span = (prev_min == prev_max ) ? (1 ) : (1.0f / (prev_max - prev_min ));
@@ -150,18 +152,54 @@ void process(float *buf, uint32_t len, void *ctx) {
150152
151153 const float val = sqrtf (I * I + Q * Q );
152154
153- const int id1 = id + 1 ;
155+ // we are in case:
156+ // pid
157+ // t (in terms of id)
158+ // . ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! pixels (pid)
159+ // ____|__val__|_______|_______|_______| samples (id)
160+ // id id+1 id+2
154161
155- while (t <= id1 ) {
156- const float pix = (t >= id ) ? ( val ) : (( contrib + val * (t - id ))* post1 ) ;
162+ if (t < id ) {
163+ const float pix = (contrib + val * (t + post - id ))* post1 ;
157164 if (pix > max ) max = pix ; else if (pix < min ) min = pix ;
158165 outbuf [pid ++ ] = (pix - prev_min ) * prev_span ;
159- t += post ;
160166 contrib = 0 ;
167+ t = offset + pid * post ;
161168 }
162169
163- const float contrfract = id1 - t + post ;
170+ // we are in case:
171+ // pid
172+ // t t+post (in terms of id)
173+ // . ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! pixels (pid)
174+ // ____|__val__|_______|_______|_______| samples (id)
175+ // id
176+
177+ while (t + post < id + 1 ) {
178+ const float pix = val ;
179+ if (pix > max ) max = pix ; else if (pix < min ) min = pix ;
180+ outbuf [pid ++ ] = (pix - prev_min ) * prev_span ;
181+ t = offset + pid * post ;
182+ }
183+
184+ // we are in case:
185+ // pid
186+ // t (in terms of id)
187+ // . ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! pixels (pid)
188+ // ____|__val__|_______|_______|_______| samples (id)
189+ // id id+1 id+2
190+
191+ const float contrfract = id + 1 - t ;
164192 contrib += (contrfract < 0 ) ? (val ) : (contrfract * val );
193+
194+
195+ // gaussian distrib is
196+ // exp(-x^2/(2*s^2))
197+ // s^2 = 0.2 is a nice number
198+ // if we put -1/(2*s^2) = a
199+ // the integral has expansion x + (a*x^3)/3 + (a^2*x^5)/10
200+ // i want this from -1 to 1 to be equal to 1
201+ // so multiply by = 1 / (2 + 2*a/3 + a^2/5)
202+
165203 }
166204
167205 context -> bufsize = outbufsize ;
@@ -171,8 +209,8 @@ void process(float *buf, uint32_t len, void *ctx) {
171209 context -> max = max ;
172210 context -> min = min ;
173211
174- // if (pid != pids)
175- // printf("Pid %d; pids %d; t %.4f, size %d, offset %.4f\n", pid, pids, t, size, context->offset);
212+ if (pid != pids )
213+ printf ("Pid %d; pids %d; t %.4f, size %d, offset %.4f\n" , pid , pids , t , size , context -> offset );
176214
177215 cb_add (& context -> circbuf , outbuf , pid );
178216}
0 commit comments