// these BLEP routines are based on code by aciddose (written for this project) #include #include "pt2_header.h" // ASSERT() #include "pt2_blep.h" static const float fMinBlepData[256+1] = // zero-crossings = 16, oversampling = 16 { 1.00004773026135f, 1.00007032652592f, 1.00002629548696f, 0.99991042477334f, 0.99971574437906f, 0.99943301491973f, 0.99905008577133f, 0.99855112191953f, 0.99791570623359f, 0.99711783269263f, 0.99612481549521f, 0.99489614857036f, 0.99338235932343f, 0.99152390900306f, 0.98925019936448f, 0.98647875083318f, 0.98311462068259f, 0.97905013042551f, 0.97416496935867f, 0.96832673577171f, 0.96139196863479f, 0.95320771064636f, 0.94361362852859f, 0.93244469872728f, 0.91953444666912f, 0.90471870605387f, 0.88783984202969f, 0.86875135933125f, 0.84732279443751f, 0.82344477044769f, 0.79703407560492f, 0.76803861210072f, 0.73644205178319f, 0.70226803036462f, 0.66558371223417f, 0.62650256440042f, 0.58518619058944f, 0.54184509505589f, 0.49673826994592f, 0.45017152956776f, 0.40249454893934f, 0.35409660154602f, 0.30540103122785f, 0.25685853424993f, 0.20893936851305f, 0.16212464609744f, 0.11689690145969f, 0.07373015922794f, 0.03307975137399f,-0.00462784755123f,-0.03900488738235f,-0.06971162926049f, -0.09646477670936f,-0.11904479056083f,-0.13730185175956f,-0.15116026871791f, -0.16062116599949f,-0.16576333755564f,-0.16674219914150f,-0.16378682930955f, -0.15719514477109f,-0.14732731208884f,-0.13459755174100f,-0.11946454074151f, -0.10242066447381f,-0.08398040562800f,-0.06466818677869f,-0.04500600213669f, -0.02550118260638f,-0.00663463608527f, 0.01115010807263f, 0.02745674499584f, 0.04194465845149f, 0.05433577298831f, 0.06441961313702f, 0.07205644376420f, 0.07717842460241f, 0.07978877284496f, 0.07995898846821f, 0.07782425560056f, 0.07357718784673f, 0.06746013419408f, 0.05975630338411f, 0.05077999709992f, 0.04086626498950f, 0.03036030675146f, 0.01960694796123f, 0.00894050709705f, -0.00132464820813f,-0.01090258650078f,-0.01954310735649f,-0.02703765766771f, -0.03322373053940f,-0.03798766068065f,-0.04126578449626f,-0.04304398709720f, -0.04335571031241f,-0.04227854375681f,-0.03992956352841f,-0.03645961883170f, -0.03204679469291f,-0.02688929818278f,-0.02119802576361f,-0.01518907043046f, -0.00907641945536f,-0.00306507731689f, 0.00265517536155f, 0.00791520624781f, 0.01257099386602f, 0.01650702214695f, 0.01963854212897f, 0.02191267793446f, 0.02330839522845f, 0.02383538912510f, 0.02353198363360f, 0.02246216509800f, 0.02071189677132f, 0.01838488000347f, 0.01559793910552f, 0.01247621163647f, 0.00914832376417f, 0.00574172184735f, 0.00237831706549f,-0.00082941942501f, -0.00378179676068f,-0.00639459247557f,-0.00860102920232f,-0.01035300983349f, -0.01162160972920f,-0.01239685183977f,-0.01268681549751f,-0.01251615129799f, -0.01192409228163f,-0.01096206506234f,-0.00969101334594f,-0.00817855034507f, -0.00649605602507f,-0.00471583017880f,-0.00290840345555f,-0.00114009622001f, 0.00052909984587f, 0.00204725942726f, 0.00337184072590f, 0.00447056083053f, 0.00532182631852f, 0.00591473333171f, 0.00624866696377f, 0.00633254323612f, 0.00618374782353f, 0.00582683374501f, 0.00529204531620f, 0.00461373775080f, 0.00382876100684f, 0.00297487301605f, 0.00208924162385f, 0.00120708679112f, 0.00036050531378f,-0.00042249002120f,-0.00111869581094f,-0.00171019786579f, -0.00218460598499f,-0.00253505394938f,-0.00275998364047f,-0.00286273941939f, -0.00285100451055f,-0.00273611501766f,-0.00253228931728f,-0.00225581097088f, -0.00192420208046f,-0.00155542135810f,-0.00116711730848f,-0.00077596209062f, -0.00039708611282f,-0.00004362750874f, 0.00027359537161f, 0.00054628617995f, 0.00076875068054f, 0.00093786279763f, 0.00105292874042f, 0.00111546456690f, 0.00112890482356f, 0.00109826120804f, 0.00102975057235f, 0.00093041107779f, 0.00080772402903f, 0.00066925697802f, 0.00052234124308f, 0.00037379418988f, 0.00022969362621f, 0.00009520862546f,-0.00002551184428f,-0.00012939382208f, -0.00021444050978f,-0.00027968738369f,-0.00032511748479f,-0.00035154514415f, -0.00036047694738f,-0.00035395882394f,-0.00033441780628f,-0.00030450629809f, -0.00026695569118f,-0.00022444495391f,-0.00017948846229f,-0.00013434593655f, -0.00009095595605f,-0.00005089322027f,-0.00001534855779f, 0.00001487029752f, 0.00003931991527f, 0.00005788765827f, 0.00007074706353f, 0.00007830581954f, 0.00008114993934f, 0.00007998745195f, 0.00007559452061f, 0.00006876638225f, 0.00006027492772f, 0.00005083414480f, 0.00004107406031f, 0.00003152327371f, 0.00002259969810f, 0.00001460873218f, 0.00000774779095f, 0.00000211592705f, -0.00000227282161f,-0.00000547372762f,-0.00000759460765f,-0.00000877914828f, -0.00000919128991f,-0.00000900141596f,-0.00000837486262f,-0.00000746303571f, -0.00000639720908f,-0.00000528489498f,-0.00000420852882f,-0.00000322610247f, -0.00000237331439f,-0.00000166677874f,-0.00000110784564f,-0.00000068662497f, -0.00000038586882f,-0.00000018444544f,-0.00000006022227f, 0.00000000774072f, 0.00000003770883f, 0.00000004445794f, 0.00000003903430f, 0.00000002896293f, 0.00000001876399f, 0.00000001063694f, 0.00000000518710f, 0.00000000209367f, 0.00000000064895f, 0.00000000013202f, 0.00000000001159f, 0.00000000000000f, 0.00000000000000f // copy of last point required for interpolation }; // linear interpolation macro #define LERP(p1, p2, frac) ((p1) + (((p2) - (p1)) * (frac))) void blepAdd(blep_t *b, const float fOffset, const float fAmplitude) { ASSERT(fOffset >= 0.0f && fOffset < 1.0f); float f = fOffset * BLEP_SP; const int32_t fInt = (int32_t)f; // get integer part of f const float *fBlepSrc = fMinBlepData + fInt; f -= fInt; // remove integer part from f int32_t i = b->index; for (int32_t n = 0; n < BLEP_NS; n++) { b->fBuffer[i] += fAmplitude * LERP(fBlepSrc[0], fBlepSrc[1], f); fBlepSrc += BLEP_SP; i = (i + 1) & BLEP_RNS; } b->samplesLeft = BLEP_NS; } float blepRun(blep_t *b, const float fInput) { float fBlepOutput = fInput + b->fBuffer[b->index]; b->fBuffer[b->index] = 0.0f; b->index = (b->index + 1) & BLEP_RNS; b->samplesLeft--; return fBlepOutput; }