JunkBox_Win_Lib 1.5.3
Loading...
Searching...
No Matches
OpenNiAudio.cpp
Go to the documentation of this file.
1
2#include "OpenNiAudio.h"
3
4#if defined(ENABLE_OPENNI) || defined(ENABLE_OPENNI2)
5
6
7using namespace jbxl;
8using namespace jbxwl;
9
10
11// 作成中
12
13
15// COpenNiMedia
16
17COpenNiMedia::COpenNiMedia(void)
18{
19}
20
21
22//
23HRESULT STDMETHODCALLTYPE COpenNiMedia::GetOutputCurrentType(DWORD index, DMO_MEDIA_TYPE *pmt)
24{
25 return S_OK;
26}
27
28
29//
30HRESULT STDMETHODCALLTYPE COpenNiMedia::ProcessOutput(DWORD dwFlags, DWORD oputBufferCount, DMO_OUTPUT_DATA_BUFFER *outputBuffers, DWORD *pdwStatus)
31{
32 return S_OK;
33}
34
35
36//
37HRESULT STDMETHODCALLTYPE COpenNiMedia::SetOutputType(DWORD index, const DMO_MEDIA_TYPE *pmt, DWORD flags)
38{
39 return S_OK;
40}
41
42
43
44
46// COpenNiAudio
47
48//COpenNiAudio::COpenNiAudio(xn::Context* context)
49COpenNiAudio::COpenNiAudio(COpenNiTool* tool)
50{
51 m_audioStream = NULL;
52// m_audioSource = NULL;
53 m_audioMedia = NULL;
54 m_pStream = NULL;
55 m_mediaObj = new COpenNiMedia();
56
57 //
58 if (tool!=NULL) init(tool);
59}
60
61
62
63COpenNiAudio::~COpenNiAudio(void)
64{
65 DEBUG_ERROR("DESTRUCTOR: COpenNiAudio: START\n");
66
67 free();
68
69 DEBUG_ERROR("DESTRUCTOR: COpenNiAudio: END\n");
70}
71
72
73
74BOOL COpenNiAudio::init(COpenNiTool* tool)
75{
76 if (tool==NULL) return FALSE;
77
78 //
79 free();
80 /*
81 XnStatus rc = XN_STATUS_ERROR;
82
83 if (context!=NULL) {
84 m_audioSource = new xn::AudioGenerator();
85 if (m_audioSource!=NULL) {
86 rc = m_audioSource->Create(*context);
87 }
88
89 if (rc==XN_STATUS_OK) {
90 HRESULT hr = m_mediaObj->QueryInterface(IID_IMediaObject, (void**)&m_audioMedia);
91 if (SUCCEEDED(hr)) {
92 BOOL ret = setMediaType();
93 if (ret) {
94 m_audioStream = new CWinAudioStream(m_audioMedia);
95 m_audioStream->QueryInterface(IID_IStream, (void**)&m_pStream);
96 return TRUE;
97 }
98 }
99 }
100 }
101 */
102 return FALSE;
103}
104
105
106
107void COpenNiAudio::free(void)
108{
109 releaseNull(m_pStream);
110 deleteNull (m_audioStream);
111
112 releaseNull(m_audioMedia);
113 deleteNull (m_mediaObj);
114
115// releaseNull(m_audioSource);
116}
117
118
119
120BOOL COpenNiAudio::setMediaType(void)
121{
122 WAVEFORMATEX format = getAudioFormat();
123
124 /*
125 XnWaveOutputMode mt;
126 mt.nSampleRate = format.nSamplesPerSec;
127 mt.nChannels = (XnUInt8)format.nChannels;
128 mt.nBitsPerSample = format.wBitsPerSample;
129
130 XnStatus ret = m_audioSource->SetWaveOutputMode(mt);
131
132 if (ret==XN_STATUS_ERROR) return FALSE;
133 */
134 return TRUE;
135}
136
137
138
139void COpenNiAudio::getAudioData(Buffer* pbuf)
140{
141 if (m_pStream==NULL || pbuf==NULL) return;
142
143 ULONG len = 0;
144
145 m_pStream->Read((void*)pbuf->buf, (ULONG)pbuf->bufsz, &len);
146 pbuf->vldsz = (int)len;
147
148 return;
149}
150
151
152
153WAVEFORMATEX COpenNiAudio::getAudioFormat(void)
154{
155 WORD blockAlign = ((OpenNiAudioBitsPerSample+7)/8)*OpenNiAudioChannels;
156 DWORD avgBytesPerSec = blockAlign*OpenNiAudioSamplesPerSec;
157
158 WAVEFORMATEX format = {
159 OpenNiAudioFormat, OpenNiAudioChannels, OpenNiAudioSamplesPerSec,
160 avgBytesPerSec, blockAlign, OpenNiAudioBitsPerSample, 0
161 };
162 return format;
163}
164
165
166#endif // defined(ENABLE_OPENNI) || defined(ENABLE_OPENNI2)
167
168
169
void deleteNull(T *&ptr)
Definition WinTools.h:229
void releaseNull(T *&ptr)
Definition WinTools.h:220