00001 /* 00002 * SpanDSP - a series of DSP components for telephony 00003 * 00004 * dds.h 00005 * 00006 * Written by Steve Underwood <steveu@coppice.org> 00007 * 00008 * Copyright (C) 2003 Steve Underwood 00009 * 00010 * All rights reserved. 00011 * 00012 * This program is free software; you can redistribute it and/or modify 00013 * it under the terms of the GNU Lesser General Public License version 2.1, 00014 * as published by the Free Software Foundation. 00015 * 00016 * This program is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU Lesser General Public License for more details. 00020 * 00021 * You should have received a copy of the GNU Lesser General Public 00022 * License along with this program; if not, write to the Free Software 00023 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00024 */ 00025 00026 /*! \file */ 00027 00028 #if !defined(_SPANDSP_DDS_H_) 00029 #define _SPANDSP_DDS_H_ 00030 00031 #if defined(__cplusplus) 00032 extern "C" 00033 { 00034 #endif 00035 00036 /*! \brief Find the phase rate value to achieve a particular frequency. 00037 \param frequency The desired frequency, in Hz. 00038 \return The phase rate which while achieve the desired frequency. 00039 */ 00040 SPAN_DECLARE(int32_t) dds_phase_rate(float frequency); 00041 00042 /*! \brief Find the frequency, in Hz, equivalent to a phase rate. 00043 \param phase_rate The phase rate. 00044 \return The equivalent frequency, in Hz. 00045 */ 00046 SPAN_DECLARE(float) dds_frequency(int32_t phase_rate); 00047 00048 /*! \brief Find the scaling factor needed to achieve a specified level in dBm0. 00049 \param level The desired signal level, in dBm0. 00050 \return The scaling factor. 00051 */ 00052 SPAN_DECLARE(int16_t) dds_scaling_dbm0(float level); 00053 00054 /*! \brief Find the scaling factor needed to achieve a specified level in dBmov. 00055 \param level The desired signal level, in dBmov. 00056 \return The scaling factor. 00057 */ 00058 SPAN_DECLARE(int16_t) dds_scaling_dbov(float level); 00059 00060 /*! \brief Find the amplitude for a particular phase. 00061 \param phase The desired phase 32 bit phase. 00062 \return The signal amplitude. 00063 */ 00064 SPAN_DECLARE(int16_t) dds_lookup(uint32_t phase); 00065 00066 /*! \brief Find the amplitude for a particular phase offset from an accumulated phase. 00067 \param phase_acc The accumulated phase. 00068 \param phase_offset The phase offset. 00069 \return The signal amplitude. 00070 */ 00071 SPAN_DECLARE(int16_t) dds_offset(uint32_t phase_acc, int32_t phase_offset); 00072 00073 /*! \brief Advance the phase, without returning any new signal sample. 00074 \param phase_acc A pointer to a phase accumulator value. 00075 \param phase_rate The phase increment to be applied. 00076 */ 00077 SPAN_DECLARE(void) dds_advance(uint32_t *phase_acc, int32_t phase_rate); 00078 00079 /*! \brief Generate an integer tone sample. 00080 \param phase_acc A pointer to a phase accumulator value. 00081 \param phase_rate The phase increment to be applied. 00082 \return The signal amplitude, between -32767 and 32767. 00083 */ 00084 SPAN_DECLARE(int16_t) dds(uint32_t *phase_acc, int32_t phase_rate); 00085 00086 /*! \brief Lookup the integer value of a specified phase. 00087 \param phase The phase accumulator value to be looked up. 00088 \return The signal amplitude, between -32767 and 32767. 00089 */ 00090 SPAN_DECLARE(int16_t) dds_lookup(uint32_t phase); 00091 00092 /*! \brief Generate an integer tone sample, with modulation. 00093 \param phase_acc A pointer to a phase accumulator value. 00094 \param phase_rate The phase increment to be applied. 00095 \param scale The scaling factor. 00096 \param phase The phase offset. 00097 \return The signal amplitude, between -32767 and 32767. 00098 */ 00099 SPAN_DECLARE(int16_t) dds_mod(uint32_t *phase_acc, int32_t phase_rate, int16_t scale, int32_t phase); 00100 00101 /*! \brief Lookup the complex integer value of a specified phase. 00102 \param phase The phase accumulator value to be looked up. 00103 \return The complex signal amplitude, between (-32767, -32767) and (32767, 32767). 00104 */ 00105 SPAN_DECLARE(complexi_t) dds_lookup_complexi(uint32_t phase); 00106 00107 /*! \brief Generate a complex integer tone sample. 00108 \param phase_acc A pointer to a phase accumulator value. 00109 \param phase_rate The phase increment to be applied. 00110 \return The complex signal amplitude, between (-32767, -32767) and (32767, 32767). 00111 */ 00112 SPAN_DECLARE(complexi_t) dds_complexi(uint32_t *phase_acc, int32_t phase_rate); 00113 00114 /*! \brief Generate a complex integer tone sample, with modulation. 00115 \param phase_acc A pointer to a phase accumulator value. 00116 \param phase_rate The phase increment to be applied. 00117 \param scale The scaling factor. 00118 \param phase The phase offset. 00119 \return The complex signal amplitude, between (-32767, -32767) and (32767, 32767). 00120 */ 00121 SPAN_DECLARE(complexi_t) dds_complexi_mod(uint32_t *phase_acc, int32_t phase_rate, int16_t scale, int32_t phase); 00122 00123 /*! \brief Generate a complex 16 bit integer tone sample. 00124 \param phase_acc A pointer to a phase accumulator value. 00125 \param phase_rate The phase increment to be applied. 00126 \return The complex signal amplitude, between (-32767, -32767) and (32767, 32767). 00127 */ 00128 SPAN_DECLARE(complexi16_t) dds_lookup_complexi16(uint32_t phase); 00129 00130 /*! \brief Generate a complex 16 bit integer tone sample. 00131 \param phase_acc A pointer to a phase accumulator value. 00132 \param phase_rate The phase increment to be applied. 00133 \return The complex signal amplitude, between (-32767, -32767) and (32767, 32767). 00134 */ 00135 SPAN_DECLARE(complexi16_t) dds_complexi16(uint32_t *phase_acc, int32_t phase_rate); 00136 00137 /*! \brief Generate a complex 16bit integer tone sample, with modulation. 00138 \param phase_acc A pointer to a phase accumulator value. 00139 \param phase_rate The phase increment to be applied. 00140 \param scale The scaling factor. 00141 \param phase The phase offset. 00142 \return The complex signal amplitude, between (-32767, -32767) and (32767, 32767). 00143 */ 00144 SPAN_DECLARE(complexi16_t) dds_complexi16_mod(uint32_t *phase_acc, int32_t phase_rate, int16_t scale, int32_t phase); 00145 00146 /*! \brief Generate a complex 32 bit integer tone sample, with modulation. 00147 \param phase_acc A pointer to a phase accumulator value. 00148 \param phase_rate The phase increment to be applied. 00149 \param scale The scaling factor. 00150 \param phase The phase offset. 00151 \return The complex signal amplitude, between (-32767, -32767) and (32767, 32767). 00152 */ 00153 SPAN_DECLARE(complexi32_t) dds_complexi32_mod(uint32_t *phase_acc, int32_t phase_rate, int16_t scale, int32_t phase); 00154 00155 /*! \brief Generate a complex 32 bit integer tone sample. 00156 \param phase_acc A pointer to a phase accumulator value. 00157 \param phase_rate The phase increment to be applied. 00158 \return The complex signal amplitude, between (-32767, -32767) and (32767, 32767). 00159 */ 00160 SPAN_DECLARE(complexi32_t) dds_lookup_complexi32(uint32_t phase); 00161 00162 /*! \brief Generate a complex 32 bit integer tone sample. 00163 \param phase_acc A pointer to a phase accumulator value. 00164 \param phase_rate The phase increment to be applied. 00165 \return The complex signal amplitude, between (-32767, -32767) and (32767, 32767). 00166 */ 00167 SPAN_DECLARE(complexi32_t) dds_complexi32(uint32_t *phase_acc, int32_t phase_rate); 00168 00169 /*! \brief Generate a complex 32 bit integer tone sample, with modulation. 00170 \param phase_acc A pointer to a phase accumulator value. 00171 \param phase_rate The phase increment to be applied. 00172 \param scale The scaling factor. 00173 \param phase The phase offset. 00174 \return The complex signal amplitude, between (-32767, -32767) and (32767, 32767). 00175 */ 00176 SPAN_DECLARE(complexi32_t) dds_complexi32_mod(uint32_t *phase_acc, int32_t phase_rate, int16_t scale, int32_t phase); 00177 00178 /*! \brief Find the phase rate equivalent to a frequency, in Hz. 00179 \param frequency The frequency, in Hz. 00180 \return The equivalent phase rate. 00181 */ 00182 SPAN_DECLARE(int32_t) dds_phase_ratef(float frequency); 00183 00184 /*! \brief Find the frequency, in Hz, equivalent to a phase rate. 00185 \param phase_rate The phase rate. 00186 \return The equivalent frequency, in Hz. 00187 */ 00188 SPAN_DECLARE(float) dds_frequencyf(int32_t phase_rate); 00189 00190 /*! \brief Find the scaling factor equivalent to a dBm0 value. 00191 \param level The signal level in dBm0. 00192 \return The equivalent scaling factor. 00193 */ 00194 SPAN_DECLARE(float) dds_scaling_dbm0f(float level); 00195 00196 /*! \brief Find the scaling factor equivalent to a dBmov value. 00197 \param level The signal level in dBmov. 00198 \return The equivalent scaling factor. 00199 */ 00200 SPAN_DECLARE(float) dds_scaling_dbovf(float level); 00201 00202 /*! \brief Advance the phase, without returning any new signal sample. 00203 \param phase_acc A pointer to a phase accumulator value. 00204 \param phase_rate The phase increment to be applied. 00205 */ 00206 SPAN_DECLARE(void) dds_advancef(uint32_t *phase_acc, int32_t phase_rate); 00207 00208 /*! \brief Generate a floating point tone sample. 00209 \param phase_acc A pointer to a phase accumulator value. 00210 \param phase_rate The phase increment to be applied. 00211 \return The signal amplitude, between -1.0 and 1.0. 00212 */ 00213 SPAN_DECLARE(float) ddsf(uint32_t *phase_acc, int32_t phase_rate); 00214 00215 /*! \brief Lookup the floating point value of a specified phase. 00216 \param phase The phase accumulator value to be looked up. 00217 \return The signal amplitude, between -1.0 and 1.0. 00218 */ 00219 SPAN_DECLARE(float) dds_lookupf(uint32_t phase); 00220 00221 /*! \brief Generate a floating point tone sample, with modulation. 00222 \param phase_acc A pointer to a phase accumulator value. 00223 \param phase_rate The phase increment to be applied. 00224 \param scale The scaling factor. 00225 \param phase The phase offset. 00226 \return The signal amplitude, between -1.0 and 1.0. 00227 */ 00228 SPAN_DECLARE(float) dds_modf(uint32_t *phase_acc, int32_t phase_rate, float scale, int32_t phase); 00229 00230 /*! \brief Generate a complex floating point tone sample. 00231 \param phase_acc A pointer to a phase accumulator value. 00232 \param phase_rate The phase increment to be applied. 00233 \return The complex signal amplitude, between (-1.0, -1.0) and (1.0, 1.0). 00234 */ 00235 SPAN_DECLARE(complexf_t) dds_complexf(uint32_t *phase_acc, int32_t phase_rate); 00236 00237 /*! \brief Lookup the complex value of a specified phase. 00238 \param phase The phase accumulator value to be looked up. 00239 \return The complex signal amplitude, between (-1.0, -1.0) and (1.0, 1.0). 00240 */ 00241 SPAN_DECLARE(complexf_t) dds_lookup_complexf(uint32_t phase_acc); 00242 00243 /*! \brief Generate a complex floating point tone sample, with modulation. 00244 \param phase_acc A pointer to a phase accumulator value. 00245 \param phase_rate The phase increment to be applied. 00246 \param scale The scaling factor. 00247 \param phase The phase offset. 00248 \return The complex signal amplitude, between (-1.0, -1.0) and (1.0, 1.0). 00249 */ 00250 SPAN_DECLARE(complexf_t) dds_complex_modf(uint32_t *phase_acc, int32_t phase_rate, float scale, int32_t phase); 00251 00252 #if defined(__cplusplus) 00253 } 00254 #endif 00255 00256 #endif 00257 /*- End of file ------------------------------------------------------------*/