1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-10 10:33:29 -05:00

Multiple audio support: implemented copy to UDP/RTP. RTP 48000 S/s only

This commit is contained in:
f4exb 2018-03-26 22:58:17 +02:00
parent ddff6c91b1
commit 2b3cc874c1
3 changed files with 61 additions and 14 deletions

View File

@ -91,7 +91,7 @@ void AudioNetSink::deleteDestination(const QString& address, uint16_t port)
void AudioNetSink::setStereo(bool stereo)
{
m_rtpBufferAudio->setPayloadType(stereo ? RTPSink::PayloadL16Stereo : RTPSink::PayloadL16Stereo);
m_rtpBufferAudio->setPayloadType(stereo ? RTPSink::PayloadL16Stereo : RTPSink::PayloadL16Mono);
}
void AudioNetSink::write(qint16 sample)
@ -116,6 +116,32 @@ void AudioNetSink::write(qint16 sample)
}
}
void AudioNetSink::write(qint16 lSample, qint16 rSample)
{
if (m_type == SinkUDP)
{
if (m_bufferIndex >= m_udpBlockSize)
{
m_udpSocket->writeDatagram((const char*)m_data, (qint64 ) m_udpBlockSize, m_address, m_port);
m_bufferIndex = 0;
}
else
{
qint16 *p = (qint16*) &m_data[m_bufferIndex];
*p = lSample;
m_bufferIndex += sizeof(qint16);
p = (qint16*) &m_data[m_bufferIndex];
*p = rSample;
m_bufferIndex += sizeof(qint16);
}
}
else if (m_type == SinkRTP)
{
m_rtpBufferAudio->write((uint8_t *) &lSample);
m_rtpBufferAudio->write((uint8_t *) &rSample);
}
}
void AudioNetSink::write(AudioSample* samples, uint32_t numSamples)
{
if (m_type == SinkUDP)

View File

@ -46,6 +46,7 @@ public:
void setStereo(bool stereo);
void write(qint16 sample);
void write(qint16 lSample, qint16 rSample);
void write(AudioSample* samples, uint32_t numSamples);
bool isRTPCapable() const;

View File

@ -261,41 +261,61 @@ qint64 AudioOutput::readData(char* data, qint64 maxLen)
//std::vector<qint32>::const_iterator src = m_mixBuffer.begin(); // Valgrind optim
qint16* dst = (qint16*) data;
qint32 s;
qint32 sl, sr;
for (uint i = 0; i < framesPerBuffer; i++)
{
// left channel
//s = *src++; // Valgrind optim
s = m_mixBuffer[2*i];
sl = m_mixBuffer[2*i];
if(s < -32768)
if(sl < -32768)
{
s = -32768;
sl = -32768;
}
else if (s > 32767)
else if (sl > 32767)
{
s = 32767;
sl = 32767;
}
*dst++ = s;
*dst++ = sl;
// right channel
//s = *src++; // Valgrind optim
s = m_mixBuffer[2*i + 1];
sr = m_mixBuffer[2*i + 1];
if(s < -32768)
if(sr < -32768)
{
s = -32768;
sr = -32768;
}
else if (s > 32767)
else if (sr > 32767)
{
s = 32767;
sr = 32767;
}
*dst++ = s;
*dst++ = sr;
if ((m_copyAudioToUdp) && (m_audioNetSink))
{
switch (m_udpChannelMode)
{
case UDPChannelStereo:
m_audioNetSink->write(sl, sr);
break;
case UDPChannelMixed:
m_audioNetSink->write((sl+sr)/2);
break;
case UDPChannelRight:
m_audioNetSink->write(sr);
break;
case UDPChannelLeft:
default:
m_audioNetSink->write(sl);
break;
}
}
}
return framesPerBuffer * 4;