MCPcopy Create free account
hub / github.com/OpenNI/OpenNI / play

Function play

Samples/NiAudioSample/NiAudioSample.cpp:64–190  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

62}
63
64XnStatus play(Context& /*context*/, AudioGenerator* aGens, XnUInt32 nNodes)
65{
66 XnStatus nRetVal = XN_STATUS_OK;
67
68#if XN_PLATFORM == XN_PLATFORM_WIN32
69 HWAVEOUT hWaveOut;
70 WAVEHDR* pAudioBuffers;
71 int nAudioNextBuffer;
72
73 if (nNodes > 1)
74 {
75 printf("Warning: only supports playing of a single node. Will play node '%s'.\n", aGens[0].GetName());
76 }
77
78 XnWaveOutputMode waveMode;
79 nRetVal = aGens[0].GetWaveOutputMode(waveMode);
80 CHECK_RC(nRetVal, "Failed getting wave output mode");
81
82 // init wave out
83 WAVEFORMATEX wf;
84 wf.wFormatTag = 0x0001; // PCM
85 wf.nChannels = waveMode.nChannels;
86 wf.nSamplesPerSec = waveMode.nSampleRate;
87 wf.wBitsPerSample = waveMode.nBitsPerSample;
88 wf.nBlockAlign = wf.wBitsPerSample * wf.nChannels / 8;
89 wf.nAvgBytesPerSec = wf.nBlockAlign * wf.nSamplesPerSec;
90 MMRESULT mmRes = waveOutOpen(&hWaveOut, WAVE_MAPPER, &wf, NULL, NULL, CALLBACK_NULL);
91 if (mmRes != MMSYSERR_NOERROR)
92 {
93 printf("Warning: Failed opening wave out device. Audio could not be played!\n");
94 return XN_STATUS_ERROR;
95 }
96
97 // create some wave headers for playing
98 pAudioBuffers = new WAVEHDR[NUMBER_OF_AUDIO_BUFFERS];
99 xnOSMemSet(pAudioBuffers, 0, sizeof(WAVEHDR)*NUMBER_OF_AUDIO_BUFFERS);
100
101 const XnUInt32 nMaxBufferSize = 2 * 1024 * 1024;
102 for (int i = 0; i < NUMBER_OF_AUDIO_BUFFERS; ++i)
103 {
104 pAudioBuffers[i].lpData = new XnChar[nMaxBufferSize];
105 pAudioBuffers[i].dwUser = i;
106 pAudioBuffers[i].dwFlags = WHDR_DONE; // mark this buffer as empty (already played)
107 }
108
109 nAudioNextBuffer = 0;
110
111 printf ("Press any key to exit...\n");
112
113 // drop data till now
114 aGens[0].WaitAndUpdateData();
115
116 while (!xnOSWasKeyboardHit())
117 {
118 // Read audio chunk
119 nRetVal = aGens[0].WaitAndUpdateData();
120 if (nRetVal != XN_STATUS_OK)
121 {

Callers 1

mainFunction · 0.85

Calls 9

xnGetStatusStringFunction · 0.85
GetNameMethod · 0.80
xnOSMemSetFunction · 0.50
xnOSWasKeyboardHitFunction · 0.50
xnOSMemCopyFunction · 0.50
GetWaveOutputModeMethod · 0.45
WaitAndUpdateDataMethod · 0.45
GetDataSizeMethod · 0.45
GetAudioBufferMethod · 0.45

Tested by

no test coverage detected