diff options
-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 2f4506f71..08d4996a8 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; |