Permalink
Browse files

channels: ensure flat fader behaves appropriately on long runs

  • Loading branch information...
1 parent c0381e0 commit ba7f4d56242359fa3b3c1768b799e847987a36d7 @osh committed Mar 27, 2016
Showing with 16 additions and 26 deletions.
  1. +16 −26 gr-channels/lib/flat_fader_impl.cc
@@ -59,47 +59,38 @@ 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+1]));
- 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+1]));
+#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+1]);
- float s_q = scale_sin*d_table.cos(2*M_PI*d_fDTs*d_m*d_table.sin(alpha_n)+d_phi[n+1]);
-
+#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+1]);
- float s_q = scale_sin*cos(2*M_PI*d_fDTs*d_m*sin(alpha_n)+d_phi[n+1]);
+#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;
}
//out[i] = in[i]*H;
d_m++;
update_theta();
return H;
-
}
void flat_fader_impl::update_theta()
@@ -114,4 +105,3 @@ namespace gr {
} /* namespace channels */
} /* namespace gr */
-

0 comments on commit ba7f4d5

Please sign in to comment.