KDAB on Qt: Implementing an Audio Mixer, Part 2

KDAB on Qt: Implementing an Audio Mixer, Part 2

Recap

In Part 1, we coated PCM audio and superimposing waveforms, and developed an algorithm to mix an arbitrary variety of audio streams into one.

Now we have to use these concepts to complete a full implementation utilizing Qt Multimedia.

Using Qt Multimedia for Audio Device Access

So what do we’d like? Well, we wish to use a single QAudioOutput, which we move an audio system and a supported audio format.

We can get these like this:

const QAudioDeviceInfo &system = QAudioDeviceInfo::defaultOutputDevice();
const QAudioFormat &format = system.most popularFormat();

Let’s assemble our QAudioOutput object utilizing the system and format:

static QAudioOutput audioOutput(system, format);

Now, to make use of it to put in writing information, we have now to name begin on the audio output, passing in a QIODevice *.

Normally we’d use the QIODevice subclass QBuffer for a single audio buffer. But on this case, we wish our personal subclass of QIODevice, so we will mix a number of buffers into one IO system.

We’ll name our subclass MixerStream. This is the place we are going to do our bufferCombine, and preserve our member checklist of streams mStreams.

We will even want one other stream sort for mStreams. For now let’s simply name it DecoderStream, ahead declare it, and fear about its implementation later.

One factor that’s good to know at this level is DecoderStream objects will get the information buffers we’d like by decoding audio information from a file. Because of this, we’ll have to preserve our audio format from above to as an information member mFormat. Then we will move it to decoders once they want it.

Implementing MixerStream

Since we’re subclassing QIODevice, we have to present reimplementations for these two protected digital capabilities:

digital qint64 QIODevice::readData(char *information, qint64 maxSize);
digital qint64 QIODevice::writeData(const char *information, qint64 maxSize);

We additionally wish to present a solution to open new streams that we’ll add to mStreams, given a filename. We’ll name this perform openStream. We can even enable looping a stream a number of occasions, so let’s add a parameter for that and provides it a default worth of 1.

Additionally, we’ll want a user-defined destructor to delete any pointers within the checklist that may stay if the MixerStream is abruptly destructed.

// mixerstream.h

#pragma as soon as

#embody 

HI-FI News

through Planet Qt http://planet.qt.io

September 19, 2024 at 10:03AM