0

I'm trying to get an input audio stream recording sample up and running through the WASAPI tools. Here's a link to what I mean: http://msdn.microsoft.com/en-us/library/windows/desktop/dd370800(v=vs.85).aspx

Here's the related code:

#include "InputTest.h"
#include "Audioclient.h"
#include "Mmdeviceapi.h"

void InputTest::TakeInput()
{
HRESULT hr;

//Parameter variables for stream initialization
AUDCLNT_SHAREMODE ShareMode = AUDCLNT_SHAREMODE_SHARED;
DWORD da = 0;
REFERENCE_TIME bufferDuration = 10;
REFERENCE_TIME periodicity = 5;
WAVEFORMATEX pFormat;
LPCGUID AudioSessionGuid = NULL;
GUID guid2 = *AudioSessionGuid;
HRESULT guidError = UuidCreate(&guid2);  //could do some error checking here.    //project ->       properties -> Linker -> Command Line -> Rpctr4.lib

//guid2 now has a generated value
//give ASG the address of the newly generated guid2
AudioSessionGuid = &guid2;


//Instantiate WaveFormat
pFormat.wFormatTag = WAVE_FORMAT_PCM;
pFormat.cbSize = 10;  //extra information sent over stream. Usually ignored in PCM format.

//If wFormatTag is WAVE_FORMAT_PCM, nAvgBytesPerSec must equal nSamplesPerSec × nBlockAlign
pFormat.nAvgBytesPerSec = 0;
pFormat.nSamplesPerSec = 0;
pFormat.nBlockAlign = 0;

pFormat.nChannels = 2;
pFormat.wBitsPerSample = 16; //PCM standard

//Pointer for stored audio stream
IAudioClient *iac = NULL;

//Endpoint device selection
IMMDeviceEnumerator *pEnumerator = NULL;
IMMDevice *pDevice = NULL;

HRESULT de;
de = pEnumerator -> GetDefaultAudioEndpoint(eRender, eConsole, &pDevice);

hr = iac -> IAudioClient::Initialize(ShareMode, da, bufferDuration, periodicity, &pFormat, AudioSessionGuid);
}`

Full error message:

error LNK2019: unresolved external symbol "public: virtual long __stdcall
IAudioClient::Initialize(enum _AUDCLNT_SHAREMODE,unsigned long,__int64,__int64,struct 
tWAVEFORMATEX const *,struct _GUID const *)" (?
Initialize@IAudioClient@@UAGJW4_AUDCLNT_SHAREMODE@@K_J1PBUtWAVEFORMATEX@@PBU_GUID@@@Z) 
referenced in function "public: void __thiscall InputTest::TakeInput(void)" (?
TakeInput@InputTest@@QAEXXZ)

Any suggestions are much appreciated as I am just now going through a good C++ practices book. What's up with this error?

Lkopo
  • 4,798
  • 8
  • 35
  • 60
lonious
  • 676
  • 9
  • 25

1 Answers1

1

Incorrect:

hr = iac -> IAudioClient::Initialize(...

Correct:

hr = iac->Initialize(...

You should be calling virtual method of COM interface pointer here, and not specific function bypassing vtable (see this question for related discussion).

Community
  • 1
  • 1
Roman R.
  • 68,205
  • 6
  • 94
  • 158