summaryrefslogtreecommitdiff
path: root/gr-vocoder/lib/codec2_decode_ps_impl.cc
diff options
context:
space:
mode:
authorMartin Braun <martin.braun@ettus.com>2014-03-07 11:21:33 +0100
committerMartin Braun <martin.braun@ettus.com>2014-03-07 18:10:21 +0100
commit01c4267261937e495545942131b5bd496eba2269 (patch)
tree78384e06068ae260358f20622526a66ceb4df482 /gr-vocoder/lib/codec2_decode_ps_impl.cc
parentca69ec5d64b67dfc714917bd94162a5d1f131d69 (diff)
vocoder: Fixed packing problem with Codec2, + GRC bindings, added example
Diffstat (limited to 'gr-vocoder/lib/codec2_decode_ps_impl.cc')
-rw-r--r--gr-vocoder/lib/codec2_decode_ps_impl.cc23
1 files changed, 20 insertions, 3 deletions
diff --git a/gr-vocoder/lib/codec2_decode_ps_impl.cc b/gr-vocoder/lib/codec2_decode_ps_impl.cc
index 57ab62422e..a4f7cccf82 100644
--- a/gr-vocoder/lib/codec2_decode_ps_impl.cc
+++ b/gr-vocoder/lib/codec2_decode_ps_impl.cc
@@ -1,6 +1,6 @@
/* -*- c++ -*- */
/*
- * Copyright 2005,2011,2013 Free Software Foundation, Inc.
+ * Copyright 2005,2011,2013,2014 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
@@ -49,7 +49,8 @@ namespace gr {
: sync_interpolator("vocoder_codec2_decode_ps",
io_signature::make(1, 1, CODEC2_BITS_PER_FRAME * sizeof(char)),
io_signature::make (1, 1, sizeof(short)),
- CODEC2_SAMPLES_PER_FRAME)
+ CODEC2_SAMPLES_PER_FRAME),
+ d_frame_buf(CODEC2_BYTES_PER_FRAME, 0)
{
if((d_codec2 = codec2_create()) == 0)
throw std::runtime_error("codec2_decode_ps_impl: codec2_create failed");
@@ -71,7 +72,8 @@ namespace gr {
assert((noutput_items % CODEC2_SAMPLES_PER_FRAME) == 0);
for(int i = 0; i < noutput_items; i += CODEC2_SAMPLES_PER_FRAME) {
- codec2_decode (d_codec2, out, const_cast<unsigned char*>(in));
+ pack_frame(in, &d_frame_buf[0]);
+ codec2_decode (d_codec2, out, const_cast<unsigned char*>(&d_frame_buf[0]));
in += CODEC2_BITS_PER_FRAME * sizeof (char);
out += CODEC2_SAMPLES_PER_FRAME;
}
@@ -79,5 +81,20 @@ namespace gr {
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, CODEC2_BYTES_PER_FRAME);
+
+ int byte_idx = 0, bit_idx = 0;
+ for(int k = 0; k < CODEC2_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 gr */