6#include <QMediaDevices>
15 class NDEVR_SOUND_MANAGER_API MicByteBuffer final :
public QObject
22 explicit MicByteBuffer(QObject* parent =
nullptr)
26 f.setSampleRate(16000);
28 f.setSampleFormat(QAudioFormat::Int16);
30 const QAudioDevice dev = QMediaDevices::defaultAudioInput();
31 m_format = dev.preferredFormat();
33 if (dev.isFormatSupported(f))
36 m_source =
new QAudioSource(dev, m_format,
this);
37 m_source->setBufferSize(4096 * 8);
41 ~MicByteBuffer()
override
56 m_io = m_source->start();
60 connect(m_io, &QIODevice::readyRead,
this, &MicByteBuffer::onReadyRead, Qt::DirectConnection);
70 disconnect(m_io,
nullptr,
this,
nullptr);
79 const QByteArray& bytes()
const
87 QByteArray takeBytes()
89 QByteArray out = std::move(m_buffer);
103 qint64 bytesCaptured()
const
111 QAudioFormat format()
const
121 void bytesAppended(qint64 appendedBytes, qint64 totalBytes);
130 const qint64 avail = m_io->bytesAvailable();
134 m_tmp.resize(
int(avail));
135 const qint64 got = m_io->read(m_tmp.data(), m_tmp.size());
139 m_buffer.append(m_tmp.constData(),
int(got));
142 emit bytesAppended(got, m_totalBytes);
146 QAudioSource* m_source =
nullptr;
147 QIODevice* m_io =
nullptr;
148 QAudioFormat m_format;
152 qint64 m_totalBytes = 0;
The primary namespace for the NDEVR SDK.