aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--grc/decoding/gsm_tch_f_decoder.xml13
-rw-r--r--lib/decoding/tch_f_decoder_impl.cc40
-rw-r--r--lib/decoding/tch_f_decoder_impl.h4
3 files changed, 28 insertions, 29 deletions
diff --git a/grc/decoding/gsm_tch_f_decoder.xml b/grc/decoding/gsm_tch_f_decoder.xml
index b15d55f..cbc3234 100644
--- a/grc/decoding/gsm_tch_f_decoder.xml
+++ b/grc/decoding/gsm_tch_f_decoder.xml
@@ -51,12 +51,6 @@
</option>
</param>
<param>
- <name>destination file</name>
- <key>file</key>
- <value>/tmp/speech.gsm</value>
- <type>file_open</type>
- </param>
- <param>
<name>Voice boundary detection</name>
<key>boundary_check</key>
<value>False</value>
@@ -80,7 +74,12 @@
<type>message</type>
<optional>1</optional>
</source>
-
+ <source>
+ <name>voice</name>
+ <type>message</type>
+ <optional>1</optional>
+ </source>
+
<doc>
If "Voice boundary detection" is enabled, then only bursts are decoded as voice where
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();
};