The Simpleapo of XAudio2 learning

Source: Internet
Author: User

Simpleapo applies a simple gain factor to the audio data by multiplying it with the processed sample data. With the example in the DirectX SDK, I split the instances into separate instructions and separated the code.
struct simpleapoparams{    float gain;}; Class __declspec (uuid ("{5EB8D611-FF96-429D-8365-2DDF89A7C1CD}")) Csimpleapo:public Csamplexapobase<csimpleapo, Simpleapoparams>{public:    Csimpleapo ();    ~csimpleapo ();    void doprocess (const simpleapoparams&, float32* __restrict pData, UINT32 cframes, UINT32 cchannels);};

Csimpleapo 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 lockforprocess function simply gets the format:

memcpy (&M_WFX, Pinputlockedparameters[0].pformat, sizeof (WAVEFORMATEX));
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 gain the data:

 parameterclass* Pparams;    Pparams = (parameterclass*) beginprocess (); if (Pinputprocessparameters[0]. Bufferflags = = xapo_buffer_silent) {memset (pinputprocessparameters[0].pbuffer, 0, Pinputproces Sparameters[0].        Validframecount * m_wfx.nchannels * sizeof (FLOAT32)); Doprocess (*pparams, (float32* __restrict) Pinputprocessparameters[0].pbuffer, Pinputproce Ssparameters[0].    Validframecount, M_wfx.nchannels); } else if (Pinputprocessparameters[0]. Bufferflags = = xapo_buffer_valid) {doprocess (*pparams, (float32* __restrict) Pinputproce Ssparameters[0].pbuffer, Pinputprocessparameters[0].    Validframecount, M_wfx.nchannels); } endprocess (); 
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/51201686

Sample code Download: http://download.csdn.net/detail/u011417605/9497124

XAudio2 Learning Simpleapo

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.