Added voice output, removed saving to file from inside the decoder - now it should be done GNU Radio way
This commit is contained in:
parent
1bfe1e09c7
commit
2b97cb1cc3
|
@ -50,12 +50,6 @@
|
|||
<key>grgsm.TCH_AFS4_75</key>
|
||||
</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>
|
||||
|
@ -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
|
||||
|
||||
|
|
|
@ -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)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue