00001 // 00002 // Copyright(c) 1993-1996 Tony Kirke 00003 // author="Tony Kirke" * 00004 /* 00005 * SPUC - Signal processing using C++ - A DSP library 00006 * 00007 * This program is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation; either version 2, or (at your option) 00010 * any later version. 00011 * 00012 * This program is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with this program; if not, write to the Free Software 00019 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00020 */ 00021 #ifndef DLYL 00022 #define DLYL 00023 namespace SPUC { 00030 00031 00032 00033 00034 00035 template <class Numeric> class delay 00036 { 00037 public: 00038 long num_taps; 00039 protected: 00040 Numeric* z; 00041 00042 public: 00044 delay(long n=0) : num_taps(n+1) { 00045 int i=0; 00046 z = new Numeric[num_taps]; 00047 for (i=0;i<num_taps;i++) z[i] = 0; 00048 } 00050 delay& operator=(const delay &rhs) { 00051 num_taps = rhs.num_taps; 00052 for (int i=0;i<num_taps;i++) z[i] = rhs.z[i]; 00053 return(*this); 00054 } 00056 ~delay(void) { if (num_taps>0) delete [] z;} 00057 void reset(void) { for (int i=0;i<num_taps;i++) z[i] = 0; } 00059 Numeric check(long i) { return(z[i]); } 00061 Numeric checkback(long i) { return(z[num_taps-1-i]); } 00063 Numeric last() { return(z[num_taps-1]);} 00065 void set_size(long n=2) { 00066 int i=0; 00067 if (num_taps>0) delete [] z; 00068 num_taps = n+1; 00069 z = new Numeric[num_taps]; 00070 for (i=0;i<num_taps;i++) z[i] = 0; 00071 } 00073 Numeric input(Numeric in) { 00074 int i; 00075 // Update history of inputs 00076 for (i=num_taps-1;i>0;i--) z[i] = z[i-1]; 00077 // Add new input 00078 z[0] = in; 00079 return(z[num_taps-1]); 00080 } 00082 inline Numeric update(Numeric in) { 00083 input(in); 00084 return(z[num_taps-1]); 00085 } 00086 }; 00087 } // namespace SPUC 00088 #endif