From 2b97cb1cc30fea3c5cd2f95d33420081a5c5121a Mon Sep 17 00:00:00 2001 From: Piotr Krysik Date: Wed, 29 Jun 2016 15:00:07 +0200 Subject: Added voice output, removed saving to file from inside the decoder - now it should be done GNU Radio way --- lib/decoding/tch_f_decoder_impl.cc | 40 +++++++++++++++++++------------------- lib/decoding/tch_f_decoder_impl.h | 4 ++-- 2 files changed, 22 insertions(+), 22 deletions(-) (limited to 'lib/decoding') diff --git a/lib/decoding/tch_f_decoder_impl.cc b/lib/decoding/tch_f_decoder_impl.cc index f409d37..b9aa057 100644 --- a/lib/decoding/tch_f_decoder_impl.cc +++ b/lib/decoding/tch_f_decoder_impl.cc @@ -52,6 +52,7 @@ namespace gr { d_collected_bursts_num(0), d_boundary_check(boundary_check), d_boundary_decode(!boundary_check), + d_header_sent(false), mBlockCoder(0x10004820009ULL, 40, 224), mU(228), mP(mU.segment(184,40)), @@ -65,18 +66,11 @@ namespace gr { mClass1A_d(mTCHD.head(50)), mTCHParity(0x0b, 3, 50) { - d_speech_file = fopen( file.c_str(), "wb" ); - if (d_speech_file == NULL) - { - throw std::runtime_error("TCH/F Decoder: can't open file\n"); - } - - const unsigned char amr_nb_magic[6] = { 0x23, 0x21, 0x41, 0x4d, 0x52, 0x0a }; - - if (d_tch_mode != TCH_FS) - { - fwrite(amr_nb_magic, 1, 6, d_speech_file); - } + //setup input/output ports + message_port_register_in(pmt::mp("bursts")); + set_msg_handler(pmt::mp("bursts"), boost::bind(&tch_f_decoder_impl::decode, this, _1)); + message_port_register_out(pmt::mp("msgs")); + message_port_register_out(pmt::mp("voice")); int j, k, B; for (k = 0; k < CONV_SIZE; k++) @@ -86,11 +80,6 @@ namespace gr { interleave_trans[k] = B * 114 + j; } - //setup input/output ports - message_port_register_in(pmt::mp("bursts")); - set_msg_handler(pmt::mp("bursts"), boost::bind(&tch_f_decoder_impl::decode, this, _1)); - message_port_register_out(pmt::mp("msgs")); - setCodingMode(mode); } @@ -100,9 +89,20 @@ namespace gr { void tch_f_decoder_impl::decode(pmt::pmt_t msg) { + if(!d_header_sent) + { + if (d_tch_mode != TCH_FS) + { + const unsigned char amr_nb_magic[7] = "#!AMR\n"; + message_port_pub(pmt::mp("voice"), pmt::cons(pmt::PMT_NIL, pmt::make_blob(amr_nb_magic,6))); + } + d_header_sent = true; + } + + d_bursts[d_collected_bursts_num] = msg; d_collected_bursts_num++; - + bool stolen = false; if (d_collected_bursts_num == 8) @@ -329,7 +329,7 @@ namespace gr { amrFrame.pack(frameBuffer); } - fwrite(frameBuffer, 1 , mTCHFrameLength, d_speech_file); + message_port_pub(pmt::mp("voice"), pmt::cons(pmt::PMT_NIL, pmt::make_blob(frameBuffer,mTCHFrameLength))); } } else @@ -378,7 +378,7 @@ namespace gr { // mTCHD.unmap(mAMRBitOrder, payload.size(), payload); mTCHD.copyTo(payload); amrFrame.pack(frameBuffer); - fwrite(frameBuffer, 1 , mAMRFrameLth, d_speech_file); + message_port_pub(pmt::mp("voice"), pmt::cons(pmt::PMT_NIL, pmt::make_blob(frameBuffer,mAMRFrameLth))); } } } diff --git a/lib/decoding/tch_f_decoder_impl.h b/lib/decoding/tch_f_decoder_impl.h index 3e8c79a..c6eda09 100644 --- a/lib/decoding/tch_f_decoder_impl.h +++ b/lib/decoding/tch_f_decoder_impl.h @@ -52,10 +52,10 @@ namespace gr { unsigned int d_collected_bursts_num; unsigned short interleave_trans[CONV_SIZE]; pmt::pmt_t d_bursts[8]; - FILE * d_speech_file; enum tch_mode d_tch_mode; bool d_boundary_check; bool d_boundary_decode; + bool d_header_sent; BitVector mU; BitVector mP; @@ -89,7 +89,7 @@ namespace gr { void decode(pmt::pmt_t msg); void setCodingMode(tch_mode mode); public: - tch_f_decoder_impl(tch_mode mode, const std::string &file, bool boundary_check=true); + tch_f_decoder_impl(tch_mode mode, const std::string &file, bool boundary_check=false); ~tch_f_decoder_impl(); }; -- cgit v1.2.3