Real time audio processing with Qt5, general concept
-
"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)
-
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. ;)
-
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)
-
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. ;)
-
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.
-
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.