mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-11-26 09:48:45 -05:00
DATV demod: audio implementation (2)
This commit is contained in:
parent
80a25cc8fb
commit
2d86373418
@ -16,6 +16,7 @@
|
|||||||
///////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
@ -41,7 +42,7 @@ DATVideoRender::DATVideoRender(QWidget *parent) : TVScreen(true, parent)
|
|||||||
m_audioFifo = nullptr;
|
m_audioFifo = nullptr;
|
||||||
m_audioSWR = nullptr;
|
m_audioSWR = nullptr;
|
||||||
m_audioSampleRate = 48000;
|
m_audioSampleRate = 48000;
|
||||||
m_audioTestIndex = 0;
|
m_audioFifoBufferIndex = 0;
|
||||||
m_videoStreamIndex = -1;
|
m_videoStreamIndex = -1;
|
||||||
m_audioStreamIndex = -1;
|
m_audioStreamIndex = -1;
|
||||||
|
|
||||||
@ -51,11 +52,11 @@ DATVideoRender::DATVideoRender(QWidget *parent) : TVScreen(true, parent)
|
|||||||
m_frame = nullptr;
|
m_frame = nullptr;
|
||||||
m_frameCount = -1;
|
m_frameCount = -1;
|
||||||
|
|
||||||
for (int i = 0; i < m_audioTestSize; i++)
|
// for (int i = 0; i < m_audioFifoBufferSize; i++)
|
||||||
{
|
// {
|
||||||
m_audioTest[2*i] = 32768.0f * sin((M_PI * i)/1024.0f);
|
// m_audioFifoBuffer[2*i] = 8192.0f * sin((M_PI * i)/(m_audioFifoBufferSize/1000.0f));
|
||||||
m_audioTest[2*i+1] = m_audioTest[2*i];
|
// m_audioFifoBuffer[2*i+1] = m_audioFifoBuffer[2*i];
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DATVideoRender::eventFilter(QObject *obj, QEvent *event)
|
bool DATVideoRender::eventFilter(QObject *obj, QEvent *event)
|
||||||
@ -584,34 +585,33 @@ bool DATVideoRender::RenderStream()
|
|||||||
av_samples_alloc((uint8_t**) &audioBuffer, nullptr, 2, m_frame->nb_samples, AV_SAMPLE_FMT_S16, 0);
|
av_samples_alloc((uint8_t**) &audioBuffer, nullptr, 2, m_frame->nb_samples, AV_SAMPLE_FMT_S16, 0);
|
||||||
int frame_count = swr_convert(m_audioSWR, (uint8_t**) &audioBuffer, m_frame->nb_samples, (const uint8_t**) m_frame->data, m_frame->nb_samples);
|
int frame_count = swr_convert(m_audioSWR, (uint8_t**) &audioBuffer, m_frame->nb_samples, (const uint8_t**) m_frame->data, m_frame->nb_samples);
|
||||||
|
|
||||||
// int res = m_audioFifo->write((const quint8*)&m_audioBuffer[0], frame_count);
|
// int ret = m_audioFifo->write((const quint8*) &audioBuffer[0], frame_count);
|
||||||
|
|
||||||
// if (res != frame_count)
|
// if (ret < frame_count) {
|
||||||
// {
|
// qDebug("DATVideoRender::RenderStream: audio frames missing %d vs %d", ret, frame_count);
|
||||||
// qDebug("DATVideoRender::RenderStream: %u/%u audio samples written", res, frame_count);
|
|
||||||
// m_audioFifo->clear();
|
|
||||||
// }
|
// }
|
||||||
|
|
||||||
int count = frame_count;
|
if (m_audioFifoBufferIndex + frame_count < m_audioFifoBufferSize)
|
||||||
int i = m_audioTestIndex;
|
|
||||||
|
|
||||||
while (count > 0)
|
|
||||||
{
|
{
|
||||||
if (i + count < m_audioTestSize)
|
std::copy(&audioBuffer[0], &audioBuffer[2*frame_count], &m_audioFifoBuffer[2*m_audioFifoBufferIndex]);
|
||||||
{
|
m_audioFifoBufferIndex += frame_count;
|
||||||
m_audioFifo->write((const quint8*)&m_audioTest[2*i], 2*count);
|
}
|
||||||
i += count;
|
else
|
||||||
count = 0;
|
{
|
||||||
}
|
int remainder = m_audioFifoBufferSize - m_audioFifoBufferIndex;
|
||||||
else
|
std::copy(&audioBuffer[0], &audioBuffer[2*remainder], &m_audioFifoBuffer[2*m_audioFifoBufferIndex]);
|
||||||
{
|
m_audioFifo->write((const quint8*) &m_audioFifoBuffer[0], m_audioFifoBufferSize);
|
||||||
m_audioFifo->write((const quint8*)&m_audioTest[2*i], 2*(m_audioTestSize - i));
|
std::copy(&audioBuffer[2*remainder], &audioBuffer[2*frame_count], &m_audioFifoBuffer[0]);
|
||||||
count -= (m_audioTestSize - i);
|
m_audioFifoBufferIndex = frame_count - remainder;
|
||||||
i = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_audioTestIndex = i;
|
// m_audioFifoBufferIndex += frame_count;
|
||||||
|
|
||||||
|
// if (m_audioFifoBufferIndex >= m_audioFifoBufferSize)
|
||||||
|
// {
|
||||||
|
// m_audioFifo->write((const quint8*)&m_audioFifoBuffer[0], m_audioFifoBufferSize);
|
||||||
|
// m_audioFifoBufferIndex -= m_audioFifoBufferSize;
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -116,9 +116,9 @@ class DATVideoRender : public TVScreen
|
|||||||
AudioFifo *m_audioFifo;
|
AudioFifo *m_audioFifo;
|
||||||
struct SwrContext* m_audioSWR;
|
struct SwrContext* m_audioSWR;
|
||||||
int m_audioSampleRate;
|
int m_audioSampleRate;
|
||||||
static const int m_audioTestSize = 32768;
|
static const int m_audioFifoBufferSize = 16000;
|
||||||
uint16_t m_audioTest[m_audioTestSize*2]; // 2 channels
|
uint16_t m_audioFifoBuffer[m_audioFifoBufferSize*2]; // 2 channels
|
||||||
int m_audioTestIndex;
|
int m_audioFifoBufferIndex;
|
||||||
|
|
||||||
uint8_t *m_pbytDecodedData[4];
|
uint8_t *m_pbytDecodedData[4];
|
||||||
int m_pintDecodedLineSize[4];
|
int m_pintDecodedLineSize[4];
|
||||||
|
Loading…
Reference in New Issue
Block a user