spandsp  0.0.6
dds.h
Go to the documentation of this file.
1 /*
2  * SpanDSP - a series of DSP components for telephony
3  *
4  * dds.h
5  *
6  * Written by Steve Underwood <steveu@coppice.org>
7  *
8  * Copyright (C) 2003 Steve Underwood
9  *
10  * All rights reserved.
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU Lesser General Public License version 2.1,
14  * as published by the Free Software Foundation.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Lesser General Public License for more details.
20  *
21  * You should have received a copy of the GNU Lesser General Public
22  * License along with this program; if not, write to the Free Software
23  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24  */
25 
26 /*! \file */
27 
28 #if !defined(_SPANDSP_DDS_H_)
29 #define _SPANDSP_DDS_H_
30 
31 #if defined(__cplusplus)
32 extern "C"
33 {
34 #endif
35 
36 /*! \brief Find the phase rate value to achieve a particular frequency.
37  \param frequency The desired frequency, in Hz.
38  \return The phase rate which while achieve the desired frequency.
39 */
40 SPAN_DECLARE(int32_t) dds_phase_rate(float frequency);
41 
42 /*! \brief Find the frequency, in Hz, equivalent to a phase rate.
43  \param phase_rate The phase rate.
44  \return The equivalent frequency, in Hz.
45 */
46 SPAN_DECLARE(float) dds_frequency(int32_t phase_rate);
47 
48 /*! \brief Find the scaling factor needed to achieve a specified level in dBm0.
49  \param level The desired signal level, in dBm0.
50  \return The scaling factor.
51 */
52 SPAN_DECLARE(int16_t) dds_scaling_dbm0(float level);
53 
54 /*! \brief Find the scaling factor needed to achieve a specified level in dBmov.
55  \param level The desired signal level, in dBmov.
56  \return The scaling factor.
57 */
58 SPAN_DECLARE(int16_t) dds_scaling_dbov(float level);
59 
60 /*! \brief Find the amplitude for a particular phase.
61  \param phase The desired phase 32 bit phase.
62  \return The signal amplitude.
63 */
64 SPAN_DECLARE(int16_t) dds_lookup(uint32_t phase);
65 
66 /*! \brief Find the amplitude for a particular phase offset from an accumulated phase.
67  \param phase_acc The accumulated phase.
68  \param phase_offset The phase offset.
69  \return The signal amplitude.
70 */
71 SPAN_DECLARE(int16_t) dds_offset(uint32_t phase_acc, int32_t phase_offset);
72 
73 /*! \brief Advance the phase, without returning any new signal sample.
74  \param phase_acc A pointer to a phase accumulator value.
75  \param phase_rate The phase increment to be applied.
76 */
77 SPAN_DECLARE(void) dds_advance(uint32_t *phase_acc, int32_t phase_rate);
78 
79 /*! \brief Generate an integer tone sample.
80  \param phase_acc A pointer to a phase accumulator value.
81  \param phase_rate The phase increment to be applied.
82  \return The signal amplitude, between -32767 and 32767.
83 */
84 SPAN_DECLARE(int16_t) dds(uint32_t *phase_acc, int32_t phase_rate);
85 
86 /*! \brief Lookup the integer value of a specified phase.
87  \param phase The phase accumulator value to be looked up.
88  \return The signal amplitude, between -32767 and 32767.
89 */
90 SPAN_DECLARE(int16_t) dds_lookup(uint32_t phase);
91 
92 /*! \brief Generate an integer tone sample, with modulation.
93  \param phase_acc A pointer to a phase accumulator value.
94  \param phase_rate The phase increment to be applied.
95  \param scale The scaling factor.
96  \param phase The phase offset.
97  \return The signal amplitude, between -32767 and 32767.
98 */
99 SPAN_DECLARE(int16_t) dds_mod(uint32_t *phase_acc, int32_t phase_rate, int16_t scale, int32_t phase);
100 
101 /*! \brief Lookup the complex integer value of a specified phase.
102  \param phase The phase accumulator value to be looked up.
103  \return The complex signal amplitude, between (-32767, -32767) and (32767, 32767).
104 */
105 SPAN_DECLARE(complexi_t) dds_lookup_complexi(uint32_t phase);
106 
107 /*! \brief Generate a complex integer tone sample.
108  \param phase_acc A pointer to a phase accumulator value.
109  \param phase_rate The phase increment to be applied.
110  \return The complex signal amplitude, between (-32767, -32767) and (32767, 32767).
111 */
112 SPAN_DECLARE(complexi_t) dds_complexi(uint32_t *phase_acc, int32_t phase_rate);
113 
114 /*! \brief Generate a complex integer tone sample, with modulation.
115  \param phase_acc A pointer to a phase accumulator value.
116  \param phase_rate The phase increment to be applied.
117  \param scale The scaling factor.
118  \param phase The phase offset.
119  \return The complex signal amplitude, between (-32767, -32767) and (32767, 32767).
120 */
121 SPAN_DECLARE(complexi_t) dds_complexi_mod(uint32_t *phase_acc, int32_t phase_rate, int16_t scale, int32_t phase);
122 
123 /*! \brief Generate a complex 16 bit integer tone sample.
124  \param phase_acc A pointer to a phase accumulator value.
125  \param phase_rate The phase increment to be applied.
126  \return The complex signal amplitude, between (-32767, -32767) and (32767, 32767).
127 */
128 SPAN_DECLARE(complexi16_t) dds_lookup_complexi16(uint32_t phase);
129 
130 /*! \brief Generate a complex 16 bit integer tone sample.
131  \param phase_acc A pointer to a phase accumulator value.
132  \param phase_rate The phase increment to be applied.
133  \return The complex signal amplitude, between (-32767, -32767) and (32767, 32767).
134 */
135 SPAN_DECLARE(complexi16_t) dds_complexi16(uint32_t *phase_acc, int32_t phase_rate);
136 
137 /*! \brief Generate a complex 16bit integer tone sample, with modulation.
138  \param phase_acc A pointer to a phase accumulator value.
139  \param phase_rate The phase increment to be applied.
140  \param scale The scaling factor.
141  \param phase The phase offset.
142  \return The complex signal amplitude, between (-32767, -32767) and (32767, 32767).
143 */
144 SPAN_DECLARE(complexi16_t) dds_complexi16_mod(uint32_t *phase_acc, int32_t phase_rate, int16_t scale, int32_t phase);
145 
146 /*! \brief Generate a complex 32 bit integer tone sample, with modulation.
147  \param phase_acc A pointer to a phase accumulator value.
148  \param phase_rate The phase increment to be applied.
149  \param scale The scaling factor.
150  \param phase The phase offset.
151  \return The complex signal amplitude, between (-32767, -32767) and (32767, 32767).
152 */
153 SPAN_DECLARE(complexi32_t) dds_complexi32_mod(uint32_t *phase_acc, int32_t phase_rate, int16_t scale, int32_t phase);
154 
155 /*! \brief Generate a complex 32 bit integer tone sample.
156  \param phase_acc A pointer to a phase accumulator value.
157  \param phase_rate The phase increment to be applied.
158  \return The complex signal amplitude, between (-32767, -32767) and (32767, 32767).
159 */
160 SPAN_DECLARE(complexi32_t) dds_lookup_complexi32(uint32_t phase);
161 
162 /*! \brief Generate a complex 32 bit integer tone sample.
163  \param phase_acc A pointer to a phase accumulator value.
164  \param phase_rate The phase increment to be applied.
165  \return The complex signal amplitude, between (-32767, -32767) and (32767, 32767).
166 */
167 SPAN_DECLARE(complexi32_t) dds_complexi32(uint32_t *phase_acc, int32_t phase_rate);
168 
169 /*! \brief Generate a complex 32 bit integer tone sample, with modulation.
170  \param phase_acc A pointer to a phase accumulator value.
171  \param phase_rate The phase increment to be applied.
172  \param scale The scaling factor.
173  \param phase The phase offset.
174  \return The complex signal amplitude, between (-32767, -32767) and (32767, 32767).
175 */
176 SPAN_DECLARE(complexi32_t) dds_complexi32_mod(uint32_t *phase_acc, int32_t phase_rate, int16_t scale, int32_t phase);
177 
178 /*! \brief Find the phase rate equivalent to a frequency, in Hz.
179  \param frequency The frequency, in Hz.
180  \return The equivalent phase rate.
181 */
182 SPAN_DECLARE(int32_t) dds_phase_ratef(float frequency);
183 
184 /*! \brief Find the frequency, in Hz, equivalent to a phase rate.
185  \param phase_rate The phase rate.
186  \return The equivalent frequency, in Hz.
187 */
188 SPAN_DECLARE(float) dds_frequencyf(int32_t phase_rate);
189 
190 /*! \brief Find the scaling factor equivalent to a dBm0 value.
191  \param level The signal level in dBm0.
192  \return The equivalent scaling factor.
193 */
194 SPAN_DECLARE(float) dds_scaling_dbm0f(float level);
195 
196 /*! \brief Find the scaling factor equivalent to a dBmov value.
197  \param level The signal level in dBmov.
198  \return The equivalent scaling factor.
199 */
200 SPAN_DECLARE(float) dds_scaling_dbovf(float level);
201 
202 /*! \brief Advance the phase, without returning any new signal sample.
203  \param phase_acc A pointer to a phase accumulator value.
204  \param phase_rate The phase increment to be applied.
205 */
206 SPAN_DECLARE(void) dds_advancef(uint32_t *phase_acc, int32_t phase_rate);
207 
208 /*! \brief Generate a floating point tone sample.
209  \param phase_acc A pointer to a phase accumulator value.
210  \param phase_rate The phase increment to be applied.
211  \return The signal amplitude, between -1.0 and 1.0.
212 */
213 SPAN_DECLARE(float) ddsf(uint32_t *phase_acc, int32_t phase_rate);
214 
215 /*! \brief Lookup the floating point value of a specified phase.
216  \param phase The phase accumulator value to be looked up.
217  \return The signal amplitude, between -1.0 and 1.0.
218 */
219 SPAN_DECLARE(float) dds_lookupf(uint32_t phase);
220 
221 /*! \brief Generate a floating point tone sample, with modulation.
222  \param phase_acc A pointer to a phase accumulator value.
223  \param phase_rate The phase increment to be applied.
224  \param scale The scaling factor.
225  \param phase The phase offset.
226  \return The signal amplitude, between -1.0 and 1.0.
227 */
228 SPAN_DECLARE(float) dds_modf(uint32_t *phase_acc, int32_t phase_rate, float scale, int32_t phase);
229 
230 /*! \brief Generate a complex floating point tone sample.
231  \param phase_acc A pointer to a phase accumulator value.
232  \param phase_rate The phase increment to be applied.
233  \return The complex signal amplitude, between (-1.0, -1.0) and (1.0, 1.0).
234 */
235 SPAN_DECLARE(complexf_t) dds_complexf(uint32_t *phase_acc, int32_t phase_rate);
236 
237 /*! \brief Lookup the complex value of a specified phase.
238  \param phase The phase accumulator value to be looked up.
239  \return The complex signal amplitude, between (-1.0, -1.0) and (1.0, 1.0).
240 */
241 SPAN_DECLARE(complexf_t) dds_lookup_complexf(uint32_t phase_acc);
242 
243 /*! \brief Generate a complex floating point tone sample, with modulation.
244  \param phase_acc A pointer to a phase accumulator value.
245  \param phase_rate The phase increment to be applied.
246  \param scale The scaling factor.
247  \param phase The phase offset.
248  \return The complex signal amplitude, between (-1.0, -1.0) and (1.0, 1.0).
249 */
250 SPAN_DECLARE(complexf_t) dds_complex_modf(uint32_t *phase_acc, int32_t phase_rate, float scale, int32_t phase);
251 
252 #if defined(__cplusplus)
253 }
254 #endif
255 
256 #endif
257 /*- End of file ------------------------------------------------------------*/
complexf_t dds_complex_modf(uint32_t *phase_acc, int32_t phase_rate, float scale, int32_t phase)
Generate a complex floating point tone sample, with modulation.
Definition: dds_float.c:2177
int16_t dds_scaling_dbm0(float level)
Find the scaling factor needed to achieve a specified level in dBm0.
Definition: dds_int.c:203
Definition: complex.h:88
complexi16_t dds_complexi16_mod(uint32_t *phase_acc, int32_t phase_rate, int16_t scale, int32_t phase)
Generate a complex 16bit integer tone sample, with modulation.
Definition: dds_int.c:306
int32_t dds_phase_rate(float frequency)
Find the phase rate value to achieve a particular frequency.
Definition: dds_int.c:191
complexi_t dds_lookup_complexi(uint32_t phase)
Lookup the complex integer value of a specified phase.
Definition: dds_int.c:263
float dds_lookupf(uint32_t phase)
Lookup the floating point value of a specified phase.
Definition: dds_float.c:2143
int16_t dds_mod(uint32_t *phase_acc, int32_t phase_rate, int16_t scale, int32_t phase)
Generate an integer tone sample, with modulation.
Definition: dds_int.c:253
complexi16_t dds_lookup_complexi16(uint32_t phase)
Generate a complex 16 bit integer tone sample.
Definition: dds_int.c:290
complexi16_t dds_complexi16(uint32_t *phase_acc, int32_t phase_rate)
Generate a complex 16 bit integer tone sample.
Definition: dds_int.c:296
int32_t dds_phase_ratef(float frequency)
Find the phase rate equivalent to a frequency, in Hz.
Definition: dds_float.c:2103
complexf_t dds_lookup_complexf(uint32_t phase)
Lookup the complex value of a specified phase.
Definition: dds_float.c:2170
int16_t dds(uint32_t *phase_acc, int32_t phase_rate)
Generate an integer tone sample.
Definition: dds_int.c:243
int16_t dds_scaling_dbov(float level)
Find the scaling factor needed to achieve a specified level in dBmov.
Definition: dds_int.c:209
void dds_advancef(uint32_t *phase_acc, int32_t phase_rate)
Advance the phase, without returning any new signal sample.
Definition: dds_float.c:2127
Definition: complex.h:77
int16_t dds_offset(uint32_t phase_acc, int32_t phase_offset)
Find the amplitude for a particular phase offset from an accumulated phase.
Definition: dds_int.c:231
float dds_frequency(int32_t phase_rate)
Find the frequency, in Hz, equivalent to a phase rate.
Definition: dds_int.c:197
float dds_modf(uint32_t *phase_acc, int32_t phase_rate, float scale, int32_t phase)
Generate a floating point tone sample, with modulation.
Definition: dds_float.c:2149
complexf_t dds_complexf(uint32_t *phase_acc, int32_t phase_rate)
Generate a complex floating point tone sample.
Definition: dds_float.c:2159
float ddsf(uint32_t *phase_acc, int32_t phase_rate)
Generate a floating point tone sample.
Definition: dds_float.c:2133
complexi32_t dds_complexi32(uint32_t *phase_acc, int32_t phase_rate)
Generate a complex 32 bit integer tone sample.
Definition: dds_int.c:323
Definition: complex.h:42
int16_t dds_lookup(uint32_t phase)
Lookup the integer value of a specified phase.
Definition: dds_int.c:215
float dds_frequencyf(int32_t phase_rate)
Find the frequency, in Hz, equivalent to a phase rate.
Definition: dds_float.c:2109
float dds_scaling_dbovf(float level)
Find the scaling factor equivalent to a dBmov value.
Definition: dds_float.c:2121
complexi_t dds_complexi(uint32_t *phase_acc, int32_t phase_rate)
Generate a complex integer tone sample.
Definition: dds_int.c:269
void dds_advance(uint32_t *phase_acc, int32_t phase_rate)
Advance the phase, without returning any new signal sample.
Definition: dds_int.c:237
complexi32_t dds_lookup_complexi32(uint32_t phase)
Generate a complex 32 bit integer tone sample.
Definition: dds_int.c:317
complexi_t dds_complexi_mod(uint32_t *phase_acc, int32_t phase_rate, int16_t scale, int32_t phase)
Generate a complex integer tone sample, with modulation.
Definition: dds_int.c:279
complexi32_t dds_complexi32_mod(uint32_t *phase_acc, int32_t phase_rate, int16_t scale, int32_t phase)
Generate a complex 32 bit integer tone sample, with modulation.
Definition: dds_int.c:333
Definition: complex.h:99
float dds_scaling_dbm0f(float level)
Find the scaling factor equivalent to a dBm0 value.
Definition: dds_float.c:2115