Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [QAudioOuput/QAudioInput] Noise sound when send audio to the network
QtWS25 Last Chance

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

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 374 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • StyleoshinS Offline
    StyleoshinS Offline
    Styleoshin
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • StyleoshinS Offline
        StyleoshinS Offline
        Styleoshin
        wrote on last edited by Styleoshin
        #3

        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.

        1 Reply Last reply
        0
        • B Offline
          B Offline
          Bonnie
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0
          • StyleoshinS Offline
            StyleoshinS Offline
            Styleoshin
            wrote on last edited by
            #5

            I will try that with Opus Audio or QAudioDecoder.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved