diff options
author | Philip Balister | 2011-10-03 14:48:09 -0400 |
---|---|---|
committer | Philip Balister | 2011-10-03 18:15:05 -0400 |
commit | 774373b4d09cab2ce341207161f0a27901bcea10 (patch) | |
tree | 8b248190ad071c4eb3633a7ebe4cded737cca0ec /gr-audio | |
parent | cb23b7a23ca8a1b1331e3d70e97425b1d52b2222 (diff) | |
download | gnuradio-774373b4d09cab2ce341207161f0a27901bcea10.tar.gz gnuradio-774373b4d09cab2ce341207161f0a27901bcea10.tar.bz2 gnuradio-774373b4d09cab2ce341207161f0a27901bcea10.zip |
audio_alsa_sink : 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>
Diffstat (limited to 'gr-audio')
-rw-r--r-- | gr-audio/lib/alsa/audio_alsa_sink.cc | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/gr-audio/lib/alsa/audio_alsa_sink.cc b/gr-audio/lib/alsa/audio_alsa_sink.cc index 5fd197ec7..0bda42470 100644 --- a/gr-audio/lib/alsa/audio_alsa_sink.cc +++ b/gr-audio/lib/alsa/audio_alsa_sink.cc @@ -326,7 +326,7 @@ audio_alsa_sink::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 = std::pow(2.0f, 16-1) - 1; unsigned int nchan = input_items.size (); const float **in = (const float **) &input_items[0]; @@ -343,7 +343,7 @@ audio_alsa_sink::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++){ - buf[bi++] = (sample_t) (in[chan][i] * (float) ((1L << (NBITS-1)) - 1)); + buf[bi++] = (sample_t) (in[chan][i] * scale_factor); } } @@ -368,7 +368,7 @@ audio_alsa_sink::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 = std::pow(2.0f, 32-1) - 1; unsigned int nchan = input_items.size (); const float **in = (const float **) &input_items[0]; @@ -385,7 +385,7 @@ audio_alsa_sink::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++){ - buf[bi++] = (sample_t) (in[chan][i] * (float) ((1L << (NBITS-1)) - 1)); + buf[bi++] = (sample_t) (in[chan][i] * scale_factor); } } @@ -410,7 +410,7 @@ audio_alsa_sink::work_s16_1x2 (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 = std::pow(2.0f, 16-1) - 1; assert (input_items.size () == 1); static const unsigned int nchan = 2; @@ -427,7 +427,7 @@ audio_alsa_sink::work_s16_1x2 (int noutput_items, // process one period of data bi = 0; for (unsigned int i = 0; i < d_period_size; i++){ - sample_t t = (sample_t) (in[0][i] * (float) ((1L << (NBITS-1)) - 1)); + sample_t t = (sample_t) (in[0][i] * scale_factor); buf[bi++] = t; buf[bi++] = t; } @@ -452,7 +452,7 @@ audio_alsa_sink::work_s32_1x2 (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 = std::pow(2.0f, 32-1) - 1; assert (input_items.size () == 1); static unsigned int nchan = 2; @@ -469,7 +469,7 @@ audio_alsa_sink::work_s32_1x2 (int noutput_items, // process one period of data bi = 0; for (unsigned int i = 0; i < d_period_size; i++){ - sample_t t = (sample_t) (in[0][i] * (float) ((1L << (NBITS-1)) - 1)); + sample_t t = (sample_t) (in[0][i] * scale_factor); buf[bi++] = t; buf[bi++] = t; } |