|
From: Martin R. <ru...@us...> - 2004-08-01 23:39:29
|
Update of /cvsroot/foo/foo/libfoo/modules/orthodox In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23435 Modified Files: FOOMReadBpf.m FOOMReadSnd.m FOOMReadTranspSnd.m FOOMTransposeBpf.m FOOMTransposeSnd.m Log Message: reintroduced changes already made to foo-ng (lost during autoporting) Index: FOOMReadSnd.m =================================================================== RCS file: /cvsroot/foo/foo/libfoo/modules/orthodox/FOOMReadSnd.m,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** FOOMReadSnd.m 31 Jul 2004 03:05:30 -0000 1.1 --- FOOMReadSnd.m 1 Aug 2004 23:39:20 -0000 1.2 *************** *** 39,126 **** @implementation FOOMReadSnd - initializeWith: substr { ! if ([substr isKindOf:[FOOSoundFile class]] == NO && ! [substr isKindOf:[FOOSoundStream class]] == NO && ! [substr isKindOf:[FOORegion class]] == NO) ! { ! FOO_ERROR(YES, self); ! } ! _substrate = substr; ! _beginT = TIMEFRAME; ! _position = 0; ! return self; } - reset { ! [super reset]; ! _position = 0; ! return self; } - startUp { ! [super startUp]; ! _begin = SEC_TO_SAM(_beginT); ! _end = _begin + [_substrate size]; ! return self; } - (BOOL)activate { ! if (_begin >= BLOCKEND || _end < SAMPLETIME) ! { ! _active = NO; ! } ! else ! { ! _active = YES; ! } ! return _active; } - (BOOL)compute { ! sample_t *p; ! int b, e, s; ! COMPUTE_PROLOGUE; ! p = DATA_OF_BUF(_buffer); ! if (_begin > SAMPLETIME) ! { ! b = _begin - SAMPLETIME; ! bzero(p, b * sizeof(sample_t)); ! } ! else ! { ! b = 0; ! } ! if (_end < BLOCKEND) ! { ! e = BLOCKSIZE - (BLOCKEND - _end); ! bzero(p + e, (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; } - (int)getTimeInterval:(double*)b :(double*)e { ! *b = _beginT; ! *e = _beginT + SAM_TO_SEC([_substrate size]); ! return (TI_BEG_END); } /* * archiving methods --- 39,137 ---- @implementation FOOMReadSnd + - 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; ! _position = 0; ! ! return self; } + - reset { ! [super reset]; ! _position = 0; ! ! return self; } + - startUp { ! [super startUp]; ! _begin = SEC_TO_SAM(_beginT); ! _end = _begin + [_substrate size]; ! ! return self; } + - (BOOL)activate { ! if (_begin >= BLOCKEND || _end < SAMPLETIME) ! { ! _active = NO; ! } ! else ! { ! _active = YES; ! } ! return _active; } + - (BOOL)compute { ! sample_t *p; ! int b, e, s; ! COMPUTE_PROLOGUE; ! p = DATA_OF_BUF(_buffer); ! if (_begin > SAMPLETIME) ! { ! b = _begin - SAMPLETIME; ! bzero(p, b * sizeof(sample_t)); ! } ! else ! { ! b = 0; ! } ! if (_end < BLOCKEND) ! { ! e = BLOCKSIZE - (BLOCKEND - _end); ! bzero(p + e, (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; } + - (int)getTimeInterval:(double*)b :(double*)e { ! *b = _beginT; ! *e = _beginT + SAM_TO_SEC([_substrate size]); ! ! return (TI_BEG_END); } + /* * archiving methods *************** *** 131,144 **** - read:(TypedStream *)stream { ! [super read:stream]; ! objc_read_types(stream, "@[8c]", &_substrate, &_beginT); ! return self; } - write:(TypedStream *)stream { ! [super write:stream]; ! objc_write_types(stream, "@[8c]", &_substrate, &_beginT); ! return self; } --- 142,155 ---- - read:(TypedStream *)stream { ! [super read:stream]; ! objc_read_types(stream, "@[8c]", &_substrate, &_beginT); ! return self; } - write:(TypedStream *)stream { ! [super write:stream]; ! objc_write_types(stream, "@[8c]", &_substrate, &_beginT); ! return self; } Index: FOOMTransposeSnd.m =================================================================== RCS file: /cvsroot/foo/foo/libfoo/modules/orthodox/FOOMTransposeSnd.m,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** FOOMTransposeSnd.m 31 Jul 2004 03:05:30 -0000 1.1 --- FOOMTransposeSnd.m 1 Aug 2004 23:39:20 -0000 1.2 *************** *** 43,51 **** @implementation FOOMTransposeSnd - initializeWith: substr taps: (int) n { ! if ([substr isKindOf: [FOOSoundFile class]] == NO && ! [substr isKindOf: [FOOSoundStream class]] == NO && ! [substr isKindOf: [FOORegion class]] == NO) { FOO_ERROR(YES, self); --- 43,52 ---- @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); *************** *** 65,248 **** _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]; ! bzero(_samples, _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 objectAt:0]; ! // 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; ! bzero(out, 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 --- 66,262 ---- _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]; ! bzero(_samples, _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; ! bzero(out, 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 Index: FOOMTransposeBpf.m =================================================================== RCS file: /cvsroot/foo/foo/libfoo/modules/orthodox/FOOMTransposeBpf.m,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** FOOMTransposeBpf.m 31 Jul 2004 03:05:30 -0000 1.1 --- FOOMTransposeBpf.m 1 Aug 2004 23:39:20 -0000 1.2 *************** *** 39,210 **** #define FIRST_TIME -1 @implementation FOOMTransposeBpf - initializeWith: substr { ! if ([substr isKindOf:[FOOBreakpointFunction class]] == NO) ! { ! FOO_ERROR(YES, self); ! } ! _substrate = substr; ! _beginT = TIMEFRAME; ! [self doInit]; ! return self; } - doInit { ! lineseg_t *sp; ! _segments = [_substrate segments]; ! _current = _segments; ! _end = NO; ! _halted = NO; ! for (sp = _current; sp->count != 0; sp++) ! { ! _last = sp; ! } ! _phase = 0; ! _previous = 0; ! return self; } - reset { ! [super reset]; ! [self doInit]; ! return self; } - startUp { ! [super startUp]; ! _begin = SEC_TO_SAM(_beginT + [_substrate beginT]); ! return self; } - (BOOL)activate { ! if (_begin >= BLOCKEND || _end == YES) ! { ! _active = NO; ! } ! else ! { ! _halted = ([INPUT(0) activate] == NO); ! _active = YES; } ! return _active; } - (BOOL)compute { ! sample_t *out, *in, prev; ! double v, d, p, dod, ai, a; ! int n, c; ! id m; ! COMPUTE_PROLOGUE; ! n = BLOCKSIZE; ! out = DATA_OF_BUF(_buffer); ! prev = _previous; ! if (_halted == YES) ! { ! while (n--) ! { ! *out++ = prev; ! } ! } ! else ! { ! m = INPUT(0); ! [m compute]; ! in = DATA_OF_MOD(m); ! c = _current->count; ! v = _current->value; ! d = _current->delta; ! a = _current->alpha; ! p = _phase; ! if (a != 0) ! { ! dod = d / (1 - transexp(a)); ! ai = a / (c - 1); ! } ! while (n--) ! { ! p += *in++; ! if (p < 0) ! { ! if (_current == _segments) ! { ! *out++ = prev; ! continue; ! } ! else ! { ! _current--; ! c = _current->count; ! v = _current->value; ! d = _current->delta; ! p += c; ! a = _current->alpha; ! if (a != 0) ! { ! dod = d / (1 - transexp(a)); ! ai = a / (c - 1); ! } ! } ! } ! else if (p >= c) ! { ! if (_current == _last) ! { ! *out++ = prev; // should be zero? ! _end = YES; ! continue; ! } ! else ! { ! _current++; ! p -= c; ! c = _current->count; ! v = _current->value; ! d = _current->delta; ! a = _current->alpha; ! if (a != 0) ! { ! ai = a / (c - 1); ! } ! } ! } ! if (a != 0) ! { ! prev = v + d * (1 - transexp(p * ai)); ! } ! else ! { ! prev = v + d * p; ! } ! *out++ = prev; ! } ! _previous = prev; ! _phase = p; ! } ! COMPUTE_EPILOGUE; } - (int)getTimeInterval:(double*)b :(double*)e { ! *b = _beginT; ! return (TI_BEG); } /* * archiving methods --- 39,222 ---- #define FIRST_TIME -1 + @implementation FOOMTransposeBpf + - initializeWith: substr { ! if ([substr isKindOfClass: [FOOBreakpointFunction class]] == NO) ! { ! FOO_ERROR(YES, self); ! } ! _substrate = substr; ! _beginT = TIMEFRAME; ! [self doInit]; ! return self; } + - doInit { ! lineseg_t *sp; ! _segments = [_substrate segments]; ! _current = _segments; ! _end = NO; ! _halted = NO; ! for (sp = _current; sp->count != 0; sp++) ! { ! _last = sp; ! } ! _phase = 0; ! _previous = 0; ! return self; } + - reset { ! [super reset]; ! [self doInit]; ! ! return self; } + - startUp { ! [super startUp]; ! _begin = SEC_TO_SAM(_beginT + [_substrate beginT]); ! ! return self; } + - (BOOL)activate { ! if (_begin >= BLOCKEND || _end == YES) ! { ! _active = NO; ! } ! else ! { ! _halted = ([INPUT(0) activate] == NO); ! _active = YES; } ! return _active; } + - (BOOL)compute { ! sample_t *out, *in, prev; ! double v, d, p, dod, ai, a; ! int n, c; ! id m; ! COMPUTE_PROLOGUE; ! n = BLOCKSIZE; ! out = DATA_OF_BUF(_buffer); ! prev = _previous; ! if (_halted == YES) ! { ! while (n--) ! { ! *out++ = prev; ! } ! } ! else ! { ! m = INPUT(0); ! [m compute]; ! in = DATA_OF_MOD(m); ! c = _current->count; ! v = _current->value; ! d = _current->delta; ! a = _current->alpha; ! p = _phase; ! if (a != 0) ! { ! dod = d / (1 - transexp(a)); ! ai = a / (c - 1); ! } ! while (n--) ! { ! p += *in++; ! if (p < 0) ! { ! if (_current == _segments) ! { ! *out++ = prev; ! continue; ! } ! else ! { ! _current--; ! c = _current->count; ! v = _current->value; ! d = _current->delta; ! p += c; ! a = _current->alpha; ! if (a != 0) ! { ! dod = d / (1 - transexp(a)); ! ai = a / (c - 1); ! } ! } ! } ! else if (p >= c) ! { ! if (_current == _last) ! { ! *out++ = prev; // should be zero? ! _end = YES; ! continue; ! } ! else ! { ! _current++; ! p -= c; ! c = _current->count; ! v = _current->value; ! d = _current->delta; ! a = _current->alpha; ! if (a != 0) ! { ! ai = a / (c - 1); ! } ! } ! } ! if (a != 0) ! { ! prev = v + d * (1 - transexp(p * ai)); ! } ! else ! { ! prev = v + d * p; ! } ! *out++ = prev; ! } ! _previous = prev; ! _phase = p; ! } ! COMPUTE_EPILOGUE; } + - (int)getTimeInterval:(double*)b :(double*)e { ! *b = _beginT; ! ! return (TI_BEG); } + /* * archiving methods Index: FOOMReadTranspSnd.m =================================================================== RCS file: /cvsroot/foo/foo/libfoo/modules/orthodox/FOOMReadTranspSnd.m,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** FOOMReadTranspSnd.m 31 Jul 2004 03:05:30 -0000 1.1 --- FOOMReadTranspSnd.m 1 Aug 2004 23:39:20 -0000 1.2 *************** *** 45,316 **** #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 isKindOf:[FOOSoundFile class]] == NO && ! [substr isKindOf:[FOOSoundStream class]] == NO && ! [substr isKindOf:[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) deallooc { ! if (_samples != NULL) ! { ! NSZoneFree([self zone], _samples); ! } ! return [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; ! bzero(p, b * sizeof(sample_t)); ! } ! else ! { ! b = 0; ! } ! if (_end < BLOCKEND) ! { ! e = BLOCKSIZE - (BLOCKEND - _end); ! bzero(p + e, (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; ! bzero(out, 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 --- 45,338 ---- #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); ! } ! ! return [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; ! bzero(p, b * sizeof(sample_t)); ! } ! else ! { ! b = 0; ! } ! if (_end < BLOCKEND) ! { ! e = BLOCKSIZE - (BLOCKEND - _end); ! bzero(p + e, (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; ! bzero(out, 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 Index: FOOMReadBpf.m =================================================================== RCS file: /cvsroot/foo/foo/libfoo/modules/orthodox/FOOMReadBpf.m,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** FOOMReadBpf.m 31 Jul 2004 03:05:30 -0000 1.1 --- FOOMReadBpf.m 1 Aug 2004 23:39:20 -0000 1.2 *************** *** 42,195 **** @implementation FOOMReadBpf - initializeWith: substr { ! lineseg_t *sp; ! if ([substr isKindOf:[FOOBreakpointFunction class]] == NO) ! { ! FOO_ERROR(YES, self); ! } ! _substrate = substr; ! _beginT = TIMEFRAME; ! _lasttime = FIRST_TIME; ! _current = [_substrate segments]; ! for (sp = _current; sp->count != 0; sp++) ! { ! ; ! } ! _last = sp; ! return self; } - reset { ! lineseg_t *sp; ! [super reset]; ! _current = [_substrate segments]; ! for (sp = _current; sp->count != 0; sp++) ! { ! ; ! } ! _last = sp; ! return self; } - startUp { ! [super startUp]; ! _begin = SEC_TO_SAM(_beginT + [_substrate beginT]); ! _end = _begin + SEC_TO_SAM([_substrate sizeT]); ! return self; } - (BOOL)activate { ! if (_begin >= BLOCKEND || _end < SAMPLETIME) ! { ! _active = NO; ! } ! else ! { ! _active = YES; ! } ! return _active; } - (BOOL)compute { ! sample_t *p, value, delta; ! double alpha; ! int count = 0, debut, fin, restSeg, restBlk, curr_count; ! COMPUTE_PROLOGUE; ! p = DATA_OF_BUF(_buffer); ! if (_lasttime == FIRST_TIME) { ! for (count = 0; count < _begin - SAMPLETIME; count++) ! { ! *p++ = 0; ! } ! _offset = 0; ! _lasttime = SAMPLETIME; } ! while (count < BLOCKSIZE) { ! if (_current == _last) ! { ! while (count++ < BLOCKSIZE) ! { ! *p++ = 0; ! } ! } ! else ! { ! debut = _offset; ! value = _current->value; ! delta = _current->delta; ! alpha = _current->alpha; ! curr_count = _current->count; ! restSeg = curr_count - _offset; ! restBlk = BLOCKSIZE - count; ! if (_offset == 0) ! { ! if (alpha == 0) ! { ! _phase = 0; ! } ! else ! { ! _factor = pow(exp(alpha), 1. / (curr_count - 1)); ! _phase = 1. / _factor; ! } ! } ! if (restBlk < restSeg) ! { ! fin = _offset + restBlk; ! count += restBlk; ! _offset += restBlk; ! } ! else ! { ! fin = _offset + restSeg; ! count += restSeg; ! _offset = 0; ! _current++; ! } ! if (alpha == 0) ! { ! double ph = _phase; ! int n = fin - debut; ! while (n--) ! { ! ph += delta; ! *p++ = value + ph; ! } ! _phase = ph; ! } ! else ! { ! double ph = _phase; ! int n = fin - debut; ! while (n--) ! { ! ph *= _factor; ! *p++ = value + delta * (1 - ph); ! } ! _phase = ph; ! } ! } } ! _lasttime = SAMPLETIME + BLOCKSIZE; ! COMPUTE_EPILOGUE; } - (int)getTimeInterval:(double*)b :(double*)e { ! *b = _beginT + [_substrate beginT]; ! *e = *b + [_substrate sizeT]; ! return (TI_BEG_END); } /* * archiving methods --- 42,206 ---- @implementation FOOMReadBpf + - initializeWith: substr { ! lineseg_t *sp; ! if ([substr isKindOfClass: [FOOBreakpointFunction class]] == NO) ! { ! FOO_ERROR(YES, self); ! } ! _substrate = substr; ! _beginT = TIMEFRAME; ! _lasttime = FIRST_TIME; ! _current = [_substrate segments]; ! for (sp = _current; sp->count != 0; sp++) ! { ! ; ! } ! _last = sp; ! ! return self; } + - reset { ! lineseg_t *sp; ! [super reset]; ! _current = [_substrate segments]; ! for (sp = _current; sp->count != 0; sp++) ! { ! ; ! } ! _last = sp; ! ! return self; } + - startUp { ! [super startUp]; ! _begin = SEC_TO_SAM(_beginT + [_substrate beginT]); ! _end = _begin + SEC_TO_SAM([_substrate sizeT]); ! ! return self; } + - (BOOL)activate { ! if (_begin >= BLOCKEND || _end < SAMPLETIME) ! { ! _active = NO; ! } ! else ! { ! _active = YES; ! } ! ! return _active; } + - (BOOL)compute { ! sample_t *p, value, delta; ! double alpha; ! int count = 0, debut, fin, restSeg, restBlk, curr_count; ! COMPUTE_PROLOGUE; ! p = DATA_OF_BUF(_buffer); ! if (_lasttime == FIRST_TIME) ! { ! for (count = 0; count < _begin - SAMPLETIME; count++) ! { ! *p++ = 0; ! } ! _offset = 0; ! _lasttime = SAMPLETIME; ! } ! while (count < BLOCKSIZE) ! { ! if (_current == _last) ! { ! while (count++ < BLOCKSIZE) ! { ! *p++ = 0; ! } ! } ! else ! { ! debut = _offset; ! value = _current->value; ! delta = _current->delta; ! alpha = _current->alpha; ! curr_count = _current->count; ! restSeg = curr_count - _offset; ! restBlk = BLOCKSIZE - count; ! if (_offset == 0) ! { ! if (alpha == 0) { ! _phase = 0; } ! else { ! _factor = pow(exp(alpha), 1. / (curr_count - 1)); ! _phase = 1. / _factor; } ! } ! if (restBlk < restSeg) ! { ! fin = _offset + restBlk; ! count += restBlk; ! _offset += restBlk; ! } ! else ! { ! fin = _offset + restSeg; ! count += restSeg; ! _offset = 0; ! _current++; ! } ! if (alpha == 0) ! { ! double ph = _phase; ! int n = fin - debut; ! while (n--) ! { ! ph += delta; ! *p++ = value + ph; ! } ! _phase = ph; ! } ! else ! { ! double ph = _phase; ! int n = fin - debut; ! while (n--) ! { ! ph *= _factor; ! *p++ = value + delta * (1 - ph); ! } ! _phase = ph; ! } ! } ! } ! _lasttime = SAMPLETIME + BLOCKSIZE; ! COMPUTE_EPILOGUE; } + - (int)getTimeInterval:(double*)b :(double*)e { ! *b = _beginT + [_substrate beginT]; ! *e = *b + [_substrate sizeT]; ! return (TI_BEG_END); } + /* * archiving methods *************** *** 200,213 **** - read:(TypedStream *)stream { ! [super read:stream]; ! objc_read_types(stream, "@[8c]", &_substrate, &_beginT); ! return self; } - write:(TypedStream *)stream { ! [super write:stream]; ! objc_write_types(stream, "@[8c]", &_substrate, &_beginT); ! return self; } --- 211,224 ---- - read:(TypedStream *)stream { ! [super read:stream]; ! objc_read_types(stream, "@[8c]", &_substrate, &_beginT); ! return self; } - write:(TypedStream *)stream { ! [super write:stream]; ! objc_write_types(stream, "@[8c]", &_substrate, &_beginT); ! return self; } |