Qt QAudioInput как отправить фиксированное количество образцов

Я пытаюсь отправить аудиопоток из моего приложения Qt на другое устройство с протоколом udp. Моя проблема в том, что целевое устройство хочет фиксированное количество выборок (в моем случае 320) для каждого пакета, который оно получает.
Чтобы сделать это, я думаю, что я должен использовать функцию setBufferSize объекта QAudioInput, который я использую, чтобы поймать звук, но документация очень странная и плохая для всего объекта QAudioInput. Как я могу контролировать количество отправляемых образцов?
Спасибо.

Вот как я отправляю поток:

QAudioFormat format;
format.setSampleRate(48000);
format.setChannelCount(1);
format.setSampleSize(16);
format.setCodec("audio/pcm");
format.setByteOrder(QAudioFormat::LittleEndian);
format.setSampleType(QAudioFormat::UnSignedInt);

//If format isn't supported find the nearest supported
QAudioDeviceInfo info(QAudioDeviceInfo::defaultInputDevice());
if (!info.isFormatSupported(format))
format = info.nearestFormat(format);

input = new QAudioInput(format);

socket = new QUdpSocket();

socket->connectToHost(ip, port);
input->start(socket);

Это путь с QByteArray:

QAudioFormat format;
format.setSampleRate(8000);
format.setChannelCount(1);
format.setSampleSize(16);
format.setCodec("audio/pcm");
format.setByteOrder(QAudioFormat::LittleEndian);
format.setSampleType(QAudioFormat::UnSignedInt);

//If format isn't supported find the nearest supported
QAudioDeviceInfo info(QAudioDeviceInfo::defaultInputDevice());
if (!info.isFormatSupported(format))
format = info.nearestFormat(format);

input = new QAudioInput(format);
input->setNotifyInterval((int)20);
connect(input, SIGNAL(notify()), this, SLOT(readMore()));
socket = new QUdpSocket();

socket->connectToHost(ip, port);
array.clear();
input->start(socket);void UDPSender::readMore()
{
array.append(device->readAll());
qDebug()<<"Array size"<<array.length();

if(array.length()>=5120) \\ at this time, I don't care about exceeded data
{
socket->write(array.mid(0,5120));
array.clear();
}
}

1

Решение

Задача ещё не решена.

Другие решения


По вопросам рекламы ammmcru@yandex.ru
Adblock
detector