@@ -121,15 +121,12 @@ void videodecodingthread(void * ctx) {
121121 int sizetopoll = height * width ;
122122 float * buffer = (float * ) malloc (sizeof (float ) * bufsize );
123123 float * screenbuffer = (float * ) malloc (sizeof (float ) * bufsize );
124-
125- float pmax , pmin ;
124+ for (i = 0 ; i < bufsize ; i ++ ) screenbuffer [i ] = 0.0f ;
126125
127126 while (context -> this -> running ) {
128- float max = -9999999999999 ;
129- float min = 9999999999999 ;
130- const float span = (pmax == pmin ) ? (0 ) : (pmax - pmin );
131- const float lowpassvalue = context -> this -> motionblur ;
132- const float antilowpassvalue = 1.0f - lowpassvalue ;
127+
128+ const double lowpassvalue = context -> this -> motionblur ;
129+ const double antilowpassvalue = 1.0 - lowpassvalue ;
133130
134131 if (context -> this -> height != height || context -> this -> width != width ) {
135132 height = context -> this -> height ;
@@ -140,22 +137,27 @@ void videodecodingthread(void * ctx) {
140137 bufsize = sizetopoll ;
141138 buffer = (float * ) realloc (buffer , sizeof (float ) * bufsize );
142139 screenbuffer = (float * ) realloc (screenbuffer , sizeof (float ) * bufsize );
140+ for (i = 0 ; i < bufsize ; i ++ ) screenbuffer [i ] = 0.0f ;
143141 }
144142 }
145143
146144 if (cb_rem_blocking (& context -> circbuf , buffer , sizetopoll ) == CB_OK ) {
147145
148- for (i = 0 ; i < sizetopoll ; i ++ ) {
149- float val = screenbuffer [i ] * lowpassvalue + buffer [i ] * antilowpassvalue ;
150-
146+ float max = buffer [0 ];
147+ float min = max ;
148+ for (i = 1 ; i < sizetopoll ; i ++ ) {
149+ const float val = buffer [i ];
151150 if (val > max ) max = val ; else if (val < min ) min = val ;
152- screenbuffer [i ] = (val - pmin ) / span ;
153151 }
154152
155- context -> cb ( screenbuffer , width , height , context -> ctx ) ;
153+ const float span = max - min ;
156154
157- pmax = max ;
158- pmin = min ;
155+ for (i = 0 ; i < sizetopoll ; i ++ ) {
156+ const float val = (buffer [i ] - min ) / span ;
157+ screenbuffer [i ] = screenbuffer [i ] * lowpassvalue + val * antilowpassvalue ;
158+ }
159+
160+ context -> cb (screenbuffer , width , height , context -> ctx );
159161 }
160162 }
161163
@@ -301,7 +303,7 @@ void process(float *buf, uint32_t len, void *ctx, int dropped) {
301303
302304
303305 // section for manual syncing
304- const int syncoffset = context -> this -> syncoffset ;
306+ const int syncoffset = - context -> this -> syncoffset ;
305307 if (syncoffset > 0 )
306308 context -> dropped += syncoffset ;
307309 else if (syncoffset < 0 )
0 commit comments