Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Multichannel audio output with QAudioOutput Class



  • Hi all,

    I am a student of electronics and mechatronics engineering and currently working on an audio project. I build a 8-channel linear speaker array as a demonstrator for speaker beamforming. I have a multichannel soundcard to handle the signal output and the input for the amplifiers.

    It's the first time I'm using Qt (on a windows system with Qt Creator), but I managed to write a working testcode. This small app outputs a simple sinewave via the QAudioOutput Class.

    As the next step, I want to output sinewaves on multiple channels at the same time.
    I red the documentation of the QAudioOutput Class, but there is just a section for setting the channel count. I didn't find any info on how to pass the multichannel buffer to the output device.

    Is it possible to use a multidimensional data array to store the data points of the sinewave in (e.g. first row of data is channel 1, second row is channel 2 and so on)?
    Or is it possible to concatenate multiple QByteArrays to one multidimensional buffer?

    Thank you.
    Kind regards, Markus.


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    What about writing to the QIODevice returned by the start method ?



  • Hi, I am back at the project again.

    What about writing to the QIODevice returned by the start method ?
    

    Yes thats how I do it. See reduced code below.

    //set audio output format unsing QAudioFormat
    //...
    //QBuffer with sine data (stored in ByteArray)
    QBuffer* input = new QBuffer(byteBuffer);
    input->open(QIODevice::ReadOnly);
    // Create an audio output with our QAudioFormat
    QAudioOutput* audio = new QAudioOutput(audioFormat, this);
    //play audio
    audio->start(input);

    The question is: if I use more than one channel, in which format do I have to send the data respectively how do I have to store multichannel data in a ByteArray?
    Is it possible to use a ByteArray for each audio channel or use a multidimensional array for the channels?
    Or do I have to concatenate the multichannel data like sample1_ch1 - sample1_ch2 - sample1_ch3 ....sample_n-ch_m in a single dimensional array?

    Thanks for your help.
    Kind regards.


  • Lifetime Qt Champion

    You should interleave the audio data as required by the number of channels.


Log in to reply