<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">I dug up the following code, but it's not from a shipping product, and I'm not sure I remember how it works.</blockquote><div><br></div><div>This is the "modified coupled form" algorithm, sometimes called "magic circle algorithm":</div><div><br></div><div><a href="https://ccrma.stanford.edu/~jos/pdf/GordonAndSmith86.pdf">https://ccrma.stanford.edu/~jos/pdf/GordonAndSmith86.pdf</a></div><div><br></div><div>It works fairly well in fixed point too - the rounding errors manifest themselves as a small DC offset, rather than as a loss of amplitude.</div><div><br></div><div>Unlike a direct form, second order filter (the recurrence y = 2 * coeff * y_ - y__), this algorithm handles coefficient changes pretty well - actually, any value of the sinZ and cosZ variable correspond to a valid state of the filter.</div><div><br></div><div>And you can get away with the sinf in the constructor (or in your buffer filling routine if you allow FM) because an appropriate polynomial approximation of degree 3 of sinf would introduce only a few cents of tuning error in the high frequencies.</div></div></div></div>