Update of /cvsroot/foo/foo/libfoo/modules In directory sc8-pr-cvs17.sourceforge.net:/tmp/cvs-serv7604 Modified Files: Makefile.am Added Files: FOOMAdd.h FOOMAdd.m FOOMAllpass.h FOOMAllpass.m FOOMBandlimitedNoise.h FOOMBandlimitedNoise.m FOOMComb.h FOOMComb.m FOOMConstant.h FOOMConstant.m FOOMConstantBiquad.h FOOMConstantBiquad.m FOOMConstantTwoPole.h FOOMConstantTwoPole.m FOOMConstantTwoPoleTwoZero.h FOOMConstantTwoPoleTwoZero.m FOOMDiff.h FOOMDiff.m FOOMDirac.h FOOMDirac.m FOOMDiv.h FOOMDiv.m FOOMExpon.h FOOMExpon.m FOOMFiltreVariableEtat.h FOOMFiltreVariableEtat.m FOOMFof.h FOOMFof.m FOOMGate.h FOOMGate.m FOOMInteg.h FOOMInteg.m FOOMKillDC.h FOOMKillDC.m FOOMLine.h FOOMLine.m FOOMLookup.h FOOMLookup.m FOOMMath.h FOOMMath.m FOOMMul.h FOOMMul.m FOOMNeg.h FOOMNeg.m FOOMNoise.h FOOMNoise.m FOOMOscillator.h FOOMOscillator.m FOOMReadBpf.h FOOMReadBpf.m FOOMReadSnd.h FOOMReadSnd.m FOOMReadTranspSnd.h FOOMReadTranspSnd.m FOOMReverb.h FOOMReverb.m FOOMReverb8.h FOOMReverb8.m FOOMReverbOutput.h FOOMReverbOutput.m FOOMSub.h FOOMSub.m FOOMTransposeBpf.h FOOMTransposeBpf.m FOOMTransposeSnd.h FOOMTransposeSnd.m FOOMVariableTwoPole.h FOOMVariableTwoPole.m Log Message: relocated modules --- NEW FILE: FOOMLookup.h --- /* -*-Mode:objc-*- */ /* * FOOMLookup.h * * module lookup * */ /* * 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: FOOMLookup.h,v 1.1 2007/12/14 14:16:12 rumori Exp $ */ #ifndef FOOM_FOOMLOOKUP_H_INCLUDED #define FOOM_FOOMLOOKUP_H_INCLUDED #include <FOO/FOOEagerModule.h> #include <FOO/FOOSubstrate.h> #include <FOO/FOOLookupTable.h> @interface FOOMLookup : FOOEagerModule <NSCoding> { /* Substrate *substrate; // statically typed */ id _substrate; sample_t *_samples; int _offset; int _count; int _taps; FOOLookupTable *_table; } - initializeWith: (FOOSubstrate *)substr taps: (int)n; @end #endif /* #ifndef FOOM_FOOMLOOKUP_H_INCLUDED */ --- NEW FILE: FOOMLookup.m --- /* -*-Mode:objc-*- */ /* * FOOMLookup.m * * module lookup * */ /* * 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: FOOMLookup.m,v 1.1 2007/12/14 14:16:12 rumori Exp $ */ #include "FOOMLookup.h" #include <FOO/FOOSoundFile.h> #include <FOO/FOOSoundStream.h> #include <FOO/FOORegion.h> #define SAMPLE_BUFFER_SIZE 1024 // should be several times the taps size @implementation FOOMLookup - initializeWith: (FOOSubstrate *)substr taps: (int)n { if ([substr isKindOfClass: [FOOSoundFile class]] == NO && [substr isKindOfClass: [FOOSoundStream class]] == NO && [substr isKindOfClass: [FOORegion class]] == NO) { FOO_ERROR(YES, self); } _substrate = substr; _taps = n; _count = SAMPLE_BUFFER_SIZE; _offset = -_count; _samples = NSZoneCalloc([self zone], _count, sizeof(sample_t)); _table = [FOOGlobalsManager getSineXoverXTable: _taps]; return self; } - (void) dealloc { NSZoneFree([self zone], _samples); [super dealloc]; } - reset { [super reset]; memset(_samples, 0, _count * sizeof(sample_t)); _offset = -_count; return self; } - (BOOL) activate { if ([_inputs count] == 0) { return (_active = NO); } _active = [[_inputs objectAtIndex: 0] activate]; return _active; } - (BOOL) compute { id m; sample_t *sb, *in, *out, *base, *delta; double sr, pos, sdelta; int n, tinc, size, ipos, cot, tot; COMPUTE_PROLOGUE; m = [_inputs objectAtIndex: 0]; [m compute]; n = BLOCKSIZE; sr = SAMPLERATE; sb = _samples; in = [[m getBuffer] data]; out = [_buffer data]; tot = _taps / 2; cot = _count / 2; size = [_substrate size]; base = [_table getBase]; delta = [_table getDelta]; tinc = [_table getSize] / tot; while (n--) { pos = *in++ * sr; ipos = (int) pos; sdelta = pos - ipos; if (ipos >= size || ipos < 0) { // not completely correct *out++ = 0; continue; } if (ipos >= _offset + _count || ipos < _offset) { _offset = ipos - cot; ipos = cot; [_substrate getSamples: sb offset: _offset size: _count]; } else { ipos -= _offset; if (ipos > (_count - tot)) { int f = ipos - cot + 1; int r = _count - f; bcopy(sb + f, sb, r * sizeof(sample_t)); _offset += f; ipos = cot - 1; [_substrate getSamples: sb + r offset: _offset + r size: f]; } else if (ipos < tot) { bcopy(sb + ipos, sb + cot, cot * sizeof(sample_t)); _offset -= cot - ipos; ipos = cot; [_substrate getSamples: sb offset: _offset size: cot]; } } { sample_t *s = sb + ipos; double fti = sdelta * tinc; // has to be double ! int ti1 = (int) fti, ti2 = tinc - ti1 - 1, si; double tdelta = fti - ti1, sum = 0; // idem for (si = 0; si > -tot; si--, ti1 += tinc) { sum += s[si] * (base[ti1] + delta[ti1] * tdelta); } tdelta = 1 - tdelta; for (si = 1; si <= tot; si++, ti2 += tinc) { sum += s[si] * (base[ti2] + delta[ti2] * tdelta); } *out++ = sum; } } COMPUTE_EPILOGUE; } /* * archiving methods */ - (void) encodeWithCoder: (NSCoder *)coder { [super encodeWithCoder: coder]; if ([coder allowsKeyedCoding]) { [coder encodeObject: _substrate forKey: @"FOOMLookup:substrate"]; [coder encodeInt: _offset forKey: @"FOOMLookup:offset"]; [coder encodeInt: _count forKey: @"FOOMLookup:count"]; [coder encodeInt: _taps forKey: @"FOOMLookup:taps"]; } else { [coder encodeObject: _substrate]; [coder encodeValueOfObjCType: @encode(int) at: &_offset]; [coder encodeValueOfObjCType: @encode(int) at: &_count]; [coder encodeValueOfObjCType: @encode(int) at: &_taps]; } return; } - (id) initWithCoder: (NSCoder *)coder { self = [super initWithCoder: coder]; if ([coder allowsKeyedCoding]) { _substrate = RETAIN([coder decodeObjectForKey: @"FOOMLookup:substrate"]); _offset = [coder decodeIntForKey: @"FOOMLookup:offset"]; _count = [coder decodeIntForKey: @"FOOMLookup:count"]; _taps = [coder decodeIntForKey: @"FOOMLookup:taps"]; } else { _substrate = RETAIN([coder decodeObject]); [coder decodeValueOfObjCType: @encode(int) at: &_offset]; [coder decodeValueOfObjCType: @encode(int) at: &_count]; [coder decodeValueOfObjCType: @encode(int) at: &_taps]; } _samples = NSZoneCalloc([self zone], _count, sizeof(sample_t)); _table = [FOOGlobalsManager getSineXoverXTable: _taps]; return self; } @end --- NEW FILE: FOOMConstant.h --- /* -*-Mode:objc-*- */ /* * FOOMConstant.h * * module constant * */ /* * 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: FOOMConstant.h,v 1.1 2007/12/14 14:16:08 rumori Exp $ */ #ifndef FOOM_FOOMCONSTANT_H_INCLUDED #define FOOM_FOOMCONSTANT_H_INCLUDED #include <FOO/FOOModule.h> @interface FOOMConstant : FOOModule <NSCoding> { sample_t _value; } - setValue: (sample_t)aValue; - (sample_t) getValue; @end #endif /* #ifndef FOOM_FOOMCONSTANT_H_INCLUDED */ --- NEW FILE: FOOMMul.m --- /* -*-Mode:objc-*- */ /* * FOOMMul.m * * modules mul * */ /* * 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: FOOMMul.m,v 1.1 2007/12/14 14:16:13 rumori Exp $ */ #include "FOOMMul.h" @implementation FOOMMul - (BOOL) activate { int i; if (INPUTS == 0) { return (_active = NO); } for (i = 0; i < INPUTS; i++) { if ([INPUT(i) activate] == NO) { return (_active = NO); } } return (_active = YES); } - (BOOL) compute { int i; id m; COMPUTE_PROLOGUE; m = INPUT(0); [m compute]; [_buffer mov: [m getBuffer]]; for (i = 1; i < INPUTS; ++i) { m = INPUT(i); [m compute]; [_buffer mul: [m getBuffer]]; } COMPUTE_EPILOGUE; } - (int) incrementBuffer { return 0; } /* * archiving methods */ - (void) encodeWithCoder: (NSCoder *)coder { [super encodeWithCoder: coder]; return; } - (id) initWithCoder: (NSCoder *)coder { self = [super initWithCoder: coder]; return self; } @end --- NEW FILE: FOOMDiv.m --- /* -*-Mode:objc-*- */ /* * FOOMDiv.m * * module div * */ /* * 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: FOOMDiv.m,v 1.1 2007/12/14 14:16:11 rumori Exp $ */ #include "FOOMDiv.h" @implementation FOOMDiv - (BOOL) activate { int i; if (INPUTS == 0) { return (_active = NO); } for (i = 0; i < INPUTS; i++) { if ([INPUT(i) activate] == NO) { return (_active = NO); } } return (_active = YES); } - (BOOL) compute { int i; id m; COMPUTE_PROLOGUE; m = INPUT(0); [m compute]; [_buffer mov: [m getBuffer]]; for (i = 1; i < [_inputs count]; i++) { m = INPUT(i); [m compute]; [_buffer div:[m getBuffer]]; } COMPUTE_EPILOGUE; } - (int)incrementBuffer { return 0; } /* * archiving methods */ - (void) encodeWithCoder: (NSCoder *)coder { [super encodeWithCoder: coder]; return; } - (id) initWithCoder: (NSCoder *)coder { self = [super initWithCoder: coder]; return self; } @end --- NEW FILE: FOOMReadTranspSnd.h --- /* -*-Mode:objc-*- */ /* * FOOMReadTranspSnd.h * * module readtranspsnd * */ /* * 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: FOOMReadTranspSnd.h,v 1.1 2007/12/14 14:16:14 rumori Exp $ */ #ifndef FOOM_FOOMREADTRANSPSND_H_INCLUDED #define FOOM_FOOMREADTRANSPSND_H_INCLUDED #include <FOO/FOOEagerModule.h> #include <FOO/FOOSoundStream.h> #include <FOO/FOOSoundFile.h> #include <FOO/FOORegion.h> #include <FOO/FOOLookupTable.h> @interface FOOMReadTranspSnd : FOOEagerModule <NSCoding> { id _substrate; /* input */ /* Substrate *substrate; /\* input *\/ */ sample_t *_samples; /* cache */ int _offset; /* cache's sample position in input */ int _count; /* size of cache */ int _endCache; /* end of cache */ int _taps; /* # of zero-crossings in sinc used for resampling */ FOOLookupTable *_table; /* sinc */ int _begin; /* begin time */ int _end; /* end time */ double _position; /* sample position in input */ double _beginT; /* begin time in seconds */ double _factor; /* transposition factor */ } - initializeWith: substr; - initializeTaps: (int)n; - initPos; - (BOOL)computeRead; - (BOOL)computeTransp; @end #endif /* #ifndef FOOM_FOOMREADTRANSPSND_H_INCLUDED */ --- NEW FILE: FOOMTransposeSnd.m --- /* -*-Mode:objc-*- */ /* * FOOMTransposeSnd.m * * module transpose sound * */ /* * 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: FOOMTransposeSnd.m,v 1.1 2007/12/14 14:16:16 rumori Exp $ */ #include "FOOMTransposeSnd.h" #define ROLL_OFF_FREQU 0.9 #define SAMPLE_BUFFER_SIZE 1024 // should be several times the taps size @implementation FOOMTransposeSnd - initializeWith: substr taps: (int) n { if ([substr isKindOfClass: [FOOSoundFile class]] == NO && [substr isKindOfClass: [FOOSoundStream class]] == NO && [substr isKindOfClass: [FOORegion class]] == NO) { FOO_ERROR(YES, self); } _substrate = substr; _beginT = TIMEFRAME; _taps = n; _count = SAMPLE_BUFFER_SIZE; if (_taps >= _count) { FOO_ERROR(YES, self); } _samples = NSZoneCalloc([self zone], _count, sizeof(sample_t)); _table = [FOOGlobalsManager getSineXoverXTable:_taps]; [self initPos]; return self; } - initPos { _position = 0; _offset = -_count; _end = _offset + _count; return self; } - (void) dealloc { if (_samples != NULL) { NSZoneFree([self zone], _samples); } [super dealloc]; } - reset { [super reset]; memset(_samples, 0, _count * sizeof(sample_t)); [self initPos]; return self; } - startUp { [super startUp]; _begin = SEC_TO_SAM(_beginT); _factor = [_substrate getSamplingRate] / SAMPLERATE; return self; } - (BOOL) activate { if (INPUTS == 0 || _begin >= BLOCKEND || _position - _taps > [_substrate size]) { return (_active = NO); } _active = [INPUT(0) activate]; return _active; } - (BOOL) compute { id m; int b, n, tinc, tot; double p; sample_t *in, *out, *base, *delta; int maxtot = _count / 2; COMPUTE_PROLOGUE; m = [_inputs objectAtIndex: 0]; [m compute]; n = BLOCKSIZE; in = [[m getBuffer] data]; out = [_buffer data]; tot = _taps / 2; if (tot > maxtot) { FOO_ERROR(NO, YES); tot = maxtot; } tinc = [_table getSize] / tot; base = [_table getBase]; delta = [_table getDelta]; if (_begin > SAMPLETIME) { b = _begin - SAMPLETIME; memset(out, 0, b * sizeof(sample_t)); in += b; out += b; n -= b; } while (n--) { p = *in++ * _factor; if (p < 0) { p = -p; } if (p > 1) { /* down sampling */ sample_t *s; double lp = p / ROLL_OFF_FREQU; double P = (_position - ((int)_position)) / lp; double ptinc = tinc / lp; double fti, sum = 0; int ti, si, ptot = tot * lp; if (ptot > maxtot) { FOO_ERROR(NO, YES); ptot = maxtot; } if (_end <= _position + ptot) { _offset = _position - ptot + 1; _end = _offset + _count; [_substrate getSamples:_samples offset:_offset size:_count]; } s = _samples + ((int)_position - _offset); for (fti = P * tinc, si = 0; si < ptot; si++, fti += ptinc) { ti = (int)fti; sum += s[-si] * (base[ti] + delta[ti] * (fti - ti)); } P = 1. / lp - P; for (fti = P * tinc, si = 1; si <= ptot; si++, fti += ptinc) { ti = (int)fti; sum += s[si] * (base[ti] + delta[ti] * (fti - ti)); } *out++ = sum / lp; } else { /* over sampling */ sample_t *s; double P = _position - ((int)_position); double fti = P * tinc; int ti1 = (int) fti, ti2 = tinc - ti1 - 1, si; double tdelta = fti - ti1, sum = 0; if (_end < _position + tot) { _offset =_position - tot + 1; _end = _offset + _count; [_substrate getSamples:_samples offset:_offset size:_count]; } s = _samples + ((int)_position - _offset); for (si = 0; si > -tot; si--, ti1 += tinc) { sum += s[si] * (base[ti1] + delta[ti1] * tdelta); } tdelta = 1 - tdelta; for (si = 1; si <= tot; si++, ti2 += tinc) { sum += s[si] * (base[ti2] + delta[ti2] * tdelta); } *out++ = sum; } _position += p; } COMPUTE_EPILOGUE; } - (int)getTimeInterval: (double*)b : (double*)e { *b = _beginT; return (TI_BEG); } /* * archiving methods */ - (void) encodeWithCoder: (NSCoder *)coder { [super encodeWithCoder: coder]; if ([coder allowsKeyedCoding]) { [coder encodeObject: _substrate forKey: @"FOOMTransposeSnd:substrate"]; [coder encodeDouble: _beginT forKey: @"FOOMTransposeSnd:beginT"]; [coder encodeInt: _count forKey: @"FOOMTransposeSnd:count"]; [coder encodeInt: _taps forKey: @"FOOMTransposeSnd:taps"]; } else { [coder encodeObject: _substrate]; [coder encodeValueOfObjCType: @encode(double) at: &_beginT]; [coder encodeValueOfObjCType: @encode(int) at: &_count]; [coder encodeValueOfObjCType: @encode(int) at: &_taps]; } return; } - (id) initWithCoder: (NSCoder *)coder { self = [super initWithCoder: coder]; if ([coder allowsKeyedCoding]) { _substrate = RETAIN([coder decodeObjectForKey: @"FOOMTransposeSnd:substrate"]); _beginT = [coder decodeDoubleForKey: @"FOOMTransposeSnd:beginT"]; _count = [coder decodeIntForKey: @"FOOMTransposeSnd:count"]; _taps = [coder decodeIntForKey: @"FOOMTransposeSnd:taps"]; } else { _substrate = RETAIN([coder decodeObject]); [coder decodeValueOfObjCType: @encode(double) at: &_beginT]; [coder decodeValueOfObjCType: @encode(int) at: &_count]; [coder decodeValueOfObjCType: @encode(int) at: &_taps]; } _samples = NSZoneCalloc([self zone], _count, sizeof(sample_t)); _table = [FOOGlobalsManager getSineXoverXTable: _taps]; return [self initPos]; } @end --- NEW FILE: FOOMNeg.m --- /* -*-Mode:objc-*- */ /* * FOOMNeg.m * * modules neg * */ /* * 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: FOOMNeg.m,v 1.1 2007/12/14 14:16:13 rumori Exp $ */ #include "FOOMNeg.h" @implementation FOOMNeg - (BOOL) activate { if (INPUTS == 0) { return (_active = NO); } _active = [INPUT(0) activate]; return _active; } - (BOOL) compute { sample_t *in, *out; int n = BLOCKSIZE; COMPUTE_PROLOGUE; [INPUT(0) compute]; in = DATA_OF_MOD(INPUT(0)); out = DATA_OF_BUF(_buffer); while (n--) { *out++ = - *in++; } 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: FOOMReadTranspSnd.m --- /* -*-Mode:objc-*- */ /* * FOOMReadTranspSnd.m * * module reverb * */ /* * 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: FOOMReadTranspSnd.m,v 1.1 2007/12/14 14:16:14 rumori Exp $ */ #include "FOOMReadTranspSnd.h" // defined in <GNUstepBase/preface.h> #ifndef ABS #define ABS(x) ((x) > 0 ? (x) : (-x)) #endif #define ROLL_OFF_FREQU 0.9 #define SAMPLE_BUFFER_SIZE 1024 // should be several times the taps size @implementation FOOMReadTranspSnd - init { [super init]; _samples = NULL; return self; } - initializeWith: substr { if ([substr isKindOfClass: [FOOSoundFile class]] == NO && [substr isKindOfClass: [FOOSoundStream class]] == NO && [substr isKindOfClass: [FOORegion class]] == NO) { FOO_ERROR(YES, self); } _substrate = substr; _beginT = TIMEFRAME; _taps = 0; [self initPos]; return self; } - initializeTaps: (int)n { _taps = n; _count = SAMPLE_BUFFER_SIZE; if (_taps < 4 || _taps >= _count) { FOO_ERROR(YES, self); } if (_samples != NULL) { NSZoneFree([self zone], _samples); } _samples = NSZoneCalloc([self zone], _count, sizeof(sample_t)); _table = [FOOGlobalsManager getSineXoverXTable:_taps]; [self initPos]; return self; } - initializeWith:substr taps: (int)n { [self initializeWith:substr]; [self initializeTaps:n]; return self; } - (void) dealloc { if (_samples != NULL) { NSZoneFree([self zone], _samples); } [super dealloc]; } - initPos { _position = 0; if (_taps != 0) { _offset = -_count; _endCache = _offset + _count; } return self; } - reset { [super reset]; [self initPos]; return self; } - startUp { [super startUp]; _begin = SEC_TO_SAM(_beginT); _end = _begin + [_substrate size]; if ([_substrate getSamplingRate] != SAMPLERATE) { _factor = [_substrate getSamplingRate] / SAMPLERATE; [self initializeTaps:[FOOGlobalsManager getDefaultTaps]]; } else { _factor = 1; } return self; } - (BOOL) activate { if (_taps == 0) { if (_begin >= BLOCKEND || _end < SAMPLETIME) _active = NO; else _active = YES; } else { if (_begin >= BLOCKEND || _position - _taps >= [_substrate size]) { _active = NO; } else { _active = YES; } } return _active; } - (BOOL)compute { if (_taps == 0) { return [self computeRead]; } else { return [self computeTransp]; } } - (BOOL)computeRead { sample_t *p; int b, e, s; COMPUTE_PROLOGUE; p = DATA_OF_BUF(_buffer); if (_begin > SAMPLETIME) { b = _begin - SAMPLETIME; memset(p, 0, b * sizeof(sample_t)); } else { b = 0; } if (_end < BLOCKEND) { e = BLOCKSIZE - (BLOCKEND - _end); memset(p + e, 0, (BLOCKSIZE - e) * sizeof(sample_t)); } else { e = BLOCKSIZE; } s = e - b; if ([_substrate getSamples: p + b offset: _position size: s] == NO) { FOO_ERROR(NO, _active); } _position += s; COMPUTE_EPILOGUE; } - (BOOL)computeTransp { int n, b, tinc, tot; double p; sample_t *out, *base, *delta; int maxtot = _count / 2; COMPUTE_PROLOGUE; n = BLOCKSIZE; out = [_buffer data]; tot = _taps / 2; if (tot > maxtot) { FOO_ERROR(NO, YES); tot = maxtot; } tinc = [_table getSize] / tot; base = [_table getBase]; delta = [_table getDelta]; if (_begin > SAMPLETIME) { b = _begin - SAMPLETIME; memset(out, 0, b * sizeof(sample_t)); out += b; n -= b; } p = _factor; if (p < 0) { p = -p; } while (n--) { if (p > 1) { /* down sampling */ sample_t *s; double lp = p / ROLL_OFF_FREQU; double P = (_position - ((int)_position)) / lp; double ptinc = tinc / lp; double fti, sum = 0; int ti, si, ptot = tot * lp; if (ptot > maxtot) { FOO_ERROR(NO, YES); ptot = maxtot; } if (_endCache <= _position + ptot) { _offset = _position - ptot + 1; _endCache = _offset + _count; [_substrate getSamples:_samples offset:_offset size:_count]; } s = _samples + ((int)_position - _offset); for (fti = P * tinc, si = 0; si < ptot; si++, fti += ptinc) { ti = (int) fti; sum += s[-si] * (base[ti] + delta[ti] * (fti - ti)); } P = 1. / lp - P; for (fti = P * tinc, si = 1; si <= ptot; si++, fti += ptinc) { ti = (int) fti; sum += s[si] * (base[ti] + delta[ti] * (fti - ti)); } *out++ = sum / lp; } else { /* over sampling */ sample_t *s; double P = _position - ((int)_position); double fti = P * tinc; int ti1 = (int) fti, ti2 = tinc - ti1 - 1, si; double tdelta = fti - ti1, sum = 0; if (_endCache < _position + tot) { _offset = _position - tot + 1; _endCache = _offset + _count; [_substrate getSamples:_samples offset:_offset size:_count]; } s = _samples + ((int)_position - _offset); for (si = 0; si > -tot; si--, ti1 += tinc) { sum += s[si] * (base[ti1] + delta[ti1] * tdelta); } tdelta = 1 - tdelta; for (si = 1; si <= tot; si++, ti2 += tinc) { sum += s[si] * (base[ti2] + delta[ti2] * tdelta); } *out++ = sum; } _position += p; } COMPUTE_EPILOGUE; } - (int)getTimeInterval:(double*)b :(double*)e { *b = _beginT; *e = _beginT + [_substrate size] / [_substrate getSamplingRate]; return (TI_BEG_END); } /* * archiving methods */ - (void) encodeWithCoder: (NSCoder *)coder { [super encodeWit... [truncated message content] |