diff --git a/Controller.cpp b/Controller.cpp index a9635a9..b06edd0 100644 --- a/Controller.cpp +++ b/Controller.cpp @@ -194,25 +194,24 @@ void CController::ReadReflectorThread() // This might complete the packet. If so, send it back to the reflector void CController::AudiotoCodec2(std::shared_ptr packet) { - uint8_t m17data[8]; - c2_32.codec2_encode(m17data, packet->GetAudio()); + // the second half is silent in case this is frame is last. + uint8_t m17data[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 0x00, 0x01, 0x43, 0x09, 0xe4, 0x9c, 0x08, 0x21 }; if (packet->IsSecond()) { - //move the c2_3200 data to the second half of the M17 packet - packet->SetM17Data(m17data, EAudioSection::secondhalf); + // get the first half from the store + memcpy(m17data, data_store[packet->GetModule()], 8); + // and then calculate the second half + c2_32.codec2_encode(m17data+8, packet->GetAudio()); } else /* the packet is first */ { - // move it into the packet - packet->SetM17Data(m17data, EAudioSection::firsthalf); - if (packet->IsLast()) - { - // we have an odd number of packets, so we have to finish up the m17 packet - const uint8_t silence[] = {0x00, 0x01, 0x43, 0x09, 0xe4, 0x9c, 0x08, 0x21 }; - //put codec silence in the second half of the codec - packet->SetM17Data(silence, EAudioSection::secondhalf); - } + // calculate the first half... + c2_32.codec2_encode(m17data, packet->GetAudio()); + // and then copy the calculated data to the data_store + memcpy(m17data, data_store[packet->GetModule()], 8); } + // put the M17 data into the packet + packet->SetM17Data(m17data); // we might be all done... if (packet->AllCodecsAreSet()) { diff --git a/Controller.h b/Controller.h index ba3dca3..92ce6d7 100644 --- a/Controller.h +++ b/Controller.h @@ -45,6 +45,7 @@ protected: std::future reflectorFuture, readambeFuture, feedambeFuture, c2Future; std::vector> dmr_device, dstar_device; std::map audio_store; + std::map data_store; CUnixDgramReader reader; CUnixDgramWriter writer; CCodec2 c2_16{false}; diff --git a/TranscoderPacket.cpp b/TranscoderPacket.cpp index 0258af0..96ee1c4 100644 --- a/TranscoderPacket.cpp +++ b/TranscoderPacket.cpp @@ -35,7 +35,7 @@ CTranscoderPacket::CTranscoderPacket(const STCPacket &tcp) : dstar_set(false), d break; case ECodecType::c2_1600: case ECodecType::c2_3200: - SetM17Data(tcp.m17, EAudioSection::all); + SetM17Data(tcp.m17); break; default: std::cerr << "Trying to allocate CTranscoderPacket with an unknown codec type!" << std::endl; @@ -68,13 +68,10 @@ const STCPacket *CTranscoderPacket::GetTCPacket() const return &tcpacket; } -void CTranscoderPacket::SetM17Data(const uint8_t *data, EAudioSection section) +void CTranscoderPacket::SetM17Data(const uint8_t *data) { - const unsigned int offset = (EAudioSection::secondhalf == section) ? 8 : 0; - const unsigned int size = (EAudioSection::all == section) ? 16 : 8; - memcpy(tcpacket.m17+offset, data, size); - if (EAudioSection::firsthalf != section) - m17_set = true; + memcpy(tcpacket.m17, data, 16); + m17_set = true; } void CTranscoderPacket::SetDStarData(const uint8_t *dstar) diff --git a/TranscoderPacket.h b/TranscoderPacket.h index db9146f..e8459f0 100644 --- a/TranscoderPacket.h +++ b/TranscoderPacket.h @@ -22,8 +22,6 @@ #include "TCPacketDef.h" -enum class EAudioSection { firsthalf, secondhalf, all }; - class CTranscoderPacket { public: @@ -39,7 +37,7 @@ public: const uint8_t *GetM17Data() const; void SetDStarData(const uint8_t *dstar); void SetDMRData(const uint8_t *dmr); - void SetM17Data(const uint8_t *m17, EAudioSection section); + void SetM17Data(const uint8_t *m17); // audio int16_t *GetAudio();