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 #include "dsp.h"
00046
00047 #if defined(FORCE_ALL_GENERICS) || \
00048 defined(FORCE_GENERIC_GEN16_SAW) || \
00049 !defined(TARGET_SPECIFIC_GEN16_SAW)
00050
00051 dsp16_t dsp16_gen_saw(dsp16_t *vect1, int size, int f, int fs, dsp16_t duty, dsp16_t delay)
00052 {
00053 int i = 0;
00054 S32 t_low_inc, t_high_inc, t;
00055 dsp16_t delta_rise, delta_decrease, delta;
00056
00057
00058 t_low_inc = fs / f;
00059
00060 t_high_inc = (((S32) duty) * ((S32) t_low_inc)) >> DSP16_QB;
00061
00062 t = (((S32) delay) * ((S32) t_low_inc)) >> DSP16_QB;
00063
00064 t_low_inc -= t_high_inc;
00065
00066
00067 delta_rise = (DSP16_Q(1.) / t_high_inc) * 2;
00068
00069 delta_decrease = (DSP16_Q(1.) / t_low_inc) * 2;
00070
00071
00072 if (t < t_high_inc)
00073 delta = DSP16_Q(-1.) + t * delta_rise;
00074 else
00075 delta = DSP16_Q(1.) - (t - t_high_inc) * delta_decrease;
00076
00077 while(i < size)
00078 {
00079 int lim, j;
00080
00081 if (i)
00082 t = 0;
00083
00084 lim = Max(0, Min(t_high_inc - t, size - i));
00085 for(j=0; j<lim; j++)
00086 vect1[i++] = (delta += delta_rise);
00087 t += lim;
00088
00089 if (j)
00090 delta = DSP16_Q(1.);
00091
00092 lim = Min(t_high_inc + t_low_inc - t, size - i);
00093 for(j=0; j<lim; j++)
00094 vect1[i++] = (delta -= delta_decrease);
00095 t += lim;
00096
00097 delta = DSP16_Q(-1.);
00098 }
00099
00100 return (t << DSP16_QB) / (t_high_inc + t_low_inc);
00101 }
00102
00103 #endif
00104
00105 #if defined(FORCE_ALL_GENERICS) || \
00106 defined(FORCE_GENERIC_GEN32_SAW) || \
00107 !defined(TARGET_SPECIFIC_GEN32_SAW)
00108
00109 dsp32_t dsp32_gen_saw(dsp32_t *vect1, int size, int f, int fs, dsp32_t duty, dsp32_t delay)
00110 {
00111 int i = 0;
00112 S32 t_low_inc, t_high_inc, t;
00113 dsp32_t delta_rise, delta_decrease, delta;
00114
00115
00116 t_low_inc = fs / f;
00117
00118 t_high_inc = (((S64) duty) * ((S64) t_low_inc)) >> DSP32_QB;
00119
00120 t = (((S64) delay) * ((S64) t_low_inc)) >> DSP32_QB;
00121
00122 t_low_inc -= t_high_inc;
00123
00124
00125 delta_rise = (DSP32_Q(1.) / t_high_inc) * 2;
00126
00127 delta_decrease = (DSP32_Q(1.) / t_low_inc) * 2;
00128
00129
00130 if (t < t_high_inc)
00131 delta = DSP32_Q(-1.) + t * delta_rise;
00132 else
00133 delta = DSP32_Q(1.) - (t - t_high_inc) * delta_decrease;
00134
00135 while(i < size)
00136 {
00137 int lim, j;
00138
00139 if (i)
00140 t = 0;
00141
00142 lim = Max(0, Min(t_high_inc - t, size - i));
00143 for(j=0; j<lim; j++)
00144 vect1[i++] = (delta += delta_rise);
00145 t += lim;
00146
00147 if (j)
00148 delta = DSP32_Q(1.);
00149
00150 lim = Min(t_high_inc + t_low_inc - t, size - i);
00151 for(j=0; j<lim; j++)
00152 vect1[i++] = (delta -= delta_decrease);
00153 t += lim;
00154
00155 delta = DSP32_Q(-1.);
00156 }
00157
00158 return (t << DSP32_QB) / (t_high_inc + t_low_inc);
00159 }
00160
00161
00162 #endif