Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

[QAudioOuput/QAudioInput] Noise sound when send audio to the network



  • Hello,
    I want to make an audio communication on the network between devices. For that, I'm using QAudioInput and QAudioOuput.
    I used the example to write and read on a file and it works perfectly.
    But the problem is on the network, I have a noise sound.

    Client code:

    // The format is configured to have a good result like the example
    void AudioNetwork::sendData()
    {
        m_audio->start(&m_socket);
    }
    

    Server code:

    // The format is the same as the client
    void Server::newConnection()
    {
        QTcpSocket* socket = m_server.nextPendingConnection();
        connect(socket,&QTcpSocket::readyRead,this,&Server::readyRead);
    
        m_device = m_audio->start();
    }
    
    void Server::readyRead()
    {
        QTcpSocket* socket = qobject_cast<QTcpSocket*>(sender());
        m_device->write(socket->readAll());
    }
    

    Second try
    In the server, I also used QBuffer, but it needs to manage the position (seek) to read. The buffer needs to be open on QIODevice::ReadWrite

    m_audio->start(&m_buffer);
    

    Third try
    I also try to write directly on a file with directly incoming data on the network, and I listen to the content with the example of QAudioOutput and get some noise. Because to obtain a good sound, we need to write directly on the file with QAudioInput, not with incoming data in the network.

    void Server::readyRead()
    {
        QTcpSocket* socket = qobject_cast<QTcpSocket*>(sender());
        QDataStream out (&m_destination_file);
        out << socket->readAll();
    }
    

    So I don't know how to get a good sound in real-time on the network.
    I'm using QTcpSocket and QTcpServer.

    Thank you.


  • Lifetime Qt Champion

    Hi,

    What about using UDP ?
    TCP ensures that everything arrives to the target but there's no guarantee about the timing.



  • I tested With QUdpSocket

    void Server::readyRead()
    {
        while (m_server.hasPendingDatagrams())
        {
           QNetworkDatagram datagram = m_server.receiveDatagram();
           m_device->write(datagram.data());
        }
    }
    

    It works better than QTcpSocket because I get the sound in real-time when I speak with a microphone. But the problem, it's the horrible noise that hurts the ears.



  • Wouldn't raw audio data be too big for real-time network transfering?
    I think people usually use audio encoding / decoding in such situation.



  • I will try that with Opus Audio or QAudioDecoder.


Log in to reply