Results 1 to 3 of 3

Thread: Real time audio processing

  1. #1
    Join Date
    Sep 2011
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows Symbian S60

    Default Real time audio processing

    I want to do the arithmetic mean of values of a buffer which I wanna to fill with QAudioInput.

    I declare these objects:
    Qt Code:
    1. QAudioFormat audioformat;
    2. QAudioInput *input;
    3. QIODevice *intermediario;
    4. QByteArray buffer;
    To copy to clipboard, switch view to plain text mode 

    I wrote this function for formatting audioformat:
    Qt Code:
    1. void formatta_audio (QAudioFormat *formato)
    2. {
    3. formato->setFrequency(1000);
    4. formato->setSampleSize(8);
    5. formato->setCodec("audio/pcm");
    6. formato->setByteOrder(QAudioFormat::LittleEndian);
    7. formato->setSampleType(QAudioFormat::UnSignedInt);
    8. formato->setChannels(1);
    9. }
    To copy to clipboard, switch view to plain text mode 

    In the MainWindow costructor I wrote this:
    Qt Code:
    1. QAudioDeviceInfo info = QAudioDeviceInfo::defaultInputDevice();
    2.  
    3. formatta_audio(&audioformat);
    4.  
    5. if (!info.isFormatSupported(audioformat))
    6. audioformat = info.nearestFormat(audioformat);
    7.  
    8. input= new QAudioInput (audioformat);
    9.  
    10. ui->setupUi(this);
    To copy to clipboard, switch view to plain text mode 

    I start the QaudioInput in this way:
    Qt Code:
    1. intermediario = input->start();
    2. connect (intermediario,SIGNAL(readyRead()),this,SLOT(cattura()));
    To copy to clipboard, switch view to plain text mode 

    And stop the QaudioInput in this way:
    Qt Code:
    1. input->stop();
    To copy to clipboard, switch view to plain text mode 

    "cattura()" function is this:
    Qt Code:
    1. void MainWindow::cattura()
    2. {
    3.  
    4. qint64 Nbytesletti;
    5. qint64 i;
    6. qint64 media=0;
    7. qint64 bytescatturati;
    8.  
    9.  
    10. bytescatturati= intermediario->bytesAvailable();
    11.  
    12. if (bytescatturati>0)
    13. {
    14.  
    15. Nbytesletti= intermediario->read(buffer.data(),bytescatturati);
    16.  
    17. for (i=0;i<Nbytesletti;i++)
    18. {
    19. media+=(qint64)buffer.at(i);
    20. }
    21.  
    22. media/=Nbytesletti;
    23.  
    24. ui->label->setText(QString("%1").arg(media));
    25. }
    26.  
    27.  
    28. }
    To copy to clipboard, switch view to plain text mode 

    I've tried a lot of times but "intermediario->bytesAvailable()" return ever "0"

    Why? What is the problem?

  2. #2
    Join Date
    Sep 2011
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows Symbian S60

    Default Re: Real time audio processing

    nobody can hellp me?

  3. #3
    Join Date
    Nov 2011
    Location
    Poland
    Posts
    17
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Real time audio processing

    In fact QAudioInput is little unpredictable.
    bytesAvaiable() returns 0, bytesRead() will give You some "positive" value.
    but only Nbytesletti returns by read() gives true bytes number, usualy much biger than byteaRead
    and completely ignores buffer size and second parameter in read() method.

    Don't give up :-)

Similar Threads

  1. new AudioEffect | processing pcm audio data
    By lebeg in forum Qt Programming
    Replies: 1
    Last Post: 20th July 2011, 19:40
  2. Real time QT application?
    By marc2050 in forum Newbie
    Replies: 1
    Last Post: 8th June 2011, 07:08
  3. QaudioOutput play buffer audio real time disconnect network ?
    By Thành Viên Mới in forum Qt Programming
    Replies: 1
    Last Post: 10th May 2011, 13:20
  4. Real time rendering
    By kaszewczyk in forum Newbie
    Replies: 1
    Last Post: 7th July 2010, 18:26
  5. real time plotting
    By gyre in forum Qwt
    Replies: 4
    Last Post: 11th December 2007, 17:13

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.