Skylicht Engine
Loading...
Searching...
No Matches
CDriverXAudio2.h
1/*
2!@
3MIT License
4
5Copyright (c) 2012 - 2019 Skylicht Technology CO., LTD
6
7Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
8(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify,
9merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
10subject to the following conditions:
11
12The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
15INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
17WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19
20This file is part of the "Skylicht Engine".
21https://github.com/skylicht-lab/skylicht-engine
22!#
23*/
24
25#pragma once
26
27#include "SkylichtAudioConfig.h"
28
29#ifdef USE_XAUDIO2
30
31#include <windows.h>
32#include <xaudio2.h>
33#pragma comment(lib,"xaudio2.lib")
34
35#include "CDriverNull.h"
36
37#include "Thread/IThread.h"
38#include "Thread/IMutex.h"
39using namespace Skylicht::System;
40
41namespace Skylicht
42{
43 namespace Audio
44 {
45 //--------------------------------------------------------------------------------------
46 // Callback structure
47 //--------------------------------------------------------------------------------------
48 struct StreamingVoiceContext : public IXAudio2VoiceCallback
49 {
50 STDMETHOD_(void, OnVoiceProcessingPassStart)(UINT32) override
51 {
52 }
53 STDMETHOD_(void, OnVoiceProcessingPassEnd)() override
54 {
55 }
56 STDMETHOD_(void, OnStreamEnd)() override
57 {
58 }
59 STDMETHOD_(void, OnBufferStart)(void*) override
60 {
61 }
62 STDMETHOD_(void, OnBufferEnd)(void*) override
63 {
64 }
65 STDMETHOD_(void, OnLoopEnd)(void*) override
66 {
67 }
68 STDMETHOD_(void, OnVoiceError)(void*, HRESULT) override
69 {
70 }
71
72 HANDLE hBufferEndEvent;
73
74 StreamingVoiceContext()
75 {
76 }
77
78 virtual ~StreamingVoiceContext()
79 {
80 }
81 };
82
83
84 class CDriverXAudio2 :
85 public CDriverNull,
86 public IThreadCallback
87 {
88 protected:
89 IXAudio2* m_xaudio;
90 IXAudio2MasteringVoice* m_masteringVoice;
91
92 StreamingVoiceContext m_voiceContext;
93 IXAudio2SourceVoice* m_sourceVoice;
94
95 public:
96 CDriverXAudio2();
97 virtual ~CDriverXAudio2();
98
99 virtual void init();
100 virtual void shutdown();
101 virtual void suspend();
102 virtual void resume();
103
104 virtual void updateThread();
105 protected:
106 int m_minBufferSize;
107 int m_v5MinLatency;
108 int m_v6MinLatency;
109
110 // Buffer parameters
111 struct SBufferParam
112 {
113 int NumBuffers;
114 int BufferSize;
115 int CurrentBuffer;
116 unsigned char** Buffers;
117
118 // MMSytem parameters
119 // WAVEFORMATEX Waveformat;
120 // WAVEHDR *WaveBlocks; // Objects containing buffer address provided (by reference) to mmsystem.
121
122 IThread* UpdateThread;
123 bool IsThreadRunning;
124 };
125
126 SBufferParam m_output;
127 SBufferParam m_input;
128 };
129 }
130}
131#endif
Definition CDriverNull.h:40
Handles all core audio functionality.
Definition AudioDebugLog.h:31
The foundation for thread and process handling.
Definition CNullMutex.h:32
Everything in the Skylicht Engine. You can start by looking at the topics.
Definition AudioDebugLog.h:29