forked from avin2/SensorKinect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathXnSensorAudioGenerator.cpp
191 lines (155 loc) · 6.75 KB
/
XnSensorAudioGenerator.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/*****************************************************************************
* *
* PrimeSense Sensor 5.0 Alpha *
* Copyright (C) 2010 PrimeSense Ltd. *
* *
* This file is part of PrimeSense Common. *
* *
* PrimeSense Sensor is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as published *
* by the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* PrimeSense Sensor is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with PrimeSense Sensor. If not, see <http://www.gnu.org/licenses/>. *
* *
*****************************************************************************/
//---------------------------------------------------------------------------
// Includes
//---------------------------------------------------------------------------
#include "XnSensorAudioGenerator.h"
//---------------------------------------------------------------------------
// XnSensorAudioGenerator class
//---------------------------------------------------------------------------
XnSensorAudioGenerator::XnSensorAudioGenerator(xn::Context& context, xn::Device& sensor, XnDeviceBase* pSensor, const XnChar* strStreamName) :
XnSensorGenerator(context, sensor, pSensor, strStreamName)
{
}
XnStatus XnSensorAudioGenerator::Init()
{
XnStatus nRetVal = XN_STATUS_OK;
nRetVal = XnSensorGenerator::Init();
XN_IS_STATUS_OK(nRetVal);
// create supported modes list
XnUInt8 aSupportedChannels[] = { 1, 2 };
XnUInt32 nSupportedChannels = sizeof(aSupportedChannels)/sizeof(XnUInt8);
XnUInt16 aSupportedBitsPerSample[] = { 16 };
XnUInt32 nSupportedBitsPerSample = sizeof(aSupportedBitsPerSample)/sizeof(XnUInt16);
XnUInt32 aSupportedSampleRates[] =
{
XN_SAMPLE_RATE_8K,
XN_SAMPLE_RATE_11K,
XN_SAMPLE_RATE_12K,
XN_SAMPLE_RATE_16K,
XN_SAMPLE_RATE_22K,
XN_SAMPLE_RATE_24K,
XN_SAMPLE_RATE_32K,
XN_SAMPLE_RATE_44K,
XN_SAMPLE_RATE_48K,
};
XnUInt32 nSupportedSampleRates = sizeof(aSupportedSampleRates)/sizeof(XnUInt32);
for (XnUInt iChannel = 0; iChannel < nSupportedChannels; ++iChannel)
{
for (XnUInt iBitsPerSample = 0; iBitsPerSample < nSupportedBitsPerSample; ++iBitsPerSample)
{
for (XnUInt iSampleRate = 0; iSampleRate < nSupportedSampleRates; ++iSampleRate)
{
XnWaveOutputMode Mode;
Mode.nChannels = aSupportedChannels[iChannel];
Mode.nBitsPerSample = aSupportedBitsPerSample[iBitsPerSample];
Mode.nSampleRate = aSupportedSampleRates[iSampleRate];
nRetVal = m_SupportedModes.AddLast(Mode);
XN_IS_STATUS_OK(nRetVal);
}
}
}
return (XN_STATUS_OK);
}
XnBool XnSensorAudioGenerator::IsCapabilitySupported(const XnChar* strCapabilityName)
{
return FALSE;
}
XnUChar* XnSensorAudioGenerator::GetAudioBuffer()
{
return (XnUChar*)m_pStreamData->pData;
}
XnUInt32 XnSensorAudioGenerator::GetSupportedWaveOutputModesCount()
{
return m_SupportedModes.Size();
}
XnStatus XnSensorAudioGenerator::GetSupportedWaveOutputModes(XnWaveOutputMode aSupportedModes[], XnUInt32& nCount)
{
XnStatus nRetVal = XN_STATUS_OK;
XN_VALIDATE_INPUT_PTR(aSupportedModes);
if (nCount < m_SupportedModes.Size())
{
return XN_STATUS_OUTPUT_BUFFER_OVERFLOW;
}
XnUInt32 i = 0;
for (XnWaveOutputModeList::Iterator it = m_SupportedModes.begin(); it != m_SupportedModes.end(); ++it, ++i)
{
aSupportedModes[i] = *it;
}
nCount = m_SupportedModes.Size();
return (XN_STATUS_OK);
}
XnStatus XnSensorAudioGenerator::SetWaveOutputMode(const XnWaveOutputMode& OutputMode)
{
XnStatus nRetVal = XN_STATUS_OK;
if (OutputMode.nBitsPerSample != 16)
{
return XN_STATUS_INVALID_OPERATION;
}
XN_PROPERTY_SET_CREATE_ON_STACK(props);
XnPropertySetAddModule(&props, m_strModule);
XnPropertySetAddIntProperty(&props, m_strModule, XN_STREAM_PROPERTY_SAMPLE_RATE, OutputMode.nSampleRate);
XnPropertySetAddIntProperty(&props, m_strModule, XN_STREAM_PROPERTY_NUMBER_OF_CHANNELS, OutputMode.nChannels);
nRetVal = m_pSensor->BatchConfig(&props);
XN_IS_STATUS_OK(nRetVal);
return (XN_STATUS_OK);
}
XnStatus XnSensorAudioGenerator::GetWaveOutputMode(XnWaveOutputMode& OutputMode)
{
XnUInt64 nValue;
OutputMode.nBitsPerSample = 16;
m_pSensor->GetProperty(m_strModule, XN_STREAM_PROPERTY_SAMPLE_RATE, &nValue);
OutputMode.nSampleRate = (XnUInt32)nValue;
m_pSensor->GetProperty(m_strModule, XN_STREAM_PROPERTY_NUMBER_OF_CHANNELS, &nValue);
OutputMode.nChannels = (XnUInt8)nValue;
return (XN_STATUS_OK);
}
XnStatus XnSensorAudioGenerator::RegisterToWaveOutputModeChanges(XnModuleStateChangedHandler handler, void* pCookie, XnCallbackHandle& hCallback)
{
const XnChar* aProps[] =
{
XN_STREAM_PROPERTY_SAMPLE_RATE,
XN_STREAM_PROPERTY_NUMBER_OF_CHANNELS,
NULL
};
return RegisterToProps(handler, pCookie, hCallback, aProps);
}
void XnSensorAudioGenerator::UnregisterFromWaveOutputModeChanges(XnCallbackHandle hCallback)
{
UnregisterFromProps(hCallback);
}
void XnSensorAudioGenerator::FilterProperties(XnActualPropertiesHash* pHash)
{
XnSensorGenerator::FilterProperties(pHash);
pHash->Remove(XN_STREAM_PROPERTY_SAMPLE_RATE);
pHash->Remove(XN_STREAM_PROPERTY_NUMBER_OF_CHANNELS);
}
//---------------------------------------------------------------------------
// XnExportedSensorAudioGenerator class
//---------------------------------------------------------------------------
XnExportedSensorAudioGenerator::XnExportedSensorAudioGenerator() :
XnExportedSensorGenerator(XN_NODE_TYPE_AUDIO, XN_STREAM_TYPE_AUDIO, FALSE)
{}
XnSensorGenerator* XnExportedSensorAudioGenerator::CreateGenerator(xn::Context& context, xn::Device& sensor, XnDeviceBase* pSensor, const XnChar* strStreamName)
{
return XN_NEW(XnSensorAudioGenerator, context, sensor, pSensor, strStreamName);
}