Kiwano Engine v1.2.x
Sound.h
1// Copyright (c) 2016-2018 Kiwano - Nomango
2//
3// Permission is hereby granted, free of charge, to any person obtaining a copy
4// of this software and associated documentation files (the "Software"), to deal
5// in the Software without restriction, including without limitation the rights
6// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7// copies of the Software, and to permit persons to whom the Software is
8// furnished to do so, subject to the following conditions:
9//
10// The above copyright notice and this permission notice shall be included in
11// all copies or substantial portions of the Software.
12//
13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19// THE SOFTWARE.
20
21#pragma once
22#include <kiwano-audio/Transcoder.h>
23#include <kiwano/core/Resource.h>
24#include <kiwano/base/ObjectBase.h>
25#include <kiwano/platform/win32/ComPtr.hpp>
26#include <xaudio2.h>
27
28namespace kiwano
29{
30namespace audio
31{
32class AudioModule;
33
34KGE_DECLARE_SMART_PTR(Sound);
35
45class KGE_API Sound : public ObjectBase
46{
47 friend class AudioModule;
48
49public:
53 Sound(const String& file_path);
54
58 Sound(const Resource& res);
59
60 Sound();
61
62 virtual ~Sound();
63
67 bool Load(const String& file_path);
68
72 bool Load(const Resource& res);
73
76 bool IsValid() const;
77
81 void Play(int loop_count = 0);
82
85 void Pause();
86
89 void Resume();
90
93 void Stop();
94
97 void Close();
98
101 bool IsPlaying() const;
102
105 float GetVolume() const;
106
110 void SetVolume(float volume);
111
112private:
113 IXAudio2SourceVoice* GetXAudio2Voice() const;
114
115 void SetXAudio2Voice(IXAudio2SourceVoice* voice);
116
117private:
118 bool opened_;
119 bool playing_;
120 Transcoder transcoder_;
121 IXAudio2SourceVoice* voice_;
122};
123
126inline IXAudio2SourceVoice* Sound::GetXAudio2Voice() const
127{
128 return voice_;
129}
130
131inline void Sound::SetXAudio2Voice(IXAudio2SourceVoice* voice)
132{
133 voice_ = voice;
134}
135} // namespace audio
136} // namespace kiwano
基础对象
Definition: ObjectBase.h:137
资源
Definition: Resource.h:41
音频模块
Definition: AudioModule.h:50
音频对象
Definition: Sound.h:46
音频解码器
Definition: Transcoder.h:43