summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim O'Shea <tim.oshea753@gmail.com>2016-03-27 01:39:48 -0400
committerTim O'Shea <tim.oshea753@gmail.com>2016-06-04 10:05:55 -0400
commit5cf34f170afbc81346c561fb2c1ba178749ab64f (patch)
treec45a2a8b59adaef52491991069c31c593bb26d38
parente89c1dcdf98281a84f0fb4070ca3b56baf5743e6 (diff)
channels: ensure flat fader behaves appropriately on long runs
-rw-r--r--gr-channels/lib/flat_fader_impl.cc44
1 files changed, 17 insertions, 27 deletions
diff --git a/gr-channels/lib/flat_fader_impl.cc b/gr-channels/lib/flat_fader_impl.cc
index 729e5d52ae..b749eb3b44 100644
--- a/gr-channels/lib/flat_fader_impl.cc
+++ b/gr-channels/lib/flat_fader_impl.cc
@@ -48,7 +48,7 @@ namespace gr {
d_table(8*1024),
- scale_sin(sqrtf(1.0/d_N)),
+ scale_sin(sqrtf(2.0/d_N)),
scale_los(sqrtf(d_K)/sqrtf(d_K+1)),
scale_nlos(1/sqrtf(d_K+1))
{
@@ -59,39 +59,31 @@ namespace gr {
}
}
-
- gr_complex flat_fader_impl::next_sample(){
- gr_complex H(0,0);
-
- for(int n=1; n<=d_N; n++){
- float alpha_n = (2*M_PI*n - M_PI + d_theta)/(4*d_N);
#if FASTSINCOS == 1
- float s_i = scale_sin*gr::fxpt::cos(gr::fxpt::float_to_fixed(2*M_PI*d_fDTs*d_m*gr::fxpt::cos(gr::fxpt::float_to_fixed(alpha_n))+d_psi[n]));
- float s_q = scale_sin*gr::fxpt::cos(gr::fxpt::float_to_fixed(2*M_PI*d_fDTs*d_m*gr::fxpt::sin(gr::fxpt::float_to_fixed(alpha_n))+d_phi[n]));
+#define _GRFASTSIN(x) gr::fxpt::sin(gr::fxpt::float_to_fixed(x))
+#define _GRFASTCOS(x) gr::fxpt::cos(gr::fxpt::float_to_fixed(x))
#elif FASTSINCOS == 2
- float s_i = scale_sin*d_table.cos(2*M_PI*d_fDTs*d_m*d_table.cos(alpha_n)+d_psi[n]);
- float s_q = scale_sin*d_table.cos(2*M_PI*d_fDTs*d_m*d_table.sin(alpha_n)+d_phi[n]);
-
+#define _GRFASTSIN(x) d_table.sin(x)
+#define _GRFASTCOS(x) d_table.cos(x)
#else
- float s_i = scale_sin*cos(2*M_PI*d_fDTs*d_m*cos(alpha_n)+d_psi[n]);
- float s_q = scale_sin*cos(2*M_PI*d_fDTs*d_m*sin(alpha_n)+d_phi[n]);
+#define _GRFASTSIN(x) sin(x)
+#define _GRFASTCOS(x) cos(x)
#endif
+ gr_complex flat_fader_impl::next_sample(){
+ gr_complex H(0,0);
+ for(int n=1; n<d_N; n++){
+ float alpha_n = (2*M_PI*n - M_PI + d_theta)/(4*d_N);
+ d_psi[n+1] = fmod(d_psi[n+1] + 2*M_PI*d_fDTs*_GRFASTCOS(alpha_n), 2*M_PI);
+ d_phi[n+1] = fmod(d_phi[n+1] + 2*M_PI*d_fDTs*_GRFASTCOS(alpha_n), 2*M_PI);
+ float s_i = scale_sin*_GRFASTCOS(d_psi[n+1]);
+ float s_q = scale_sin*_GRFASTSIN(d_phi[n+1]);
H += gr_complex(s_i, s_q);
}
if(d_LOS){
-#if FASTSINCOS == 1
- float los_i = gr::fxpt::cos(gr::fxpt::float_to_fixed(2*M_PI*d_fDTs*d_m*gr::fxpt::cos(gr::fxpt::float_to_fixed(d_theta_los)) + d_psi[0]));
- float los_q = gr::fxpt::sin(gr::fxpt::float_to_fixed(2*M_PI*d_fDTs*d_m*gr::fxpt::cos(gr::fxpt::float_to_fixed(d_theta_los)) + d_psi[0]));
-#elif FASTSINCOS == 2
- float los_i = d_table.cos(2*M_PI*d_fDTs*d_m*d_table.cos(d_theta_los) + d_psi[0]);
- float los_q = d_table.sin(2*M_PI*d_fDTs*d_m*d_table.cos(d_theta_los) + d_psi[0]);
-#else
- float los_i = cos(2*M_PI*d_fDTs*d_m*cos(d_theta_los) + d_psi[0]);
- float los_q = sin(2*M_PI*d_fDTs*d_m*cos(d_theta_los) + d_psi[0]);
-#endif
-
+ float los_i = _GRFASTCOS(2*M_PI*d_fDTs*d_m*_GRFASTCOS(d_theta_los) + d_psi[0]);
+ float los_q = _GRFASTSIN(2*M_PI*d_fDTs*d_m*_GRFASTCOS(d_theta_los) + d_psi[0]);
H = H*scale_nlos + gr_complex(los_i,los_q)*scale_los;
}
@@ -99,7 +91,6 @@ namespace gr {
d_m++;
update_theta();
return H;
-
}
void flat_fader_impl::update_theta()
@@ -114,4 +105,3 @@ namespace gr {
} /* namespace channels */
} /* namespace gr */
-