Update of /cvsroot/foo/foo/libfoo/modules/orthodox
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32253
Added Files:
FOOMKillDC.h FOOMKillDC.m
Log Message:
new kill-dc module
--- NEW FILE: FOOMKillDC.m ---
/* -*-Mode:objc-*- */
/*
* FOOMKillDC.m
*
* module kill dc
*
*/
/*
* foo sound synthesis system
*
* (C) 1993-2005 Gerhard Eckel, Ramon Gonzalez-Arroyo
* (C) 2003-2005 Martin Rumori
* (C) 1993-1996 IRCAM, ZKM
*/
/*
* This file is part of foo.
*
* foo is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* foo is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with foo; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* $Id: FOOMKillDC.m,v 1.1 2005/08/26 19:32:25 gurx Exp $ */
#include "FOOMKillDC.h"
#include <math.h>
#define INFINITE_TAIL 2147483647 // 2^31-1 samples => ~12 hours at 50 kHz
@implementation FOOMKillDC
- initializeParams: (double*)p
{
_coef = p[0];
_xm = 0;
_ym = 0;
_first = YES;
return self;
}
- reset
{
[super reset];
_xm = 0;
_ym = 0;
_first = YES;
return self;
}
- (BOOL) activate
{
_active = NO;
if (INPUTS == 0)
{
return _active;
}
if ([INPUT(0) activate] == YES)
{
_tail = INFINITE_TAIL;
_active = YES;
}
else if (_tail > 0)
{
if (_tail == INFINITE_TAIL)
{
_tail = INFINITE_TAIL; // calculate tail here, now infinite !
}
else
{
_tail -= BLOCKSIZE;
}
_active = YES;
}
else
{
_active = NO;
}
return _active;
}
- (BOOL) compute
{
sample_t *in, *out, y;
double coef, xmt, ymt, offt, val;
int n;
id m ;
COMPUTE_PROLOGUE;
n = BLOCKSIZE;
m = INPUT(0);
[m compute];
in = DATA_OF_MOD(m);
out = DATA_OF_BUF(_buffer);
if (_first == YES)
{
_first = NO;
_off = *in;
}
coef = _coef;
offt = _off;
xmt = _xm;
ymt = _ym;
while (n--)
{
val = *in++ - offt;
y = val - xmt + coef * ymt;
xmt = val;
ymt = y;
*out++ = y;
}
_xm = xmt;
_ym = ymt;
COMPUTE_EPILOGUE;
}
/*
* archiving methods
*/
- (void) encodeWithCoder: (NSCoder *)coder
{
[super encodeWithCoder: coder];
if ([coder allowsKeyedCoding])
{
[coder encodeDouble: _coef forKey: @"FOOMKillDC:coef"];
}
else
{
[coder encodeValueOfObjCType: @encode(double) at: &_coef];
}
return;
}
- (id) initWithCoder: (NSCoder *)coder
{
self = [super initWithCoder: coder];
if ([coder allowsKeyedCoding])
{
_coef = [coder decodeDoubleForKey: @"FOOMKillDC:coef"];
}
else
{
[coder decodeValueOfObjCType: @encode(double) at: &_coef];
}
return self;
}
@end
--- NEW FILE: FOOMKillDC.h ---
/* -*-Mode:objc-*- */
/*
* FOOMKillDC.h
*
* module kill dc
*
*/
/*
* foo sound synthesis system
*
* (C) 1993-2005 Gerhard Eckel, Ramon Gonzalez-Arroyo
* (C) 2003-2005 Martin Rumori
* (C) 1993-1996 IRCAM, ZKM
*/
/*
* This file is part of foo.
*
* foo is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* foo is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with foo; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* $Id: FOOMKillDC.h,v 1.1 2005/08/26 19:32:25 gurx Exp $ */
#ifndef FOOM_FOOMKillDC_H_INCLUDED
#define FOOM_FOOMKillDC_H_INCLUDED
#include <FOO/FOOEagerModule.h>
@interface FOOMKillDC : FOOEagerModule <NSCoding>
{
double _coef;
double _xm, _ym;
int _tail;
int _first;
double _off;
}
- initializeParams: (double*)p;
@end
#endif /* #ifndef FOOM_FOOMKillDC_H_INCLUDED */
|