E2113 Virtual function XAudio2

This is the forum for miscellaneous technical/programming questions.

Moderator: 2ffat

Post Reply
mark_c
BCBJ Master
BCBJ Master
Posts: 263
Joined: Thu Jun 21, 2012 1:13 am

E2113 Virtual function XAudio2

Post by mark_c »

hello, to manage XAudio I am implementing an interface following the Microsoft specifications. When I compile though, I get the following error message which I can't explain to myself.
[bcc32 Error] callback.h(9): E2113 Virtual function 'MyVoiceCallback::OnStreamEnd()' conflicts with base class 'IXAudio2VoiceCallback'
Full parser context
Unit1.cpp(17): #include tools\callback.h
callback.h(1): class MyVoiceCallback
I am using
Embarcadero® C ++ Builder 10.2 Version 25.0.27659.1188
Copyright © 2017 Embarcadero Technologies, Inc. All Rights Reserved.

I also read the following link but I have not solved the problem

http://docwiki.embarcadero.com/RADStudi ... _(C%2B%2B)
rlebeau
BCBJ Author
BCBJ Author
Posts: 1759
Joined: Wed Jun 01, 2005 3:21 am
Location: California, USA
Contact:

Re: E2113 Virtual function XAudio2

Post by rlebeau »

mark_c wrote: Mon Nov 30, 2020 1:09 pm hello, to manage XAudio I am implementing an interface following the Microsoft specifications. When I compile though, I get the following error message which I can't explain to myself.
The error, and that descriptive webpage for it, are pretty self-explanatory on this matter. The declaration of your MyVoiceCallback::OnStreamEnd() method does not EXACTLY match the declaration of the IXAudio2VoiceCallback::OnStreamEnd() method.

But you have not shown your actual code, so we can't tell you what you are doing wrong with it.
Remy Lebeau (TeamB)
Lebeau Software
mark_c
BCBJ Master
BCBJ Master
Posts: 263
Joined: Thu Jun 21, 2012 1:13 am

Re: E2113 Virtual function XAudio2

Post by mark_c »

sorry

https://docs.microsoft.com/en-us/window ... -callbacks

Code: Select all

class MyVoiceCallback : public IXAudio2VoiceCallback
{
public:
    HANDLE hBufferEndEvent;
	MyVoiceCallback(): hBufferEndEvent( CreateEvent( NULL, FALSE, FALSE, NULL ) ){}
    ~MyVoiceCallback(){ CloseHandle( hBufferEndEvent ); }

	//Called when the voice has just finished playing a contiguous audio stream.
	void OnStreamEnd() { SetEvent( hBufferEndEvent ); }

    //Unused methods are stubs
	void OnBufferEnd(void * pBufferContext)    { }
	void OnBufferStart(void * pBufferContext) {    }
	void OnLoopEnd(void * pBufferContext) {    }
	void OnVoiceError(void *pBufferContext, HRESULT Error) { }
	void OnVoiceProcessingPassEnd() { }
	void OnVoiceProcessingPassStart(UINT32 SamplesRequired) {    }
};
xaudio2.h

Code: Select all

#undef INTERFACE
#define INTERFACE IXAudio2VoiceCallback
DECLARE_INTERFACE(IXAudio2VoiceCallback)
{
    // Called just before this voice's processing pass begins.
    STDMETHOD_(void, OnVoiceProcessingPassStart) (THIS_ UINT32 BytesRequired) PURE;

    // Called just after this voice's processing pass ends.
    STDMETHOD_(void, OnVoiceProcessingPassEnd) (THIS) PURE;

    // Called when this voice has just finished playing a buffer stream
    // (as marked with the XAUDIO2_END_OF_STREAM flag on the last buffer).
    STDMETHOD_(void, OnStreamEnd) (THIS) PURE;

    // Called when this voice is about to start processing a new buffer.
    STDMETHOD_(void, OnBufferStart) (THIS_ void* pBufferContext) PURE;

    // Called when this voice has just finished processing a buffer.
    // The buffer can now be reused or destroyed.
    STDMETHOD_(void, OnBufferEnd) (THIS_ void* pBufferContext) PURE;

    // Called when this voice has just reached the end position of a loop.
    STDMETHOD_(void, OnLoopEnd) (THIS_ void* pBufferContext) PURE;

    // Called in the event of a critical error during voice processing,
    // such as a failing xAPO or an error from the hardware XMA decoder.
    // The voice may have to be destroyed and re-created to recover from
    // the error.  The callback arguments report which buffer was being
    // processed when the error occurred, and its HRESULT code.
    STDMETHOD_(void, OnVoiceError) (THIS_ void* pBufferContext, HRESULT Error) PURE;
};
rlebeau
BCBJ Author
BCBJ Author
Posts: 1759
Joined: Wed Jun 01, 2005 3:21 am
Location: California, USA
Contact:

Re: E2113 Virtual function XAudio2

Post by rlebeau »

All of your callback methods are missing the __stdcall calling convention. That is why they are not overriding the IXAudio2VoiceCallback methods correctly. For example, this declaration:

STDMETHOD_(void, OnStreamEnd) (THIS) PURE;

Gets expanded to this:

virtual void __stdcall OnStreamEnd() = 0;

You could simply add in the missing __stdcall by hand, eg:

Code: Select all

class MyVoiceCallback : public IXAudio2VoiceCallback
{
public:
	HANDLE hBufferEndEvent;
	MyVoiceCallback(): hBufferEndEvent( CreateEvent( NULL, FALSE, FALSE, NULL ) ){}
	~MyVoiceCallback(){ CloseHandle( hBufferEndEvent ); }

	//Called when the voice has just finished playing a contiguous audio stream.
	void __stdcall OnStreamEnd() { SetEvent( hBufferEndEvent ); }

	//Unused methods are stubs
	void __stdcall OnBufferEnd(void * pBufferContext)    { }
	void __stdcall OnBufferStart(void * pBufferContext) {    }
	void __stdcall OnLoopEnd(void * pBufferContext) {    }
	void __stdcall OnVoiceError(void *pBufferContext, HRESULT Error) { }
	void __stdcall OnVoiceProcessingPassEnd() { }
	void __stdcall OnVoiceProcessingPassStart(UINT32 SamplesRequired) {    }
};
But, consider using the STDMETHODIMP_() macro instead, to match xaudio2.h's use of the STDMETHOD_() macro, eg:

Code: Select all

class MyVoiceCallback : public IXAudio2VoiceCallback
{
public:
	HANDLE hBufferEndEvent;
	MyVoiceCallback(): hBufferEndEvent( CreateEvent( NULL, FALSE, FALSE, NULL ) ){}
	~MyVoiceCallback(){ CloseHandle( hBufferEndEvent ); }

	//Called when the voice has just finished playing a contiguous audio stream.
	STDMETHODIMP_(void) OnStreamEnd() { SetEvent( hBufferEndEvent ); }

	//Unused methods are stubs
	STDMETHODIMP_(void) OnBufferEnd(void * pBufferContext)    { }
	STDMETHODIMP_(void) OnBufferStart(void * pBufferContext) {    }
	STDMETHODIMP_(void) OnLoopEnd(void * pBufferContext) {    }
	STDMETHODIMP_(void) OnVoiceError(void *pBufferContext, HRESULT Error) { }
	STDMETHODIMP_(void) OnVoiceProcessingPassEnd() { }
	STDMETHODIMP_(void) OnVoiceProcessingPassStart(UINT32 SamplesRequired) {    }
};
See:

The macros for declaring and implementing COM interfaces

Defining COM Interfaces Using Standard COM Macros
Remy Lebeau (TeamB)
Lebeau Software
mark_c
BCBJ Master
BCBJ Master
Posts: 263
Joined: Thu Jun 21, 2012 1:13 am

Re: E2113 Virtual function XAudio2

Post by mark_c »

thanks Remy
Post Reply