This repository has been archived by the owner on Dec 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 225
/
SimplePlay3DSoundXDK.h
108 lines (86 loc) · 4.04 KB
/
SimplePlay3DSoundXDK.h
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
//--------------------------------------------------------------------------------------
// SimplePlay3DSoundXDK.h
//
// Advanced Technology Group (ATG)
// Copyright (C) Microsoft Corporation. All rights reserved.
//--------------------------------------------------------------------------------------
#pragma once
#include "DeviceResources.h"
#include "StepTimer.h"
#include "WAVFileReader.h"
// A basic sample implementation that creates a D3D11 device and
// provides a render loop.
class Sample
{
public:
Sample() noexcept(false);
~Sample() = default;
Sample(Sample&&) = default;
Sample& operator= (Sample&&) = default;
Sample(Sample const&) = delete;
Sample& operator= (Sample const&) = delete;
// Initialization and management
void Initialize(IUnknown* window);
// Basic game loop
void Tick();
// Messages
void OnSuspending();
void OnResuming();
private:
//Audio functions
void SetReverb(int index);
void SetupEnvironment();
void PlayFile(const wchar_t* filename);
void AdjustFront(float value, X3DAUDIO_VECTOR *orientFront, float *angle);
//Draw functions
void XM_CALLCONV DrawGrid(size_t xdivs, size_t ydivs, DirectX::FXMVECTOR color);
void DrawCircle(X3DAUDIO_VECTOR position, float radius);
void XM_CALLCONV DrawEmitter(X3DAUDIO_CONE* cone, X3DAUDIO_VECTOR position, float angle, DirectX::FXMVECTOR color, UINT size);
void XM_CALLCONV DrawListener(X3DAUDIO_VECTOR position, DirectX::FXMVECTOR color);
void Update(DX::StepTimer const& timer);
void Render();
void Clear();
void CreateDeviceDependentResources();
void CreateWindowSizeDependentResources();
// UI resources.
std::unique_ptr<DX::DeviceResources> m_deviceResources;
std::unique_ptr<DirectX::PrimitiveBatch<DirectX::VertexPositionColor>> m_batch;
Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> m_circleTexture;
Microsoft::WRL::ComPtr<ID3D11InputLayout> m_batchInputLayout;
std::unique_ptr<DirectX::CommonStates> m_states;
std::unique_ptr<DirectX::BasicEffect> m_batchEffect;
std::unique_ptr<DirectX::SpriteBatch> m_spriteBatch;
std::unique_ptr<DirectX::SpriteFont> m_font;
std::unique_ptr<DirectX::SpriteFont> m_ctrlFont;
// Rendering loop timer.
DX::StepTimer m_timer;
//XAudio2 interfaces
std::unique_ptr<uint8_t[]> m_waveFile;
Microsoft::WRL::ComPtr<IXAudio2> m_XAudio2;
IXAudio2MasteringVoice* m_masteringVoice;
IXAudio2SourceVoice* m_sourceVoice;
IXAudio2SubmixVoice* m_submixVoice;
Microsoft::WRL::ComPtr<IUnknown> m_reverbEffect;
std::unique_ptr<float[]> m_matrix;
//X3DAudio values
X3DAUDIO_DISTANCE_CURVE_POINT m_volumePoints[10];
X3DAUDIO_DISTANCE_CURVE m_volumeCurve;
X3DAUDIO_DISTANCE_CURVE_POINT m_reverbPoints[10];
X3DAUDIO_DISTANCE_CURVE m_reverbCurve;
X3DAUDIO_HANDLE m_X3DInstance;
X3DAUDIO_LISTENER m_X3DListener;
X3DAUDIO_EMITTER m_X3DEmitter;
X3DAUDIO_DSP_SETTINGS m_X3DDSPSettings;
XAUDIO2_VOICE_DETAILS m_deviceDetails;
X3DAUDIO_CONE m_emitterCone;
// Game state
int m_reverbIndex;
float m_listenerAngle;
float m_emitterAngle;
// Input devices.
std::unique_ptr<DirectX::GamePad> m_gamePad;
DirectX::GamePad::ButtonStateTracker m_gamePadButtons;
bool m_gamepadPresent;
// DirectXTK objects.
std::unique_ptr<DirectX::GraphicsMemory> m_graphicsMemory;
};