-------- End of gnuplot file ---------------------
*/
/*
* adapted from Sound Tools skeleton effect file.
*/
#include <math.h>
#include "st.h"
/* Private data for deemph file */
typedef struct deemphstuff {
LONG lastin;
double lastout;
} *deemph_t;
/*
* Process options
*
* Don't do initialization now.
* The 'info' fields are not yet filled in.
*/
void deemph_getopts(effp, n, argv)
eff_t effp;
int n;
char **argv;
{
if (n)
fail("Deemphasis filtering effect takes no options.\n");
if (sizeof(double)*PRIVSIZE < sizeof(struct deemphstuff))
fail("Internal error: PRIVSIZE too small.\n");
}
/*
* Prepare processing.
* Do all initializations.
*/
void deemph_start(effp)
eff_t effp;
{
/* check the input format */
if (effp->ininfo.style != SIGN2
|| effp->ininfo.rate != 44100
|| effp->ininfo.size != WORD)
fail("The deemphasis effect works only with audio cd like samples.\nThe input format however has %d Hz sample rate and %d-byte%s signed linearly coded samples.",
effp->ininfo.rate, effp->ininfo.size,
effp->ininfo.style != SIGN2 ? ", but not" : "");
{
deemph_t deemph = (deemph_t) effp->priv;
deemph->lastin = 0;
deemph->lastout = 0.0;
}
}
/*
* Processed signed long samples from ibuf to obuf.
* Return number of samples processed.
*/
/* filter coefficients */
#define a1 -0.62786881719628784282
#define b0 0.45995451989513153057
#define b1 -0.08782333709141937339
void deemph_flow(effp, ibuf, obuf, isamp, osamp)
eff_t effp;
LONG *ibuf, *obuf;
int *isamp, *osamp;
{
deemph_t deemph = (deemph_t) effp->priv;
int len, done;
len = ((*isamp > *osamp) ? *osamp : *isamp);
for(done = len; done; done--) {
deemph->lastout = *ibuf * b0 +
deemph->lastin * b1 -
deemph->lastout * a1;
deemph->lastin = *ibuf++;
*obuf++ = deemph->lastout > 0.0 ?
deemph->lastout + 0.5 :
deemph->lastout - 0.5;
}
}
/*
* Drain out remaining samples if the effect generates any.
*/
void deemph_drain(effp, obuf, osamp)
LONG *obuf;
int *osamp;
{
/* nothing to do */
}
/*
* Do anything required when you stop reading samples.