|
From: Martin R. <ru...@us...> - 2004-08-26 09:50:31
|
Update of /cvsroot/foo/foo/libfoo/modules/banff In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27918 Added Files: FOOMAllpass.h FOOMAllpass.m FOOMComb.h FOOMComb.m Makefile.am Log Message: added experimental modules --- NEW FILE: FOOMAllpass.h --- /* -*-Mode:objc-*- */ /* * FOOMAllpass.h * * allpass module * */ /* * foo sound synthesis system * * (C)1993-2004 Gerhard Eckel, Ramon Gonzalez-Arroyo, IRCAM, ZKM * (C)2003-2004 Martin Rumori */ /* * 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: FOOMAllpass.h,v 1.1 2004/08/26 09:50:22 rumori Exp $ */ #ifndef FOOM_FOOMALLPASS_H_INCLUDED #define FOOM_FOOMALLPASS_H_INCLUDED #include <FOO/FOOModule.h> @interface FOOMAllpass : FOOModule <NSCoding> { int _order; sample_t *_states; } - (id) initWithOrder: (int)order; @end #endif /* #ifndef FOOM_FOOMALLPASS_H_INCLUDED */ --- NEW FILE: Makefile.am --- # foo/libfoo/modules/banff/Makefile.am # 2004 rumori # $Id: Makefile.am,v 1.1 2004/08/26 09:50:22 rumori Exp $ noinst_LTLIBRARIES = libfoombanff.la NULL = libfoombanff_la_SOURCES = \ FOOMAllpass.h \ FOOMAllpass.m \ FOOMComb.h \ FOOMComb.m \ $(NULL) if USE_GNUSTEP_BASE include @GNUSTEP_MAKEFILES@/library-combo.make include @GNUSTEP_MAKEFILES@/common.make include @GNUSTEP_MAKEFILES@/Additional/base.make endif FOO_CFLAGS = @FOO_CFLAGS@ FOO_OBJCFLAGS = @FOO_OBJCFLAGS@ @FOO_GNUSTEP_OBJCFLAGS@ FOO_LDFLAGS = @FOO_LDFLAGS@ @FOO_GNUSTEP_LDFLAGS@ FOO_LIBS = @FOO_LIBS@ libfoombanff_la_CFLAGS = $(FOO_CFLAGS) libfoombanff_la_OBJCFLAGS = $(FOO_OBJCFLAGS) \ $(FND_DEFINE) libfoombanff_la_LIBADD = -lm --- NEW FILE: FOOMComb.m --- /* -*-Mode:objc-*- */ /* * FOOMComb.m * * feedback delay line * */ /* * foo sound synthesis system * * (C)1993-2004 Gerhard Eckel, Ramon Gonzalez-Arroyo, IRCAM, ZKM * (C)2003-2004 Martin Rumori */ /* * 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: FOOMComb.m,v 1.1 2004/08/26 09:50:22 rumori Exp $ */ #include "FOOMComb.h" @implementation FOOMComb - (id) initWithTaps: (int)taps maxDelay: (double)maxDelay { _taps = taps; _table = [FOOGlobalsManager getSineXoverXTable: _taps]; _line = NULL; _maxDelayT = maxDelay; return self; } - (void) dealloc { NSZoneFree([self zone], _line); _line = NULL; [super dealloc]; } - reset { [super reset]; if (_line) { NSZoneFree([self zone], _line); _line = NULL; } _ptr = 0; return self; } - startUp { [super startUp]; _maxDelay = SEC_TO_SAM(_maxDelayT); _line = NSZoneCalloc([self zone], _maxDelay, sizeof(sample_t)); _ptr = 0; return self; } - (BOOL) activate { // if (INPUTS < 2 || [INPUT(0) activate] == NO || [INPUT(1) activate] == NO) // { // _active = NO; // } // else // { // _active = YES; // } // take feedback in account [INPUT(0) activate]; [INPUT(1) activate]; [INPUT(2) activate]; [INPUT(3) activate]; return (_active = YES); } - (BOOL) compute { FOOModule *m0, *m1, *m2, *m3; sample_t *input, *delay, *feedback, *wetdry, *output; int i, n, dpos, ipos; double tap, sr, fpos, fti, tdelta; int tot, tinc, ti1, ti2; // total of taps, tap increment sample_t *base, *delta; // lookup table, delta table COMPUTE_PROLOGUE; m0 = INPUT(0); m1 = INPUT(1); m2 = INPUT(2); m3 = INPUT(3); [m0 compute]; [m1 compute]; [m2 compute]; [m3 compute]; input = DATA_OF_MOD(m0); delay = DATA_OF_MOD(m1); feedback = DATA_OF_MOD(m2); wetdry = DATA_OF_MOD(m3); output = DATA_OF_BUF(_buffer); n = BLOCKSIZE; sr = SAMPLERATE; tot = _taps / 2; tinc = [_table getSize] / tot; base = [_table getBase]; delta = [_table getDelta]; while (n--) { // interpolate tap = 0; fpos = *delay++ * sr; ipos = (int)fpos; // shorter delay than samples for interpolation? if (ipos < tot) { FOO_ERROR(NO, YES); ipos = tot; } fti = (fpos - ipos) * tinc; ti1 = (int)fti; ti2 = tinc - ti1 - 1; tdelta = fti - ti1; dpos = _ptr + ipos; while (dpos > _maxDelay - 1) { // wrap around dpos -= _maxDelay; } for (i = tot; i > 0; --i, ti1 += tinc) { tap += _line[dpos--] * (base[ti1] + delta[ti1] * tdelta); if (dpos < 0) { dpos = _maxDelay - 1; } } tdelta = 1 - tdelta; dpos = _ptr + ipos + 1; while (dpos > _maxDelay - 1) { // wrap around dpos -= _maxDelay; } for (i = tot; i > 0; --i, ti2 += tinc) { tap += _line[dpos++] * (base[ti2] + delta[ti2] * tdelta); if (dpos > _maxDelay - 1) { dpos = 0; } } // copy + feedback to delay line _line[_ptr] = tap * *feedback++ + *input; --_ptr; if (_ptr < 0) { // wrap around _ptr = _maxDelay - 1; } // output *output++ = *wetdry * tap + (1 - *wetdry) * *input++; ++wetdry; } COMPUTE_EPILOGUE; } /* * archiving methods */ - (void) encodeWithCoder: (NSCoder *)coder { [super encodeWithCoder: coder]; return; } - (id) initWithCoder: (NSCoder *)coder { self = [super initWithCoder: coder]; return self; } @end --- NEW FILE: FOOMComb.h --- /* -*-Mode:objc-*- */ /* * FOOMComb.h * * feedback delay line * */ /* * foo sound synthesis system * * (C)1993-2004 Gerhard Eckel, Ramon Gonzalez-Arroyo, IRCAM, ZKM * (C)2003-2004 Martin Rumori */ /* * 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: FOOMComb.h,v 1.1 2004/08/26 09:50:22 rumori Exp $ */ #ifndef FOOM_FOOMCOMB_H_INCLUDED #define FOOM_FOOMCOMB_H_INCLUDED #include <FOO/FOOModule.h> #include <FOO/FOOLookupTable.h> @interface FOOMComb : FOOModule <NSCoding> { int _maxDelay; // maximum delay in samples = size of delay line double _maxDelayT; // maximum delay in seconds sample_t *_line; // delay line int _ptr; // write index in delay line int _taps; // num of taps for resampling FOOLookupTable *_table; // sinc table for resampling } - (id) initWithTaps: (int)taps maxDelay: (double)maxDelay; @end #endif /* #ifndef FOOM_FOOMALLPASS_H_INCLUDED */ --- NEW FILE: FOOMAllpass.m --- /* -*-Mode:objc-*- */ /* * FOOMAllpass.m * * module allpass * */ /* * foo sound synthesis system * * (C)1993-2004 Gerhard Eckel, Ramon Gonzalez-Arroyo, IRCAM, ZKM * (C)2003-2004 Martin Rumori */ /* * 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: FOOMAllpass.m,v 1.1 2004/08/26 09:50:22 rumori Exp $ */ #include "FOOMAllpass.h" @implementation FOOMAllpass - (id) initWithOrder: (int)order { _order = order; _states = NSZoneCalloc([self zone], order + 1, sizeof(sample_t)); return self; } - (void) dealloc { NSZoneFree([self zone], _states); [super dealloc]; } - (BOOL) activate { // if (INPUTS < 2 || [INPUT(0) activate] == NO || [INPUT(1) activate] == NO) // { // _active = NO; // } // else // { // _active = YES; // } // take feedback in account [INPUT(0) activate]; [INPUT(1) activate]; _active = YES; return _active; } - (BOOL) compute { FOOModule *m, *r; int j, n; sample_t last, tmp, *out, *in, *rho; COMPUTE_PROLOGUE; m = INPUT(0); r = INPUT(1); [m compute]; [r compute]; in = DATA_OF_MOD(m); rho = DATA_OF_MOD(r); out = DATA_OF_BUF(_buffer); n = BLOCKSIZE; while (n--) { // first in chain tmp = _states[0]; _states[0] = *in++; for (j = 1; j <= _order; ++j) { last = tmp; tmp = _states[j]; _states[j] = *rho * (_states[j] - _states[j - 1]) + last; } // last in chain *out++ = _states[_order]; rho++; } COMPUTE_EPILOGUE; } - (int) incrementBuffer { return 0; } /* * archiving methods */ - (void) encodeWithCoder: (NSCoder *)coder { [super encodeWithCoder: coder]; if ([coder allowsKeyedCoding]) { [coder encodeInt: _order forKey: @"FOOMAllpass:order"]; } else { [coder encodeValueOfObjCType: @encode(int) at: &_order]; } return; } - (id) initWithCoder: (NSCoder *)coder { self = [super initWithCoder: coder]; if ([coder allowsKeyedCoding]) { _order = [coder decodeIntForKey: @"FOOMAllpass:order"]; } else { [coder decodeValueOfObjCType: @encode(int) at: &_order]; } _states = NSZoneCalloc([self zone], _order + 1, sizeof(sample_t)); return self; } @end |