From ef564cdb4f4d657bf246611e8fd2815e7f3bcad5 Mon Sep 17 00:00:00 2001 From: f4exb Date: Wed, 13 Feb 2019 10:34:36 +0100 Subject: [PATCH] Copy audio to UDP/RTP: added a 8 bit linear option --- sdrbase/audio/audionetsink.cpp | 16 ++++++++++++++ sdrbase/audio/audionetsink.h | 7 ++++--- sdrbase/audio/audiooutput.h | 7 ++++--- sdrbase/util/rtpsink.cpp | 20 +++++++++++++----- sdrbase/util/rtpsink.h | 1 + sdrgui/gui/audiodialog.ui | 38 ++++++++++++++++++++++++++++++++++ 6 files changed, 78 insertions(+), 11 deletions(-) diff --git a/sdrbase/audio/audionetsink.cpp b/sdrbase/audio/audionetsink.cpp index f11415d00..a5ebc4af8 100644 --- a/sdrbase/audio/audionetsink.cpp +++ b/sdrbase/audio/audionetsink.cpp @@ -119,6 +119,9 @@ void AudioNetSink::setParameters(Codec codec, bool stereo, int sampleRate) m_audioCompressor.fillULaw(); m_rtpBufferAudio->setPayloadInformation(RTPSink::PayloadPCMU8, sampleRate); break; + case CodecL8: + m_rtpBufferAudio->setPayloadInformation(RTPSink::PayloadL8, sampleRate); + break; case CodecL16: // actually no codec default: m_rtpBufferAudio->setPayloadInformation(stereo ? RTPSink::PayloadL16Stereo : RTPSink::PayloadL16Mono, sampleRate); @@ -148,6 +151,13 @@ void AudioNetSink::write(qint16 sample) m_bufferIndex += sizeof(qint8); } break; + case CodecL8: + { + qint8 *p = (qint8*) &m_data[m_bufferIndex]; + *p = sample / 256; + m_bufferIndex += sizeof(qint8); + } + break; case CodecL16: default: { @@ -170,6 +180,12 @@ void AudioNetSink::write(qint16 sample) m_rtpBufferAudio->write((uint8_t *) &p); } break; + case CodecL8: + { + qint8 p = sample / 256; + m_rtpBufferAudio->write((uint8_t *) &p); + } + break; case CodecL16: default: m_rtpBufferAudio->write((uint8_t *) &sample); diff --git a/sdrbase/audio/audionetsink.h b/sdrbase/audio/audionetsink.h index 284a5ee7a..240565d7a 100644 --- a/sdrbase/audio/audionetsink.h +++ b/sdrbase/audio/audionetsink.h @@ -40,9 +40,10 @@ public: typedef enum { - CodecL16, - CodecPCMA, - CodecPCMU + CodecL16, //!< Linear 16 bit samples (no formatting) + CodecL8, //!< Linear 8 bit samples + CodecPCMA, //!< PCM A-law 8 bit samples + CodecPCMU //!< PCM Mu-law 8 bit samples } Codec; AudioNetSink(QObject *parent); //!< without RTP diff --git a/sdrbase/audio/audiooutput.h b/sdrbase/audio/audiooutput.h index 0e9fb8dc9..140e32397 100644 --- a/sdrbase/audio/audiooutput.h +++ b/sdrbase/audio/audiooutput.h @@ -43,9 +43,10 @@ public: enum UDPChannelCodec { - UDPCodecL16, //!< Linear 16 bit (no codec) - UDPCodecALaw, - UDPCodecULaw + UDPCodecL16, //!< Linear 16 bit (no codec) + UDPCodecL8, //!< Linear 8 bit + UDPCodecALaw, //!< PCM A-law 8 bit + UDPCodecULaw //!< PCM Mu-law 8 bit }; AudioOutput(); diff --git a/sdrbase/util/rtpsink.cpp b/sdrbase/util/rtpsink.cpp index 791e0ef3e..999b16679 100644 --- a/sdrbase/util/rtpsink.cpp +++ b/sdrbase/util/rtpsink.cpp @@ -84,26 +84,32 @@ void RTPSink::setPayloadInformation(PayloadType payloadType, int sampleRate) m_sampleBytes = 1; m_rtpSession.SetDefaultPayloadType(8); m_packetSamples = m_sampleRate / 50; // 20ms packet samples - timestampinc = m_sampleRate / 50; // 8k -> 160 packets in 20ms + timestampinc = m_sampleRate / 50; // 1 channel break; case PayloadPCMU8: m_sampleBytes = 1; m_rtpSession.SetDefaultPayloadType(0); m_packetSamples = m_sampleRate / 50; // 20ms packet samples - timestampinc = m_sampleRate / 50; // 8k -> 160 packets in 20ms + timestampinc = m_sampleRate / 50; // 1 channel + break; + case PayloadL8: + m_sampleBytes = 1; + m_rtpSession.SetDefaultPayloadType(96); + m_packetSamples = m_sampleRate / 50; // 20ms packet samples + timestampinc = m_sampleRate / 50; // 1 channel break; case PayloadL16Stereo: m_sampleBytes = 4; m_rtpSession.SetDefaultPayloadType(96); m_packetSamples = m_sampleRate / 50; // 20ms packet samples - timestampinc = m_sampleRate / 100; + timestampinc = m_sampleRate / 100; // 2 channels break; case PayloadL16Mono: default: m_sampleBytes = 2; m_rtpSession.SetDefaultPayloadType(96); m_packetSamples = m_sampleRate / 50; // 20ms packet samples - timestampinc = m_sampleRate / 50; + timestampinc = m_sampleRate / 50; // 1 channel break; } @@ -220,7 +226,11 @@ void RTPSink::write(const uint8_t *sampleByte) qCritical("RTPSink::write: cannot write packet: %s", qrtplib::RTPGetErrorString(status).c_str()); } - writeNetBuf(&m_byteBuffer[0], sampleByte, elemLength(m_payloadType), m_sampleBytes, m_endianReverse); + writeNetBuf(&m_byteBuffer[0], + sampleByte, + elemLength(m_payloadType), + m_sampleBytes, + m_endianReverse); m_sampleBufferIndex = 1; } } diff --git a/sdrbase/util/rtpsink.h b/sdrbase/util/rtpsink.h index 568d44551..ea69b4549 100644 --- a/sdrbase/util/rtpsink.h +++ b/sdrbase/util/rtpsink.h @@ -42,6 +42,7 @@ public: { PayloadL16Mono, PayloadL16Stereo, + PayloadL8, PayloadPCMA8, PayloadPCMU8 } PayloadType; diff --git a/sdrgui/gui/audiodialog.ui b/sdrgui/gui/audiodialog.ui index e0f14fce4..43109542e 100644 --- a/sdrgui/gui/audiodialog.ui +++ b/sdrgui/gui/audiodialog.ui @@ -253,6 +253,11 @@ L16 + + + L8 + + PCMA/8k @@ -540,6 +545,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +