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 // 00022 #ifndef A_D 00023 #define A_D 00024 #include <math.h> 00025 #include <complex.h> 00026 namespace SPUC {// 00033 // 00034 // Class for A/D conversion. 00035 // Bit width is specified in constructor. Default is 8 bits. 00036 // Handles real and complex samples 00037 // \image html a_d.gif 00038 // \image latex a_d.eps 00039 class a_d 00040 { 00041 protected: 00042 char size; 00043 long max; 00044 long min; 00045 00046 public: 00047 complex<long> sample(complex<double> x) { 00048 return( complex<long>( sample(x.real()),sample(x.imag()) ) ); 00049 } 00050 00052 a_d(char h=8) : size(h) { 00053 max = ((1<<(size-1)) - 1 ); 00054 min = ~max; 00055 } 00057 long sample(double x) { 00058 long quant; 00059 quant = (long)floor(x+0.5); 00060 if (quant>max) quant = max; 00061 if (quant<min) quant = min; 00062 return(quant); 00063 } 00064 }; 00065 } // namespace SPUC 00066 #endif