00001
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 #include "dsp.h"
00047
00048 #ifndef MIN
00049 # define MIN(x, y) (((x) < (y))?(x):(y))
00050 #endif
00051
00052 #if defined(FORCE_ALL_GENERICS) || \
00053 defined(FORCE_GENERIC_GEN16_RECT) || \
00054 !defined(TARGET_SPECIFIC_GEN16_RECT)
00055
00056 void dsp16_gen_rect(dsp16_t *vect1, int size, int f, int fs, dsp16_t duty, dsp16_t delay)
00057 {
00058 int i = 0;
00059 int t_low_inc, t_high_inc, cp;
00060 int t_low, t_high, t_delay;
00061
00062
00063 t_low_inc = fs / f;
00064
00065 t_high_inc = (((S32) duty) * ((S32) t_low_inc)) >> DSP16_QB;
00066
00067 t_delay = (((S32) delay) * ((S32) t_low_inc)) >> DSP16_QB;
00068
00069 t_low_inc -= t_high_inc;
00070
00071 i = 0;
00072
00073
00074 t_high = MIN(t_high_inc, t_delay - t_low_inc);
00075 t_low = MIN(t_low_inc, t_delay);
00076 if (t_high > 0)
00077 t_low += t_high;
00078
00079
00080 while(i < size)
00081 {
00082
00083 cp = MIN(t_high, size);
00084 for(; i<cp; i++)
00085 vect1[i] = DSP16_Q(1.);
00086
00087
00088 cp = MIN(t_low, size);
00089 for(; i<cp; i++)
00090 vect1[i] = DSP16_Q(-1.);
00091
00092 t_high = t_high_inc + i;
00093 t_low = t_high + t_low_inc;
00094 }
00095
00096 }
00097
00098 #endif
00099
00100 #if defined(FORCE_ALL_GENERICS) || \
00101 defined(FORCE_GENERIC_GEN32_RECT) || \
00102 !defined(TARGET_SPECIFIC_GEN32_RECT)
00103
00104 void dsp32_gen_rect(dsp32_t *vect1, int size, int f, int fs, dsp32_t duty, dsp32_t delay)
00105 {
00106 int i = 0;
00107 int t_low_inc, t_high_inc, cp;
00108 int t_low, t_high, t_delay;
00109
00110
00111 t_low_inc = fs / f;
00112
00113 t_high_inc = (((S64) duty) * ((S64) t_low_inc)) >> DSP32_QB;
00114
00115 t_delay = (((S64) delay) * ((S64) t_low_inc)) >> DSP32_QB;
00116
00117 t_low_inc -= t_high_inc;
00118
00119 i = 0;
00120
00121
00122 t_high = MIN(t_high_inc, t_delay - t_low_inc);
00123 t_low = MIN(t_low_inc, t_delay);
00124 if (t_high > 0)
00125 t_low += t_high;
00126
00127
00128 while(i < size)
00129 {
00130
00131 cp = MIN(t_high, size);
00132 for(; i<cp; i++)
00133 vect1[i] = DSP32_Q(1.);
00134
00135
00136 cp = MIN(t_low, size);
00137 for(; i<cp; i++)
00138 vect1[i] = DSP32_Q(-1.);
00139
00140 t_high = t_high_inc + i;
00141 t_low = t_high + t_low_inc;
00142 }
00143
00144 }
00145
00146 #endif