DirectSound---Capture audio, qml/c++ integrated interaction

Source: Internet
Author: User

Tag: Buffer ref operation object out open Blog Write desc

DirectSound's audio capture principle is similar to the playback principle, which loops through the captured data on a buffer and provides the Notify notification function.

1. Audio capture

Because the capture process and the playback process are similar, we do not repeat here, only simple function references and illustrations are given:

The last two are the sound capture interfaces to control the opening and closing of the AEC (echo cancellation), Noise Fill (Noise fill), Ns (Noise suppression):

HRESULT directsoundcaptureenumerate (lpdsenumcallback lpdsenumcallback,lpvoid lpcontext)
HRESULT DirectSoundCaptureCreate8 (Lpcguid lpcguid, LPDIRECTSOUNDCAPTURE8 * LPLPDSC, Lpunknown punkouter)
Idirectsoundcapture8::getcaps (Lpdsccaps pdsccaps)
HRESULT Idirectsoundcapture8::createcapturebuffer (Lpcdscbufferdesc pcdscbufferdesc, Lpdirectsoundcapturebuffer * Ppdscbuffer, Lpunknown Punkouter)
HRESULT Idirectsoundbuffer8::getobjectinpath (Refguid rguidobject, DWORD dwindex, Refguid rguidinterface, LPVOID * Ppobject)
IDirectSoundCaptureFXAec8
IDirectSoundCaptureFXNoiseSuppress8

The flowchart is as follows:

2. Write to WAV

Write WAV file, we can use Microsoft's own Mmio series functions, but remember not to read and write to their memory location mixed operation, otherwise there will be a variety of brain-free problems.

Hmmio Mmioopen (LPTSTR szfilename, Lpmmioinfo lpmmioinfo, DWORD dwopenflags);
Mmresult Mmiocreatechunk (Hmmio Hmmio, Lpmmckinfo lpck, UINT wflag);
Long Mmiowrite (Hmmio Hmmio, char _huge *pch, long CCH);
Mmresult mmioascend (Hmmio Hmmio, Lpmmckinfo lpck, UINT wflags);
Mmresult Mmioclose (Hmmio Hmmio, UINT wflags);

3. qml/c++ Integrated Interaction

This time I tried to use the QML to draw the interface, how to say: Data binding is really good, many of the only UI layer of mutual logic can be directly in the UI code to solve, do not go deep into the C + + logic code, but the C + + data type conversion to QML is not very convenient, and the type system of the two is not natural (for example, when using C + + type in QML, register is required, too many extra operations).

In QML, it is necessary to use QT's meta-object system for private C + + types, so we need to:

    • inherit from Qobject and bring the Q_object macro.
    • attributes are declared with Q_property.
    • enumerations are described with Q_enum.
    • signals, Slots are supported by default, and other functions need to be declared with q_invokable.

在这个例子中,我需要传给Qml一个设备列表,但是Qml的list在Qt/C++中并没有直接对应的类型,这里需要用到Qt的QVariantList,在C++传给Qml时QVariantList会被直接转换成list。此外i,QVariantMap可以在Qml中可以被隐式转换成JavaScript的Array,但是不是那么自然。

This is probably the case with the example:

class CppDsCapture : public QObject{    Q_OBJECT    Q_PROPERTY(QVariantList avaiableDeviceNames READ avaiableDeviceNames)public:    enum EffectType {        AcousticEchoCancellationMicrosoft,        AcousticEchoCancellationSystem,        NoiseSuppressionMicrosoft,        NoiseSuppressionSystem,        None    };    Q_ENUM(EffectType)    ...    //////////////////////////////////////////////////////////////    //  QML functions    Q_INVOKABLE void    openDevice(unsigned deviceIndex);    ...}
4. Running Results

The complete code is shown in the link.

DirectSound---Capture audio, qml/c++ integrated interaction

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.