Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7999531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:31:59+00:00 2026-06-04T15:31:59+00:00

My goal is to transmit *.wav file over LAN network without delay or with

  • 0

My goal is to transmit *.wav file over LAN network without delay or with minimal one.

Also we read a file on a server machine by parts, 320 bytes both. After this we send packets by UDP and write receiving in jitter-buffer. The size of the jitter-buffer is 10.
What delays should I set on timers for clear sound?

Here is the sender:

void MainWindow::on_start_tx_triggered()
{
    timer1 = new QTimer (this);
    udpSocketout = new QUdpSocket(this);
    qDebug()<<"Start";
    for (int i = 0; i < playlist.size(); ++i)
    {
        inputFile.setFileName(playlist.at(i));
        qDebug()<<inputFile.fileName();
        if (!inputFile.open(QIODevice::ReadOnly))
        {
            qDebug()<< "file not found;";
        }
    }
    connect(timer1, SIGNAL(timeout()), this, SLOT(writeDatagrams()));
    timer1->start(5);
}

void MainWindow::writeDatagrams()
{
    if(!inputFile.atEnd()){
        payloadout = inputFile.read(320);
    }
    qDebug()<<payloadout;
    QDataStream out(&datagramout, QIODevice::WriteOnly);
    out.setVersion(QDataStream::Qt_4_7);
    out << qint64(0);
    out << payloadout;
    out.device()->seek(qint64(0));
    out << qint64(datagramout.size() - sizeof(qint64));
    qint64 writtenBytes = udpSocketout->writeDatagram(datagramout, remoteHOST, remotePORT);
    qDebug() << "Sent " << writtenBytes << " bytes.";
}

Here is the receiver and player:

void MainWindow::on_start_rx_triggered()
{
    udpSocketin = new QUdpSocket(this);
    udpSocketin->bind(localHOST, localPORT);
    connect(udpSocketin, SIGNAL(readyRead()),
            this, SLOT(readDatagrams()));
    QDataStream out(&datagramout, QIODevice::WriteOnly);
    out.setVersion(QDataStream::Qt_4_7);
    timer2 =  new QTimer (this);
    connect(timer2, SIGNAL(timeout()), this, SLOT(playbuff()));
    timer2->start(50);
    audioout = new QAudioOutput(format, this);
}

void MainWindow::readDatagrams()
{
    datagramin.resize(udpSocketin->pendingDatagramSize());
    qint64 receiveBytes = udpSocketin->readDatagram(datagramin.data(), datagramin.size());
    qDebug() << "Receive " << receiveBytes << " bytes.";
    QDataStream in(&datagramin, QIODevice::ReadOnly);
    in.setVersion(QDataStream::Qt_4_7);
    quint64 size = 0;
    if(in.device()->size() > sizeof(quint64))
    {
        in >> size;
    }
    else
        return;
    if(in.device()->size() < size)
        return;
    in >> payloadin;
    qDebug() << payloadin.size();
    emit jitterbuff();
}

void MainWindow::jitterbuff()
{
    if (buff_pos < SIZE_OF_BUF)
    {
        QDataStream out(&buffered, QIODevice::WriteOnly);
        out.setVersion(QDataStream::Qt_4_7);
        out << payloadin;
        buff_pos++;
    }
    else
        buff_pos = 0;
}

void MainWindow::playbuff()
{
    qDebug() << "YES!!!";
    buffer = new QBuffer(&buffered);
    buffer->open(QIODevice::ReadOnly);
    audioout->start(buffer);
    QEventLoop loop;
    QTimer::singleShot(50, &loop, SLOT(quit()));
    loop.exec();
    buffer->close();
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T15:32:01+00:00Added an answer on June 4, 2026 at 3:32 pm

    This problem was solved. QAdioOutput has two modes; there are “push” and “pull”. I give a pointer to a QIODevice, and write data directly to this. Solution:

    Reading UDP socket:

    void MainWindow::on_start_rx_triggered()
    {
        udpSocketin = new QUdpSocket(this);
        udpSocketin->bind(localPORT);
        connect(udpSocketin, SIGNAL(readyRead()), this, SLOT(readDatagrams()));
        QDataStream out(&datagramout, QIODevice::WriteOnly);
        out.setVersion(QDataStream::Qt_4_7);
        timer2 = new QTimer (this);
        connect(timer2, SIGNAL(timeout()), this, SLOT(playbuff()));
        timer2->setInterval(15*9);
        audioout = new QAudioOutput(format, this);
        input = audioout->start();
    }
    
    void MainWindow::readDatagrams()
    {
        if (udpSocketin->hasPendingDatagrams()){
        datagramin.resize(udpSocketin->pendingDatagramSize());
        qint64 receiveBytes = udpSocketin->readDatagram(datagramin.data(), datagramin.size());
        if (receiveBytes <= 0)
        {
            msg.warning(this, "File ERROR", "The end!", QMessageBox::Ok);
            emit on_stop_rx_triggered();
        }
        QDataStream in(&datagramin, QIODevice::ReadOnly);
        in.setVersion(QDataStream::Qt_4_7);
        quint64 size = 0;
        if(in.device()->size() > sizeof(quint64))
        {
            in >> size;
        }
        else return;
        in >> rxfilename;
        in >> name;
        in >> payloadin;
        emit jitterbuff();
    }
    
    void MainWindow::jitterbuff()
    {
        if (buff_pos < SIZE_OF_BUF)
        {
            buffered.append(payloadin);
            buff_pos++;
        }
        else
        {
            timer2->start();
            buffered.clear();
            buff_pos = 0;
        }
    }
    
    void MainWindow::playbuff()
    {
        if (!buffered.isEmpty())
        {
            buffer = new QBuffer(&buffered);
            buffer->open(QIODevice::ReadOnly);
            input->write(buffered);
            buffer->close();
        }
    }
    

    Writing to UDP socket:

    void MainWindow::on_start_tx_triggered()
    {
        timer1 = new QTimer (this);
        udpSocketout = new QUdpSocket(this);
        inputFile.setFileName(playlist.at(playIDfile));
        if (!inputFile.open(QIODevice::ReadOnly))
        {
            msg.warning(this, "File ERROR", "File not found!", QMessageBox::Ok);
            return;
        }
        fileinfo = new QFileInfo (inputFile);
        txfilename = fileinfo->fileName();
        ui->playedFile->setText("Now played: " + txfilename);
        connect(timer1, SIGNAL(timeout()), this, SLOT(writeDatagrams()));
        timer1->start(15);
    }
    void  MainWindow::writeDatagrams()
    {
    
        if(!inputFile.atEnd()){
            payloadout = inputFile.read(SIZE_OF_SOUND);
            QDataStream out(&datagramout, QIODevice::WriteOnly);
            out.setVersion(QDataStream::Qt_4_7);
            out << qint64(0);
            out << txfilename;
            out << name;
            out << payloadout;
            out.device()->seek(qint64(0));
            out << qint64(datagramout.size() - sizeof(qint64));
            qint64 writtenBytes = udpSocketout->writeDatagram(datagramout, remoteHOST, remotePORT);
        }
    }
    

    If somebody will have seems problem, I will try to help him/her.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Goal: Add a new file to a remote git repository without checking the whole
Goal Replace one div with another after 5 seconds delay using jQuery. Description I
Goal Pass images generated by one process efficiently and at very high speed to
I am planning on having 3 fragmentlists contained within one activity. The goal is
Goal is to replace 'byebye' with 'Hello ' # START: file.txt contains string byebye
Goal: simple browser app, for navigating files on a web server, in a tree
Goal: Enable closing of the application's window(s) independently without affecting others. The application is
Goal: Show data from server in wxPython GUI on client Newcomer to Twisted. I
Goal: have a single assembler source file which will assemble both to x86 (i386)
GOAL My goal is to find a text file or library that enables me

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.