diff options
author | Philip Balister <philip@opensdr.com> | 2011-10-07 16:08:06 -0400 |
---|---|---|
committer | Philip Balister <philip@opensdr.com> | 2011-10-07 16:08:06 -0400 |
commit | 334f45e5599fd816d614a4b2a3092b0ac2d2904e (patch) | |
tree | 347521946290038c190cf4b981b77dc58d01ba7d | |
parent | 178590c3afae08ccafd3db711e2cfa65c841403f (diff) |
audio_alsa_source : Fix warning on 32 bit builds.
On machines where sizeof(long) = sizeof(int) the code for calculating
scale factors produced an overflow warning. This change simplifies the
code by eliminating the shift. The compiler should calculate the constant
at compile time anyway.
Signed-off-by: Philip Balister <philip@opensdr.com>
-rw-r--r-- | gr-audio/lib/alsa/audio_alsa_source.cc | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/gr-audio/lib/alsa/audio_alsa_source.cc b/gr-audio/lib/alsa/audio_alsa_source.cc index 2f4506f71c..08d4996a87 100644 --- a/gr-audio/lib/alsa/audio_alsa_source.cc +++ b/gr-audio/lib/alsa/audio_alsa_source.cc @@ -308,7 +308,7 @@ audio_alsa_source::work_s16 (int noutput_items, gr_vector_void_star &output_items) { typedef gr_int16 sample_t; // the type of samples we're creating - static const int NBITS = 16; // # of bits in a sample + static const float scale_factor = 1.0 / std::pow(2.0f, 16-1); unsigned int nchan = output_items.size (); float **out = (float **) &output_items[0]; @@ -329,7 +329,7 @@ audio_alsa_source::work_s16 (int noutput_items, bi = 0; for (unsigned int i = 0; i < d_period_size; i++){ for (unsigned int chan = 0; chan < nchan; chan++){ - out[chan][i] = (float) buf[bi++] * (1.0 / (float) ((1L << (NBITS-1)) - 1)); + out[chan][i] = (float) buf[bi++] * scale_factor; } } @@ -346,7 +346,7 @@ audio_alsa_source::work_s16_2x1 (int noutput_items, gr_vector_void_star &output_items) { typedef gr_int16 sample_t; // the type of samples we're creating - static const int NBITS = 16; // # of bits in a sample + static const float scale_factor = 1.0 / std::pow(2.0f, 16-1); unsigned int nchan = output_items.size (); float **out = (float **) &output_items[0]; @@ -370,7 +370,7 @@ audio_alsa_source::work_s16_2x1 (int noutput_items, for (unsigned int i = 0; i < d_period_size; i++){ int t = (buf[bi] + buf[bi+1]) / 2; bi += 2; - out[0][i] = (float) t * (1.0 / (float) ((1L << (NBITS-1)) - 1)); + out[0][i] = (float) t * scale_factor; } return d_period_size; @@ -385,7 +385,7 @@ audio_alsa_source::work_s32 (int noutput_items, gr_vector_void_star &output_items) { typedef gr_int32 sample_t; // the type of samples we're creating - static const int NBITS = 32; // # of bits in a sample + static const float scale_factor = 1.0 / std::pow(2.0f, 32-1); unsigned int nchan = output_items.size (); float **out = (float **) &output_items[0]; @@ -406,7 +406,7 @@ audio_alsa_source::work_s32 (int noutput_items, bi = 0; for (unsigned int i = 0; i < d_period_size; i++){ for (unsigned int chan = 0; chan < nchan; chan++){ - out[chan][i] = (float) buf[bi++] * (1.0 / (float) ((1L << (NBITS-1)) - 1)); + out[chan][i] = (float) buf[bi++] * scale_factor; } } @@ -423,7 +423,7 @@ audio_alsa_source::work_s32_2x1 (int noutput_items, gr_vector_void_star &output_items) { typedef gr_int32 sample_t; // the type of samples we're creating - static const int NBITS = 32; // # of bits in a sample + static const float scale_factor = 1.0 / std::pow(2.0f, 32-1); unsigned int nchan = output_items.size (); float **out = (float **) &output_items[0]; @@ -447,7 +447,7 @@ audio_alsa_source::work_s32_2x1 (int noutput_items, for (unsigned int i = 0; i < d_period_size; i++){ int t = (buf[bi] + buf[bi+1]) / 2; bi += 2; - out[0][i] = (float) t * (1.0 / (float) ((1L << (NBITS-1)) - 1)); + out[0][i] = (float) t * scale_factor; } return d_period_size; |