hear only noises with QAudioOutput
-
Hi, I work with audio capture from microphone.
This is server
QAudioRecorder* recorder = new QAudioRecorder(); QAudioProbe* probe = new QAudioProbe; connect(probe, SIGNAL(audioBufferProbed(QAudioBuffer)), this, SLOT(processBuffer(QAudioBuffer))); QAudioEncoderSettings audioSettings; audioSettings.setCodec("audio/mpeg"); audioSettings.setQuality(QMultimedia::HighQuality); recorder->setEncodingSettings(audioSettings); qDebug() << "probe ritorna " << probe->setSource(recorder); // Returns true, hopefully. //qDebug() << "" << recorder->setOutputLocation(QUrl::fromLocalFile("test")); recorder->record(); // Now we can do things like calculating levels or performing an FFT myAudioServer = new MyAudioServer(); myAudioServer->startServer();This is the way as trasfer to socket
void QtVideoWidgetsIssueTrack::processBuffer(const QAudioBuffer& buffer){ QByteArray byteArr; byteArr.append(buffer.constData<char>(), buffer.byteCount()); QByteArray Data = byteArr; qDebug() << myAudioServer->isListening(); QTcpSocket* myAudioClient = myAudioServer->getSocket(); qDebug() << myAudioClient; qDebug() << "in processBuffer"; if (myAudioClient != nullptr) { myAudioClient->write(Data, Data.count()); myAudioClient->waitForBytesWritten(); } }Now the client
void MyThreadAudioTcpSocket::readyRead() { while (socket->bytesAvailable() > 0) { //fare il play da QByteArray // get default output device QByteArray* yourSoundData = new QByteArray(socket->readAll()); QBuffer* buffer = new QBuffer; buffer->setData(yourSoundData->data(),yourSoundData->size()); buffer->open(QBuffer::ReadOnly); QAudioFormat format; format.setSampleSize(16); format.setSampleRate(22050); format.setChannelCount(1); format.setCodec("audio/mpeg"); format.setByteOrder(QAudioFormat::LittleEndian); format.setSampleType(QAudioFormat::UnSignedInt); QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice()); if (!info.isFormatSupported(format)) { format = info.nearestFormat(format); qDebug() << "formato non supportato"; } QAudioOutput *output = new QAudioOutput(format); output->moveToThread(this); output->start(buffer); } }I attach what I hear, only noise... !
wav fileSomeone can You help me to understand where wrong in source code.
-
Hi, I work with audio capture from microphone.
This is server
QAudioRecorder* recorder = new QAudioRecorder(); QAudioProbe* probe = new QAudioProbe; connect(probe, SIGNAL(audioBufferProbed(QAudioBuffer)), this, SLOT(processBuffer(QAudioBuffer))); QAudioEncoderSettings audioSettings; audioSettings.setCodec("audio/mpeg"); audioSettings.setQuality(QMultimedia::HighQuality); recorder->setEncodingSettings(audioSettings); qDebug() << "probe ritorna " << probe->setSource(recorder); // Returns true, hopefully. //qDebug() << "" << recorder->setOutputLocation(QUrl::fromLocalFile("test")); recorder->record(); // Now we can do things like calculating levels or performing an FFT myAudioServer = new MyAudioServer(); myAudioServer->startServer();This is the way as trasfer to socket
void QtVideoWidgetsIssueTrack::processBuffer(const QAudioBuffer& buffer){ QByteArray byteArr; byteArr.append(buffer.constData<char>(), buffer.byteCount()); QByteArray Data = byteArr; qDebug() << myAudioServer->isListening(); QTcpSocket* myAudioClient = myAudioServer->getSocket(); qDebug() << myAudioClient; qDebug() << "in processBuffer"; if (myAudioClient != nullptr) { myAudioClient->write(Data, Data.count()); myAudioClient->waitForBytesWritten(); } }Now the client
void MyThreadAudioTcpSocket::readyRead() { while (socket->bytesAvailable() > 0) { //fare il play da QByteArray // get default output device QByteArray* yourSoundData = new QByteArray(socket->readAll()); QBuffer* buffer = new QBuffer; buffer->setData(yourSoundData->data(),yourSoundData->size()); buffer->open(QBuffer::ReadOnly); QAudioFormat format; format.setSampleSize(16); format.setSampleRate(22050); format.setChannelCount(1); format.setCodec("audio/mpeg"); format.setByteOrder(QAudioFormat::LittleEndian); format.setSampleType(QAudioFormat::UnSignedInt); QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice()); if (!info.isFormatSupported(format)) { format = info.nearestFormat(format); qDebug() << "formato non supportato"; } QAudioOutput *output = new QAudioOutput(format); output->moveToThread(this); output->start(buffer); } }I attach what I hear, only noise... !
wav fileSomeone can You help me to understand where wrong in source code.
@zabitqt said in hear only noises with QAudioOutput:
void MyThreadAudioTcpSocket::readyRead()
{while (socket->bytesAvailable() > 0) { //fare il play da QByteArray // get default output device QByteArray* yourSoundData = new QByteArray(socket->readAll()); QBuffer* buffer = new QBuffer; buffer->setData(yourSoundData->data(),yourSoundData->size()); buffer->open(QBuffer::ReadOnly); QAudioFormat format; format.setSampleSize(16); format.setSampleRate(22050); format.setChannelCount(1); format.setCodec("audio/mpeg"); format.setByteOrder(QAudioFormat::LittleEndian); format.setSampleType(QAudioFormat::UnSignedInt); QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice()); if (!info.isFormatSupported(format)) { format = info.nearestFormat(format); qDebug() << "formato non supportato"; } QAudioOutput *output = new QAudioOutput(format); output->moveToThread(this); output->start(buffer); }}
Are you serious? If there ould be a contest to create as much memleaks as possible this would be probably under the top ten.
-
@zabitqt said in hear only noises with QAudioOutput:
void MyThreadAudioTcpSocket::readyRead()
{while (socket->bytesAvailable() > 0) { //fare il play da QByteArray // get default output device QByteArray* yourSoundData = new QByteArray(socket->readAll()); QBuffer* buffer = new QBuffer; buffer->setData(yourSoundData->data(),yourSoundData->size()); buffer->open(QBuffer::ReadOnly); QAudioFormat format; format.setSampleSize(16); format.setSampleRate(22050); format.setChannelCount(1); format.setCodec("audio/mpeg"); format.setByteOrder(QAudioFormat::LittleEndian); format.setSampleType(QAudioFormat::UnSignedInt); QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice()); if (!info.isFormatSupported(format)) { format = info.nearestFormat(format); qDebug() << "formato non supportato"; } QAudioOutput *output = new QAudioOutput(format); output->moveToThread(this); output->start(buffer); }}
Are you serious? If there ould be a contest to create as much memleaks as possible this would be probably under the top ten.
@Christian-Ehrlicher Ok but I don't think the problem are memleaks... I don't realease Memory correctly and close connection but... Can you suggest me how improve code please. It's my first project in c++
-
@Christian-Ehrlicher Ok but I don't think the problem are memleaks... I don't realease Memory correctly and close connection but... Can you suggest me how improve code please. It's my first project in c++
@zabitqt said in hear only noises with QAudioOutput:
It's my first project in c++
Then please start with something easier - the Qt examples are a good start