[PATCH] Fix for warning

From: Philip B. [email protected]

Here is a proposed fix for a compile warning on 32 bit machines. I am
interested in feedback on how I replace the shift with 2^(NBITS-1). I
don’t see any reason to keep teh shift, since the compiler should do the
math at compile time. I am a little worried about the NBITS=32 case and
how
is implicitedly converted to a float.

Philip B. (1):
audio_alsa_sink : Fix warning on 32 bit builds.

gr-audio/lib/alsa/audio_alsa_sink.cc | 8 +++±—
1 files changed, 4 insertions(+), 4 deletions(-)


1.7.6.4

From: Philip B. [email protected]

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 B. [email protected]

gr-audio/lib/alsa/audio_alsa_sink.cc | 8 +++±—
1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/gr-audio/lib/alsa/audio_alsa_sink.cc
b/gr-audio/lib/alsa/audio_alsa_sink.cc
index 5fd197e…2aa6fc0 100644
— a/gr-audio/lib/alsa/audio_alsa_sink.cc
+++ b/gr-audio/lib/alsa/audio_alsa_sink.cc
@@ -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] * ((2^(NBITS-1)) - 1));
    }
    }

@@ -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] * ((2^(NBITS-1)) - 1));
    }
    }

@@ -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] * ((2^(NBITS-1)) - 1));
     buf[bi++] = t;
     buf[bi++] = t;
    
    }
    @@ -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] * ((2^(NBITS-1)) - 1));
     buf[bi++] = t;
     buf[bi++] = t;
    
    }

    1.7.6.4