Category : C Source Code
Archive   : SOX.ZIP
Filename : LOWP.C

 
Output of file : LOWP.C contained in archive : SOX.ZIP

/*
* July 5, 1991
* Copyright 1991 Lance Norskog And Sundry Contributors
* This source code is freely redistributable and may be used for
* any purpose. This copyright notice must be maintained.
* Lance Norskog And Sundry Contributors are not responsible for
* the consequences of using this software.
*/

/*
* Sound Tools Low-Pass effect file.
*
* Algorithm: 1nd order filter.
* From Fugue source code:
*
* output[N] = input[N] * A + input[N-1] * B
*
* A = 2.0 * pi * center
* B = exp(-A / frequency)
*/

#include
#include "st.h"

/* Private data for Lowpass effect */
typedef struct lowpstuff {
float center;
double A, B;
double in1;
} *lowp_t;

/*
* Process options
*/
lowp_getopts(effp, n, argv)
eff_t effp;
int n;
char **argv;
{
lowp_t lowp = (lowp_t) effp->priv;

if ((n < 1) || !sscanf(argv[0], "%f", &lowp->center))
fail("Usage: lowp center");
}

/*
* Prepare processing.
*/
lowp_start(effp)
eff_t effp;
{
lowp_t lowp = (lowp_t) effp->priv;
if (lowp->center > effp->ininfo.rate*2)
fail("Lowpass: center must be < minimum data rate*2\n");

lowp->A = (M_PI * 2.0 * lowp->center) / effp->ininfo.rate;
lowp->B = exp(-lowp->A / effp->ininfo.rate);
lowp->in1 = 0.0;
}

/*
* Processed signed long samples from ibuf to obuf.
* Return number of samples processed.
*/

lowp_flow(effp, ibuf, obuf, isamp, osamp)
eff_t effp;
long *ibuf, *obuf;
int *isamp, *osamp;
{
lowp_t lowp = (lowp_t) effp->priv;
register counter, tablen;
int len, done;
register long mult;
register short *sinetab;
double d, d1;
long l;

len = ((*isamp > *osamp) ? *osamp : *isamp);

/* yeah yeah yeah registers & integer arithmetic yeah yeah yeah */
for(done = 0; done < len; done++) {
l = *ibuf++;
d = lowp->A * (l / 65536) + lowp->B * (lowp->in1 / 65536);
d *= 0.8;
if (d > 32767)
d = 32767;
if (d < - 32767)
d = - 32767;
lowp->in1 = l;
*obuf++ = d * 65536;
}
}

/*
* Do anything required when you stop reading samples.
* Don't close input file!
*/
lowp_stop(effp)
eff_t effp;
{
/* nothing to do */
}



  3 Responses to “Category : C Source Code
Archive   : SOX.ZIP
Filename : LOWP.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/