6#ifdef ENABLE_KINECT_SDK
13CKinectAudio::CKinectAudio(INuiSensor* sensor,
int mode)
18 m_audioProperty = NULL;
22 if (sensor!=NULL) init(sensor, mode);
27CKinectAudio::~CKinectAudio(
void)
29 DEBUG_INFO(
"DESTRUCTOR: CKinectAudio: START\n");
33 DEBUG_INFO(
"DESTRUCTOR: CKinectAudio: END\n");
38BOOL CKinectAudio::init(INuiSensor* sensor,
int mode)
43 HRESULT hr = sensor->NuiGetAudioSource(&m_audioSource);
44 if (SUCCEEDED(hr)) hr = m_audioSource->QueryInterface(IID_IMediaObject, (
void**)&m_audioMedia);
45 if (SUCCEEDED(hr)) hr = m_audioSource->QueryInterface(IID_IPropertyStore, (
void**)&m_audioProperty);
48 BOOL ret = setProperty(mode);
49 if (ret) ret = setMediaType();
52 m_audioStream->QueryInterface(IID_IStream, (
void**)&m_pStream);
62void CKinectAudio::free(
void)
83BOOL CKinectAudio::setProperty(
int mode)
85 if (m_audioProperty==NULL)
return FALSE;
89 PropVariantInit(&prop);
91 prop.lVal = (LONG)mode;
92 m_audioProperty->SetValue(MFPKEY_WMAAECMA_SYSTEM_MODE, prop);
93 PropVariantClear(&prop);
100BOOL CKinectAudio::setMediaType(
void)
102 if (m_audioMedia==NULL)
return FALSE;
104 DMO_MEDIA_TYPE mt = {0};
105 MoInitMediaType(&mt,
sizeof(WAVEFORMATEX));
106 mt.majortype = MEDIATYPE_Audio;
107 mt.subtype = MEDIASUBTYPE_PCM;
109 mt.bFixedSizeSamples = TRUE;
110 mt.bTemporalCompression = FALSE;
111 mt.formattype = FORMAT_WaveFormatEx;
112 memcpy(mt.pbFormat, &getAudioFormat(),
sizeof(WAVEFORMATEX));
114 HRESULT hr = m_audioMedia->SetOutputType(0, &mt, 0);
115 MoFreeMediaType(&mt);
117 if (FAILED(hr))
return FALSE;
123void CKinectAudio::getAudioData(Buffer* pbuf)
125 if (m_pStream==NULL || pbuf==NULL)
return;
129 m_pStream->Read((
void*)pbuf->buf, (ULONG)pbuf->bufsz, &len);
130 pbuf->vldsz = (int)len;
137WAVEFORMATEX CKinectAudio::getAudioFormat(
void)
139 WORD blockAlign = ((KinectAudioBitsPerSample+7)/8)*KinectAudioChannels;
140 DWORD avgBytesPerSec = blockAlign*KinectAudioSamplesPerSec;
142 WAVEFORMATEX format = {
143 KinectAudioFormat, KinectAudioChannels, KinectAudioSamplesPerSec,
144 avgBytesPerSec, blockAlign, KinectAudioBitsPerSample, 0
void releaseNull(T *&ptr)