## An ffmpeg and SDL Tutorial

The function we are using is a weighted mean using a geometric series as its weights. A weighted mean is defined like this:

```w_0*x_0 + w_1*x_1 + ... + w_n*x_n
---------------------------------
w_0 + w_1 + ... + w_n
```
If you substitute 1 in for each w_n, you get your normal everyday arithmetic mean (a.k.a. an average).

Our function is basically a repetition of:

```total = d_x + c*avg;
```
However, you can also look at it like this:
```total = c^n*d_0 + c^(n-1)*d_1 + ... + c*d_(n-1) + d_n
```
in which case, this is just the top part of a weighted mean with c^n, c^(n-1)... as the weights. That means the bottom half is c^n+c^(n-1)..., which, as you may have guessed, is a simple geometric sum which works out to 1/(1-c) as n approaches infinity.

So, by approximation, the weighted mean of our sequence of diffs is simply:

``` total
-------  = total * (1-c)
1
-----
(1-c)
```
So when we get the final total and want to know the average, we just multiply it by 1-c and get the answer! There is probably a name for this way of taking the mean of a sequence, but I'm pretty ignorant and I don't know it. If you know it, please email me.