diff options
author | Marcus Müller <mmueller@gnuradio.org> | 2019-08-07 21:45:12 +0200 |
---|---|---|
committer | Marcus Müller <marcus@hostalia.de> | 2019-08-09 23:04:28 +0200 |
commit | f7bbf2c1d8d780294f3e016aff239ca35eb6516e (patch) | |
tree | e09ab6112e02b2215b2d59ac24d3d6ea2edac745 /gr-vocoder/lib | |
parent | 78431dc6941e3acc67c858277dfe4a0ed583643c (diff) |
Tree: clang-format without the include sorting
Diffstat (limited to 'gr-vocoder/lib')
46 files changed, 2285 insertions, 2481 deletions
diff --git a/gr-vocoder/lib/alaw_decode_bs_impl.cc b/gr-vocoder/lib/alaw_decode_bs_impl.cc index 2f4330457..eadc7f458 100644 --- a/gr-vocoder/lib/alaw_decode_bs_impl.cc +++ b/gr-vocoder/lib/alaw_decode_bs_impl.cc @@ -29,44 +29,39 @@ #include <limits.h> namespace gr { - namespace vocoder { +namespace vocoder { extern "C" { #include "g7xx/g72x.h" } - alaw_decode_bs::sptr - alaw_decode_bs::make() - { - return gnuradio::get_initial_sptr - (new alaw_decode_bs_impl()); - } - - alaw_decode_bs_impl::alaw_decode_bs_impl() - : sync_block("vocoder_alaw_decode_bs", - io_signature::make(1, 1, sizeof(unsigned char)), - io_signature::make(1, 1, sizeof(short))) - { - } +alaw_decode_bs::sptr alaw_decode_bs::make() +{ + return gnuradio::get_initial_sptr(new alaw_decode_bs_impl()); +} - alaw_decode_bs_impl::~alaw_decode_bs_impl() - { - } +alaw_decode_bs_impl::alaw_decode_bs_impl() + : sync_block("vocoder_alaw_decode_bs", + io_signature::make(1, 1, sizeof(unsigned char)), + io_signature::make(1, 1, sizeof(short))) +{ +} - int - alaw_decode_bs_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - const unsigned char *in = (const unsigned char*)input_items[0]; - short *out = (short*)output_items[0]; +alaw_decode_bs_impl::~alaw_decode_bs_impl() {} - for(int i = 0; i < noutput_items; i++) { - out[i] = alaw2linear(in[i]); - } +int alaw_decode_bs_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + const unsigned char* in = (const unsigned char*)input_items[0]; + short* out = (short*)output_items[0]; - return noutput_items; + for (int i = 0; i < noutput_items; i++) { + out[i] = alaw2linear(in[i]); } - } /* namespace vocoder */ + return noutput_items; +} + +} /* namespace vocoder */ } /* namespace gr */ diff --git a/gr-vocoder/lib/alaw_decode_bs_impl.h b/gr-vocoder/lib/alaw_decode_bs_impl.h index cf515bc6f..9872dab2e 100644 --- a/gr-vocoder/lib/alaw_decode_bs_impl.h +++ b/gr-vocoder/lib/alaw_decode_bs_impl.h @@ -26,20 +26,20 @@ #include <gnuradio/vocoder/alaw_decode_bs.h> namespace gr { - namespace vocoder { +namespace vocoder { - class alaw_decode_bs_impl : public alaw_decode_bs - { - public: - alaw_decode_bs_impl(); - ~alaw_decode_bs_impl(); +class alaw_decode_bs_impl : public alaw_decode_bs +{ +public: + alaw_decode_bs_impl(); + ~alaw_decode_bs_impl(); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace vocoder */ +} /* namespace vocoder */ } /* namespace gr */ #endif /* INCLUDED_VOCODER_ALAW_DECODE_BS_IMPL_H */ diff --git a/gr-vocoder/lib/alaw_encode_sb_impl.cc b/gr-vocoder/lib/alaw_encode_sb_impl.cc index 9c941e790..388b9c874 100644 --- a/gr-vocoder/lib/alaw_encode_sb_impl.cc +++ b/gr-vocoder/lib/alaw_encode_sb_impl.cc @@ -29,44 +29,39 @@ #include <limits.h> namespace gr { - namespace vocoder { +namespace vocoder { extern "C" { #include "g7xx/g72x.h" } - alaw_encode_sb::sptr - alaw_encode_sb::make() - { - return gnuradio::get_initial_sptr - (new alaw_encode_sb_impl()); - } - - alaw_encode_sb_impl::alaw_encode_sb_impl() - : sync_block("avocoder_law_encode_sb", - io_signature::make(1, 1, sizeof(short)), - io_signature::make(1, 1, sizeof(unsigned char))) - { - } +alaw_encode_sb::sptr alaw_encode_sb::make() +{ + return gnuradio::get_initial_sptr(new alaw_encode_sb_impl()); +} - alaw_encode_sb_impl::~alaw_encode_sb_impl() - { - } +alaw_encode_sb_impl::alaw_encode_sb_impl() + : sync_block("avocoder_law_encode_sb", + io_signature::make(1, 1, sizeof(short)), + io_signature::make(1, 1, sizeof(unsigned char))) +{ +} - int - alaw_encode_sb_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - const short *in = (const short*)input_items[0]; - unsigned char *out = (unsigned char*)output_items[0]; +alaw_encode_sb_impl::~alaw_encode_sb_impl() {} - for(int i = 0; i < noutput_items; i++) { - out[i] = linear2alaw(in[i]); - } +int alaw_encode_sb_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + const short* in = (const short*)input_items[0]; + unsigned char* out = (unsigned char*)output_items[0]; - return noutput_items; + for (int i = 0; i < noutput_items; i++) { + out[i] = linear2alaw(in[i]); } - } /* namespace vocoder */ + return noutput_items; +} + +} /* namespace vocoder */ } /* namespace gr */ diff --git a/gr-vocoder/lib/alaw_encode_sb_impl.h b/gr-vocoder/lib/alaw_encode_sb_impl.h index 6afa95859..bc506cac0 100644 --- a/gr-vocoder/lib/alaw_encode_sb_impl.h +++ b/gr-vocoder/lib/alaw_encode_sb_impl.h @@ -26,20 +26,20 @@ #include <gnuradio/vocoder/alaw_encode_sb.h> namespace gr { - namespace vocoder { +namespace vocoder { - class alaw_encode_sb_impl : public alaw_encode_sb - { - public: - alaw_encode_sb_impl(); - ~alaw_encode_sb_impl(); +class alaw_encode_sb_impl : public alaw_encode_sb +{ +public: + alaw_encode_sb_impl(); + ~alaw_encode_sb_impl(); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace vocoder */ +} /* namespace vocoder */ } /* namespace gr */ #endif /* INCLUDED_VOCODER_ALAW_ENCODE_SB_IMPL_H */ diff --git a/gr-vocoder/lib/codec2.cc b/gr-vocoder/lib/codec2.cc index 6d0ef6135..09e45900b 100644 --- a/gr-vocoder/lib/codec2.cc +++ b/gr-vocoder/lib/codec2.cc @@ -27,7 +27,7 @@ #include <gnuradio/vocoder/codec2.h> namespace gr { - namespace vocoder { +namespace vocoder { - } /* namespace vocoder */ +} /* namespace vocoder */ } /* namespace gr */ diff --git a/gr-vocoder/lib/codec2_decode_ps_impl.cc b/gr-vocoder/lib/codec2_decode_ps_impl.cc index c3c682beb..e0140f06b 100644 --- a/gr-vocoder/lib/codec2_decode_ps_impl.cc +++ b/gr-vocoder/lib/codec2_decode_ps_impl.cc @@ -35,78 +35,75 @@ extern "C" { #include <assert.h> namespace gr { - namespace vocoder { - - codec2_decode_ps::sptr - codec2_decode_ps::make(int mode) - { - CODEC2 *codec2; - int samples_per_frame, bits_per_frame; - - // Check the number of input samples and output bits per frame. - codec2 = codec2_create(mode); - samples_per_frame = codec2_samples_per_frame(codec2); - bits_per_frame = codec2_bits_per_frame(codec2); - codec2_destroy(codec2); - - return gnuradio::get_initial_sptr - (new codec2_decode_ps_impl(mode, samples_per_frame, bits_per_frame)); - } +namespace vocoder { +codec2_decode_ps::sptr codec2_decode_ps::make(int mode) +{ + CODEC2* codec2; + int samples_per_frame, bits_per_frame; - codec2_decode_ps_impl::codec2_decode_ps_impl (int mode, int samples_per_frame, int bits_per_frame) - : sync_interpolator("vocoder_codec2_decode_ps", - io_signature::make(1, 1, bits_per_frame * sizeof(char)), - io_signature::make (1, 1, sizeof(short)), - samples_per_frame), - d_frame_buf((bits_per_frame + 7) / 8, 0) - { - if((d_codec2 = codec2_create(mode)) == 0) - throw std::runtime_error("codec2_decode_ps_impl: codec2_create failed"); - d_samples_per_frame = samples_per_frame; - d_bits_per_frame = bits_per_frame; - d_bytes_per_frame = (bits_per_frame + 7) / 8; - } + // Check the number of input samples and output bits per frame. + codec2 = codec2_create(mode); + samples_per_frame = codec2_samples_per_frame(codec2); + bits_per_frame = codec2_bits_per_frame(codec2); + codec2_destroy(codec2); + + return gnuradio::get_initial_sptr( + new codec2_decode_ps_impl(mode, samples_per_frame, bits_per_frame)); +} - codec2_decode_ps_impl::~codec2_decode_ps_impl() - { - codec2_destroy(d_codec2); - } - int - codec2_decode_ps_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - const unsigned char *in = (const unsigned char*)input_items[0]; - short *out = (short *) output_items[0]; +codec2_decode_ps_impl::codec2_decode_ps_impl(int mode, + int samples_per_frame, + int bits_per_frame) + : sync_interpolator("vocoder_codec2_decode_ps", + io_signature::make(1, 1, bits_per_frame * sizeof(char)), + io_signature::make(1, 1, sizeof(short)), + samples_per_frame), + d_frame_buf((bits_per_frame + 7) / 8, 0) +{ + if ((d_codec2 = codec2_create(mode)) == 0) + throw std::runtime_error("codec2_decode_ps_impl: codec2_create failed"); + d_samples_per_frame = samples_per_frame; + d_bits_per_frame = bits_per_frame; + d_bytes_per_frame = (bits_per_frame + 7) / 8; +} + +codec2_decode_ps_impl::~codec2_decode_ps_impl() { codec2_destroy(d_codec2); } - assert((noutput_items % d_samples_per_frame) == 0); +int codec2_decode_ps_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + const unsigned char* in = (const unsigned char*)input_items[0]; + short* out = (short*)output_items[0]; - for(int i = 0; i < noutput_items; i += d_samples_per_frame) { - pack_frame(in, &d_frame_buf[0]); - codec2_decode (d_codec2, out, const_cast<unsigned char*>(&d_frame_buf[0])); - in += d_bits_per_frame * sizeof (char); - out += d_samples_per_frame; - } + assert((noutput_items % d_samples_per_frame) == 0); - return noutput_items; + for (int i = 0; i < noutput_items; i += d_samples_per_frame) { + pack_frame(in, &d_frame_buf[0]); + codec2_decode(d_codec2, out, const_cast<unsigned char*>(&d_frame_buf[0])); + in += d_bits_per_frame * sizeof(char); + out += d_samples_per_frame; } - void - codec2_decode_ps_impl::pack_frame(const unsigned char *in_unpacked, unsigned char *out_packed) - { - memset((void *) &d_frame_buf[0], 0x00, d_bytes_per_frame); - - int byte_idx = 0, bit_idx = 0; - for(int k = 0; k < d_bits_per_frame; k++) { - out_packed[byte_idx] |= ((in_unpacked[k] & 0x01) << (7-bit_idx)); - bit_idx = (bit_idx + 1) % 8; - if (bit_idx == 0) { - byte_idx++; - } - } + return noutput_items; +} + +void codec2_decode_ps_impl::pack_frame(const unsigned char* in_unpacked, + unsigned char* out_packed) +{ + memset((void*)&d_frame_buf[0], 0x00, d_bytes_per_frame); + + int byte_idx = 0, bit_idx = 0; + for (int k = 0; k < d_bits_per_frame; k++) { + out_packed[byte_idx] |= ((in_unpacked[k] & 0x01) << (7 - bit_idx)); + bit_idx = (bit_idx + 1) % 8; + if (bit_idx == 0) { + byte_idx++; + } } +} - } /* namespace vocoder */ +} /* namespace vocoder */ } /* namespace gr */ diff --git a/gr-vocoder/lib/codec2_decode_ps_impl.h b/gr-vocoder/lib/codec2_decode_ps_impl.h index db5ba2eef..d14603be9 100644 --- a/gr-vocoder/lib/codec2_decode_ps_impl.h +++ b/gr-vocoder/lib/codec2_decode_ps_impl.h @@ -26,27 +26,29 @@ #include <gnuradio/vocoder/codec2_decode_ps.h> namespace gr { - namespace vocoder { +namespace vocoder { - class codec2_decode_ps_impl : public codec2_decode_ps - { - private: - CODEC2 *d_codec2; - int d_samples_per_frame, d_bits_per_frame, d_bytes_per_frame; - std::vector<unsigned char> d_frame_buf; //!< Store 1 packed frame for decoding +class codec2_decode_ps_impl : public codec2_decode_ps +{ +private: + CODEC2* d_codec2; + int d_samples_per_frame, d_bits_per_frame, d_bytes_per_frame; + std::vector<unsigned char> d_frame_buf; //!< Store 1 packed frame for decoding - void pack_frame(const unsigned char *in_unpacked, unsigned char *out_packed); //!< Pack the bytes from unpacked bits for codec2 + void pack_frame( + const unsigned char* in_unpacked, + unsigned char* out_packed); //!< Pack the bytes from unpacked bits for codec2 - public: - codec2_decode_ps_impl(int mode, int samples_per_frame, int bits_per_frame); - ~codec2_decode_ps_impl(); +public: + codec2_decode_ps_impl(int mode, int samples_per_frame, int bits_per_frame); + ~codec2_decode_ps_impl(); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace vocoder */ +} /* namespace vocoder */ } /* namespace gr */ #endif /* INCLUDED_VOCODER_CODEC2_DECODE_PS_IMPL_H */ diff --git a/gr-vocoder/lib/codec2_encode_sp_impl.cc b/gr-vocoder/lib/codec2_encode_sp_impl.cc index ae76b0947..6e69b69c2 100644 --- a/gr-vocoder/lib/codec2_encode_sp_impl.cc +++ b/gr-vocoder/lib/codec2_encode_sp_impl.cc @@ -36,72 +36,68 @@ extern "C" { #include <iomanip> namespace gr { - namespace vocoder { +namespace vocoder { - codec2_encode_sp::sptr - codec2_encode_sp::make(int mode) - { - CODEC2 *codec2; - int samples_per_frame, bits_per_frame; +codec2_encode_sp::sptr codec2_encode_sp::make(int mode) +{ + CODEC2* codec2; + int samples_per_frame, bits_per_frame; - // Check the number of input samples and output bits per frame. - codec2 = codec2_create(mode); - samples_per_frame = codec2_samples_per_frame(codec2); - bits_per_frame = codec2_bits_per_frame(codec2); - codec2_destroy(codec2); + // Check the number of input samples and output bits per frame. + codec2 = codec2_create(mode); + samples_per_frame = codec2_samples_per_frame(codec2); + bits_per_frame = codec2_bits_per_frame(codec2); + codec2_destroy(codec2); - return gnuradio::get_initial_sptr - (new codec2_encode_sp_impl(mode, samples_per_frame, bits_per_frame)); - } + return gnuradio::get_initial_sptr( + new codec2_encode_sp_impl(mode, samples_per_frame, bits_per_frame)); +} - codec2_encode_sp_impl::codec2_encode_sp_impl(int mode, int samples_per_frame, int bits_per_frame) - : sync_decimator("vocoder_codec2_encode_sp", - io_signature::make(1, 1, sizeof(short)), - io_signature::make(1, 1, bits_per_frame * sizeof(char)), - samples_per_frame), +codec2_encode_sp_impl::codec2_encode_sp_impl(int mode, + int samples_per_frame, + int bits_per_frame) + : sync_decimator("vocoder_codec2_encode_sp", + io_signature::make(1, 1, sizeof(short)), + io_signature::make(1, 1, bits_per_frame * sizeof(char)), + samples_per_frame), d_frame_buf((bits_per_frame + 7) / 8, 0) - { - if((d_codec2 = codec2_create(mode)) == 0) - throw std::runtime_error("codec2_encode_sp_impl: codec2_create failed"); - d_samples_per_frame = samples_per_frame; - d_bits_per_frame = bits_per_frame; - } - - codec2_encode_sp_impl::~codec2_encode_sp_impl() - { - codec2_destroy(d_codec2); - } +{ + if ((d_codec2 = codec2_create(mode)) == 0) + throw std::runtime_error("codec2_encode_sp_impl: codec2_create failed"); + d_samples_per_frame = samples_per_frame; + d_bits_per_frame = bits_per_frame; +} - int - codec2_encode_sp_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - const short *in = (const short*)input_items[0]; - unsigned char *out = (unsigned char*)output_items[0]; +codec2_encode_sp_impl::~codec2_encode_sp_impl() { codec2_destroy(d_codec2); } - for(int i = 0; i < noutput_items; i++) { - codec2_encode(d_codec2, &d_frame_buf[0], const_cast<short*>(in)); - unpack_frame((const unsigned char *) &d_frame_buf[0], out); - in += d_samples_per_frame; - out += d_bits_per_frame * sizeof(char); - } +int codec2_encode_sp_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + const short* in = (const short*)input_items[0]; + unsigned char* out = (unsigned char*)output_items[0]; - return noutput_items; + for (int i = 0; i < noutput_items; i++) { + codec2_encode(d_codec2, &d_frame_buf[0], const_cast<short*>(in)); + unpack_frame((const unsigned char*)&d_frame_buf[0], out); + in += d_samples_per_frame; + out += d_bits_per_frame * sizeof(char); } - void - codec2_encode_sp_impl::unpack_frame(const unsigned char *packed, unsigned char *out) - { - int byte_idx = 0, bit_idx = 0; - for(int k = 0; k < d_bits_per_frame; k++) { - out[k] = (packed[byte_idx] >> (7-bit_idx)) & 0x01; - bit_idx = (bit_idx + 1) % 8; - if (bit_idx == 0) { - byte_idx++; - } - } + return noutput_items; +} + +void codec2_encode_sp_impl::unpack_frame(const unsigned char* packed, unsigned char* out) +{ + int byte_idx = 0, bit_idx = 0; + for (int k = 0; k < d_bits_per_frame; k++) { + out[k] = (packed[byte_idx] >> (7 - bit_idx)) & 0x01; + bit_idx = (bit_idx + 1) % 8; + if (bit_idx == 0) { + byte_idx++; + } } +} - } /* namespace vocoder */ +} /* namespace vocoder */ } /* namespace gr */ diff --git a/gr-vocoder/lib/codec2_encode_sp_impl.h b/gr-vocoder/lib/codec2_encode_sp_impl.h index 17d6f4e2a..445790442 100644 --- a/gr-vocoder/lib/codec2_encode_sp_impl.h +++ b/gr-vocoder/lib/codec2_encode_sp_impl.h @@ -26,27 +26,29 @@ #include <gnuradio/vocoder/codec2_encode_sp.h> namespace gr { - namespace vocoder { +namespace vocoder { - class codec2_encode_sp_impl : public codec2_encode_sp - { - private: - CODEC2 *d_codec2; - int d_samples_per_frame, d_bits_per_frame; - std::vector<unsigned char> d_frame_buf; //!< Save 1 CODEC2 frame +class codec2_encode_sp_impl : public codec2_encode_sp +{ +private: + CODEC2* d_codec2; + int d_samples_per_frame, d_bits_per_frame; + std::vector<unsigned char> d_frame_buf; //!< Save 1 CODEC2 frame - void unpack_frame(const unsigned char *packed, unsigned char *out); //!< Unpack the bytes from codec2 into unpacked bits + void + unpack_frame(const unsigned char* packed, + unsigned char* out); //!< Unpack the bytes from codec2 into unpacked bits - public: - codec2_encode_sp_impl(int mode, int samples_per_frame, int bits_per_frame); - ~codec2_encode_sp_impl(); +public: + codec2_encode_sp_impl(int mode, int samples_per_frame, int bits_per_frame); + ~codec2_encode_sp_impl(); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace vocoder */ +} /* namespace vocoder */ } /* namespace gr */ #endif /* INCLUDED_VOCODER_CODEC2_ENCODE_SP_IMPL_H */ diff --git a/gr-vocoder/lib/cvsd_decode_bs_impl.cc b/gr-vocoder/lib/cvsd_decode_bs_impl.cc index f0603b78d..103ebfcc5 100644 --- a/gr-vocoder/lib/cvsd_decode_bs_impl.cc +++ b/gr-vocoder/lib/cvsd_decode_bs_impl.cc @@ -29,164 +29,170 @@ #include <limits.h> namespace gr { - namespace vocoder { - - cvsd_decode_bs::sptr - cvsd_decode_bs::make(short min_step, short max_step, double step_decay, - double accum_decay, int K, int J, - short pos_accum_max, short neg_accum_max) - { - return gnuradio::get_initial_sptr - (new cvsd_decode_bs_impl(min_step, max_step, - step_decay, accum_decay, K, J, - pos_accum_max, neg_accum_max)); +namespace vocoder { + +cvsd_decode_bs::sptr cvsd_decode_bs::make(short min_step, + short max_step, + double step_decay, + double accum_decay, + int K, + int J, + short pos_accum_max, + short neg_accum_max) +{ + return gnuradio::get_initial_sptr(new cvsd_decode_bs_impl( + min_step, max_step, step_decay, accum_decay, K, J, pos_accum_max, neg_accum_max)); +} + +cvsd_decode_bs_impl::cvsd_decode_bs_impl(short min_step, + short max_step, + double step_decay, + double accum_decay, + int K, + int J, + short pos_accum_max, + short neg_accum_max) + : sync_interpolator("vocoder_cvsd_decode_bs", + io_signature::make(1, 1, sizeof(unsigned char)), + io_signature::make(1, 1, sizeof(short)), + 8), + d_min_step(min_step), + d_max_step(max_step), + d_step_decay(step_decay), + d_accum_decay(accum_decay), + d_K(K), + d_J(J), + d_pos_accum_max(pos_accum_max), + d_neg_accum_max(neg_accum_max), + d_accum(0), + d_loop_counter(1), + d_runner(0), + d_runner_mask(0), + d_stepsize(min_step) +{ + if (d_K > 32) + throw std::runtime_error("cvsd_decode_bs_impl: K must be <= 32\n"); + + if (d_J > d_K) + throw std::runtime_error("cvsd_decode_bs_impl: J must be <= K\n"); +} + +cvsd_decode_bs_impl::~cvsd_decode_bs_impl() +{ + // nothing else required in this example +} + +unsigned char cvsd_decode_bs_impl::cvsd_bitwise_sum(unsigned int input) +{ + unsigned int temp = input; + unsigned char bits = 0; + + while (temp) { + temp = temp & (temp - 1); + bits++; } - - cvsd_decode_bs_impl::cvsd_decode_bs_impl(short min_step, short max_step, double step_decay, - double accum_decay, int K, int J, - short pos_accum_max, short neg_accum_max) - : sync_interpolator("vocoder_cvsd_decode_bs", - io_signature::make(1, 1, sizeof(unsigned char)), - io_signature::make(1, 1, sizeof(short)), - 8), - d_min_step(min_step), d_max_step(max_step), d_step_decay(step_decay), - d_accum_decay(accum_decay), d_K(K), d_J(J), - d_pos_accum_max(pos_accum_max), d_neg_accum_max(neg_accum_max), - d_accum(0), - d_loop_counter(1), - d_runner(0), - d_runner_mask(0), - d_stepsize(min_step) - { - if(d_K > 32) - throw std::runtime_error("cvsd_decode_bs_impl: K must be <= 32\n"); - - if(d_J > d_K) - throw std::runtime_error("cvsd_decode_bs_impl: J must be <= K\n"); - } - - cvsd_decode_bs_impl::~cvsd_decode_bs_impl() - { - // nothing else required in this example - } - - unsigned char - cvsd_decode_bs_impl::cvsd_bitwise_sum(unsigned int input) - { - unsigned int temp = input; - unsigned char bits = 0; - - while(temp) { - temp=temp&(temp-1); - bits++; - } - return bits; - } - - int - cvsd_decode_bs_impl::cvsd_round(double input) - { - double temp; - temp=input+0.5; - temp=floor(temp); - - return (int)temp; - } - - unsigned int - cvsd_decode_bs_impl::cvsd_pow(short radix, short power) - { - double d_radix = (double) radix; - int i_power = (int) power; - double output; - - output = pow(d_radix,i_power); - return ( (unsigned int)cvsd_round(output)); - } - - int - cvsd_decode_bs_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - const unsigned char *in = (const unsigned char*)input_items[0]; - short *out = (short *) output_items[0]; - - int i=0; - short output_short=0; // 2 bytes 0 .. 65,535 - unsigned char bit_count=0; // 1 byte, 0 .. 255 - unsigned int mask=0; // 4 bytes, 0 .. 4,294,967,295 - unsigned char input_byte=0; // 1 bytes - unsigned char input_bit=0; // 1 byte, 0 .. 255 - - // Loop through each input data point - for(i = 0; i < noutput_items/8.0; i++) { - input_byte = in[i]; - // Initialize bit counter - bit_count=0; - - while(bit_count<8) { - // Compute the Appropriate Mask - mask=cvsd_pow(2,7-bit_count); - - // Pull off the corresponding bit - input_bit = input_byte & mask; - - // Update the bit counter - bit_count++; - - // Update runner with the next input bit - // Runner is a shift-register; shift left, add on newest output bit - d_runner = (d_runner<<1) | ((unsigned int) input_bit); - - // Run this only if you have >= J bits in your shift register - if(d_loop_counter>=d_J) { - // Update Step Size - d_runner_mask=(cvsd_pow(2,d_J)-1); - if((cvsd_bitwise_sum(d_runner & d_runner_mask)>=d_J) || - (cvsd_bitwise_sum((~d_runner) & d_runner_mask)>=d_J)) { - // Runs of 1s and 0s - d_stepsize = std::min( (short) (d_stepsize + d_min_step), d_max_step); - } - else { - // No runs of 1s and 0s - d_stepsize = std::max( (short) cvsd_round(d_stepsize*d_step_decay), d_min_step); - } - } - - // Update Accum (i.e. the reference value) - if(input_bit) { - d_accum = d_accum+d_stepsize; - } - else { - d_accum = d_accum-d_stepsize; - } - - // Multiply by Accum_Decay - d_accum = (cvsd_round(d_accum*d_accum_decay)); - - // Check for overflow - if(d_accum >=((int) d_pos_accum_max)) { - d_accum = (int)d_pos_accum_max; - } - else if(d_accum <=((int) d_neg_accum_max)) { - d_accum = (int)d_neg_accum_max; - } - - // Find the output short to write to the file - output_short = ((short)d_accum); - - if(d_loop_counter <= d_K) { - d_loop_counter++; - } - - *(out++) = output_short; - } // while () - - } // for() - - return noutput_items; - } - - } /* namespace vocoder */ + return bits; +} + +int cvsd_decode_bs_impl::cvsd_round(double input) +{ + double temp; + temp = input + 0.5; + temp = floor(temp); + + return (int)temp; +} + +unsigned int cvsd_decode_bs_impl::cvsd_pow(short radix, short power) +{ + double d_radix = (double)radix; + int i_power = (int)power; + double output; + + output = pow(d_radix, i_power); + return ((unsigned int)cvsd_round(output)); +} + +int cvsd_decode_bs_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + const unsigned char* in = (const unsigned char*)input_items[0]; + short* out = (short*)output_items[0]; + + int i = 0; + short output_short = 0; // 2 bytes 0 .. 65,535 + unsigned char bit_count = 0; // 1 byte, 0 .. 255 + unsigned int mask = 0; // 4 bytes, 0 .. 4,294,967,295 + unsigned char input_byte = 0; // 1 bytes + unsigned char input_bit = 0; // 1 byte, 0 .. 255 + + // Loop through each input data point + for (i = 0; i < noutput_items / 8.0; i++) { + input_byte = in[i]; + // Initialize bit counter + bit_count = 0; + + while (bit_count < 8) { + // Compute the Appropriate Mask + mask = cvsd_pow(2, 7 - bit_count); + + // Pull off the corresponding bit + input_bit = input_byte & mask; + + // Update the bit counter + bit_count++; + + // Update runner with the next input bit + // Runner is a shift-register; shift left, add on newest output bit + d_runner = (d_runner << 1) | ((unsigned int)input_bit); + + // Run this only if you have >= J bits in your shift register + if (d_loop_counter >= d_J) { + // Update Step Size + d_runner_mask = (cvsd_pow(2, d_J) - 1); + if ((cvsd_bitwise_sum(d_runner & d_runner_mask) >= d_J) || + (cvsd_bitwise_sum((~d_runner) & d_runner_mask) >= d_J)) { + // Runs of 1s and 0s + d_stepsize = std::min((short)(d_stepsize + d_min_step), d_max_step); + } else { + // No runs of 1s and 0s + d_stepsize = std::max((short)cvsd_round(d_stepsize * d_step_decay), + d_min_step); + } + } + + // Update Accum (i.e. the reference value) + if (input_bit) { + d_accum = d_accum + d_stepsize; + } else { + d_accum = d_accum - d_stepsize; + } + + // Multiply by Accum_Decay + d_accum = (cvsd_round(d_accum * d_accum_decay)); + + // Check for overflow + if (d_accum >= ((int)d_pos_accum_max)) { + d_accum = (int)d_pos_accum_max; + } else if (d_accum <= ((int)d_neg_accum_max)) { + d_accum = (int)d_neg_accum_max; + } + + // Find the output short to write to the file + output_short = ((short)d_accum); + + if (d_loop_counter <= d_K) { + d_loop_counter++; + } + + *(out++) = output_short; + } // while () + + } // for() + + return noutput_items; +} + +} /* namespace vocoder */ } /* namespace gr */ diff --git a/gr-vocoder/lib/cvsd_decode_bs_impl.h b/gr-vocoder/lib/cvsd_decode_bs_impl.h index 867dfff99..29e7ca5db 100644 --- a/gr-vocoder/lib/cvsd_decode_bs_impl.h +++ b/gr-vocoder/lib/cvsd_decode_bs_impl.h @@ -26,67 +26,70 @@ #include <gnuradio/vocoder/cvsd_decode_bs.h> namespace gr { - namespace vocoder { +namespace vocoder { - class cvsd_decode_bs_impl : public cvsd_decode_bs - { - private: - //! Member functions required by the encoder/decoder - //! \brief Rounding function specific to CVSD - //! \return the input value rounded to the nearest integer - int cvsd_round(double input); +class cvsd_decode_bs_impl : public cvsd_decode_bs +{ +private: + //! Member functions required by the encoder/decoder + //! \brief Rounding function specific to CVSD + //! \return the input value rounded to the nearest integer + int cvsd_round(double input); - //! \brief A power function specific to CVSD data formats - //! \return (radix)^power, where radix and power are short integers - unsigned int cvsd_pow(short radix, short power); + //! \brief A power function specific to CVSD data formats + //! \return (radix)^power, where radix and power are short integers + unsigned int cvsd_pow(short radix, short power); - //! \brief Sums number of 1's in the input - //! \return the number of 1s in the four bytes of an input unsigned integer - unsigned char cvsd_bitwise_sum(unsigned int input); + //! \brief Sums number of 1's in the input + //! \return the number of 1s in the four bytes of an input unsigned integer + unsigned char cvsd_bitwise_sum(unsigned int input); - short d_min_step; - short d_max_step; - double d_step_decay; - double d_accum_decay; + short d_min_step; + short d_max_step; + double d_step_decay; + double d_accum_decay; - int d_K; //!< \brief Size of shift register; the number of output bits remembered in shift register - int d_J; //!< \brief Number of bits in the shift register that are equal; size of run of 1s, 0s + int d_K; //!< \brief Size of shift register; the number of output bits remembered in + //!< shift register + int d_J; //!< \brief Number of bits in the shift register that are equal; size of run + //!< of 1s, 0s - short d_pos_accum_max; - short d_neg_accum_max; + short d_pos_accum_max; + short d_neg_accum_max; - int d_accum; //!< \brief Current value of internal reference - int d_loop_counter; //!< \brief Current value of the loop counter - unsigned int d_runner; //!< \brief Current value of the shift register - unsigned int d_runner_mask; //!< \brief Value of the mask to access the last J bits of the shift register - short d_stepsize; //!< \brief Current value of the step sizer + int d_accum; //!< \brief Current value of internal reference + int d_loop_counter; //!< \brief Current value of the loop counter + unsigned int d_runner; //!< \brief Current value of the shift register + unsigned int d_runner_mask; //!< \brief Value of the mask to access the last J bits of + //!< the shift register + short d_stepsize; //!< \brief Current value of the step sizer - public: - cvsd_decode_bs_impl(short min_step=10, - short max_step=1280, - double step_decay=0.9990234375, - double accum_decay= 0.96875, - int K=32, - int J=4, - short pos_accum_max=32767, - short neg_accum_max=-32767); - ~cvsd_decode_bs_impl(); +public: + cvsd_decode_bs_impl(short min_step = 10, + short max_step = 1280, + double step_decay = 0.9990234375, + double accum_decay = 0.96875, + int K = 32, + int J = 4, + short pos_accum_max = 32767, + short neg_accum_max = -32767); + ~cvsd_decode_bs_impl(); - short min_step() { return d_min_step; } - short max_step() { return d_max_step; } - double step_decay() { return d_step_decay; } - double accum_decay() { return d_accum_decay; } - int K() { return d_K; } - int J() { return d_J; } - short pos_accum_max() { return d_pos_accum_max; } - short neg_accum_max() { return d_neg_accum_max; } + short min_step() { return d_min_step; } + short max_step() { return d_max_step; } + double step_decay() { return d_step_decay; } + double accum_decay() { return d_accum_decay; } + int K() { return d_K; } + int J() { return d_J; } + short pos_accum_max() { return d_pos_accum_max; } + short neg_accum_max() { return d_neg_accum_max; } - int work (int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace vocoder */ +} /* namespace vocoder */ } /* namespace gr */ #endif /* INCLUDED_VOCODER_CVSD_DECODE_BS_IMPL_H */ diff --git a/gr-vocoder/lib/cvsd_encode_sb_impl.cc b/gr-vocoder/lib/cvsd_encode_sb_impl.cc index 3c4656cf3..26766fbf0 100644 --- a/gr-vocoder/lib/cvsd_encode_sb_impl.cc +++ b/gr-vocoder/lib/cvsd_encode_sb_impl.cc @@ -29,164 +29,172 @@ #include <limits.h> namespace gr { - namespace vocoder { - - cvsd_encode_sb::sptr - cvsd_encode_sb::make(short min_step, short max_step, double step_decay, - double accum_decay, int K, int J, - short pos_accum_max, short neg_accum_max) - { - return gnuradio::get_initial_sptr - (new cvsd_encode_sb_impl(min_step, max_step, - step_decay, accum_decay, K, J, - pos_accum_max, neg_accum_max)); +namespace vocoder { + +cvsd_encode_sb::sptr cvsd_encode_sb::make(short min_step, + short max_step, + double step_decay, + double accum_decay, + int K, + int J, + short pos_accum_max, + short neg_accum_max) +{ + return gnuradio::get_initial_sptr(new cvsd_encode_sb_impl( + min_step, max_step, step_decay, accum_decay, K, J, pos_accum_max, neg_accum_max)); +} + +cvsd_encode_sb_impl::cvsd_encode_sb_impl(short min_step, + short max_step, + double step_decay, + double accum_decay, + int K, + int J, + short pos_accum_max, + short neg_accum_max) + : sync_decimator("vocoder_cvsd_encode_sb", + io_signature::make(1, 1, sizeof(short)), + io_signature::make(1, 1, sizeof(unsigned char)), + 8), + d_min_step(min_step), + d_max_step(max_step), + d_step_decay(step_decay), + d_accum_decay(accum_decay), + d_K(K), + d_J(J), + d_pos_accum_max(pos_accum_max), + d_neg_accum_max(neg_accum_max), + d_accum(0), + d_loop_counter(1), + d_runner(0), + d_stepsize(min_step) +{ + if (d_K > 32) + throw std::runtime_error("cvsd_decode_bs_impl: K must be <= 32\n"); + + if (d_J > d_K) + throw std::runtime_error("cvsd_decode_bs_impl: J must be <= K\n"); +} + +cvsd_encode_sb_impl::~cvsd_encode_sb_impl() +{ + // nothing else required in this example +} + +unsigned char cvsd_encode_sb_impl::cvsd_bitwise_sum(unsigned int input) +{ + unsigned int temp = input; + unsigned char bits = 0; + + while (temp) { + temp = temp & (temp - 1); + bits++; } - - cvsd_encode_sb_impl::cvsd_encode_sb_impl(short min_step, short max_step, double step_decay, - double accum_decay, int K, int J, - short pos_accum_max, short neg_accum_max) - : sync_decimator("vocoder_cvsd_encode_sb", - io_signature::make(1, 1, sizeof(short)), - io_signature::make(1, 1, sizeof(unsigned char)), - 8), - d_min_step (min_step), d_max_step(max_step), d_step_decay(step_decay), - d_accum_decay(accum_decay), d_K(K), d_J(J), - d_pos_accum_max(pos_accum_max), d_neg_accum_max(neg_accum_max), - d_accum(0), - d_loop_counter(1), - d_runner(0), - d_stepsize(min_step) - { - if(d_K > 32) - throw std::runtime_error("cvsd_decode_bs_impl: K must be <= 32\n"); - - if(d_J > d_K) - throw std::runtime_error("cvsd_decode_bs_impl: J must be <= K\n"); - } - - cvsd_encode_sb_impl::~cvsd_encode_sb_impl() - { - // nothing else required in this example - } - - unsigned char - cvsd_encode_sb_impl::cvsd_bitwise_sum(unsigned int input) - { - unsigned int temp = input; - unsigned char bits = 0; - - while(temp) { - temp=temp&(temp-1); - bits++; - } - return bits; - } - - int - cvsd_encode_sb_impl::cvsd_round(double input) - { - double temp; - temp=input+0.5; - temp=floor(temp); - - return (int)temp; - } - - unsigned int - cvsd_encode_sb_impl::cvsd_pow(short radix, short power) - { - double d_radix = (double)radix; - int i_power = (int)power; - double output; - - output = pow(d_radix,i_power); - return ((unsigned int)cvsd_round(output)); - } - - int - cvsd_encode_sb_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - const short *in = (const short*)input_items[0]; - unsigned char *out = (unsigned char*)output_items[0]; - - unsigned short i=0; // 2 bytes, 0 .. 65,535 - unsigned char output_bit=0; // 1 byte, 0 .. 255 - unsigned char output_byte=0; // 1 bytes 0.255 - unsigned char bit_count=0; // 1 byte, 0 .. 255 - unsigned int mask=0; // 4 bytes, 0 .. 4,294,967,295 - - // Loop through each input data point - for(i = 0; i < noutput_items*8; i++) { - if((int)in[i] >= d_accum) { // Note: sign((data(n)-accum)) - output_bit=1; - } - else { - output_bit=0; - } - - // Update Accum (i.e. the reference value) - if(output_bit) { - d_accum=d_accum+d_stepsize; - //printf("Adding %d to the accum; the result is: %d.\n", d_stepsize, d_accum); - } - else { - d_accum=d_accum-d_stepsize; - //printf("Subtracting %d to the accum; the result is: %d.\n", d_stepsize, d_accum); - } - - // Multiply by Accum_Decay - d_accum = (cvsd_round(d_accum*d_accum_decay)); - - // Check for overflow - if(d_accum >= ((int)d_pos_accum_max)) { - d_accum = (int)d_pos_accum_max; - } - else if(d_accum <= ((int) d_neg_accum_max)) { - d_accum = (int) d_neg_accum_max; - } - - // Update runner with the last output bit - // Update Step Size - if(d_loop_counter >= d_J) { // Run this only if you have >= J bits in your shift register - mask = (cvsd_pow(2, d_J) - 1); - if((cvsd_bitwise_sum(d_runner & mask) >= d_J) || - (cvsd_bitwise_sum((~d_runner) & mask) >= d_J)) { - // Runs of 1s and 0s - d_stepsize = std::min((short)(d_stepsize + d_min_step), d_max_step); - } - else { - // No runs of 1s and 0s - d_stepsize = std::max((short)cvsd_round(d_stepsize*d_step_decay), d_min_step); - } - } - - // Runner is a shift-register; shift left, add on newest output bit - d_runner = (d_runner<<1) | ((unsigned int) output_bit); - - // Update the output type; shift left, add on newest output bit - // If you have put in 8 bits, output it as a byte - output_byte = (output_byte<<1) | output_bit; - bit_count++; - - if(d_loop_counter <= d_K) { - d_loop_counter++; - } - - // If you have put 8 bits, output and clear. - if(bit_count==8) { - // Read in short from the file - *(out++) = output_byte; - - // Reset the bit_count - bit_count=0; - output_byte=0; - } - } // While - - return noutput_items; - } - - } /* namespace vocoder */ + return bits; +} + +int cvsd_encode_sb_impl::cvsd_round(double input) +{ + double temp; + temp = input + 0.5; + temp = floor(temp); + + return (int)temp; +} + +unsigned int cvsd_encode_sb_impl::cvsd_pow(short radix, short power) +{ + double d_radix = (double)radix; + int i_power = (int)power; + double output; + + output = pow(d_radix, i_power); + return ((unsigned int)cvsd_round(output)); +} + +int cvsd_encode_sb_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + const short* in = (const short*)input_items[0]; + unsigned char* out = (unsigned char*)output_items[0]; + + unsigned short i = 0; // 2 bytes, 0 .. 65,535 + unsigned char output_bit = 0; // 1 byte, 0 .. 255 + unsigned char output_byte = 0; // 1 bytes 0.255 + unsigned char bit_count = 0; // 1 byte, 0 .. 255 + unsigned int mask = 0; // 4 bytes, 0 .. 4,294,967,295 + + // Loop through each input data point + for (i = 0; i < noutput_items * 8; i++) { + if ((int)in[i] >= d_accum) { // Note: sign((data(n)-accum)) + output_bit = 1; + } else { + output_bit = 0; + } + + // Update Accum (i.e. the reference value) + if (output_bit) { + d_accum = d_accum + d_stepsize; + // printf("Adding %d to the accum; the result is: %d.\n", d_stepsize, + // d_accum); + } else { + d_accum = d_accum - d_stepsize; + // printf("Subtracting %d to the accum; the result is: %d.\n", d_stepsize, + // d_accum); + } + + // Multiply by Accum_Decay + d_accum = (cvsd_round(d_accum * d_accum_decay)); + + // Check for overflow + if (d_accum >= ((int)d_pos_accum_max)) { + d_accum = (int)d_pos_accum_max; + } else if (d_accum <= ((int)d_neg_accum_max)) { + d_accum = (int)d_neg_accum_max; + } + + // Update runner with the last output bit + // Update Step Size + if (d_loop_counter >= + d_J) { // Run this only if you have >= J bits in your shift register + mask = (cvsd_pow(2, d_J) - 1); + if ((cvsd_bitwise_sum(d_runner & mask) >= d_J) || + (cvsd_bitwise_sum((~d_runner) & mask) >= d_J)) { + // Runs of 1s and 0s + d_stepsize = std::min((short)(d_stepsize + d_min_step), d_max_step); + } else { + // No runs of 1s and 0s + d_stepsize = + std::max((short)cvsd_round(d_stepsize * d_step_decay), d_min_step); + } + } + + // Runner is a shift-register; shift left, add on newest output bit + d_runner = (d_runner << 1) | ((unsigned int)output_bit); + + // Update the output type; shift left, add on newest output bit + // If you have put in 8 bits, output it as a byte + output_byte = (output_byte << 1) | output_bit; + bit_count++; + + if (d_loop_counter <= d_K) { + d_loop_counter++; + } + + // If you have put 8 bits, output and clear. + if (bit_count == 8) { + // Read in short from the file + *(out++) = output_byte; + + // Reset the bit_count + bit_count = 0; + output_byte = 0; + } + } // While + + return noutput_items; +} + +} /* namespace vocoder */ } /* namespace gr */ diff --git a/gr-vocoder/lib/cvsd_encode_sb_impl.h b/gr-vocoder/lib/cvsd_encode_sb_impl.h index 8b9282b86..9b77a4c74 100644 --- a/gr-vocoder/lib/cvsd_encode_sb_impl.h +++ b/gr-vocoder/lib/cvsd_encode_sb_impl.h @@ -26,67 +26,70 @@ #include <gnuradio/vocoder/cvsd_encode_sb.h> namespace gr { - namespace vocoder { +namespace vocoder { - class cvsd_encode_sb_impl : public cvsd_encode_sb - { - private: - //! Member functions required by the encoder/decoder - //! \brief Rounding function specific to CVSD - //! \return the input value rounded to the nearest integer - int cvsd_round(double input); +class cvsd_encode_sb_impl : public cvsd_encode_sb +{ +private: + //! Member functions required by the encoder/decoder + //! \brief Rounding function specific to CVSD + //! \return the input value rounded to the nearest integer + int cvsd_round(double input); - //! \brief A power function specific to CVSD data formats - //! \return (radix)^power, where radix and power are short integers - unsigned int cvsd_pow(short radix, short power); + //! \brief A power function specific to CVSD data formats + //! \return (radix)^power, where radix and power are short integers + unsigned int cvsd_pow(short radix, short power); - //! \brief Sums number of 1's in the input - //! \return the number of 1s in the four bytes of an input unsigned integer - unsigned char cvsd_bitwise_sum(unsigned int input); + //! \brief Sums number of 1's in the input + //! \return the number of 1s in the four bytes of an input unsigned integer + unsigned char cvsd_bitwise_sum(unsigned int input); - // Members variables related to the CVSD encoder use to update internal reference value - short d_min_step; - short d_max_step; - double d_step_decay; - double d_accum_decay; + // Members variables related to the CVSD encoder use to update internal reference + // value + short d_min_step; + short d_max_step; + double d_step_decay; + double d_accum_decay; - int d_K; //!< \brief Size of shift register; the number of output bits remembered in shift register - int d_J; //!< \brief Number of bits in the shift register that are equal; size of run of 1s, 0s + int d_K; //!< \brief Size of shift register; the number of output bits remembered in + //!< shift register + int d_J; //!< \brief Number of bits in the shift register that are equal; size of run + //!< of 1s, 0s - short d_pos_accum_max; - short d_neg_accum_max; + short d_pos_accum_max; + short d_neg_accum_max; - int d_accum; //!< \brief Current value of internal reference - int d_loop_counter; //!< \brief Current value of the loop counter - unsigned int d_runner; //!< \brief Current value of the shift register - short d_stepsize; //!< \brief Current value of the step sizer + int d_accum; //!< \brief Current value of internal reference + int d_loop_counter; //!< \brief Current value of the loop counter + unsigned int d_runner; //!< \brief Current value of the shift register + short d_stepsize; //!< \brief Current value of the step sizer - public: - cvsd_encode_sb_impl(short min_step=10, - short max_step=1280, - double step_decay=0.9990234375, - double accum_decay= 0.96875, - int K=32, - int J=4, - short pos_accum_max=32767, - short neg_accum_max=-32767); - ~cvsd_encode_sb_impl(); +public: + cvsd_encode_sb_impl(short min_step = 10, + short max_step = 1280, + double step_decay = 0.9990234375, + double accum_decay = 0.96875, + int K = 32, + int J = 4, + short pos_accum_max = 32767, + short neg_accum_max = -32767); + ~cvsd_encode_sb_impl(); - short min_step() { return d_min_step; } - short max_step() { return d_max_step; } - double step_decay() { return d_step_decay; } - double accum_decay() { return d_accum_decay; } - int K() { return d_K; } - int J() { return d_J; } - short pos_accum_max() { return d_pos_accum_max; } - short neg_accum_max() { return d_neg_accum_max; } + short min_step() { return d_min_step; } + short max_step() { return d_max_step; } + double step_decay() { return d_step_decay; } + double accum_decay() { return d_accum_decay; } + int K() { return d_K; } + int J() { return d_J; } + short pos_accum_max() { return d_pos_accum_max; } + short neg_accum_max() { return d_neg_accum_max; } - int work (int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace vocoder */ +} /* namespace vocoder */ } /* namespace gr */ #endif /* INCLUDED_VOCODER_CVSD_ENCODE_SB_IMPL_H */ diff --git a/gr-vocoder/lib/freedv_api.cc b/gr-vocoder/lib/freedv_api.cc index 063a6bb9f..a0dc7e887 100644 --- a/gr-vocoder/lib/freedv_api.cc +++ b/gr-vocoder/lib/freedv_api.cc @@ -27,7 +27,7 @@ #include <gnuradio/vocoder/freedv_api.h> namespace gr { - namespace vocoder { +namespace vocoder { - } /* namespace vocoder */ +} /* namespace vocoder */ } /* namespace gr */ diff --git a/gr-vocoder/lib/freedv_rx_ss_impl.cc b/gr-vocoder/lib/freedv_rx_ss_impl.cc index f1096b239..af7c45878 100644 --- a/gr-vocoder/lib/freedv_rx_ss_impl.cc +++ b/gr-vocoder/lib/freedv_rx_ss_impl.cc @@ -31,137 +31,135 @@ #include <assert.h> extern "C" { - void put_next_rx_char(void *callback_state, char c) { - struct freedv_rx_callback_state* pstate; - - pstate = (struct freedv_rx_callback_state*) callback_state; - if (pstate->ftxt != NULL) { - //fprintf(pstate->ftxt, "%c\n", c); - } - return; +void put_next_rx_char(void* callback_state, char c) +{ + struct freedv_rx_callback_state* pstate; + + pstate = (struct freedv_rx_callback_state*)callback_state; + if (pstate->ftxt != NULL) { + // fprintf(pstate->ftxt, "%c\n", c); } + return; +} } namespace gr { - namespace vocoder { +namespace vocoder { - freedv_rx_ss::sptr - freedv_rx_ss::make(int mode, float squelch_thresh, int interleave_frames) - { - return gnuradio::get_initial_sptr - (new freedv_rx_ss_impl(mode, squelch_thresh, interleave_frames)); - } +freedv_rx_ss::sptr +freedv_rx_ss::make(int mode, float squelch_thresh, int interleave_frames) +{ + return gnuradio::get_initial_sptr( + new freedv_rx_ss_impl(mode, squelch_thresh, interleave_frames)); +} - freedv_rx_ss_impl::freedv_rx_ss_impl (int mode, float squelch_thresh, int interleave_frames) - : gr::block("vocoder_freedv_rx_ss", - io_signature::make(1, 1, sizeof(short)), - io_signature::make(1, 1, sizeof(short))), - d_mode(mode), d_squelch_thresh(squelch_thresh), d_interleave_frames(interleave_frames) - { +freedv_rx_ss_impl::freedv_rx_ss_impl(int mode, + float squelch_thresh, + int interleave_frames) + : gr::block("vocoder_freedv_rx_ss", + io_signature::make(1, 1, sizeof(short)), + io_signature::make(1, 1, sizeof(short))), + d_mode(mode), + d_squelch_thresh(squelch_thresh), + d_interleave_frames(interleave_frames) +{ #ifdef FREEDV_MODE_700D - if (mode == FREEDV_MODE_700D) { - d_adv.interleave_frames = interleave_frames; - if((d_freedv = freedv_open_advanced(mode, &d_adv)) ==NULL) - throw std::runtime_error("freedv_tx_ss_impl: freedv_open_advanced failed"); - } else { - if((d_freedv = freedv_open(mode)) == NULL) - throw std::runtime_error("freedv_tx_ss_impl: freedv_open failed"); - } + if (mode == FREEDV_MODE_700D) { + d_adv.interleave_frames = interleave_frames; + if ((d_freedv = freedv_open_advanced(mode, &d_adv)) == NULL) + throw std::runtime_error("freedv_tx_ss_impl: freedv_open_advanced failed"); + } else { + if ((d_freedv = freedv_open(mode)) == NULL) + throw std::runtime_error("freedv_tx_ss_impl: freedv_open failed"); + } #else - if((d_freedv = freedv_open(mode)) == NULL) + if ((d_freedv = freedv_open(mode)) == NULL) throw std::runtime_error("freedv_rx_ss_impl: freedv_open failed"); #endif - freedv_set_snr_squelch_thresh(d_freedv, d_squelch_thresh); - freedv_set_squelch_en(d_freedv, 0); - freedv_set_callback_txt(d_freedv, put_next_rx_char, NULL, (void *) &d_cb_state); - d_speech_samples = freedv_get_n_speech_samples(d_freedv); - d_max_modem_samples = freedv_get_n_max_modem_samples(d_freedv); - d_nin = freedv_nin(d_freedv); - set_output_multiple(d_max_modem_samples); - } + freedv_set_snr_squelch_thresh(d_freedv, d_squelch_thresh); + freedv_set_squelch_en(d_freedv, 0); + freedv_set_callback_txt(d_freedv, put_next_rx_char, NULL, (void*)&d_cb_state); + d_speech_samples = freedv_get_n_speech_samples(d_freedv); + d_max_modem_samples = freedv_get_n_max_modem_samples(d_freedv); + d_nin = freedv_nin(d_freedv); + set_output_multiple(d_max_modem_samples); +} - freedv_rx_ss_impl::~freedv_rx_ss_impl() - { - int total_bits; - int total_bit_errors; +freedv_rx_ss_impl::~freedv_rx_ss_impl() +{ + int total_bits; + int total_bit_errors; - if (freedv_get_test_frames(d_freedv)) { + if (freedv_get_test_frames(d_freedv)) { total_bits = freedv_get_total_bits(d_freedv); total_bit_errors = freedv_get_total_bit_errors(d_freedv); - fprintf(stderr, "bits: %d errors: %d BER: %3.2f\n", total_bits, total_bit_errors, (1.0*total_bit_errors)/total_bits); - } - freedv_close(d_freedv); + fprintf(stderr, + "bits: %d errors: %d BER: %3.2f\n", + total_bits, + total_bit_errors, + (1.0 * total_bit_errors) / total_bits); } + freedv_close(d_freedv); +} - void - freedv_rx_ss_impl::forecast(int noutput_items, - gr_vector_int &ninput_items_required) - { - unsigned ninputs = ninput_items_required.size(); - for(unsigned i = 0; i < ninputs; i++) +void freedv_rx_ss_impl::forecast(int noutput_items, gr_vector_int& ninput_items_required) +{ + unsigned ninputs = ninput_items_required.size(); + for (unsigned i = 0; i < ninputs; i++) ninput_items_required[i] = std::max(d_nin, noutput_items); - } +} - int - freedv_rx_ss_impl::general_work(int noutput_items, - gr_vector_int &ninput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - short *in = (short *) input_items[0]; - short *out = (short *) output_items[0]; +int freedv_rx_ss_impl::general_work(int noutput_items, + gr_vector_int& ninput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + short* in = (short*)input_items[0]; + short* out = (short*)output_items[0]; - int in_offset = 0, out_offset = 0; + int in_offset = 0, out_offset = 0; - while ((noutput_items - out_offset) >= d_max_modem_samples - && (ninput_items[0] - in_offset) >= d_nin) { + while ((noutput_items - out_offset) >= d_max_modem_samples && + (ninput_items[0] - in_offset) >= d_nin) { d_nout = freedv_rx(d_freedv, out + out_offset, in + in_offset); out_offset += d_nout; in_offset += d_nin; d_nin = freedv_nin(d_freedv); - } + } - freedv_get_modem_stats(d_freedv, &d_sync, &d_snr_est); - freedv_get_modem_extended_stats(d_freedv, &d_stats); - d_total_bit_errors = freedv_get_total_bit_errors(d_freedv); + freedv_get_modem_stats(d_freedv, &d_sync, &d_snr_est); + freedv_get_modem_extended_stats(d_freedv, &d_stats); + d_total_bit_errors = freedv_get_total_bit_errors(d_freedv); - consume_each(in_offset); - return out_offset; - } + consume_each(in_offset); + return out_offset; +} - void put_next_rx_proto(void *callback_state,char *proto_bits) { - return; - } +void put_next_rx_proto(void* callback_state, char* proto_bits) { return; } - void datarx(void *callback_state, unsigned char *packet, size_t size) { - return; - } +void datarx(void* callback_state, unsigned char* packet, size_t size) { return; } - void datatx(void *callback_state, unsigned char *packet, size_t *size) { - return; - } +void datatx(void* callback_state, unsigned char* packet, size_t* size) { return; } - void freedv_rx_ss_impl::set_squelch_thresh(float squelch_thresh) - { - gr::thread::scoped_lock l(d_setlock); - d_squelch_thresh = squelch_thresh; - freedv_set_snr_squelch_thresh(d_freedv, d_squelch_thresh); - } +void freedv_rx_ss_impl::set_squelch_thresh(float squelch_thresh) +{ + gr::thread::scoped_lock l(d_setlock); + d_squelch_thresh = squelch_thresh; + freedv_set_snr_squelch_thresh(d_freedv, d_squelch_thresh); +} - void freedv_rx_ss_impl::set_squelch_en(bool squelch_enabled) - { - gr::thread::scoped_lock l(d_setlock); - d_squelch_en = squelch_enabled; - if (squelch_enabled) - freedv_set_squelch_en(d_freedv, 1); - else - freedv_set_squelch_en(d_freedv, 0); - } +void freedv_rx_ss_impl::set_squelch_en(bool squelch_enabled) +{ + gr::thread::scoped_lock l(d_setlock); + d_squelch_en = squelch_enabled; + if (squelch_enabled) + freedv_set_squelch_en(d_freedv, 1); + else + freedv_set_squelch_en(d_freedv, 0); +} - float freedv_rx_ss_impl::squelch_thresh() { - return(d_squelch_thresh); - } +float freedv_rx_ss_impl::squelch_thresh() { return (d_squelch_thresh); } - } /* namespace vocoder */ +} /* namespace vocoder */ } /* namespace gr */ diff --git a/gr-vocoder/lib/freedv_rx_ss_impl.h b/gr-vocoder/lib/freedv_rx_ss_impl.h index 56a770be3..7f8a1971c 100644 --- a/gr-vocoder/lib/freedv_rx_ss_impl.h +++ b/gr-vocoder/lib/freedv_rx_ss_impl.h @@ -26,62 +26,62 @@ #include <gnuradio/vocoder/freedv_rx_ss.h> extern "C" { - struct freedv_rx_callback_state { - FILE *ftxt; - }; - static void put_next_rx_char(void *callback_state, char c); - void put_next_rx_proto(void *callback_state,char *proto_bits); - void datarx(void *callback_state, unsigned char *packet, size_t size); - void datatx(void *callback_state, unsigned char *packet, size_t *size); +struct freedv_rx_callback_state { + FILE* ftxt; +}; +static void put_next_rx_char(void* callback_state, char c); +void put_next_rx_proto(void* callback_state, char* proto_bits); +void datarx(void* callback_state, unsigned char* packet, size_t size); +void datatx(void* callback_state, unsigned char* packet, size_t* size); } namespace gr { - namespace vocoder { +namespace vocoder { - class freedv_rx_ss_impl : public freedv_rx_ss - { - private: - short *d_speech_out; - short *d_demod_in; - struct freedv *d_freedv; - int d_nin, d_nout, d_frame; - struct freedv_rx_callback_state d_cb_state; - struct MODEM_STATS d_stats; - int d_mode; - int d_sync; - int d_total_bits; - int d_total_bit_errors; - float d_snr_est; - float d_squelch_thresh; - bool d_squelch_en; - int d_speech_samples; - int d_max_modem_samples; - float d_clock_offset; - int d_use_codecrx; - int d_interleave_frames; +class freedv_rx_ss_impl : public freedv_rx_ss +{ +private: + short* d_speech_out; + short* d_demod_in; + struct freedv* d_freedv; + int d_nin, d_nout, d_frame; + struct freedv_rx_callback_state d_cb_state; + struct MODEM_STATS d_stats; + int d_mode; + int d_sync; + int d_total_bits; + int d_total_bit_errors; + float d_snr_est; + float d_squelch_thresh; + bool d_squelch_en; + int d_speech_samples; + int d_max_modem_samples; + float d_clock_offset; + int d_use_codecrx; + int d_interleave_frames; #ifdef FREEDV_MODE_700D - struct freedv_advanced d_adv; + struct freedv_advanced d_adv; #endif - struct CODEC2 *d_c2 = NULL; + struct CODEC2* d_c2 = NULL; - public: - freedv_rx_ss_impl(int mode, float squelch_thresh, int interleave_frames); - ~freedv_rx_ss_impl(); +public: + freedv_rx_ss_impl(int mode, float squelch_thresh, int interleave_frames); + ~freedv_rx_ss_impl(); - void set_squelch_thresh(float squelch_thresh); - float squelch_thresh(); - void set_squelch_en(bool squelch_enabled); + void set_squelch_thresh(float squelch_thresh); + float squelch_thresh(); + void set_squelch_en(bool squelch_enabled); - // Where all the action really happens - void forecast(int noutput_items, gr_vector_int &ninput_items_required); + // Where all the action really happens + void forecast(int noutput_items, gr_vector_int& ninput_items_required); - int general_work(int noutput_items, - gr_vector_int &ninput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int general_work(int noutput_items, + gr_vector_int& ninput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace vocoder */ +} /* namespace vocoder */ } /* namespace gr */ #endif /* INCLUDED_VOCODER_FREEDV_RX_SS_IMPL_H */ diff --git a/gr-vocoder/lib/freedv_tx_ss_impl.cc b/gr-vocoder/lib/freedv_tx_ss_impl.cc index e56267d5e..4ef5302d1 100644 --- a/gr-vocoder/lib/freedv_tx_ss_impl.cc +++ b/gr-vocoder/lib/freedv_tx_ss_impl.cc @@ -32,9 +32,8 @@ #include <iomanip> extern "C" { - char - get_next_tx_char(void *callback_state) - { +char get_next_tx_char(void* callback_state) +{ char c; struct freedv_tx_callback_state* pstate; @@ -42,100 +41,101 @@ extern "C" { c = *pstate->ptx_str++; if (*pstate->ptx_str == 0) { - pstate->ptx_str = pstate->tx_str; - c = 0x0d; // FreeDV uses Carriage Return termination + pstate->ptx_str = pstate->tx_str; + c = 0x0d; // FreeDV uses Carriage Return termination } return c; - } +} } namespace gr { - namespace vocoder { +namespace vocoder { - freedv_tx_ss::sptr - freedv_tx_ss::make(int mode, const std::string msg_txt, int interleave_frames) - { - return gnuradio::get_initial_sptr - (new freedv_tx_ss_impl(mode, msg_txt, interleave_frames)); - } +freedv_tx_ss::sptr +freedv_tx_ss::make(int mode, const std::string msg_txt, int interleave_frames) +{ + return gnuradio::get_initial_sptr( + new freedv_tx_ss_impl(mode, msg_txt, interleave_frames)); +} - freedv_tx_ss_impl::freedv_tx_ss_impl(int mode, const std::string msg_txt, int interleave_frames) - : sync_block("vocoder_freedv_tx_ss", - io_signature::make(1, 1, sizeof(short)), - io_signature::make(1, 1, sizeof(short))), - d_mode(mode), d_msg_text(msg_txt), d_interleave_frames(interleave_frames) - { +freedv_tx_ss_impl::freedv_tx_ss_impl(int mode, + const std::string msg_txt, + int interleave_frames) + : sync_block("vocoder_freedv_tx_ss", + io_signature::make(1, 1, sizeof(short)), + io_signature::make(1, 1, sizeof(short))), + d_mode(mode), + d_msg_text(msg_txt), + d_interleave_frames(interleave_frames) +{ #ifdef FREEDV_MODE_700D - if (mode == FREEDV_MODE_700D) { - d_adv.interleave_frames = interleave_frames; - if((d_freedv = freedv_open_advanced(mode, &d_adv)) ==NULL) - throw std::runtime_error("freedv_tx_ss_impl: freedv_open_advanced failed"); - } else { - if((d_freedv = freedv_open(mode)) == NULL) - throw std::runtime_error("freedv_tx_ss_impl: freedv_open failed"); - } + if (mode == FREEDV_MODE_700D) { + d_adv.interleave_frames = interleave_frames; + if ((d_freedv = freedv_open_advanced(mode, &d_adv)) == NULL) + throw std::runtime_error("freedv_tx_ss_impl: freedv_open_advanced failed"); + } else { + if ((d_freedv = freedv_open(mode)) == NULL) + throw std::runtime_error("freedv_tx_ss_impl: freedv_open failed"); + } #else - if((d_freedv = freedv_open(mode)) == NULL) + if ((d_freedv = freedv_open(mode)) == NULL) throw std::runtime_error("freedv_tx_ss_impl: freedv_open failed"); #endif - snprintf(d_cb_state.tx_str,79,"%s",d_msg_text.c_str()); - d_cb_state.ptx_str = d_cb_state.tx_str; - freedv_set_callback_txt(d_freedv, NULL, get_next_tx_char, (void *) &d_cb_state); - d_nom_modem_samples = freedv_get_n_nom_modem_samples(d_freedv); - set_output_multiple(d_nom_modem_samples); - } + snprintf(d_cb_state.tx_str, 79, "%s", d_msg_text.c_str()); + d_cb_state.ptx_str = d_cb_state.tx_str; + freedv_set_callback_txt(d_freedv, NULL, get_next_tx_char, (void*)&d_cb_state); + d_nom_modem_samples = freedv_get_n_nom_modem_samples(d_freedv); + set_output_multiple(d_nom_modem_samples); +} - freedv_tx_ss_impl::~freedv_tx_ss_impl() - { - freedv_close(d_freedv); - } +freedv_tx_ss_impl::~freedv_tx_ss_impl() { freedv_close(d_freedv); } - void freedv_tx_ss_impl::set_clip(int val) - { - d_clip = val; +void freedv_tx_ss_impl::set_clip(int val) +{ + d_clip = val; #if defined(FREEDV_MODE_700C) || defined(FREEDV_MODE_700D) - freedv_set_clip(d_freedv, d_clip); + freedv_set_clip(d_freedv, d_clip); #endif - } +} - void freedv_tx_ss_impl::set_clip(bool val) - { - if (val) - freedv_tx_ss_impl::set_clip(1); - else - freedv_tx_ss_impl::set_clip(0); - } +void freedv_tx_ss_impl::set_clip(bool val) +{ + if (val) + freedv_tx_ss_impl::set_clip(1); + else + freedv_tx_ss_impl::set_clip(0); +} - void freedv_tx_ss_impl::set_tx_bpf(int val) - { - d_tx_bpf = val; +void freedv_tx_ss_impl::set_tx_bpf(int val) +{ + d_tx_bpf = val; #ifdef FREEDV_MODE_700D - freedv_set_tx_bpf(d_freedv, d_tx_bpf); + freedv_set_tx_bpf(d_freedv, d_tx_bpf); #endif - } +} - void freedv_tx_ss_impl::set_tx_bpf(bool val) - { - if (val) - freedv_tx_ss_impl::set_tx_bpf(1); - else - freedv_tx_ss_impl::set_tx_bpf(0); - } +void freedv_tx_ss_impl::set_tx_bpf(bool val) +{ + if (val) + freedv_tx_ss_impl::set_tx_bpf(1); + else + freedv_tx_ss_impl::set_tx_bpf(0); +} - int - freedv_tx_ss_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - short *in = (short*)input_items[0]; - short *out = (short*)output_items[0]; - int i; - - for(i=0;i<(noutput_items/d_nom_modem_samples);i++) - freedv_tx(d_freedv, &(out[i*d_nom_modem_samples]), &(in[i*d_nom_modem_samples])); - return noutput_items; - } +int freedv_tx_ss_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + short* in = (short*)input_items[0]; + short* out = (short*)output_items[0]; + int i; + + for (i = 0; i < (noutput_items / d_nom_modem_samples); i++) + freedv_tx( + d_freedv, &(out[i * d_nom_modem_samples]), &(in[i * d_nom_modem_samples])); + return noutput_items; +} - } /* namespace vocoder */ +} /* namespace vocoder */ } /* namespace gr */ diff --git a/gr-vocoder/lib/freedv_tx_ss_impl.h b/gr-vocoder/lib/freedv_tx_ss_impl.h index 167ee28ea..5db48097e 100644 --- a/gr-vocoder/lib/freedv_tx_ss_impl.h +++ b/gr-vocoder/lib/freedv_tx_ss_impl.h @@ -26,58 +26,58 @@ #include <gnuradio/vocoder/freedv_tx_ss.h> extern "C" { - struct freedv_tx_callback_state { - char tx_str[80]; - char *ptx_str; +struct freedv_tx_callback_state { + char tx_str[80]; + char* ptx_str; int calls; - }; - char get_next_tx_char(void *callback_state); - void get_next_proto(void *callback_state,char *proto_bits); - void datarx(void *callback_state, unsigned char *packet, size_t size); - void datatx(void *callback_state, unsigned char *packet, size_t *size); +}; +char get_next_tx_char(void* callback_state); +void get_next_proto(void* callback_state, char* proto_bits); +void datarx(void* callback_state, unsigned char* packet, size_t size); +void datatx(void* callback_state, unsigned char* packet, size_t* size); } namespace gr { - namespace vocoder { +namespace vocoder { - class freedv_tx_ss_impl : public freedv_tx_ss - { - private: - short *d_speech_in; - short *d_mod_out; - struct freedv_tx_callback_state d_cb_state; - struct freedv *d_freedv; - int d_mode; - std::string d_msg_text; - int d_interleave_frames; - float d_squelch_thresh; - int d_speech_samples; - int d_nom_modem_samples; - int d_use_codectx; - int d_use_datatx; - int d_clip; - int d_tx_bpf; +class freedv_tx_ss_impl : public freedv_tx_ss +{ +private: + short* d_speech_in; + short* d_mod_out; + struct freedv_tx_callback_state d_cb_state; + struct freedv* d_freedv; + int d_mode; + std::string d_msg_text; + int d_interleave_frames; + float d_squelch_thresh; + int d_speech_samples; + int d_nom_modem_samples; + int d_use_codectx; + int d_use_datatx; + int d_clip; + int d_tx_bpf; #ifdef FREEDV_MODE_700D - struct freedv_advanced d_adv; + struct freedv_advanced d_adv; #endif - struct CODEC2 *d_c2; + struct CODEC2* d_c2; - public: - freedv_tx_ss_impl(int mode, const std::string txt_msg, int interleave_frames); - ~freedv_tx_ss_impl(); +public: + freedv_tx_ss_impl(int mode, const std::string txt_msg, int interleave_frames); + ~freedv_tx_ss_impl(); - void set_clip(bool val); - void set_clip(int val); - void set_tx_bpf(bool val); - void set_tx_bpf(int val); + void set_clip(bool val); + void set_clip(int val); + void set_tx_bpf(bool val); + void set_tx_bpf(int val); - // Where all the action really happens - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + // Where all the action really happens + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace vocoder */ +} /* namespace vocoder */ } /* namespace gr */ #endif /* INCLUDED_VOCODER_FREEDV_TX_SS_IMPL_H */ diff --git a/gr-vocoder/lib/g721_decode_bs_impl.cc b/gr-vocoder/lib/g721_decode_bs_impl.cc index 74e43e122..760b7dc99 100644 --- a/gr-vocoder/lib/g721_decode_bs_impl.cc +++ b/gr-vocoder/lib/g721_decode_bs_impl.cc @@ -29,40 +29,35 @@ #include <limits.h> namespace gr { - namespace vocoder { +namespace vocoder { - g721_decode_bs::sptr - g721_decode_bs::make() - { - return gnuradio::get_initial_sptr - (new g721_decode_bs_impl()); - } +g721_decode_bs::sptr g721_decode_bs::make() +{ + return gnuradio::get_initial_sptr(new g721_decode_bs_impl()); +} - g721_decode_bs_impl::g721_decode_bs_impl() - : sync_block("vocoder_g721_decode_bs", - io_signature::make(1, 1, sizeof(unsigned char)), - io_signature::make(1, 1, sizeof(short))) - { - g72x_init_state(&d_state); - } +g721_decode_bs_impl::g721_decode_bs_impl() + : sync_block("vocoder_g721_decode_bs", + io_signature::make(1, 1, sizeof(unsigned char)), + io_signature::make(1, 1, sizeof(short))) +{ + g72x_init_state(&d_state); +} - g721_decode_bs_impl::~g721_decode_bs_impl() - { - } +g721_decode_bs_impl::~g721_decode_bs_impl() {} - int - g721_decode_bs_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - const unsigned char *in = (const unsigned char*)input_items[0]; - short *out = (short*)output_items[0]; +int g721_decode_bs_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + const unsigned char* in = (const unsigned char*)input_items[0]; + short* out = (short*)output_items[0]; - for(int i = 0; i < noutput_items; i++) - out[i] = g721_decoder(in[i], AUDIO_ENCODING_LINEAR, &d_state); + for (int i = 0; i < noutput_items; i++) + out[i] = g721_decoder(in[i], AUDIO_ENCODING_LINEAR, &d_state); - return noutput_items; - } + return noutput_items; +} - } /* namespace vocoder */ +} /* namespace vocoder */ } /* namespace gr */ diff --git a/gr-vocoder/lib/g721_decode_bs_impl.h b/gr-vocoder/lib/g721_decode_bs_impl.h index 40a147525..1e224c2b1 100644 --- a/gr-vocoder/lib/g721_decode_bs_impl.h +++ b/gr-vocoder/lib/g721_decode_bs_impl.h @@ -30,23 +30,23 @@ extern "C" { } namespace gr { - namespace vocoder { +namespace vocoder { - class g721_decode_bs_impl : public g721_decode_bs - { - private: - g72x_state d_state; +class g721_decode_bs_impl : public g721_decode_bs +{ +private: + g72x_state d_state; - public: - g721_decode_bs_impl(); - ~g721_decode_bs_impl(); +public: + g721_decode_bs_impl(); + ~g721_decode_bs_impl(); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace vocoder */ +} /* namespace vocoder */ } /* namespace gr */ #endif /* INCLUDED_VOCODER_G721_DECODE_BS_IMPL_H */ diff --git a/gr-vocoder/lib/g721_encode_sb_impl.cc b/gr-vocoder/lib/g721_encode_sb_impl.cc index 73243f814..5241daa1e 100644 --- a/gr-vocoder/lib/g721_encode_sb_impl.cc +++ b/gr-vocoder/lib/g721_encode_sb_impl.cc @@ -29,40 +29,35 @@ #include <limits.h> namespace gr { - namespace vocoder { +namespace vocoder { - g721_encode_sb::sptr - g721_encode_sb::make() - { - return gnuradio::get_initial_sptr - (new g721_encode_sb_impl()); - } +g721_encode_sb::sptr g721_encode_sb::make() +{ + return gnuradio::get_initial_sptr(new g721_encode_sb_impl()); +} - g721_encode_sb_impl::g721_encode_sb_impl() - : sync_block("vocoder_g721_encode_sb", - io_signature::make(1, 1, sizeof(short)), - io_signature::make(1, 1, sizeof(unsigned char))) - { - g72x_init_state(&d_state); - } +g721_encode_sb_impl::g721_encode_sb_impl() + : sync_block("vocoder_g721_encode_sb", + io_signature::make(1, 1, sizeof(short)), + io_signature::make(1, 1, sizeof(unsigned char))) +{ + g72x_init_state(&d_state); +} - g721_encode_sb_impl::~g721_encode_sb_impl() - { - } +g721_encode_sb_impl::~g721_encode_sb_impl() {} - int - g721_encode_sb_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - const short *in = (const short*)input_items[0]; - unsigned char *out = (unsigned char*)output_items[0]; +int g721_encode_sb_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + const short* in = (const short*)input_items[0]; + unsigned char* out = (unsigned char*)output_items[0]; - for(int i = 0; i < noutput_items; i++) - out[i] = g721_encoder(in[i], AUDIO_ENCODING_LINEAR, &d_state); + for (int i = 0; i < noutput_items; i++) + out[i] = g721_encoder(in[i], AUDIO_ENCODING_LINEAR, &d_state); - return noutput_items; - } + return noutput_items; +} - } /* namespace vocoder */ +} /* namespace vocoder */ } /* namespace gr */ diff --git a/gr-vocoder/lib/g721_encode_sb_impl.h b/gr-vocoder/lib/g721_encode_sb_impl.h index 73fb0eea4..9efebe4c3 100644 --- a/gr-vocoder/lib/g721_encode_sb_impl.h +++ b/gr-vocoder/lib/g721_encode_sb_impl.h @@ -30,23 +30,23 @@ extern "C" { } namespace gr { - namespace vocoder { +namespace vocoder { - class g721_encode_sb_impl : public g721_encode_sb - { - private: - g72x_state d_state; +class g721_encode_sb_impl : public g721_encode_sb +{ +private: + g72x_state d_state; - public: - g721_encode_sb_impl(); - ~g721_encode_sb_impl(); +public: + g721_encode_sb_impl(); + ~g721_encode_sb_impl(); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace vocoder */ +} /* namespace vocoder */ } /* namespace gr */ #endif /* INCLUDED_VOCODER_G721_ENCODE_SB_IMPL_H */ diff --git a/gr-vocoder/lib/g723_24_decode_bs_impl.cc b/gr-vocoder/lib/g723_24_decode_bs_impl.cc index c78229c4f..376d8241d 100644 --- a/gr-vocoder/lib/g723_24_decode_bs_impl.cc +++ b/gr-vocoder/lib/g723_24_decode_bs_impl.cc @@ -29,40 +29,35 @@ #include <limits.h> namespace gr { - namespace vocoder { +namespace vocoder { - g723_24_decode_bs::sptr - g723_24_decode_bs::make() - { - return gnuradio::get_initial_sptr - (new g723_24_decode_bs_impl()); - } +g723_24_decode_bs::sptr g723_24_decode_bs::make() +{ + return gnuradio::get_initial_sptr(new g723_24_decode_bs_impl()); +} - g723_24_decode_bs_impl::g723_24_decode_bs_impl() - : sync_block("vocoder_g723_24_decode_bs", - io_signature::make(1, 1, sizeof(unsigned char)), - io_signature::make(1, 1, sizeof(short))) - { - g72x_init_state(&d_state); - } +g723_24_decode_bs_impl::g723_24_decode_bs_impl() + : sync_block("vocoder_g723_24_decode_bs", + io_signature::make(1, 1, sizeof(unsigned char)), + io_signature::make(1, 1, sizeof(short))) +{ + g72x_init_state(&d_state); +} - g723_24_decode_bs_impl::~g723_24_decode_bs_impl() - { - } +g723_24_decode_bs_impl::~g723_24_decode_bs_impl() {} - int - g723_24_decode_bs_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - const unsigned char *in = (const unsigned char*)input_items[0]; - short *out = (short*)output_items[0]; +int g723_24_decode_bs_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + const unsigned char* in = (const unsigned char*)input_items[0]; + short* out = (short*)output_items[0]; - for(int i = 0; i < noutput_items; i++) - out[i] = g723_24_decoder(in[i], AUDIO_ENCODING_LINEAR, &d_state); + for (int i = 0; i < noutput_items; i++) + out[i] = g723_24_decoder(in[i], AUDIO_ENCODING_LINEAR, &d_state); - return noutput_items; - } + return noutput_items; +} - } /* namespace vocoder */ +} /* namespace vocoder */ } /* namespace gr */ diff --git a/gr-vocoder/lib/g723_24_decode_bs_impl.h b/gr-vocoder/lib/g723_24_decode_bs_impl.h index 454bed76c..fb85f625f 100644 --- a/gr-vocoder/lib/g723_24_decode_bs_impl.h +++ b/gr-vocoder/lib/g723_24_decode_bs_impl.h @@ -30,23 +30,23 @@ extern "C" { } namespace gr { - namespace vocoder { +namespace vocoder { - class g723_24_decode_bs_impl : public g723_24_decode_bs - { - private: - g72x_state d_state; +class g723_24_decode_bs_impl : public g723_24_decode_bs +{ +private: + g72x_state d_state; - public: - g723_24_decode_bs_impl(); - ~g723_24_decode_bs_impl(); +public: + g723_24_decode_bs_impl(); + ~g723_24_decode_bs_impl(); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace vocoder */ +} /* namespace vocoder */ } /* namespace gr */ #endif /* INCLUDED_VOCODER_G723_24_DECODE_BS_IMPL_H */ diff --git a/gr-vocoder/lib/g723_24_encode_sb_impl.cc b/gr-vocoder/lib/g723_24_encode_sb_impl.cc index cf721e358..771711bb9 100644 --- a/gr-vocoder/lib/g723_24_encode_sb_impl.cc +++ b/gr-vocoder/lib/g723_24_encode_sb_impl.cc @@ -29,40 +29,35 @@ #include <limits.h> namespace gr { - namespace vocoder { +namespace vocoder { - g723_24_encode_sb::sptr - g723_24_encode_sb::make() - { - return gnuradio::get_initial_sptr - (new g723_24_encode_sb_impl()); - } +g723_24_encode_sb::sptr g723_24_encode_sb::make() +{ + return gnuradio::get_initial_sptr(new g723_24_encode_sb_impl()); +} - g723_24_encode_sb_impl::g723_24_encode_sb_impl() - : sync_block("vocoder_g723_24_encode_sb", - io_signature::make(1, 1, sizeof(short)), - io_signature::make(1, 1, sizeof(unsigned char))) - { - g72x_init_state(&d_state); - } +g723_24_encode_sb_impl::g723_24_encode_sb_impl() + : sync_block("vocoder_g723_24_encode_sb", + io_signature::make(1, 1, sizeof(short)), + io_signature::make(1, 1, sizeof(unsigned char))) +{ + g72x_init_state(&d_state); +} - g723_24_encode_sb_impl::~g723_24_encode_sb_impl() - { - } +g723_24_encode_sb_impl::~g723_24_encode_sb_impl() {} - int - g723_24_encode_sb_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - const short *in = (const short*)input_items[0]; - unsigned char *out = (unsigned char*)output_items[0]; +int g723_24_encode_sb_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + const short* in = (const short*)input_items[0]; + unsigned char* out = (unsigned char*)output_items[0]; - for(int i = 0; i < noutput_items; i++) - out[i] = g723_24_encoder(in[i], AUDIO_ENCODING_LINEAR, &d_state); + for (int i = 0; i < noutput_items; i++) + out[i] = g723_24_encoder(in[i], AUDIO_ENCODING_LINEAR, &d_state); - return noutput_items; - } + return noutput_items; +} - } /* namespace vocoder */ +} /* namespace vocoder */ } /* namespace gr */ diff --git a/gr-vocoder/lib/g723_24_encode_sb_impl.h b/gr-vocoder/lib/g723_24_encode_sb_impl.h index 9b18a0e93..3c34981e5 100644 --- a/gr-vocoder/lib/g723_24_encode_sb_impl.h +++ b/gr-vocoder/lib/g723_24_encode_sb_impl.h @@ -30,23 +30,23 @@ extern "C" { } namespace gr { - namespace vocoder { +namespace vocoder { - class g723_24_encode_sb_impl : public g723_24_encode_sb - { - private: - g72x_state d_state; +class g723_24_encode_sb_impl : public g723_24_encode_sb +{ +private: + g72x_state d_state; - public: - g723_24_encode_sb_impl(); - ~g723_24_encode_sb_impl(); +public: + g723_24_encode_sb_impl(); + ~g723_24_encode_sb_impl(); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace vocoder */ +} /* namespace vocoder */ } /* namespace gr */ #endif /* INCLUDED_VOCODER_G723_24_ENCODE_SB_IMPL_H */ diff --git a/gr-vocoder/lib/g723_40_decode_bs_impl.cc b/gr-vocoder/lib/g723_40_decode_bs_impl.cc index 78bc99d92..352b33881 100644 --- a/gr-vocoder/lib/g723_40_decode_bs_impl.cc +++ b/gr-vocoder/lib/g723_40_decode_bs_impl.cc @@ -29,40 +29,35 @@ #include <limits.h> namespace gr { - namespace vocoder { +namespace vocoder { - g723_40_decode_bs::sptr - g723_40_decode_bs::make() - { - return gnuradio::get_initial_sptr - (new g723_40_decode_bs_impl()); - } +g723_40_decode_bs::sptr g723_40_decode_bs::make() +{ + return gnuradio::get_initial_sptr(new g723_40_decode_bs_impl()); +} - g723_40_decode_bs_impl::g723_40_decode_bs_impl() - : sync_block("vocoder_g723_40_decode_bs", - io_signature::make(1, 1, sizeof(unsigned char)), - io_signature::make(1, 1, sizeof(short))) - { - g72x_init_state(&d_state); - } +g723_40_decode_bs_impl::g723_40_decode_bs_impl() + : sync_block("vocoder_g723_40_decode_bs", + io_signature::make(1, 1, sizeof(unsigned char)), + io_signature::make(1, 1, sizeof(short))) +{ + g72x_init_state(&d_state); +} - g723_40_decode_bs_impl::~g723_40_decode_bs_impl() - { - } +g723_40_decode_bs_impl::~g723_40_decode_bs_impl() {} - int - g723_40_decode_bs_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - const unsigned char *in = (const unsigned char*)input_items[0]; - short *out = (short*)output_items[0]; +int g723_40_decode_bs_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + const unsigned char* in = (const unsigned char*)input_items[0]; + short* out = (short*)output_items[0]; - for(int i = 0; i < noutput_items; i++) - out[i] = g723_40_decoder(in[i], AUDIO_ENCODING_LINEAR, &d_state); + for (int i = 0; i < noutput_items; i++) + out[i] = g723_40_decoder(in[i], AUDIO_ENCODING_LINEAR, &d_state); - return noutput_items; - } + return noutput_items; +} - } /* namespace vocoder */ +} /* namespace vocoder */ } /* namespace gr */ diff --git a/gr-vocoder/lib/g723_40_decode_bs_impl.h b/gr-vocoder/lib/g723_40_decode_bs_impl.h index 81a08727a..52a9cf6cb 100644 --- a/gr-vocoder/lib/g723_40_decode_bs_impl.h +++ b/gr-vocoder/lib/g723_40_decode_bs_impl.h @@ -30,23 +30,23 @@ extern "C" { } namespace gr { - namespace vocoder { +namespace vocoder { - class g723_40_decode_bs_impl : public g723_40_decode_bs - { - private: - g72x_state d_state; +class g723_40_decode_bs_impl : public g723_40_decode_bs +{ +private: + g72x_state d_state; - public: - g723_40_decode_bs_impl(); - ~g723_40_decode_bs_impl(); +public: + g723_40_decode_bs_impl(); + ~g723_40_decode_bs_impl(); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace vocoder */ +} /* namespace vocoder */ } /* namespace gr */ #endif /* INCLUDED_VOCODER_G723_40_DECODE_BS_IMPL_H */ diff --git a/gr-vocoder/lib/g723_40_encode_sb_impl.cc b/gr-vocoder/lib/g723_40_encode_sb_impl.cc index ff1910c55..16ae70c9a 100644 --- a/gr-vocoder/lib/g723_40_encode_sb_impl.cc +++ b/gr-vocoder/lib/g723_40_encode_sb_impl.cc @@ -29,40 +29,35 @@ #include <limits.h> namespace gr { - namespace vocoder { +namespace vocoder { - g723_40_encode_sb::sptr - g723_40_encode_sb::make() - { - return gnuradio::get_initial_sptr - (new g723_40_encode_sb_impl()); - } +g723_40_encode_sb::sptr g723_40_encode_sb::make() +{ + return gnuradio::get_initial_sptr(new g723_40_encode_sb_impl()); +} - g723_40_encode_sb_impl::g723_40_encode_sb_impl() - : sync_block("vocoder_g723_40_encode_sb", - io_signature::make(1, 1, sizeof(short)), - io_signature::make(1, 1, sizeof(unsigned char))) - { - g72x_init_state(&d_state); - } +g723_40_encode_sb_impl::g723_40_encode_sb_impl() + : sync_block("vocoder_g723_40_encode_sb", + io_signature::make(1, 1, sizeof(short)), + io_signature::make(1, 1, sizeof(unsigned char))) +{ + g72x_init_state(&d_state); +} - g723_40_encode_sb_impl::~g723_40_encode_sb_impl() - { - } +g723_40_encode_sb_impl::~g723_40_encode_sb_impl() {} - int - g723_40_encode_sb_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - const short *in = (const short*)input_items[0]; - unsigned char *out = (unsigned char*)output_items[0]; +int g723_40_encode_sb_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + const short* in = (const short*)input_items[0]; + unsigned char* out = (unsigned char*)output_items[0]; - for(int i = 0; i < noutput_items; i++) - out[i] = g723_40_encoder(in[i], AUDIO_ENCODING_LINEAR, &d_state); + for (int i = 0; i < noutput_items; i++) + out[i] = g723_40_encoder(in[i], AUDIO_ENCODING_LINEAR, &d_state); - return noutput_items; - } + return noutput_items; +} - } /* namespace vocoder */ +} /* namespace vocoder */ } /* namespace gr */ diff --git a/gr-vocoder/lib/g723_40_encode_sb_impl.h b/gr-vocoder/lib/g723_40_encode_sb_impl.h index 326ed7def..db94f3b41 100644 --- a/gr-vocoder/lib/g723_40_encode_sb_impl.h +++ b/gr-vocoder/lib/g723_40_encode_sb_impl.h @@ -30,23 +30,23 @@ extern "C" { } namespace gr { - namespace vocoder { +namespace vocoder { - class g723_40_encode_sb_impl : public g723_40_encode_sb - { - private: - g72x_state d_state; +class g723_40_encode_sb_impl : public g723_40_encode_sb +{ +private: + g72x_state d_state; - public: - g723_40_encode_sb_impl(); - ~g723_40_encode_sb_impl(); +public: + g723_40_encode_sb_impl(); + ~g723_40_encode_sb_impl(); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace vocoder */ +} /* namespace vocoder */ } /* namespace gr */ #endif /* INCLUDED_VOCODER_G723_40_ENCODE_SB_IMPL_H */ diff --git a/gr-vocoder/lib/g7xx/decode.c b/gr-vocoder/lib/g7xx/decode.c index cf8c739c5..b2ce68ffd 100644 --- a/gr-vocoder/lib/g7xx/decode.c +++ b/gr-vocoder/lib/g7xx/decode.c @@ -13,101 +13,96 @@ * Unpack input codes and pass them back as bytes. * Returns 1 if there is residual input, returns -1 if eof, else returns 0. */ -int -unpack_input( - unsigned char *code, - int bits) +int unpack_input(unsigned char* code, int bits) { - static unsigned int in_buffer = 0; - static int in_bits = 0; - unsigned char in_byte; + static unsigned int in_buffer = 0; + static int in_bits = 0; + unsigned char in_byte; - if (in_bits < bits) { - if (fread(&in_byte, sizeof (char), 1, stdin) != 1) { - *code = 0; - return (-1); - } - in_buffer |= (in_byte << in_bits); - in_bits += 8; - } - *code = in_buffer & ((1 << bits) - 1); - in_buffer >>= bits; - in_bits -= bits; - return (in_bits > 0); + if (in_bits < bits) { + if (fread(&in_byte, sizeof(char), 1, stdin) != 1) { + *code = 0; + return (-1); + } + in_buffer |= (in_byte << in_bits); + in_bits += 8; + } + *code = in_buffer & ((1 << bits) - 1); + in_buffer >>= bits; + in_bits -= bits; + return (in_bits > 0); } -main( - int argc, - char **argv) +main(int argc, char** argv) { - short sample; - unsigned char code; - int n; - struct g72x_state state; - int out_coding; - int out_size; - int (*dec_routine)(); - int dec_bits; + short sample; + unsigned char code; + int n; + struct g72x_state state; + int out_coding; + int out_size; + int (*dec_routine)(); + int dec_bits; - g72x_init_state(&state); - out_coding = AUDIO_ENCODING_ULAW; - out_size = sizeof (char); - dec_routine = g721_decoder; - dec_bits = 4; + g72x_init_state(&state); + out_coding = AUDIO_ENCODING_ULAW; + out_size = sizeof(char); + dec_routine = g721_decoder; + dec_bits = 4; - /* Process encoding argument, if any */ - while ((argc > 1) && (argv[1][0] == '-')) { - switch (argv[1][1]) { - case '3': - dec_routine = g723_24_decoder; - dec_bits = 3; - break; - case '4': - dec_routine = g721_decoder; - dec_bits = 4; - break; - case '5': - dec_routine = g723_40_decoder; - dec_bits = 5; - break; - case 'u': - out_coding = AUDIO_ENCODING_ULAW; - out_size = sizeof (char); - break; - case 'a': - out_coding = AUDIO_ENCODING_ALAW; - out_size = sizeof (char); - break; - case 'l': - out_coding = AUDIO_ENCODING_LINEAR; - out_size = sizeof (short); - break; - default: -fprintf(stderr, "CCITT ADPCM Decoder -- usage:\n"); -fprintf(stderr, "\tdecode [-3|4|5] [-a|u|l] < infile > outfile\n"); -fprintf(stderr, "where:\n"); -fprintf(stderr, "\t-3\tProcess G.723 24kbps (3-bit) input data\n"); -fprintf(stderr, "\t-4\tProcess G.721 32kbps (4-bit) input data [default]\n"); -fprintf(stderr, "\t-5\tProcess G.723 40kbps (5-bit) input data\n"); -fprintf(stderr, "\t-a\tGenerate 8-bit A-law data\n"); -fprintf(stderr, "\t-u\tGenerate 8-bit u-law data [default]\n"); -fprintf(stderr, "\t-l\tGenerate 16-bit linear PCM data\n"); - exit(1); - } - argc--; - argv++; - } + /* Process encoding argument, if any */ + while ((argc > 1) && (argv[1][0] == '-')) { + switch (argv[1][1]) { + case '3': + dec_routine = g723_24_decoder; + dec_bits = 3; + break; + case '4': + dec_routine = g721_decoder; + dec_bits = 4; + break; + case '5': + dec_routine = g723_40_decoder; + dec_bits = 5; + break; + case 'u': + out_coding = AUDIO_ENCODING_ULAW; + out_size = sizeof(char); + break; + case 'a': + out_coding = AUDIO_ENCODING_ALAW; + out_size = sizeof(char); + break; + case 'l': + out_coding = AUDIO_ENCODING_LINEAR; + out_size = sizeof(short); + break; + default: + fprintf(stderr, "CCITT ADPCM Decoder -- usage:\n"); + fprintf(stderr, "\tdecode [-3|4|5] [-a|u|l] < infile > outfile\n"); + fprintf(stderr, "where:\n"); + fprintf(stderr, "\t-3\tProcess G.723 24kbps (3-bit) input data\n"); + fprintf(stderr, "\t-4\tProcess G.721 32kbps (4-bit) input data [default]\n"); + fprintf(stderr, "\t-5\tProcess G.723 40kbps (5-bit) input data\n"); + fprintf(stderr, "\t-a\tGenerate 8-bit A-law data\n"); + fprintf(stderr, "\t-u\tGenerate 8-bit u-law data [default]\n"); + fprintf(stderr, "\t-l\tGenerate 16-bit linear PCM data\n"); + exit(1); + } + argc--; + argv++; + } - /* Read and unpack input codes and process them */ - while (unpack_input(&code, dec_bits) >= 0) { - sample = (*dec_routine)(code, out_coding, &state); - if (out_size == 2) { - fwrite(&sample, out_size, 1, stdout); - } else { - code = (unsigned char)sample; - fwrite(&code, out_size, 1, stdout); - } - } - fclose(stdout); + /* Read and unpack input codes and process them */ + while (unpack_input(&code, dec_bits) >= 0) { + sample = (*dec_routine)(code, out_coding, &state); + if (out_size == 2) { + fwrite(&sample, out_size, 1, stdout); + } else { + code = (unsigned char)sample; + fwrite(&code, out_size, 1, stdout); + } + } + fclose(stdout); } diff --git a/gr-vocoder/lib/g7xx/encode.c b/gr-vocoder/lib/g7xx/encode.c index e74482869..257b829aa 100644 --- a/gr-vocoder/lib/g7xx/encode.c +++ b/gr-vocoder/lib/g7xx/encode.c @@ -13,107 +13,102 @@ * Pack output codes into bytes and write them to stdout. * Returns 1 if there is residual output, else returns 0. */ -int -pack_output( - unsigned code, - int bits) +int pack_output(unsigned code, int bits) { - static unsigned int out_buffer = 0; - static int out_bits = 0; - unsigned char out_byte; + static unsigned int out_buffer = 0; + static int out_bits = 0; + unsigned char out_byte; - out_buffer |= (code << out_bits); - out_bits += bits; - if (out_bits >= 8) { - out_byte = out_buffer & 0xff; - out_bits -= 8; - out_buffer >>= 8; - fwrite(&out_byte, sizeof (char), 1, stdout); - } - return (out_bits > 0); + out_buffer |= (code << out_bits); + out_bits += bits; + if (out_bits >= 8) { + out_byte = out_buffer & 0xff; + out_bits -= 8; + out_buffer >>= 8; + fwrite(&out_byte, sizeof(char), 1, stdout); + } + return (out_bits > 0); } -main( - int argc, - char **argv) +main(int argc, char** argv) { - struct g72x_state state; - unsigned char sample_char; - short sample_short; - unsigned char code; - int resid; - int in_coding; - int in_size; - unsigned *in_buf; - int (*enc_routine)(); - int enc_bits; + struct g72x_state state; + unsigned char sample_char; + short sample_short; + unsigned char code; + int resid; + int in_coding; + int in_size; + unsigned* in_buf; + int (*enc_routine)(); + int enc_bits; - g72x_init_state(&state); + g72x_init_state(&state); - /* Set defaults to u-law input, G.721 output */ - in_coding = AUDIO_ENCODING_ULAW; - in_size = sizeof (char); - in_buf = (unsigned *)&sample_char; - enc_routine = g721_encoder; - enc_bits = 4; + /* Set defaults to u-law input, G.721 output */ + in_coding = AUDIO_ENCODING_ULAW; + in_size = sizeof(char); + in_buf = (unsigned*)&sample_char; + enc_routine = g721_encoder; + enc_bits = 4; - /* Process encoding argument, if any */ - while ((argc > 1) && (argv[1][0] == '-')) { - switch (argv[1][1]) { - case '3': - enc_routine = g723_24_encoder; - enc_bits = 3; - break; - case '4': - enc_routine = g721_encoder; - enc_bits = 4; - break; - case '5': - enc_routine = g723_40_encoder; - enc_bits = 5; - break; - case 'u': - in_coding = AUDIO_ENCODING_ULAW; - in_size = sizeof (char); - in_buf = (unsigned *)&sample_char; - break; - case 'a': - in_coding = AUDIO_ENCODING_ALAW; - in_size = sizeof (char); - in_buf = (unsigned *)&sample_char; - break; - case 'l': - in_coding = AUDIO_ENCODING_LINEAR; - in_size = sizeof (short); - in_buf = (unsigned *)&sample_short; - break; - default: -fprintf(stderr, "CCITT ADPCM Encoder -- usage:\n"); -fprintf(stderr, "\tencode [-3|4|5] [-a|u|l] < infile > outfile\n"); -fprintf(stderr, "where:\n"); -fprintf(stderr, "\t-3\tGenerate G.723 24kbps (3-bit) data\n"); -fprintf(stderr, "\t-4\tGenerate G.721 32kbps (4-bit) data [default]\n"); -fprintf(stderr, "\t-5\tGenerate G.723 40kbps (5-bit) data\n"); -fprintf(stderr, "\t-a\tProcess 8-bit A-law input data\n"); -fprintf(stderr, "\t-u\tProcess 8-bit u-law input data [default]\n"); -fprintf(stderr, "\t-l\tProcess 16-bit linear PCM input data\n"); - exit(1); - } - argc--; - argv++; - } + /* Process encoding argument, if any */ + while ((argc > 1) && (argv[1][0] == '-')) { + switch (argv[1][1]) { + case '3': + enc_routine = g723_24_encoder; + enc_bits = 3; + break; + case '4': + enc_routine = g721_encoder; + enc_bits = 4; + break; + case '5': + enc_routine = g723_40_encoder; + enc_bits = 5; + break; + case 'u': + in_coding = AUDIO_ENCODING_ULAW; + in_size = sizeof(char); + in_buf = (unsigned*)&sample_char; + break; + case 'a': + in_coding = AUDIO_ENCODING_ALAW; + in_size = sizeof(char); + in_buf = (unsigned*)&sample_char; + break; + case 'l': + in_coding = AUDIO_ENCODING_LINEAR; + in_size = sizeof(short); + in_buf = (unsigned*)&sample_short; + break; + default: + fprintf(stderr, "CCITT ADPCM Encoder -- usage:\n"); + fprintf(stderr, "\tencode [-3|4|5] [-a|u|l] < infile > outfile\n"); + fprintf(stderr, "where:\n"); + fprintf(stderr, "\t-3\tGenerate G.723 24kbps (3-bit) data\n"); + fprintf(stderr, "\t-4\tGenerate G.721 32kbps (4-bit) data [default]\n"); + fprintf(stderr, "\t-5\tGenerate G.723 40kbps (5-bit) data\n"); + fprintf(stderr, "\t-a\tProcess 8-bit A-law input data\n"); + fprintf(stderr, "\t-u\tProcess 8-bit u-law input data [default]\n"); + fprintf(stderr, "\t-l\tProcess 16-bit linear PCM input data\n"); + exit(1); + } + argc--; + argv++; + } - /* Read input file and process */ - while (fread(in_buf, in_size, 1, stdin) == 1) { - code = (*enc_routine)(in_size == 2 ? sample_short : sample_char, - in_coding, &state); - resid = pack_output(code, enc_bits); - } + /* Read input file and process */ + while (fread(in_buf, in_size, 1, stdin) == 1) { + code = + (*enc_routine)(in_size == 2 ? sample_short : sample_char, in_coding, &state); + resid = pack_output(code, enc_bits); + } - /* Write zero codes until all residual codes are written out */ - while (resid) { - resid = pack_output(0, enc_bits); - } - fclose(stdout); + /* Write zero codes until all residual codes are written out */ + while (resid) { + resid = pack_output(0, enc_bits); + } + fclose(stdout); } diff --git a/gr-vocoder/lib/g7xx/g711.c b/gr-vocoder/lib/g7xx/g711.c index d4d60a5c2..e73739892 100644 --- a/gr-vocoder/lib/g7xx/g711.c +++ b/gr-vocoder/lib/g7xx/g711.c @@ -29,65 +29,52 @@ * * u-law, A-law and linear PCM conversions. */ -#define SIGN_BIT (0x80) /* Sign bit for a A-law byte. */ -#define QUANT_MASK (0xf) /* Quantization field mask. */ -#define NSEGS (8) /* Number of A-law segments. */ -#define SEG_SHIFT (4) /* Left shift for segment number. */ -#define SEG_MASK (0x70) /* Segment field mask. */ +#define SIGN_BIT (0x80) /* Sign bit for a A-law byte. */ +#define QUANT_MASK (0xf) /* Quantization field mask. */ +#define NSEGS (8) /* Number of A-law segments. */ +#define SEG_SHIFT (4) /* Left shift for segment number. */ +#define SEG_MASK (0x70) /* Segment field mask. */ -static short seg_end[8] = {0xFF, 0x1FF, 0x3FF, 0x7FF, - 0xFFF, 0x1FFF, 0x3FFF, 0x7FFF}; +static short seg_end[8] = { 0xFF, 0x1FF, 0x3FF, 0x7FF, 0xFFF, 0x1FFF, 0x3FFF, 0x7FFF }; /* copy from CCITT G.711 specifications */ -unsigned char _u2a[128] = { /* u- to A-law conversions */ - 1, 1, 2, 2, 3, 3, 4, 4, - 5, 5, 6, 6, 7, 7, 8, 8, - 9, 10, 11, 12, 13, 14, 15, 16, - 17, 18, 19, 20, 21, 22, 23, 24, - 25, 27, 29, 31, 33, 34, 35, 36, - 37, 38, 39, 40, 41, 42, 43, 44, - 46, 48, 49, 50, 51, 52, 53, 54, - 55, 56, 57, 58, 59, 60, 61, 62, - 64, 65, 66, 67, 68, 69, 70, 71, - 72, 73, 74, 75, 76, 77, 78, 79, - 81, 82, 83, 84, 85, 86, 87, 88, - 89, 90, 91, 92, 93, 94, 95, 96, - 97, 98, 99, 100, 101, 102, 103, 104, - 105, 106, 107, 108, 109, 110, 111, 112, - 113, 114, 115, 116, 117, 118, 119, 120, - 121, 122, 123, 124, 125, 126, 127, 128}; +unsigned char _u2a[128] = { /* u- to A-law conversions */ + 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, + 7, 7, 8, 8, 9, 10, 11, 12, 13, 14, 15, 16, + 17, 18, 19, 20, 21, 22, 23, 24, 25, 27, 29, 31, + 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, + 46, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, + 59, 60, 61, 62, 64, 65, 66, 67, 68, 69, 70, 71, + 72, 73, 74, 75, 76, 77, 78, 79, 81, 82, 83, 84, + 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, + 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, + 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, + 121, 122, 123, 124, 125, 126, 127, 128 +}; -unsigned char _a2u[128] = { /* A- to u-law conversions */ - 1, 3, 5, 7, 9, 11, 13, 15, - 16, 17, 18, 19, 20, 21, 22, 23, - 24, 25, 26, 27, 28, 29, 30, 31, - 32, 32, 33, 33, 34, 34, 35, 35, - 36, 37, 38, 39, 40, 41, 42, 43, - 44, 45, 46, 47, 48, 48, 49, 49, - 50, 51, 52, 53, 54, 55, 56, 57, - 58, 59, 60, 61, 62, 63, 64, 64, - 65, 66, 67, 68, 69, 70, 71, 72, - 73, 74, 75, 76, 77, 78, 79, 79, - 80, 81, 82, 83, 84, 85, 86, 87, - 88, 89, 90, 91, 92, 93, 94, 95, - 96, 97, 98, 99, 100, 101, 102, 103, - 104, 105, 106, 107, 108, 109, 110, 111, - 112, 113, 114, 115, 116, 117, 118, 119, - 120, 121, 122, 123, 124, 125, 126, 127}; +unsigned char _a2u[128] = { /* A- to u-law conversions */ + 1, 3, 5, 7, 9, 11, 13, 15, 16, 17, 18, 19, + 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, + 32, 32, 33, 33, 34, 34, 35, 35, 36, 37, 38, 39, + 40, 41, 42, 43, 44, 45, 46, 47, 48, 48, 49, 49, + 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, + 62, 63, 64, 64, 65, 66, 67, 68, 69, 70, 71, 72, + 73, 74, 75, 76, 77, 78, 79, 79, 80, 81, 82, 83, + 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, + 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, + 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, + 120, 121, 122, 123, 124, 125, 126, 127 +}; -static int -search( - int val, - short *table, - int size) +static int search(int val, short* table, int size) { - int i; + int i; - for (i = 0; i < size; i++) { - if (val <= *table++) - return (i); - } - return (size); + for (i = 0; i < size; i++) { + if (val <= *table++) + return (i); + } + return (size); } /* @@ -109,68 +96,64 @@ search( * For further information see John C. Bellamy's Digital Telephony, 1982, * John Wiley & Sons, pps 98-111 and 472-476. */ -unsigned char -linear2alaw( - int pcm_val) /* 2's complement (16-bit range) */ +unsigned char linear2alaw(int pcm_val) /* 2's complement (16-bit range) */ { - int mask; - int seg; - unsigned char aval; + int mask; + int seg; + unsigned char aval; - if (pcm_val >= 0) { - mask = 0xD5; /* sign (7th) bit = 1 */ - } else { - mask = 0x55; /* sign bit = 0 */ - pcm_val = -pcm_val - 8; - } + if (pcm_val >= 0) { + mask = 0xD5; /* sign (7th) bit = 1 */ + } else { + mask = 0x55; /* sign bit = 0 */ + pcm_val = -pcm_val - 8; + } - /* Convert the scaled magnitude to segment number. */ - seg = search(pcm_val, seg_end, 8); + /* Convert the scaled magnitude to segment number. */ + seg = search(pcm_val, seg_end, 8); - /* Combine the sign, segment, and quantization bits. */ + /* Combine the sign, segment, and quantization bits. */ - if (seg >= 8) /* out of range, return maximum value. */ - return (0x7F ^ mask); - else { - aval = seg << SEG_SHIFT; - if (seg < 2) - aval |= (pcm_val >> 4) & QUANT_MASK; - else - aval |= (pcm_val >> (seg + 3)) & QUANT_MASK; - return (aval ^ mask); - } + if (seg >= 8) /* out of range, return maximum value. */ + return (0x7F ^ mask); + else { + aval = seg << SEG_SHIFT; + if (seg < 2) + aval |= (pcm_val >> 4) & QUANT_MASK; + else + aval |= (pcm_val >> (seg + 3)) & QUANT_MASK; + return (aval ^ mask); + } } /* * alaw2linear() - Convert an A-law value to 16-bit linear PCM * */ -int -alaw2linear( - unsigned char a_val) +int alaw2linear(unsigned char a_val) { - int t; - int seg; + int t; + int seg; - a_val ^= 0x55; + a_val ^= 0x55; - t = (a_val & QUANT_MASK) << 4; - seg = ((unsigned)a_val & SEG_MASK) >> SEG_SHIFT; - switch (seg) { - case 0: - t += 8; - break; - case 1: - t += 0x108; - break; - default: - t += 0x108; - t <<= seg - 1; - } - return ((a_val & SIGN_BIT) ? t : -t); + t = (a_val & QUANT_MASK) << 4; + seg = ((unsigned)a_val & SEG_MASK) >> SEG_SHIFT; + switch (seg) { + case 0: + t += 8; + break; + case 1: + t += 0x108; + break; + default: + t += 0x108; + t <<= seg - 1; + } + return ((a_val & SIGN_BIT) ? t : -t); } -#define BIAS (0x84) /* Bias for linear code. */ +#define BIAS (0x84) /* Bias for linear code. */ /* * linear2ulaw() - Convert a linear PCM value to u-law @@ -201,37 +184,34 @@ alaw2linear( * For further information see John C. Bellamy's Digital Telephony, 1982, * John Wiley & Sons, pps 98-111 and 472-476. */ -unsigned char -linear2ulaw( - int pcm_val) /* 2's complement (16-bit range) */ +unsigned char linear2ulaw(int pcm_val) /* 2's complement (16-bit range) */ { - int mask; - int seg; - unsigned char uval; + int mask; + int seg; + unsigned char uval; - /* Get the sign and the magnitude of the value. */ - if (pcm_val < 0) { - pcm_val = BIAS - pcm_val; - mask = 0x7F; - } else { - pcm_val += BIAS; - mask = 0xFF; - } + /* Get the sign and the magnitude of the value. */ + if (pcm_val < 0) { + pcm_val = BIAS - pcm_val; + mask = 0x7F; + } else { + pcm_val += BIAS; + mask = 0xFF; + } - /* Convert the scaled magnitude to segment number. */ - seg = search(pcm_val, seg_end, 8); - - /* - * Combine the sign, segment, quantization bits; - * and complement the code word. - */ - if (seg >= 8) /* out of range, return maximum value. */ - return (0x7F ^ mask); - else { - uval = (seg << 4) | ((pcm_val >> (seg + 3)) & 0xF); - return (uval ^ mask); - } + /* Convert the scaled magnitude to segment number. */ + seg = search(pcm_val, seg_end, 8); + /* + * Combine the sign, segment, quantization bits; + * and complement the code word. + */ + if (seg >= 8) /* out of range, return maximum value. */ + return (0x7F ^ mask); + else { + uval = (seg << 4) | ((pcm_val >> (seg + 3)) & 0xF); + return (uval ^ mask); + } } /* @@ -243,41 +223,34 @@ linear2ulaw( * Note that this function expects to be passed the complement of the * original code word. This is in keeping with ISDN conventions. */ -int -ulaw2linear( - unsigned char u_val) +int ulaw2linear(unsigned char u_val) { - int t; + int t; - /* Complement to obtain normal u-law value. */ - u_val = ~u_val; + /* Complement to obtain normal u-law value. */ + u_val = ~u_val; - /* - * Extract and bias the quantization bits. Then - * shift up by the segment number and subtract out the bias. - */ - t = ((u_val & QUANT_MASK) << 3) + BIAS; - t <<= ((unsigned)u_val & SEG_MASK) >> SEG_SHIFT; + /* + * Extract and bias the quantization bits. Then + * shift up by the segment number and subtract out the bias. + */ + t = ((u_val & QUANT_MASK) << 3) + BIAS; + t <<= ((unsigned)u_val & SEG_MASK) >> SEG_SHIFT; - return ((u_val & SIGN_BIT) ? (BIAS - t) : (t - BIAS)); + return ((u_val & SIGN_BIT) ? (BIAS - t) : (t - BIAS)); } /* A-law to u-law conversion */ -unsigned char -alaw2ulaw( - unsigned char aval) +unsigned char alaw2ulaw(unsigned char aval) { - aval &= 0xff; - return ((aval & 0x80) ? (0xFF ^ _a2u[aval ^ 0xD5]) : - (0x7F ^ _a2u[aval ^ 0x55])); + aval &= 0xff; + return ((aval & 0x80) ? (0xFF ^ _a2u[aval ^ 0xD5]) : (0x7F ^ _a2u[aval ^ 0x55])); } /* u-law to A-law conversion */ -unsigned char -ulaw2alaw( - unsigned char uval) +unsigned char ulaw2alaw(unsigned char uval) { - uval &= 0xff; - return ((uval & 0x80) ? (0xD5 ^ (_u2a[0xFF ^ uval] - 1)) : - (0x55 ^ (_u2a[0x7F ^ uval] - 1))); + uval &= 0xff; + return ((uval & 0x80) ? (0xD5 ^ (_u2a[0xFF ^ uval] - 1)) + : (0x55 ^ (_u2a[0x7F ^ uval] - 1))); } diff --git a/gr-vocoder/lib/g7xx/g721.c b/gr-vocoder/lib/g7xx/g721.c index 445f177e8..dd0f930e1 100644 --- a/gr-vocoder/lib/g7xx/g721.c +++ b/gr-vocoder/lib/g7xx/g721.c @@ -50,24 +50,24 @@ */ #include "g72x.h" -static short qtab_721[7] = {-124, 80, 178, 246, 300, 349, 400}; +static short qtab_721[7] = { -124, 80, 178, 246, 300, 349, 400 }; /* * Maps G.721 code word to reconstructed scale factor normalized log * magnitude values. */ -static short _dqlntab[16] = {-2048, 4, 135, 213, 273, 323, 373, 425, - 425, 373, 323, 273, 213, 135, 4, -2048}; +static short _dqlntab[16] = { -2048, 4, 135, 213, 273, 323, 373, 425, + 425, 373, 323, 273, 213, 135, 4, -2048 }; /* Maps G.721 code word to log of scale factor multiplier. */ -static short _witab[16] = {-12, 18, 41, 64, 112, 198, 355, 1122, - 1122, 355, 198, 112, 64, 41, 18, -12}; +static short _witab[16] = { -12, 18, 41, 64, 112, 198, 355, 1122, + 1122, 355, 198, 112, 64, 41, 18, -12 }; /* * Maps G.721 code words to a set of values whose long and short * term averages are computed and then compared to give an indication * how stationary (steady state) the signal is. */ -static short _fitab[16] = {0, 0, 0, 0x200, 0x200, 0x200, 0x600, 0xE00, - 0xE00, 0x600, 0x200, 0x200, 0x200, 0, 0, 0}; +static short _fitab[16] = { 0, 0, 0, 0x200, 0x200, 0x200, 0x600, 0xE00, + 0xE00, 0x600, 0x200, 0x200, 0x200, 0, 0, 0 }; /* * g721_encoder() @@ -75,52 +75,48 @@ static short _fitab[16] = {0, 0, 0, 0x200, 0x200, 0x200, 0x600, 0xE00, * Encodes the input vale of linear PCM, A-law or u-law data sl and returns * the resulting code. -1 is returned for unknown input coding value. */ -int -g721_encoder( - int sl, - int in_coding, - struct g72x_state *state_ptr) +int g721_encoder(int sl, int in_coding, struct g72x_state* state_ptr) { - short sezi, se, sez; /* ACCUM */ - short d; /* SUBTA */ - short sr; /* ADDB */ - short y; /* MIX */ - short dqsez; /* ADDC */ - short dq, i; - - switch (in_coding) { /* linearize input sample to 14-bit PCM */ - case AUDIO_ENCODING_ALAW: - sl = alaw2linear(sl) >> 2; - break; - case AUDIO_ENCODING_ULAW: - sl = ulaw2linear(sl) >> 2; - break; - case AUDIO_ENCODING_LINEAR: - sl >>= 2; /* 14-bit dynamic range */ - break; - default: - return (-1); - } - - sezi = predictor_zero(state_ptr); - sez = sezi >> 1; - se = (sezi + predictor_pole(state_ptr)) >> 1; /* estimated signal */ - - d = sl - se; /* estimation difference */ - - /* quantize the prediction difference */ - y = step_size(state_ptr); /* quantizer step size */ - i = quantize(d, y, qtab_721, 7); /* i = ADPCM code */ - - dq = reconstruct(i & 8, _dqlntab[i], y); /* quantized est diff */ - - sr = (dq < 0) ? se - (dq & 0x3FFF) : se + dq; /* reconst. signal */ - - dqsez = sr + sez - se; /* pole prediction diff. */ - - update(4, y, _witab[i] << 5, _fitab[i], dq, sr, dqsez, state_ptr); - - return (i); + short sezi, se, sez; /* ACCUM */ + short d; /* SUBTA */ + short sr; /* ADDB */ + short y; /* MIX */ + short dqsez; /* ADDC */ + short dq, i; + + switch (in_coding) { /* linearize input sample to 14-bit PCM */ + case AUDIO_ENCODING_ALAW: + sl = alaw2linear(sl) >> 2; + break; + case AUDIO_ENCODING_ULAW: + sl = ulaw2linear(sl) >> 2; + break; + case AUDIO_ENCODING_LINEAR: + sl >>= 2; /* 14-bit dynamic range */ + break; + default: + return (-1); + } + + sezi = predictor_zero(state_ptr); + sez = sezi >> 1; + se = (sezi + predictor_pole(state_ptr)) >> 1; /* estimated signal */ + + d = sl - se; /* estimation difference */ + + /* quantize the prediction difference */ + y = step_size(state_ptr); /* quantizer step size */ + i = quantize(d, y, qtab_721, 7); /* i = ADPCM code */ + + dq = reconstruct(i & 8, _dqlntab[i], y); /* quantized est diff */ + + sr = (dq < 0) ? se - (dq & 0x3FFF) : se + dq; /* reconst. signal */ + + dqsez = sr + sez - se; /* pole prediction diff. */ + + update(4, y, _witab[i] << 5, _fitab[i], dq, sr, dqsez, state_ptr); + + return (i); } /* @@ -132,42 +128,38 @@ g721_encoder( * returns the resulting linear PCM, A-law or u-law value. * return -1 for unknown out_coding value. */ -int -g721_decoder( - int i, - int out_coding, - struct g72x_state *state_ptr) +int g721_decoder(int i, int out_coding, struct g72x_state* state_ptr) { - short sezi, sei, sez, se; /* ACCUM */ - short y; /* MIX */ - short sr; /* ADDB */ - short dq; - short dqsez; - - i &= 0x0f; /* mask to get proper bits */ - sezi = predictor_zero(state_ptr); - sez = sezi >> 1; - sei = sezi + predictor_pole(state_ptr); - se = sei >> 1; /* se = estimated signal */ - - y = step_size(state_ptr); /* dynamic quantizer step size */ - - dq = reconstruct(i & 0x08, _dqlntab[i], y); /* quantized diff. */ - - sr = (dq < 0) ? (se - (dq & 0x3FFF)) : se + dq; /* reconst. signal */ - - dqsez = sr - se + sez; /* pole prediction diff. */ - - update(4, y, _witab[i] << 5, _fitab[i], dq, sr, dqsez, state_ptr); - - switch (out_coding) { - case AUDIO_ENCODING_ALAW: - return (tandem_adjust_alaw(sr, se, y, i, 8, qtab_721)); - case AUDIO_ENCODING_ULAW: - return (tandem_adjust_ulaw(sr, se, y, i, 8, qtab_721)); - case AUDIO_ENCODING_LINEAR: - return (sr << 2); /* sr was 14-bit dynamic range */ - default: - return (-1); - } + short sezi, sei, sez, se; /* ACCUM */ + short y; /* MIX */ + short sr; /* ADDB */ + short dq; + short dqsez; + + i &= 0x0f; /* mask to get proper bits */ + sezi = predictor_zero(state_ptr); + sez = sezi >> 1; + sei = sezi + predictor_pole(state_ptr); + se = sei >> 1; /* se = estimated signal */ + + y = step_size(state_ptr); /* dynamic quantizer step size */ + + dq = reconstruct(i & 0x08, _dqlntab[i], y); /* quantized diff. */ + + sr = (dq < 0) ? (se - (dq & 0x3FFF)) : se + dq; /* reconst. signal */ + + dqsez = sr - se + sez; /* pole prediction diff. */ + + update(4, y, _witab[i] << 5, _fitab[i], dq, sr, dqsez, state_ptr); + + switch (out_coding) { + case AUDIO_ENCODING_ALAW: + return (tandem_adjust_alaw(sr, se, y, i, 8, qtab_721)); + case AUDIO_ENCODING_ULAW: + return (tandem_adjust_ulaw(sr, se, y, i, 8, qtab_721)); + case AUDIO_ENCODING_LINEAR: + return (sr << 2); /* sr was 14-bit dynamic range */ + default: + return (-1); + } } diff --git a/gr-vocoder/lib/g7xx/g723_24.c b/gr-vocoder/lib/g7xx/g723_24.c index 452f4daeb..1f45c89f0 100644 --- a/gr-vocoder/lib/g7xx/g723_24.c +++ b/gr-vocoder/lib/g7xx/g723_24.c @@ -43,19 +43,19 @@ * Maps G.723_24 code word to reconstructed scale factor normalized log * magnitude values. */ -static short _dqlntab[8] = {-2048, 135, 273, 373, 373, 273, 135, -2048}; +static short _dqlntab[8] = { -2048, 135, 273, 373, 373, 273, 135, -2048 }; /* Maps G.723_24 code word to log of scale factor multiplier. */ -static short _witab[8] = {-128, 960, 4384, 18624, 18624, 4384, 960, -128}; +static short _witab[8] = { -128, 960, 4384, 18624, 18624, 4384, 960, -128 }; /* * Maps G.723_24 code words to a set of values whose long and short * term averages are computed and then compared to give an indication * how stationary (steady state) the signal is. */ -static short _fitab[8] = {0, 0x200, 0x400, 0xE00, 0xE00, 0x400, 0x200, 0}; +static short _fitab[8] = { 0, 0x200, 0x400, 0xE00, 0xE00, 0x400, 0x200, 0 }; -static short qtab_723_24[3] = {8, 218, 331}; +static short qtab_723_24[3] = { 8, 218, 331 }; /* * g723_24_encoder() @@ -63,52 +63,48 @@ static short qtab_723_24[3] = {8, 218, 331}; * Encodes a linear PCM, A-law or u-law input sample and returns its 3-bit code. * Returns -1 if invalid input coding value. */ -int -g723_24_encoder( - int sl, - int in_coding, - struct g72x_state *state_ptr) +int g723_24_encoder(int sl, int in_coding, struct g72x_state* state_ptr) { - short sei, sezi, se, sez; /* ACCUM */ - short d; /* SUBTA */ - short y; /* MIX */ - short sr; /* ADDB */ - short dqsez; /* ADDC */ - short dq, i; - - switch (in_coding) { /* linearize input sample to 14-bit PCM */ - case AUDIO_ENCODING_ALAW: - sl = alaw2linear(sl) >> 2; - break; - case AUDIO_ENCODING_ULAW: - sl = ulaw2linear(sl) >> 2; - break; - case AUDIO_ENCODING_LINEAR: - sl >>= 2; /* sl of 14-bit dynamic range */ - break; - default: - return (-1); - } - - sezi = predictor_zero(state_ptr); - sez = sezi >> 1; - sei = sezi + predictor_pole(state_ptr); - se = sei >> 1; /* se = estimated signal */ - - d = sl - se; /* d = estimation diff. */ - - /* quantize prediction difference d */ - y = step_size(state_ptr); /* quantizer step size */ - i = quantize(d, y, qtab_723_24, 3); /* i = ADPCM code */ - dq = reconstruct(i & 4, _dqlntab[i], y); /* quantized diff. */ - - sr = (dq < 0) ? se - (dq & 0x3FFF) : se + dq; /* reconstructed signal */ - - dqsez = sr + sez - se; /* pole prediction diff. */ - - update(3, y, _witab[i], _fitab[i], dq, sr, dqsez, state_ptr); - - return (i); + short sei, sezi, se, sez; /* ACCUM */ + short d; /* SUBTA */ + short y; /* MIX */ + short sr; /* ADDB */ + short dqsez; /* ADDC */ + short dq, i; + + switch (in_coding) { /* linearize input sample to 14-bit PCM */ + case AUDIO_ENCODING_ALAW: + sl = alaw2linear(sl) >> 2; + break; + case AUDIO_ENCODING_ULAW: + sl = ulaw2linear(sl) >> 2; + break; + case AUDIO_ENCODING_LINEAR: + sl >>= 2; /* sl of 14-bit dynamic range */ + break; + default: + return (-1); + } + + sezi = predictor_zero(state_ptr); + sez = sezi >> 1; + sei = sezi + predictor_pole(state_ptr); + se = sei >> 1; /* se = estimated signal */ + + d = sl - se; /* d = estimation diff. */ + + /* quantize prediction difference d */ + y = step_size(state_ptr); /* quantizer step size */ + i = quantize(d, y, qtab_723_24, 3); /* i = ADPCM code */ + dq = reconstruct(i & 4, _dqlntab[i], y); /* quantized diff. */ + + sr = (dq < 0) ? se - (dq & 0x3FFF) : se + dq; /* reconstructed signal */ + + dqsez = sr + sez - se; /* pole prediction diff. */ + + update(3, y, _witab[i], _fitab[i], dq, sr, dqsez, state_ptr); + + return (i); } /* @@ -118,41 +114,37 @@ g723_24_encoder( * the resulting 16-bit linear PCM, A-law or u-law sample value. * -1 is returned if the output coding is unknown. */ -int -g723_24_decoder( - int i, - int out_coding, - struct g72x_state *state_ptr) +int g723_24_decoder(int i, int out_coding, struct g72x_state* state_ptr) { - short sezi, sei, sez, se; /* ACCUM */ - short y; /* MIX */ - short sr; /* ADDB */ - short dq; - short dqsez; - - i &= 0x07; /* mask to get proper bits */ - sezi = predictor_zero(state_ptr); - sez = sezi >> 1; - sei = sezi + predictor_pole(state_ptr); - se = sei >> 1; /* se = estimated signal */ - - y = step_size(state_ptr); /* adaptive quantizer step size */ - dq = reconstruct(i & 0x04, _dqlntab[i], y); /* unquantize pred diff */ - - sr = (dq < 0) ? (se - (dq & 0x3FFF)) : (se + dq); /* reconst. signal */ - - dqsez = sr - se + sez; /* pole prediction diff. */ - - update(3, y, _witab[i], _fitab[i], dq, sr, dqsez, state_ptr); - - switch (out_coding) { - case AUDIO_ENCODING_ALAW: - return (tandem_adjust_alaw(sr, se, y, i, 4, qtab_723_24)); - case AUDIO_ENCODING_ULAW: - return (tandem_adjust_ulaw(sr, se, y, i, 4, qtab_723_24)); - case AUDIO_ENCODING_LINEAR: - return (sr << 2); /* sr was of 14-bit dynamic range */ - default: - return (-1); - } + short sezi, sei, sez, se; /* ACCUM */ + short y; /* MIX */ + short sr; /* ADDB */ + short dq; + short dqsez; + + i &= 0x07; /* mask to get proper bits */ + sezi = predictor_zero(state_ptr); + sez = sezi >> 1; + sei = sezi + predictor_pole(state_ptr); + se = sei >> 1; /* se = estimated signal */ + + y = step_size(state_ptr); /* adaptive quantizer step size */ + dq = reconstruct(i & 0x04, _dqlntab[i], y); /* unquantize pred diff */ + + sr = (dq < 0) ? (se - (dq & 0x3FFF)) : (se + dq); /* reconst. signal */ + + dqsez = sr - se + sez; /* pole prediction diff. */ + + update(3, y, _witab[i], _fitab[i], dq, sr, dqsez, state_ptr); + + switch (out_coding) { + case AUDIO_ENCODING_ALAW: + return (tandem_adjust_alaw(sr, se, y, i, 4, qtab_723_24)); + case AUDIO_ENCODING_ULAW: + return (tandem_adjust_ulaw(sr, se, y, i, 4, qtab_723_24)); + case AUDIO_ENCODING_LINEAR: + return (sr << 2); /* sr was of 14-bit dynamic range */ + default: + return (-1); + } } diff --git a/gr-vocoder/lib/g7xx/g723_40.c b/gr-vocoder/lib/g7xx/g723_40.c index 4858baf40..3f52f8f40 100644 --- a/gr-vocoder/lib/g7xx/g723_40.c +++ b/gr-vocoder/lib/g7xx/g723_40.c @@ -51,29 +51,28 @@ * Maps G.723_40 code word to ructeconstructed scale factor normalized log * magnitude values. */ -static short _dqlntab[32] = {-2048, -66, 28, 104, 169, 224, 274, 318, - 358, 395, 429, 459, 488, 514, 539, 566, - 566, 539, 514, 488, 459, 429, 395, 358, - 318, 274, 224, 169, 104, 28, -66, -2048}; +static short _dqlntab[32] = { -2048, -66, 28, 104, 169, 224, 274, 318, 358, 395, 429, + 459, 488, 514, 539, 566, 566, 539, 514, 488, 459, 429, + 395, 358, 318, 274, 224, 169, 104, 28, -66, -2048 }; /* Maps G.723_40 code word to log of scale factor multiplier. */ -static short _witab[32] = {448, 448, 768, 1248, 1280, 1312, 1856, 3200, - 4512, 5728, 7008, 8960, 11456, 14080, 16928, 22272, - 22272, 16928, 14080, 11456, 8960, 7008, 5728, 4512, - 3200, 1856, 1312, 1280, 1248, 768, 448, 448}; +static short _witab[32] = { 448, 448, 768, 1248, 1280, 1312, 1856, 3200, + 4512, 5728, 7008, 8960, 11456, 14080, 16928, 22272, + 22272, 16928, 14080, 11456, 8960, 7008, 5728, 4512, + 3200, 1856, 1312, 1280, 1248, 768, 448, 448 }; /* * Maps G.723_40 code words to a set of values whose long and short * term averages are computed and then compared to give an indication * how stationary (steady state) the signal is. */ -static short _fitab[32] = {0, 0, 0, 0, 0, 0x200, 0x200, 0x200, - 0x200, 0x200, 0x400, 0x600, 0x800, 0xA00, 0xC00, 0xC00, - 0xC00, 0xC00, 0xA00, 0x800, 0x600, 0x400, 0x200, 0x200, - 0x200, 0x200, 0x200, 0, 0, 0, 0, 0}; +static short _fitab[32] = { 0, 0, 0, 0, 0, 0x200, 0x200, 0x200, + 0x200, 0x200, 0x400, 0x600, 0x800, 0xA00, 0xC00, 0xC00, + 0xC00, 0xC00, 0xA00, 0x800, 0x600, 0x400, 0x200, 0x200, + 0x200, 0x200, 0x200, 0, 0, 0, 0, 0 }; -static short qtab_723_40[15] = {-122, -16, 68, 139, 198, 250, 298, 339, - 378, 413, 445, 475, 502, 528, 553}; +static short qtab_723_40[15] = { -122, -16, 68, 139, 198, 250, 298, 339, + 378, 413, 445, 475, 502, 528, 553 }; /* * g723_40_encoder() @@ -82,53 +81,49 @@ static short qtab_723_40[15] = {-122, -16, 68, 139, 198, 250, 298, 339, * the resulting 5-bit CCITT G.723 40Kbps code. * Returns -1 if the input coding value is invalid. */ -int -g723_40_encoder( - int sl, - int in_coding, - struct g72x_state *state_ptr) +int g723_40_encoder(int sl, int in_coding, struct g72x_state* state_ptr) { - short sei, sezi, se, sez; /* ACCUM */ - short d; /* SUBTA */ - short y; /* MIX */ - short sr; /* ADDB */ - short dqsez; /* ADDC */ - short dq, i; - - switch (in_coding) { /* linearize input sample to 14-bit PCM */ - case AUDIO_ENCODING_ALAW: - sl = alaw2linear(sl) >> 2; - break; - case AUDIO_ENCODING_ULAW: - sl = ulaw2linear(sl) >> 2; - break; - case AUDIO_ENCODING_LINEAR: - sl >>= 2; /* sl of 14-bit dynamic range */ - break; - default: - return (-1); - } - - sezi = predictor_zero(state_ptr); - sez = sezi >> 1; - sei = sezi + predictor_pole(state_ptr); - se = sei >> 1; /* se = estimated signal */ - - d = sl - se; /* d = estimation difference */ - - /* quantize prediction difference */ - y = step_size(state_ptr); /* adaptive quantizer step size */ - i = quantize(d, y, qtab_723_40, 15); /* i = ADPCM code */ - - dq = reconstruct(i & 0x10, _dqlntab[i], y); /* quantized diff */ - - sr = (dq < 0) ? se - (dq & 0x7FFF) : se + dq; /* reconstructed signal */ - - dqsez = sr + sez - se; /* dqsez = pole prediction diff. */ - - update(5, y, _witab[i], _fitab[i], dq, sr, dqsez, state_ptr); - - return (i); + short sei, sezi, se, sez; /* ACCUM */ + short d; /* SUBTA */ + short y; /* MIX */ + short sr; /* ADDB */ + short dqsez; /* ADDC */ + short dq, i; + + switch (in_coding) { /* linearize input sample to 14-bit PCM */ + case AUDIO_ENCODING_ALAW: + sl = alaw2linear(sl) >> 2; + break; + case AUDIO_ENCODING_ULAW: + sl = ulaw2linear(sl) >> 2; + break; + case AUDIO_ENCODING_LINEAR: + sl >>= 2; /* sl of 14-bit dynamic range */ + break; + default: + return (-1); + } + + sezi = predictor_zero(state_ptr); + sez = sezi >> 1; + sei = sezi + predictor_pole(state_ptr); + se = sei >> 1; /* se = estimated signal */ + + d = sl - se; /* d = estimation difference */ + + /* quantize prediction difference */ + y = step_size(state_ptr); /* adaptive quantizer step size */ + i = quantize(d, y, qtab_723_40, 15); /* i = ADPCM code */ + + dq = reconstruct(i & 0x10, _dqlntab[i], y); /* quantized diff */ + + sr = (dq < 0) ? se - (dq & 0x7FFF) : se + dq; /* reconstructed signal */ + + dqsez = sr + sez - se; /* dqsez = pole prediction diff. */ + + update(5, y, _witab[i], _fitab[i], dq, sr, dqsez, state_ptr); + + return (i); } /* @@ -138,41 +133,37 @@ g723_40_encoder( * the resulting 16-bit linear PCM, A-law or u-law sample value. * -1 is returned if the output coding is unknown. */ -int -g723_40_decoder( - int i, - int out_coding, - struct g72x_state *state_ptr) +int g723_40_decoder(int i, int out_coding, struct g72x_state* state_ptr) { - short sezi, sei, sez, se; /* ACCUM */ - short y; /* MIX */ - short sr; /* ADDB */ - short dq; - short dqsez; - - i &= 0x1f; /* mask to get proper bits */ - sezi = predictor_zero(state_ptr); - sez = sezi >> 1; - sei = sezi + predictor_pole(state_ptr); - se = sei >> 1; /* se = estimated signal */ - - y = step_size(state_ptr); /* adaptive quantizer step size */ - dq = reconstruct(i & 0x10, _dqlntab[i], y); /* estimation diff. */ - - sr = (dq < 0) ? (se - (dq & 0x7FFF)) : (se + dq); /* reconst. signal */ - - dqsez = sr - se + sez; /* pole prediction diff. */ - - update(5, y, _witab[i], _fitab[i], dq, sr, dqsez, state_ptr); - - switch (out_coding) { - case AUDIO_ENCODING_ALAW: - return (tandem_adjust_alaw(sr, se, y, i, 0x10, qtab_723_40)); - case AUDIO_ENCODING_ULAW: - return (tandem_adjust_ulaw(sr, se, y, i, 0x10, qtab_723_40)); - case AUDIO_ENCODING_LINEAR: - return (sr << 2); /* sr was of 14-bit dynamic range */ - default: - return (-1); - } + short sezi, sei, sez, se; /* ACCUM */ + short y; /* MIX */ + short sr; /* ADDB */ + short dq; + short dqsez; + + i &= 0x1f; /* mask to get proper bits */ + sezi = predictor_zero(state_ptr); + sez = sezi >> 1; + sei = sezi + predictor_pole(state_ptr); + se = sei >> 1; /* se = estimated signal */ + + y = step_size(state_ptr); /* adaptive quantizer step size */ + dq = reconstruct(i & 0x10, _dqlntab[i], y); /* estimation diff. */ + + sr = (dq < 0) ? (se - (dq & 0x7FFF)) : (se + dq); /* reconst. signal */ + + dqsez = sr - se + sez; /* pole prediction diff. */ + + update(5, y, _witab[i], _fitab[i], dq, sr, dqsez, state_ptr); + + switch (out_coding) { + case AUDIO_ENCODING_ALAW: + return (tandem_adjust_alaw(sr, se, y, i, 0x10, qtab_723_40)); + case AUDIO_ENCODING_ULAW: + return (tandem_adjust_ulaw(sr, se, y, i, 0x10, qtab_723_40)); + case AUDIO_ENCODING_LINEAR: + return (sr << 2); /* sr was of 14-bit dynamic range */ + default: + return (-1); + } } diff --git a/gr-vocoder/lib/g7xx/g72x.c b/gr-vocoder/lib/g7xx/g72x.c index 9a823c755..cadcf7707 100644 --- a/gr-vocoder/lib/g7xx/g72x.c +++ b/gr-vocoder/lib/g7xx/g72x.c @@ -32,8 +32,8 @@ #include "g72x.h" -static short power2[15] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80, - 0x100, 0x200, 0x400, 0x800, 0x1000, 0x2000, 0x4000}; +static short power2[15] = { 1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80, + 0x100, 0x200, 0x400, 0x800, 0x1000, 0x2000, 0x4000 }; /* * quan() @@ -43,18 +43,14 @@ static short power2[15] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80, * * Using linear search for simple coding. */ -static int -quan( - int val, - short *table, - int size) +static int quan(int val, short* table, int size) { - int i; + int i; - for (i = 0; i < size; i++) - if (val < *table++) - break; - return (i); + for (i = 0; i < size; i++) + if (val < *table++) + break; + return (i); } /* @@ -63,26 +59,21 @@ quan( * returns the integer product of the 14-bit integer "an" and * "floating point" representation (4-bit exponent, 6-bit mantessa) "srn". */ -static int -fmult( - int an, - int srn) +static int fmult(int an, int srn) { - short anmag, anexp, anmant; - short wanexp, wanmant; - short retval; + short anmag, anexp, anmant; + short wanexp, wanmant; + short retval; - anmag = (an > 0) ? an : ((-an) & 0x1FFF); - anexp = quan(anmag, power2, 15) - 6; - anmant = (anmag == 0) ? 32 : - (anexp >= 0) ? anmag >> anexp : anmag << -anexp; - wanexp = anexp + ((srn >> 6) & 0xF) - 13; + anmag = (an > 0) ? an : ((-an) & 0x1FFF); + anexp = quan(anmag, power2, 15) - 6; + anmant = (anmag == 0) ? 32 : (anexp >= 0) ? anmag >> anexp : anmag << -anexp; + wanexp = anexp + ((srn >> 6) & 0xF) - 13; - wanmant = (anmant * (srn & 077) + 0x30) >> 4; - retval = (wanexp >= 0) ? ((wanmant << wanexp) & 0x7FFF) : - (wanmant >> -wanexp); + wanmant = (anmant * (srn & 077) + 0x30) >> 4; + retval = (wanexp >= 0) ? ((wanmant << wanexp) & 0x7FFF) : (wanmant >> -wanexp); - return (((an ^ srn) < 0) ? -retval : retval); + return (((an ^ srn) < 0) ? -retval : retval); } /* @@ -92,27 +83,25 @@ fmult( * pointed to by 'state_ptr'. * All the initial state values are specified in the CCITT G.721 document. */ -void -g72x_init_state( - struct g72x_state *state_ptr) +void g72x_init_state(struct g72x_state* state_ptr) { - int cnta; - - state_ptr->yl = 34816; - state_ptr->yu = 544; - state_ptr->dms = 0; - state_ptr->dml = 0; - state_ptr->ap = 0; - for (cnta = 0; cnta < 2; cnta++) { - state_ptr->a[cnta] = 0; - state_ptr->pk[cnta] = 0; - state_ptr->sr[cnta] = 32; - } - for (cnta = 0; cnta < 6; cnta++) { - state_ptr->b[cnta] = 0; - state_ptr->dq[cnta] = 32; - } - state_ptr->td = 0; + int cnta; + + state_ptr->yl = 34816; + state_ptr->yu = 544; + state_ptr->dms = 0; + state_ptr->dml = 0; + state_ptr->ap = 0; + for (cnta = 0; cnta < 2; cnta++) { + state_ptr->a[cnta] = 0; + state_ptr->pk[cnta] = 0; + state_ptr->sr[cnta] = 32; + } + for (cnta = 0; cnta < 6; cnta++) { + state_ptr->b[cnta] = 0; + state_ptr->dq[cnta] = 32; + } + state_ptr->td = 0; } /* @@ -121,17 +110,15 @@ g72x_init_state( * computes the estimated signal from 6-zero predictor. * */ -int -predictor_zero( - struct g72x_state *state_ptr) +int predictor_zero(struct g72x_state* state_ptr) { - int i; - int sezi; + int i; + int sezi; - sezi = fmult(state_ptr->b[0] >> 2, state_ptr->dq[0]); - for (i = 1; i < 6; i++) /* ACCUM */ - sezi += fmult(state_ptr->b[i] >> 2, state_ptr->dq[i]); - return (sezi); + sezi = fmult(state_ptr->b[0] >> 2, state_ptr->dq[0]); + for (i = 1; i < 6; i++) /* ACCUM */ + sezi += fmult(state_ptr->b[i] >> 2, state_ptr->dq[i]); + return (sezi); } /* * predictor_pole() @@ -139,12 +126,10 @@ predictor_zero( * computes the estimated signal from 2-pole predictor. * */ -int -predictor_pole( - struct g72x_state *state_ptr) +int predictor_pole(struct g72x_state* state_ptr) { - return (fmult(state_ptr->a[1] >> 2, state_ptr->sr[1]) + - fmult(state_ptr->a[0] >> 2, state_ptr->sr[0])); + return (fmult(state_ptr->a[1] >> 2, state_ptr->sr[1]) + + fmult(state_ptr->a[0] >> 2, state_ptr->sr[0])); } /* * step_size() @@ -152,26 +137,24 @@ predictor_pole( * computes the quantization step size of the adaptive quantizer. * */ -int -step_size( - struct g72x_state *state_ptr) +int step_size(struct g72x_state* state_ptr) { - int y; - int dif; - int al; - - if (state_ptr->ap >= 256) - return (state_ptr->yu); - else { - y = state_ptr->yl >> 6; - dif = state_ptr->yu - y; - al = state_ptr->ap >> 2; - if (dif > 0) - y += (dif * al) >> 6; - else if (dif < 0) - y += (dif * al + 0x3F) >> 6; - return (y); - } + int y; + int dif; + int al; + + if (state_ptr->ap >= 256) + return (state_ptr->yu); + else { + y = state_ptr->yl >> 6; + dif = state_ptr->yu - y; + al = state_ptr->ap >> 2; + if (dif > 0) + y += (dif * al) >> 6; + else if (dif < 0) + y += (dif * al + 0x3F) >> 6; + return (y); + } } /* @@ -183,49 +166,47 @@ step_size( * size scale factor division operation is done in the log base 2 domain * as a subtraction. */ -int -quantize( - int d, /* Raw difference signal sample */ - int y, /* Step size multiplier */ - short *table, /* quantization table */ - int size) /* table size of short integers */ +int quantize(int d, /* Raw difference signal sample */ + int y, /* Step size multiplier */ + short* table, /* quantization table */ + int size) /* table size of short integers */ { - short dqm; /* Magnitude of 'd' */ - short exp; /* Integer part of base 2 log of 'd' */ - short mant; /* Fractional part of base 2 log */ - short dl; /* Log of magnitude of 'd' */ - short dln; /* Step size scale factor normalized log */ - int i; - - /* - * LOG - * - * Compute base 2 log of 'd', and store in 'dl'. - */ - dqm = abs(d); - exp = quan(dqm >> 1, power2, 15); - mant = ((dqm << 7) >> exp) & 0x7F; /* Fractional portion. */ - dl = (exp << 7) + mant; - - /* - * SUBTB - * - * "Divide" by step size multiplier. - */ - dln = dl - (y >> 2); - - /* - * QUAN - * - * Obtain codword i for 'd'. - */ - i = quan(dln, table, size); - if (d < 0) /* take 1's complement of i */ - return ((size << 1) + 1 - i); - else if (i == 0) /* take 1's complement of 0 */ - return ((size << 1) + 1); /* new in 1988 */ - else - return (i); + short dqm; /* Magnitude of 'd' */ + short exp; /* Integer part of base 2 log of 'd' */ + short mant; /* Fractional part of base 2 log */ + short dl; /* Log of magnitude of 'd' */ + short dln; /* Step size scale factor normalized log */ + int i; + + /* + * LOG + * + * Compute base 2 log of 'd', and store in 'dl'. + */ + dqm = abs(d); + exp = quan(dqm >> 1, power2, 15); + mant = ((dqm << 7) >> exp) & 0x7F; /* Fractional portion. */ + dl = (exp << 7) + mant; + + /* + * SUBTB + * + * "Divide" by step size multiplier. + */ + dln = dl - (y >> 2); + + /* + * QUAN + * + * Obtain codword i for 'd'. + */ + i = quan(dln, table, size); + if (d < 0) /* take 1's complement of i */ + return ((size << 1) + 1 - i); + else if (i == 0) /* take 1's complement of 0 */ + return ((size << 1) + 1); /* new in 1988 */ + else + return (i); } /* * reconstruct() @@ -234,27 +215,25 @@ quantize( * codeword 'i' and quantization step size scale factor 'y'. * Multiplication is performed in log base 2 domain as addition. */ -int -reconstruct( - int sign, /* 0 for non-negative value */ - int dqln, /* G.72x codeword */ - int y) /* Step size multiplier */ +int reconstruct(int sign, /* 0 for non-negative value */ + int dqln, /* G.72x codeword */ + int y) /* Step size multiplier */ { - short dql; /* Log of 'dq' magnitude */ - short dex; /* Integer part of log */ - short dqt; - short dq; /* Reconstructed difference signal sample */ - - dql = dqln + (y >> 2); /* ADDA */ - - if (dql < 0) { - return ((sign) ? -0x8000 : 0); - } else { /* ANTILOG */ - dex = (dql >> 7) & 15; - dqt = 128 + (dql & 127); - dq = (dqt << 7) >> (14 - dex); - return ((sign) ? (dq - 0x8000) : dq); - } + short dql; /* Log of 'dq' magnitude */ + short dex; /* Integer part of log */ + short dqt; + short dq; /* Reconstructed difference signal sample */ + + dql = dqln + (y >> 2); /* ADDA */ + + if (dql < 0) { + return ((sign) ? -0x8000 : 0); + } else { /* ANTILOG */ + dex = (dql >> 7) & 15; + dqt = 128 + (dql & 127); + dq = (dqt << 7) >> (14 - dex); + return ((sign) ? (dq - 0x8000) : dq); + } } @@ -263,194 +242,190 @@ reconstruct( * * updates the state variables for each output code */ -void -update( - int code_size, /* distinguish 723_40 with others */ - int y, /* quantizer step size */ - int wi, /* scale factor multiplier */ - int fi, /* for long/short term energies */ - int dq, /* quantized prediction difference */ - int sr, /* reconstructed signal */ - int dqsez, /* difference from 2-pole predictor */ - struct g72x_state *state_ptr) /* coder state pointer */ +void update(int code_size, /* distinguish 723_40 with others */ + int y, /* quantizer step size */ + int wi, /* scale factor multiplier */ + int fi, /* for long/short term energies */ + int dq, /* quantized prediction difference */ + int sr, /* reconstructed signal */ + int dqsez, /* difference from 2-pole predictor */ + struct g72x_state* state_ptr) /* coder state pointer */ { - int cnt; - short mag, exp; /* Adaptive predictor, FLOAT A */ - short a2p = 0; /* LIMC */ - short a1ul; /* UPA1 */ - short pks1; /* UPA2 */ - short fa1; - char tr; /* tone/transition detector */ - short ylint, thr2, dqthr; - short ylfrac, thr1; - short pk0; - - pk0 = (dqsez < 0) ? 1 : 0; /* needed in updating predictor poles */ - - mag = dq & 0x7FFF; /* prediction difference magnitude */ - /* TRANS */ - ylint = state_ptr->yl >> 15; /* exponent part of yl */ - ylfrac = (state_ptr->yl >> 10) & 0x1F; /* fractional part of yl */ - thr1 = (32 + ylfrac) << ylint; /* threshold */ - thr2 = (ylint > 9) ? 31 << 10 : thr1; /* limit thr2 to 31 << 10 */ - dqthr = (thr2 + (thr2 >> 1)) >> 1; /* dqthr = 0.75 * thr2 */ - if (state_ptr->td == 0) /* signal supposed voice */ - tr = 0; - else if (mag <= dqthr) /* supposed data, but small mag */ - tr = 0; /* treated as voice */ - else /* signal is data (modem) */ - tr = 1; - - /* - * Quantizer scale factor adaptation. - */ - - /* FUNCTW & FILTD & DELAY */ - /* update non-steady state step size multiplier */ - state_ptr->yu = y + ((wi - y) >> 5); - - /* LIMB */ - if (state_ptr->yu < 544) /* 544 <= yu <= 5120 */ - state_ptr->yu = 544; - else if (state_ptr->yu > 5120) - state_ptr->yu = 5120; - - /* FILTE & DELAY */ - /* update steady state step size multiplier */ - state_ptr->yl += state_ptr->yu + ((-state_ptr->yl) >> 6); - - /* - * Adaptive predictor coefficients. - */ - if (tr == 1) { /* reset a's and b's for modem signal */ - state_ptr->a[0] = 0; - state_ptr->a[1] = 0; - state_ptr->b[0] = 0; - state_ptr->b[1] = 0; - state_ptr->b[2] = 0; - state_ptr->b[3] = 0; - state_ptr->b[4] = 0; - state_ptr->b[5] = 0; - } else { /* update a's and b's */ - pks1 = pk0 ^ state_ptr->pk[0]; /* UPA2 */ - - /* update predictor pole a[1] */ - a2p = state_ptr->a[1] - (state_ptr->a[1] >> 7); - if (dqsez != 0) { - fa1 = (pks1) ? state_ptr->a[0] : -state_ptr->a[0]; - if (fa1 < -8191) /* a2p = function of fa1 */ - a2p -= 0x100; - else if (fa1 > 8191) - a2p += 0xFF; - else - a2p += fa1 >> 5; - - if (pk0 ^ state_ptr->pk[1]) - /* LIMC */ - if (a2p <= -12160) - a2p = -12288; - else if (a2p >= 12416) - a2p = 12288; - else - a2p -= 0x80; - else if (a2p <= -12416) - a2p = -12288; - else if (a2p >= 12160) - a2p = 12288; - else - a2p += 0x80; - } - - /* TRIGB & DELAY */ - state_ptr->a[1] = a2p; - - /* UPA1 */ - /* update predictor pole a[0] */ - state_ptr->a[0] -= state_ptr->a[0] >> 8; - if (dqsez != 0){ - if (pks1 == 0) - state_ptr->a[0] += 192; - else - state_ptr->a[0] -= 192; - } - - /* LIMD */ - a1ul = 15360 - a2p; - if (state_ptr->a[0] < -a1ul) - state_ptr->a[0] = -a1ul; - else if (state_ptr->a[0] > a1ul) - state_ptr->a[0] = a1ul; - - /* UPB : update predictor zeros b[6] */ - for (cnt = 0; cnt < 6; cnt++) { - if (code_size == 5) /* for 40Kbps G.723 */ - state_ptr->b[cnt] -= state_ptr->b[cnt] >> 9; - else /* for G.721 and 24Kbps G.723 */ - state_ptr->b[cnt] -= state_ptr->b[cnt] >> 8; - if (dq & 0x7FFF) { /* XOR */ - if ((dq ^ state_ptr->dq[cnt]) >= 0) - state_ptr->b[cnt] += 128; - else - state_ptr->b[cnt] -= 128; - } - } - } - - for (cnt = 5; cnt > 0; cnt--) - state_ptr->dq[cnt] = state_ptr->dq[cnt-1]; - /* FLOAT A : convert dq[0] to 4-bit exp, 6-bit mantissa f.p. */ - if (mag == 0) { - state_ptr->dq[0] = (dq >= 0) ? 0x20 : 0xFC20; - } else { - exp = quan(mag, power2, 15); - state_ptr->dq[0] = (dq >= 0) ? - (exp << 6) + ((mag << 6) >> exp) : - (exp << 6) + ((mag << 6) >> exp) - 0x400; - } - - state_ptr->sr[1] = state_ptr->sr[0]; - /* FLOAT B : convert sr to 4-bit exp., 6-bit mantissa f.p. */ - if (sr == 0) { - state_ptr->sr[0] = 0x20; - } else if (sr > 0) { - exp = quan(sr, power2, 15); - state_ptr->sr[0] = (exp << 6) + ((sr << 6) >> exp); - } else if (sr > -32768) { - mag = -sr; - exp = quan(mag, power2, 15); - state_ptr->sr[0] = (exp << 6) + ((mag << 6) >> exp) - 0x400; - } else - state_ptr->sr[0] = 0xFC20; - - /* DELAY A */ - state_ptr->pk[1] = state_ptr->pk[0]; - state_ptr->pk[0] = pk0; - - /* TONE */ - if (tr == 1) /* this sample has been treated as data */ - state_ptr->td = 0; /* next one will be treated as voice */ - else if (a2p < -11776) /* small sample-to-sample correlation */ - state_ptr->td = 1; /* signal may be data */ - else /* signal is voice */ - state_ptr->td = 0; - - /* - * Adaptation speed control. - */ - state_ptr->dms += (fi - state_ptr->dms) >> 5; /* FILTA */ - state_ptr->dml += (((fi << 2) - state_ptr->dml) >> 7); /* FILTB */ - - if (tr == 1) - state_ptr->ap = 256; - else if (y < 1536) /* SUBTC */ - state_ptr->ap += (0x200 - state_ptr->ap) >> 4; - else if (state_ptr->td == 1) - state_ptr->ap += (0x200 - state_ptr->ap) >> 4; - else if (abs((state_ptr->dms << 2) - state_ptr->dml) >= - (state_ptr->dml >> 3)) - state_ptr->ap += (0x200 - state_ptr->ap) >> 4; - else - state_ptr->ap += (-state_ptr->ap) >> 4; + int cnt; + short mag, exp; /* Adaptive predictor, FLOAT A */ + short a2p = 0; /* LIMC */ + short a1ul; /* UPA1 */ + short pks1; /* UPA2 */ + short fa1; + char tr; /* tone/transition detector */ + short ylint, thr2, dqthr; + short ylfrac, thr1; + short pk0; + + pk0 = (dqsez < 0) ? 1 : 0; /* needed in updating predictor poles */ + + mag = dq & 0x7FFF; /* prediction difference magnitude */ + /* TRANS */ + ylint = state_ptr->yl >> 15; /* exponent part of yl */ + ylfrac = (state_ptr->yl >> 10) & 0x1F; /* fractional part of yl */ + thr1 = (32 + ylfrac) << ylint; /* threshold */ + thr2 = (ylint > 9) ? 31 << 10 : thr1; /* limit thr2 to 31 << 10 */ + dqthr = (thr2 + (thr2 >> 1)) >> 1; /* dqthr = 0.75 * thr2 */ + if (state_ptr->td == 0) /* signal supposed voice */ + tr = 0; + else if (mag <= dqthr) /* supposed data, but small mag */ + tr = 0; /* treated as voice */ + else /* signal is data (modem) */ + tr = 1; + + /* + * Quantizer scale factor adaptation. + */ + + /* FUNCTW & FILTD & DELAY */ + /* update non-steady state step size multiplier */ + state_ptr->yu = y + ((wi - y) >> 5); + + /* LIMB */ + if (state_ptr->yu < 544) /* 544 <= yu <= 5120 */ + state_ptr->yu = 544; + else if (state_ptr->yu > 5120) + state_ptr->yu = 5120; + + /* FILTE & DELAY */ + /* update steady state step size multiplier */ + state_ptr->yl += state_ptr->yu + ((-state_ptr->yl) >> 6); + + /* + * Adaptive predictor coefficients. + */ + if (tr == 1) { /* reset a's and b's for modem signal */ + state_ptr->a[0] = 0; + state_ptr->a[1] = 0; + state_ptr->b[0] = 0; + state_ptr->b[1] = 0; + state_ptr->b[2] = 0; + state_ptr->b[3] = 0; + state_ptr->b[4] = 0; + state_ptr->b[5] = 0; + } else { /* update a's and b's */ + pks1 = pk0 ^ state_ptr->pk[0]; /* UPA2 */ + + /* update predictor pole a[1] */ + a2p = state_ptr->a[1] - (state_ptr->a[1] >> 7); + if (dqsez != 0) { + fa1 = (pks1) ? state_ptr->a[0] : -state_ptr->a[0]; + if (fa1 < -8191) /* a2p = function of fa1 */ + a2p -= 0x100; + else if (fa1 > 8191) + a2p += 0xFF; + else + a2p += fa1 >> 5; + + if (pk0 ^ state_ptr->pk[1]) + /* LIMC */ + if (a2p <= -12160) + a2p = -12288; + else if (a2p >= 12416) + a2p = 12288; + else + a2p -= 0x80; + else if (a2p <= -12416) + a2p = -12288; + else if (a2p >= 12160) + a2p = 12288; + else + a2p += 0x80; + } + + /* TRIGB & DELAY */ + state_ptr->a[1] = a2p; + + /* UPA1 */ + /* update predictor pole a[0] */ + state_ptr->a[0] -= state_ptr->a[0] >> 8; + if (dqsez != 0) { + if (pks1 == 0) + state_ptr->a[0] += 192; + else + state_ptr->a[0] -= 192; + } + + /* LIMD */ + a1ul = 15360 - a2p; + if (state_ptr->a[0] < -a1ul) + state_ptr->a[0] = -a1ul; + else if (state_ptr->a[0] > a1ul) + state_ptr->a[0] = a1ul; + + /* UPB : update predictor zeros b[6] */ + for (cnt = 0; cnt < 6; cnt++) { + if (code_size == 5) /* for 40Kbps G.723 */ + state_ptr->b[cnt] -= state_ptr->b[cnt] >> 9; + else /* for G.721 and 24Kbps G.723 */ + state_ptr->b[cnt] -= state_ptr->b[cnt] >> 8; + if (dq & 0x7FFF) { /* XOR */ + if ((dq ^ state_ptr->dq[cnt]) >= 0) + state_ptr->b[cnt] += 128; + else + state_ptr->b[cnt] -= 128; + } + } + } + + for (cnt = 5; cnt > 0; cnt--) + state_ptr->dq[cnt] = state_ptr->dq[cnt - 1]; + /* FLOAT A : convert dq[0] to 4-bit exp, 6-bit mantissa f.p. */ + if (mag == 0) { + state_ptr->dq[0] = (dq >= 0) ? 0x20 : 0xFC20; + } else { + exp = quan(mag, power2, 15); + state_ptr->dq[0] = (dq >= 0) ? (exp << 6) + ((mag << 6) >> exp) + : (exp << 6) + ((mag << 6) >> exp) - 0x400; + } + + state_ptr->sr[1] = state_ptr->sr[0]; + /* FLOAT B : convert sr to 4-bit exp., 6-bit mantissa f.p. */ + if (sr == 0) { + state_ptr->sr[0] = 0x20; + } else if (sr > 0) { + exp = quan(sr, power2, 15); + state_ptr->sr[0] = (exp << 6) + ((sr << 6) >> exp); + } else if (sr > -32768) { + mag = -sr; + exp = quan(mag, power2, 15); + state_ptr->sr[0] = (exp << 6) + ((mag << 6) >> exp) - 0x400; + } else + state_ptr->sr[0] = 0xFC20; + + /* DELAY A */ + state_ptr->pk[1] = state_ptr->pk[0]; + state_ptr->pk[0] = pk0; + + /* TONE */ + if (tr == 1) /* this sample has been treated as data */ + state_ptr->td = 0; /* next one will be treated as voice */ + else if (a2p < -11776) /* small sample-to-sample correlation */ + state_ptr->td = 1; /* signal may be data */ + else /* signal is voice */ + state_ptr->td = 0; + + /* + * Adaptation speed control. + */ + state_ptr->dms += (fi - state_ptr->dms) >> 5; /* FILTA */ + state_ptr->dml += (((fi << 2) - state_ptr->dml) >> 7); /* FILTB */ + + if (tr == 1) + state_ptr->ap = 256; + else if (y < 1536) /* SUBTC */ + state_ptr->ap += (0x200 - state_ptr->ap) >> 4; + else if (state_ptr->td == 1) + state_ptr->ap += (0x200 - state_ptr->ap) >> 4; + else if (abs((state_ptr->dms << 2) - state_ptr->dml) >= (state_ptr->dml >> 3)) + state_ptr->ap += (0x200 - state_ptr->ap) >> 4; + else + state_ptr->ap += (-state_ptr->ap) >> 4; } /* @@ -471,106 +446,86 @@ update( * Return: * adjusted A-law or u-law compressed sample. */ -int -tandem_adjust_alaw( - int sr, /* decoder output linear PCM sample */ - int se, /* predictor estimate sample */ - int y, /* quantizer step size */ - int i, /* decoder input code */ - int sign, - short *qtab) +int tandem_adjust_alaw(int sr, /* decoder output linear PCM sample */ + int se, /* predictor estimate sample */ + int y, /* quantizer step size */ + int i, /* decoder input code */ + int sign, + short* qtab) { - unsigned char sp; /* A-law compressed 8-bit code */ - short dx; /* prediction error */ - char id; /* quantized prediction error */ - int sd; /* adjusted A-law decoded sample value */ - int im; /* biased magnitude of i */ - int imx; /* biased magnitude of id */ - - if (sr <= -32768) - sr = -1; - sp = linear2alaw((sr >> 1) << 3); /* short to A-law compression */ - dx = (alaw2linear(sp) >> 2) - se; /* 16-bit prediction error */ - id = quantize(dx, y, qtab, sign - 1); - - if (id == i) { /* no adjustment on sp */ - return (sp); - } else { /* sp adjustment needed */ - /* ADPCM codes : 8, 9, ... F, 0, 1, ... , 6, 7 */ - im = i ^ sign; /* 2's complement to biased unsigned */ - imx = id ^ sign; - - if (imx > im) { /* sp adjusted to next lower value */ - if (sp & 0x80) { - sd = (sp == 0xD5) ? 0x55 : - ((sp ^ 0x55) - 1) ^ 0x55; - } else { - sd = (sp == 0x2A) ? 0x2A : - ((sp ^ 0x55) + 1) ^ 0x55; - } - } else { /* sp adjusted to next higher value */ - if (sp & 0x80) - sd = (sp == 0xAA) ? 0xAA : - ((sp ^ 0x55) + 1) ^ 0x55; - else - sd = (sp == 0x55) ? 0xD5 : - ((sp ^ 0x55) - 1) ^ 0x55; - } - return (sd); - } + unsigned char sp; /* A-law compressed 8-bit code */ + short dx; /* prediction error */ + char id; /* quantized prediction error */ + int sd; /* adjusted A-law decoded sample value */ + int im; /* biased magnitude of i */ + int imx; /* biased magnitude of id */ + + if (sr <= -32768) + sr = -1; + sp = linear2alaw((sr >> 1) << 3); /* short to A-law compression */ + dx = (alaw2linear(sp) >> 2) - se; /* 16-bit prediction error */ + id = quantize(dx, y, qtab, sign - 1); + + if (id == i) { /* no adjustment on sp */ + return (sp); + } else { /* sp adjustment needed */ + /* ADPCM codes : 8, 9, ... F, 0, 1, ... , 6, 7 */ + im = i ^ sign; /* 2's complement to biased unsigned */ + imx = id ^ sign; + + if (imx > im) { /* sp adjusted to next lower value */ + if (sp & 0x80) { + sd = (sp == 0xD5) ? 0x55 : ((sp ^ 0x55) - 1) ^ 0x55; + } else { + sd = (sp == 0x2A) ? 0x2A : ((sp ^ 0x55) + 1) ^ 0x55; + } + } else { /* sp adjusted to next higher value */ + if (sp & 0x80) + sd = (sp == 0xAA) ? 0xAA : ((sp ^ 0x55) + 1) ^ 0x55; + else + sd = (sp == 0x55) ? 0xD5 : ((sp ^ 0x55) - 1) ^ 0x55; + } + return (sd); + } } -int -tandem_adjust_ulaw( - int sr, /* decoder output linear PCM sample */ - int se, /* predictor estimate sample */ - int y, /* quantizer step size */ - int i, /* decoder input code */ - int sign, - short *qtab) +int tandem_adjust_ulaw(int sr, /* decoder output linear PCM sample */ + int se, /* predictor estimate sample */ + int y, /* quantizer step size */ + int i, /* decoder input code */ + int sign, + short* qtab) { - unsigned char sp; /* u-law compressed 8-bit code */ - short dx; /* prediction error */ - char id; /* quantized prediction error */ - int sd; /* adjusted u-law decoded sample value */ - int im; /* biased magnitude of i */ - int imx; /* biased magnitude of id */ - - if (sr <= -32768) - sr = 0; - sp = linear2ulaw(sr << 2); /* short to u-law compression */ - dx = (ulaw2linear(sp) >> 2) - se; /* 16-bit prediction error */ - id = quantize(dx, y, qtab, sign - 1); - if (id == i) { - return (sp); - } else { - /* ADPCM codes : 8, 9, ... F, 0, 1, ... , 6, 7 */ - im = i ^ sign; /* 2's complement to biased unsigned */ - imx = id ^ sign; - if (imx > im) { /* sp adjusted to next lower value */ - if (sp & 0x80) - sd = (sp == 0xFF) ? 0x7E : sp + 1; - else - sd = (sp == 0) ? 0 : sp - 1; - - } else { /* sp adjusted to next higher value */ - if (sp & 0x80) - sd = (sp == 0x80) ? 0x80 : sp - 1; - else - sd = (sp == 0x7F) ? 0xFE : sp + 1; - } - return (sd); - } + unsigned char sp; /* u-law compressed 8-bit code */ + short dx; /* prediction error */ + char id; /* quantized prediction error */ + int sd; /* adjusted u-law decoded sample value */ + int im; /* biased magnitude of i */ + int imx; /* biased magnitude of id */ + + if (sr <= -32768) + sr = 0; + sp = linear2ulaw(sr << 2); /* short to u-law compression */ + dx = (ulaw2linear(sp) >> 2) - se; /* 16-bit prediction error */ + id = quantize(dx, y, qtab, sign - 1); + if (id == i) { + return (sp); + } else { + /* ADPCM codes : 8, 9, ... F, 0, 1, ... , 6, 7 */ + im = i ^ sign; /* 2's complement to biased unsigned */ + imx = id ^ sign; + if (imx > im) { /* sp adjusted to next lower value */ + if (sp & 0x80) + sd = (sp == 0xFF) ? 0x7E : sp + 1; + else + sd = (sp == 0) ? 0 : sp - 1; + + } else { /* sp adjusted to next higher value */ + if (sp & 0x80) + sd = (sp == 0x80) ? 0x80 : sp - 1; + else + sd = (sp == 0x7F) ? 0xFE : sp + 1; + } + return (sd); + } } - - - - - - - - - - - - diff --git a/gr-vocoder/lib/g7xx/g72x.h b/gr-vocoder/lib/g7xx/g72x.h index 618678866..86dcadd21 100644 --- a/gr-vocoder/lib/g7xx/g72x.h +++ b/gr-vocoder/lib/g7xx/g72x.h @@ -31,11 +31,11 @@ * */ #ifndef _G72X_H -#define _G72X_H +#define _G72X_H -#define AUDIO_ENCODING_ULAW (1) /* ISDN u-law */ -#define AUDIO_ENCODING_ALAW (2) /* ISDN A-law */ -#define AUDIO_ENCODING_LINEAR (3) /* PCM 2's-complement (0-center) */ +#define AUDIO_ENCODING_ULAW (1) /* ISDN u-law */ +#define AUDIO_ENCODING_ALAW (2) /* ISDN A-law */ +#define AUDIO_ENCODING_LINEAR (3) /* PCM 2's-complement (0-center) */ /* * The following is the definition of the state structure @@ -47,110 +47,68 @@ * included in this Recommendation. */ struct g72x_state { - long yl; /* Locked or steady state step size multiplier. */ - short yu; /* Unlocked or non-steady state step size multiplier. */ - short dms; /* Short term energy estimate. */ - short dml; /* Long term energy estimate. */ - short ap; /* Linear weighting coefficient of 'yl' and 'yu'. */ - - short a[2]; /* Coefficients of pole portion of prediction filter. */ - short b[6]; /* Coefficients of zero portion of prediction filter. */ - short pk[2]; /* - * Signs of previous two samples of a partially - * reconstructed signal. - */ - short dq[6]; /* - * Previous 6 samples of the quantized difference - * signal represented in an internal floating point - * format. - */ - short sr[2]; /* - * Previous 2 samples of the quantized difference - * signal represented in an internal floating point - * format. - */ - char td; /* delayed tone detect, new in 1988 version */ + long yl; /* Locked or steady state step size multiplier. */ + short yu; /* Unlocked or non-steady state step size multiplier. */ + short dms; /* Short term energy estimate. */ + short dml; /* Long term energy estimate. */ + short ap; /* Linear weighting coefficient of 'yl' and 'yu'. */ + + short a[2]; /* Coefficients of pole portion of prediction filter. */ + short b[6]; /* Coefficients of zero portion of prediction filter. */ + short pk[2]; /* + * Signs of previous two samples of a partially + * reconstructed signal. + */ + short dq[6]; /* + * Previous 6 samples of the quantized difference + * signal represented in an internal floating point + * format. + */ + short sr[2]; /* + * Previous 2 samples of the quantized difference + * signal represented in an internal floating point + * format. + */ + char td; /* delayed tone detect, new in 1988 version */ }; /* External function definitions. */ -extern void g72x_init_state(struct g72x_state *); -extern int g721_encoder( - int sample, - int in_coding, - struct g72x_state *state_ptr); -extern int g721_decoder( - int code, - int out_coding, - struct g72x_state *state_ptr); -extern int g723_24_encoder( - int sample, - int in_coding, - struct g72x_state *state_ptr); -extern int g723_24_decoder( - int code, - int out_coding, - struct g72x_state *state_ptr); -extern int g723_40_encoder( - int sample, - int in_coding, - struct g72x_state *state_ptr); -extern int g723_40_decoder( - int code, - int out_coding, - struct g72x_state *state_ptr); - - -extern int -quantize( - int d, - int y, - short *table, - int size); -extern int reconstruct(int,int,int);void - -extern update( - int code_size, - int y, - int wi, - int fi, - int dq, - int sr, - int dqsez, - struct g72x_state *state_ptr); -extern int -tandem_adjust_alaw( - int sr, - int se, - int y, - int i, - int sign, - short *qtab); - -extern int -tandem_adjust_ulaw( - int sr, - int se, - int y, - int i, - int sign, - short *qtab); - -extern unsigned char -linear2alaw( - int pcm_val); - -extern int -alaw2linear( - unsigned char a_val); - -extern unsigned char -linear2ulaw(int pcm_val); - -extern int ulaw2linear( unsigned char u_val); - -extern int predictor_zero(struct g72x_state *state_ptr); - -extern int predictor_pole( struct g72x_state *state_ptr); -extern int step_size( struct g72x_state *state_ptr); +extern void g72x_init_state(struct g72x_state*); +extern int g721_encoder(int sample, int in_coding, struct g72x_state* state_ptr); +extern int g721_decoder(int code, int out_coding, struct g72x_state* state_ptr); +extern int g723_24_encoder(int sample, int in_coding, struct g72x_state* state_ptr); +extern int g723_24_decoder(int code, int out_coding, struct g72x_state* state_ptr); +extern int g723_40_encoder(int sample, int in_coding, struct g72x_state* state_ptr); +extern int g723_40_decoder(int code, int out_coding, struct g72x_state* state_ptr); + + +extern int quantize(int d, int y, short* table, int size); +extern int reconstruct(int, int, int); +void + + extern update(int code_size, + int y, + int wi, + int fi, + int dq, + int sr, + int dqsez, + struct g72x_state* state_ptr); +extern int tandem_adjust_alaw(int sr, int se, int y, int i, int sign, short* qtab); + +extern int tandem_adjust_ulaw(int sr, int se, int y, int i, int sign, short* qtab); + +extern unsigned char linear2alaw(int pcm_val); + +extern int alaw2linear(unsigned char a_val); + +extern unsigned char linear2ulaw(int pcm_val); + +extern int ulaw2linear(unsigned char u_val); + +extern int predictor_zero(struct g72x_state* state_ptr); + +extern int predictor_pole(struct g72x_state* state_ptr); +extern int step_size(struct g72x_state* state_ptr); #endif /* !_G72X_H */ diff --git a/gr-vocoder/lib/gsm_fr_decode_ps_impl.cc b/gr-vocoder/lib/gsm_fr_decode_ps_impl.cc index 4bf85ac9e..27841bf34 100644 --- a/gr-vocoder/lib/gsm_fr_decode_ps_impl.cc +++ b/gr-vocoder/lib/gsm_fr_decode_ps_impl.cc @@ -24,55 +24,49 @@ #include "config.h" #endif -#define GSM_SAMPLES_PER_FRAME 160 +#define GSM_SAMPLES_PER_FRAME 160 #include "gsm_fr_decode_ps_impl.h" #include <gnuradio/io_signature.h> #include <stdexcept> #include <assert.h> namespace gr { - namespace vocoder { +namespace vocoder { - gsm_fr_decode_ps::sptr - gsm_fr_decode_ps::make() - { - return gnuradio::get_initial_sptr - (new gsm_fr_decode_ps_impl()); - } +gsm_fr_decode_ps::sptr gsm_fr_decode_ps::make() +{ + return gnuradio::get_initial_sptr(new gsm_fr_decode_ps_impl()); +} - gsm_fr_decode_ps_impl::gsm_fr_decode_ps_impl() - : sync_interpolator("vocoder_gsm_fr_decode_ps", - io_signature::make(1, 1, sizeof(gsm_frame)), - io_signature::make(1, 1, sizeof(short)), - GSM_SAMPLES_PER_FRAME) - { - if((d_gsm = gsm_create()) == 0) - throw std::runtime_error("gsm_fr_decode_ps_impl: gsm_create failed"); - } +gsm_fr_decode_ps_impl::gsm_fr_decode_ps_impl() + : sync_interpolator("vocoder_gsm_fr_decode_ps", + io_signature::make(1, 1, sizeof(gsm_frame)), + io_signature::make(1, 1, sizeof(short)), + GSM_SAMPLES_PER_FRAME) +{ + if ((d_gsm = gsm_create()) == 0) + throw std::runtime_error("gsm_fr_decode_ps_impl: gsm_create failed"); +} - gsm_fr_decode_ps_impl::~gsm_fr_decode_ps_impl() - { - gsm_destroy(d_gsm); - } +gsm_fr_decode_ps_impl::~gsm_fr_decode_ps_impl() { gsm_destroy(d_gsm); } - int - gsm_fr_decode_ps_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - const unsigned char *in = (const unsigned char*)input_items[0]; - short *out = (short*)output_items[0]; +int gsm_fr_decode_ps_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + const unsigned char* in = (const unsigned char*)input_items[0]; + short* out = (short*)output_items[0]; - assert((noutput_items % GSM_SAMPLES_PER_FRAME) == 0); + assert((noutput_items % GSM_SAMPLES_PER_FRAME) == 0); - for(int i = 0; i < noutput_items; i += GSM_SAMPLES_PER_FRAME) { - gsm_decode(d_gsm, const_cast<unsigned char*>(in), out); - in += sizeof(gsm_frame); - out += GSM_SAMPLES_PER_FRAME; - } - - return noutput_items; + for (int i = 0; i < noutput_items; i += GSM_SAMPLES_PER_FRAME) { + gsm_decode(d_gsm, const_cast<unsigned char*>(in), out); + in += sizeof(gsm_frame); + out += GSM_SAMPLES_PER_FRAME; } - } /* namespace vocoder */ + return noutput_items; +} + +} /* namespace vocoder */ } /* namespace gr */ diff --git a/gr-vocoder/lib/gsm_fr_decode_ps_impl.h b/gr-vocoder/lib/gsm_fr_decode_ps_impl.h index afd4dd34a..e573038ad 100644 --- a/gr-vocoder/lib/gsm_fr_decode_ps_impl.h +++ b/gr-vocoder/lib/gsm_fr_decode_ps_impl.h @@ -25,28 +25,28 @@ #include <gnuradio/vocoder/gsm_fr_decode_ps.h> -extern "C"{ +extern "C" { #include "gsm.h" } namespace gr { - namespace vocoder { +namespace vocoder { - class gsm_fr_decode_ps_impl : public gsm_fr_decode_ps - { - private: - struct gsm_state *d_gsm; +class gsm_fr_decode_ps_impl : public gsm_fr_decode_ps +{ +private: + struct gsm_state* d_gsm; - public: - gsm_fr_decode_ps_impl(); - ~gsm_fr_decode_ps_impl(); +public: + gsm_fr_decode_ps_impl(); + ~gsm_fr_decode_ps_impl(); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace vocoder */ +} /* namespace vocoder */ } /* namespace gr */ #endif /* INCLUDED_VOCODER_GSM_FR_DECODE_PS_IMPL_H */ diff --git a/gr-vocoder/lib/gsm_fr_encode_sp_impl.cc b/gr-vocoder/lib/gsm_fr_encode_sp_impl.cc index 9cbd4da67..22f84721c 100644 --- a/gr-vocoder/lib/gsm_fr_encode_sp_impl.cc +++ b/gr-vocoder/lib/gsm_fr_encode_sp_impl.cc @@ -24,52 +24,46 @@ #include "config.h" #endif -#define GSM_SAMPLES_PER_FRAME 160 +#define GSM_SAMPLES_PER_FRAME 160 #include "gsm_fr_encode_sp_impl.h" #include <gnuradio/io_signature.h> #include <stdexcept> namespace gr { - namespace vocoder { +namespace vocoder { - gsm_fr_encode_sp::sptr - gsm_fr_encode_sp::make() - { - return gnuradio::get_initial_sptr - (new gsm_fr_encode_sp_impl()); - } +gsm_fr_encode_sp::sptr gsm_fr_encode_sp::make() +{ + return gnuradio::get_initial_sptr(new gsm_fr_encode_sp_impl()); +} - gsm_fr_encode_sp_impl::gsm_fr_encode_sp_impl() - : sync_decimator("vocoder_gsm_fr_encode_sp", - io_signature::make(1, 1, sizeof(short)), - io_signature::make(1, 1, sizeof(gsm_frame)), - GSM_SAMPLES_PER_FRAME) - { - if((d_gsm = gsm_create ()) == 0) - throw std::runtime_error("gsm_fr_encode_sp_impl: gsm_create failed"); - } +gsm_fr_encode_sp_impl::gsm_fr_encode_sp_impl() + : sync_decimator("vocoder_gsm_fr_encode_sp", + io_signature::make(1, 1, sizeof(short)), + io_signature::make(1, 1, sizeof(gsm_frame)), + GSM_SAMPLES_PER_FRAME) +{ + if ((d_gsm = gsm_create()) == 0) + throw std::runtime_error("gsm_fr_encode_sp_impl: gsm_create failed"); +} - gsm_fr_encode_sp_impl::~gsm_fr_encode_sp_impl() - { - gsm_destroy (d_gsm); - } +gsm_fr_encode_sp_impl::~gsm_fr_encode_sp_impl() { gsm_destroy(d_gsm); } - int - gsm_fr_encode_sp_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - const short *in = (const short*)input_items[0]; - unsigned char *out = (unsigned char*)output_items[0]; +int gsm_fr_encode_sp_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + const short* in = (const short*)input_items[0]; + unsigned char* out = (unsigned char*)output_items[0]; - for(int i = 0; i < noutput_items; i++) { - gsm_encode(d_gsm, const_cast<short*>(in), out); - in += GSM_SAMPLES_PER_FRAME; - out += sizeof(gsm_frame); - } - - return noutput_items; + for (int i = 0; i < noutput_items; i++) { + gsm_encode(d_gsm, const_cast<short*>(in), out); + in += GSM_SAMPLES_PER_FRAME; + out += sizeof(gsm_frame); } - } /* namespace vocoder */ + return noutput_items; +} + +} /* namespace vocoder */ } /* namespace gr */ diff --git a/gr-vocoder/lib/gsm_fr_encode_sp_impl.h b/gr-vocoder/lib/gsm_fr_encode_sp_impl.h index 4b045ac65..acc85575c 100644 --- a/gr-vocoder/lib/gsm_fr_encode_sp_impl.h +++ b/gr-vocoder/lib/gsm_fr_encode_sp_impl.h @@ -25,28 +25,28 @@ #include <gnuradio/vocoder/gsm_fr_encode_sp.h> -extern "C"{ +extern "C" { #include "gsm.h" } namespace gr { - namespace vocoder { +namespace vocoder { - class gsm_fr_encode_sp_impl : public gsm_fr_encode_sp - { - private: - struct gsm_state *d_gsm; +class gsm_fr_encode_sp_impl : public gsm_fr_encode_sp +{ +private: + struct gsm_state* d_gsm; - public: - gsm_fr_encode_sp_impl(); - ~gsm_fr_encode_sp_impl(); +public: + gsm_fr_encode_sp_impl(); + ~gsm_fr_encode_sp_impl(); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace vocoder */ +} /* namespace vocoder */ } /* namespace gr */ #endif /* INCLUDED_VOCODER_GSM_FR_ENCODE_SP_IMPL_H */ diff --git a/gr-vocoder/lib/ulaw_decode_bs_impl.cc b/gr-vocoder/lib/ulaw_decode_bs_impl.cc index bbf58a54d..6757c3bfe 100644 --- a/gr-vocoder/lib/ulaw_decode_bs_impl.cc +++ b/gr-vocoder/lib/ulaw_decode_bs_impl.cc @@ -29,44 +29,39 @@ #include <limits.h> namespace gr { - namespace vocoder { +namespace vocoder { extern "C" { #include "g7xx/g72x.h" } - ulaw_decode_bs::sptr - ulaw_decode_bs::make() - { - return gnuradio::get_initial_sptr - (new ulaw_decode_bs_impl()); - } - - ulaw_decode_bs_impl::ulaw_decode_bs_impl() - : sync_block("vocoder_ulaw_decode_bs", - io_signature::make(1, 1, sizeof(unsigned char)), - io_signature::make(1, 1, sizeof(short))) - { - } +ulaw_decode_bs::sptr ulaw_decode_bs::make() +{ + return gnuradio::get_initial_sptr(new ulaw_decode_bs_impl()); +} - ulaw_decode_bs_impl::~ulaw_decode_bs_impl() - { - } +ulaw_decode_bs_impl::ulaw_decode_bs_impl() + : sync_block("vocoder_ulaw_decode_bs", + io_signature::make(1, 1, sizeof(unsigned char)), + io_signature::make(1, 1, sizeof(short))) +{ +} - int - ulaw_decode_bs_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - const unsigned char *in = (const unsigned char*)input_items[0]; - short *out = (short*)output_items[0]; +ulaw_decode_bs_impl::~ulaw_decode_bs_impl() {} - for(int i = 0; i < noutput_items; i++) { - out[i] = ulaw2linear(in[i]); - } +int ulaw_decode_bs_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + const unsigned char* in = (const unsigned char*)input_items[0]; + short* out = (short*)output_items[0]; - return noutput_items; + for (int i = 0; i < noutput_items; i++) { + out[i] = ulaw2linear(in[i]); } - } /* namespace vocoder */ + return noutput_items; +} + +} /* namespace vocoder */ } /* namespace gr */ diff --git a/gr-vocoder/lib/ulaw_decode_bs_impl.h b/gr-vocoder/lib/ulaw_decode_bs_impl.h index 20390466c..5578cc4b2 100644 --- a/gr-vocoder/lib/ulaw_decode_bs_impl.h +++ b/gr-vocoder/lib/ulaw_decode_bs_impl.h @@ -26,20 +26,20 @@ #include <gnuradio/vocoder/ulaw_decode_bs.h> namespace gr { - namespace vocoder { +namespace vocoder { - class ulaw_decode_bs_impl : public ulaw_decode_bs - { - public: - ulaw_decode_bs_impl(); - ~ulaw_decode_bs_impl(); +class ulaw_decode_bs_impl : public ulaw_decode_bs +{ +public: + ulaw_decode_bs_impl(); + ~ulaw_decode_bs_impl(); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace vocoder */ +} /* namespace vocoder */ } /* namespace gr */ #endif /* INCLUDED_VOCODER_ULAW_DECODE_BS_IMPL_H */ diff --git a/gr-vocoder/lib/ulaw_encode_sb_impl.cc b/gr-vocoder/lib/ulaw_encode_sb_impl.cc index 83d386496..4ec3e1ec4 100644 --- a/gr-vocoder/lib/ulaw_encode_sb_impl.cc +++ b/gr-vocoder/lib/ulaw_encode_sb_impl.cc @@ -29,44 +29,39 @@ #include <limits.h> namespace gr { - namespace vocoder { +namespace vocoder { extern "C" { #include "g7xx/g72x.h" } - ulaw_encode_sb::sptr - ulaw_encode_sb::make() - { - return gnuradio::get_initial_sptr - (new ulaw_encode_sb_impl()); - } - - ulaw_encode_sb_impl::ulaw_encode_sb_impl() - : sync_block("vocoder_ulaw_encode_sb", - io_signature::make(1, 1, sizeof(short)), - io_signature::make(1, 1, sizeof(unsigned char))) - { - } +ulaw_encode_sb::sptr ulaw_encode_sb::make() +{ + return gnuradio::get_initial_sptr(new ulaw_encode_sb_impl()); +} - ulaw_encode_sb_impl::~ulaw_encode_sb_impl() - { - } +ulaw_encode_sb_impl::ulaw_encode_sb_impl() + : sync_block("vocoder_ulaw_encode_sb", + io_signature::make(1, 1, sizeof(short)), + io_signature::make(1, 1, sizeof(unsigned char))) +{ +} - int - ulaw_encode_sb_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) - { - const short *in = (const short*)input_items[0]; - unsigned char *out = (unsigned char*)output_items[0]; +ulaw_encode_sb_impl::~ulaw_encode_sb_impl() {} - for(int i = 0; i < noutput_items; i++) { - out[i] = linear2ulaw(in[i]); - } +int ulaw_encode_sb_impl::work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + const short* in = (const short*)input_items[0]; + unsigned char* out = (unsigned char*)output_items[0]; - return noutput_items; + for (int i = 0; i < noutput_items; i++) { + out[i] = linear2ulaw(in[i]); } - } /* namespace vocoder */ + return noutput_items; +} + +} /* namespace vocoder */ } /* namespace gr */ diff --git a/gr-vocoder/lib/ulaw_encode_sb_impl.h b/gr-vocoder/lib/ulaw_encode_sb_impl.h index c9d3eb234..e4cc9422b 100644 --- a/gr-vocoder/lib/ulaw_encode_sb_impl.h +++ b/gr-vocoder/lib/ulaw_encode_sb_impl.h @@ -26,20 +26,20 @@ #include <gnuradio/vocoder/ulaw_encode_sb.h> namespace gr { - namespace vocoder { +namespace vocoder { - class ulaw_encode_sb_impl : public ulaw_encode_sb - { - public: - ulaw_encode_sb_impl(); - ~ulaw_encode_sb_impl(); +class ulaw_encode_sb_impl : public ulaw_encode_sb +{ +public: + ulaw_encode_sb_impl(); + ~ulaw_encode_sb_impl(); - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - }; + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; - } /* namespace vocoder */ +} /* namespace vocoder */ } /* namespace gr */ #endif /* INCLUDED_VOCODER_ULAW_ENCODE_SB_IMPL_H */ |