discuss-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Discuss-gnuradio] [PATCH] audio_alsa_sink : Fix warning on 32 bit build


From: philip
Subject: [Discuss-gnuradio] [PATCH] audio_alsa_sink : Fix warning on 32 bit builds.
Date: Mon, 3 Oct 2011 16:06:58 -0400

From: Philip Balister <address@hidden>

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 <address@hidden>
---
 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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]