The Monitorapo of XAudio2 learning

Source: Internet
Author: User

Monitorapo transmits audio data to the main thread by means of a lock-independent communication channel that is initialized by the application. Add Monitorapo to the source of the previous article, adding two effects to a source voice.

The main use of pipelines is to write the data in the Doprocess function in APO and then read it in the main thread.

#include "DXUTLockFreePipe.h" typedef dxutlockfreepipe<monitor_apo_pipe_len> MONITORAPOPIPE;STRUCT monitorapoparams{    monitorapopipe *pipe;}; Class __declspec (uuid ("{a4945b8a-eb14-4c96-8067-df726b528091}")) Cmonitorapo:public csamplexapobase< Cmonitorapo, Monitorapoparams>{public:    Cmonitorapo ();    ~cmonitorapo ();    void doprocess (const monitorapoparams&, float32* __restrict pData, UINT32 cframes, UINT32 cchannels);};
you need to use the template class Dxutlockfreepipe and the template class Csamplexapobase, which is a pipeline to get the data. The latter is xapo used to accomplish special effects.
Csimpleapo *psimplexapo = NULL; Csimpleapo::createinstance (null, 0, &AMP;PSIMPLEXAPO);//Create Xapo instance Cmonitorapo *pmpnitorapo = null; Cmonitorapo::createinstance (NULL, 0, &pmpnitorapo); Xaudio2_effect_descriptor descriptor[2];//Effect Description, contains a xapo of information descriptor[0]. Initialstate = true;descriptor[0]. Outputchannels = 2;descriptor[0].peffect = dynamic_cast<ixapo*> (Psimplexapo),//cast descriptor[1]. Initialstate = true;descriptor[1]. Outputchannels = 2;descriptor[1].peffect = dynamic_cast<ixapo*> (Pmpnitorapo);//cast Xaudio2_effect_chain echain;//effect chain containing several effects objects echain.effectcount = 2;echain.peffectdescriptors = DESCRIPTOR;HR = psourcevoice-> Seteffectchain (&echain);//Pass the effect chain to Voiceif (FAILED (HR)) return 0; Psimplexapo->release ();//voice takes over this object after it is passed to voice. Prevent external modification to this object, Release Pmpnitorapo->release (); Simpleapoparams simpleparams;//Set Parameter Simpleparams.gain = 1.2F;HR = Psourcevoice->seteffectparameters (0, & Simpleparams, sizeof (simpleapoparams));//Pass settings to Voiceif (FAILED (HR)) return 0; Monitorapoparams monitorparams;monitorparams.pipe = new monitorapopipe;hr = Psourcevoice->seteffectparameters (1, & Monitorparams, sizeof (monitorapoparams));//Pass settings to Voiceif (FAILED (HR)) return 0;

Cmonitorapo is derived from a template class Csamplexapobase, which is located in the file SampleAPOBase.h. The Xapo class and parameter classes are required when instantiating a template class: Apoclass and Parameterclass. A parameter class can be a struct body.

The template class implements the static instantiation function CreateInstance, as well as the lockforprocess and process interface functions. A pure virtual function doprocess is reserved to allow subclasses to implement different requirements.

The process function realizes that if the flag bit of the input buffer is xapo_buffer_silent, the buffer is set to 0. If xapo_buffer_valid, the data is valid, call Doprocess to write the data to the pipeline:

void Cmonitorapo::D oprocess (const monitorapoparams& params, float32* __restrict pData, UINT32 cframes, UINT32 Cchann ELS) {    if (cframes)    {        monitorapopipe* pipe = params.pipe;        if (pipe)            pipe->write (PData, Cframes * cchannels * (Waveformat (). wBitsPerSample >> 3));}    }
where the Beginprocess interface can get the latest parameters set through Seteffectparameters. Xapo can only call this method within the process function.

Endprocess tells Cxapoparametersbase,xapo that the latest parameters for receiving settings have been completed. This method must also be called within the process method.


AC qq:1245178753

This address: http://blog.csdn.net/u011417605/article/details/51202619

SOURCE Download: http://download.csdn.net/detail/u011417605/9497187

The Monitorapo of XAudio2 learning

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.