Real time audio processing with Qt5, general concept



  • Hi,

    I would like to write a small Synthesizer with QT but right now, I don't realy know what the best approach would be.

    What I thought I could do is use the QAudioOutput to "request" new samples from an class via signals and this class then would push new samples in the audio buffer. However, the ability to push samples to the QAudioOutput class must be something, I'vecome up with in my dreams. ;)
    What I basicly need is some mechanic for the application to request new files which I then can process myself.

    What would you suggest? I am realy new to QT and starting with a real time audio application is not the best way to learn QT, I guess. That's why I ask you, so I could at least have the generel concept for the hardest part of this thing.

    Thanks in advance!


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Can you elaborate on what you mean by "real time audio processing" ?

    Also which OS are you targeting ?

    By the way it's Qt, QT stands for Apple QuickTime which in this case could be confusing.



  • "Qt": My bad! ;)

    I basicly want to program a little synthesizer. Like I said, what would be cool is if the program requests samples wich get processed by another libary. This part should be quite easy since there are multiple cool DSP libarys out there.

    I have to work out the details but the Synth should response quite quickly to User imput, I think of a buffer around 100-500 milliseconds for the start.

    So what I had in mind is something like this: (I neve did real time audio stuff before so this is what I came up with and propably totaly unefficient..)

    • the processing-function generates 1 sample at a time which get pushed into the buffer
    • this process is repeated until the buffer is full
    • when the buffer is half empty (for example), it sends a signal to a function which repeats the whole thing

    I am currently targeting windows, however the software I have in mind would work best on mobile devies. The project Is part of a curse in my studies and my prof would like to see the applications run on multiple platforms (esp one mobile)


  • Lifetime Qt Champion

    For such requirements you should rather use a dedicated library like portaudio. You can still to the GUI with Qt, but the Qt audio classes are not designed to do real time audio processing.



  • Hi!

    Isn't Qt suitable for this because there is no "interface" for me to connect or is it more about performance? Not using Qt would realy limit me, I think...

    Thanks for your help. ;)


  • Lifetime Qt Champion

    You can use Qt without any problem, but the audi real time part will require additional libraries like port audio (really easy to integrate by the way)


  • Moderators

    Hi,

    If you want to do real-time processing, you can use

    QAudioInput to acquire PCM samples, OR a 3rd-party decoder to convert your file into PCM samples

    A 3rd-party DSP library to process the samples

    QAudioOutput to play back the processed samples

    See the "Spectrum Example":http://qt-project.org/doc/qt-5/qtmultimedia-spectrum-example.html for some ideas.

    [quote author="RuhigBrauner" date="1396906352"]- the processing-function generates 1 sample at a time which get pushed into the buffer[/quote]You might find that 1 sample at a time is inefficient. Write the buffer in chunks instead (for example, process 512 samples and output 512 samples at a time). Your system's audio backend will have its own internal buffer that is separate from the QAudioOutput buffer.



  • Hi,

    JKSH, thats what I had in mind as well. But right now, I don't realy know how to actually push samples to AudioOutput. I mean, there is no realy way to playback samples other than using files, right? (QIODevice pointer)

    The example is a bit large to start with I think. But it looks like It uses AudioBuffer and AudioOutput in combination, right? But how?

    "1 sample at a time". I just wasn't sure where to collect them before sending them over to the Audio Device. ;)


  • Lifetime Qt Champion

    QtMultimedia uses the OS audio system, which means on Windows it's not realtime (and depending on what you use, you don't get what you asked for). Maybe low-latency would be a better term for this part of the discussion. Thus using something like portaudio which as support of ASIO would be better for the acquisition-playback part.


  • Moderators

    See the QAudioOutput documentation for a shorter example: http://qt-project.org/doc/qt-5/qaudiooutput.html

    The QIODevice is your buffer. You write your samples into the QIODevice, and QAudioOutput will read from it.



  • Hi,

    I noticed this way as well and I guess it would work. I decided to focus on windows for right now and add android support later on. So I am free to use portaudio now and it's way easier than working with QAudioOutput. (At least for my level of knowledge ;) )

    But thanks for the help!



  • Hi,
    I suggest you following library:
    http://audiere.sourceforge.net/home.php
    I already used that library for a synthesizer in a Qt application.
    It is very small, fast and easy to use.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.