MGL(Win32)
読み取り中…
検索中…
一致する文字列を見つけられません
mgl_audio_source_instance.h
[詳解]
1// SPDX-License-Identifier: Zlib
2/* ------------------------------------------------------------------------- */
9/* ------------------------------------------------------------------------- */
10
11#ifndef INCGUARD_MGL_AUDIO_SOURCE_INSTANCE_H_1610735558
12#define INCGUARD_MGL_AUDIO_SOURCE_INSTANCE_H_1610735558
13
14#include <atomic>
15
18#include <mgl/mgl_environment.h>
19
20namespace MGL::Audio
21{
24{
25public:
26 /* ------------------------------------------------------------------------- */
32 /* ------------------------------------------------------------------------- */
33 SourceInstance(SharedVoice &voice, bool isAutoRemove) noexcept;
34
35 /* ------------------------------------------------------------------------- */
39 /* ------------------------------------------------------------------------- */
40 ~SourceInstance() noexcept
41 {
42 _voice->Stop();
43 }
44
45 bool Play(uint32_t trackIndex, LoopType loopType, float volume) noexcept;
46 bool Update(float &outDataL, float &outDataR) noexcept;
47
48 /* ------------------------------------------------------------------------- */
53 /* ------------------------------------------------------------------------- */
54 void Pause(bool isEnabled) noexcept
55 {
56 _isPaused = isEnabled;
57 }
58
59 /* ------------------------------------------------------------------------- */
65 /* ------------------------------------------------------------------------- */
66 bool IsPaused() const noexcept
67 {
68 return _isPaused;
69 }
70
71 /* ------------------------------------------------------------------------- */
75 /* ------------------------------------------------------------------------- */
76 void Remove() noexcept
77 {
78 const std::lock_guard<std::mutex> lock(_mutex);
79
80 _status = Status::Remove;
81 }
82
83 /* ------------------------------------------------------------------------- */
89 /* ------------------------------------------------------------------------- */
90 void SetVolume(float volume) noexcept
91 {
92 const std::lock_guard<std::mutex> lock(_mutex);
93
94 _fade.Cancel();
95 _volume = volume;
96 }
97
98 /* ------------------------------------------------------------------------- */
107 /* ------------------------------------------------------------------------- */
108 void SetVolume(float volume, float fadeTimeSec, float samplesPerSec, bool isAutoStop) noexcept
109 {
110 const std::lock_guard<std::mutex> lock(_mutex);
111
112 _fade.Start(_volume, volume, fadeTimeSec, samplesPerSec, isAutoStop);
113 }
114
115 /* ------------------------------------------------------------------------- */
120 /* ------------------------------------------------------------------------- */
121 float GetVolume() const noexcept
122 {
123 return _volume;
124 }
125
126 /* ------------------------------------------------------------------------- */
132 /* ------------------------------------------------------------------------- */
133 bool IsPlaying() const noexcept
134 {
135 return _status == Status::Play;
136 }
137
138 /* ------------------------------------------------------------------------- */
144 /* ------------------------------------------------------------------------- */
145 constexpr bool IsFading() const noexcept
146 {
147 return _fade.IsActive();
148 }
149
150 /* ------------------------------------------------------------------------- */
155 /* ------------------------------------------------------------------------- */
156 void SetAutoRemove(bool isEnabled) noexcept
157 {
158 _isAutoRemove = isEnabled;
159 }
160
161private:
162 SharedVoice _voice;
163
164 uint32_t _trackIndex{0};
165 size_t _currentFrame{0};
166 std::atomic<LoopType> _loopType{LoopType::ResourceDefault};
167
168 std::atomic<bool> _isAutoRemove;
169 std::atomic<bool> _isPaused{false};
170 std::atomic<float> _volume{0.0f};
171
173 enum class Status : uint8_t
174 {
175 Standby,
176 Play,
177 Remove
178 };
179 std::atomic<Status> _status{Status::Standby};
180
181 Fade _fade;
182
183 std::mutex _mutex;
184};
185
187using SharedSourceInstance = std::shared_ptr<SourceInstance>;
188
190using WeakSourceInstance = std::weak_ptr<SourceInstance>;
191
192} // namespace MGL::Audio
193
194#endif // INCGUARD_MGL_AUDIO_SOURCE_INSTANCE_H_1610735558
195
196// vim: et ts=4 sw=4 sts=4
void Cancel() noexcept
キャンセル
Definition mgl_audio_fade.cc:83
void Start(float currentVolume, float targetVolume, float fadeTimeSec, float samplesPerSec, bool isAutoStop) noexcept
開始
Definition mgl_audio_fade.cc:27
constexpr bool IsActive() const noexcept
有効状態を取得
Definition mgl_audio_fade.h:36
MGL オーディオソースインスタンス
Definition mgl_audio_source_instance.h:24
bool Play(uint32_t trackIndex, LoopType loopType, float volume) noexcept
再生開始
Definition mgl_audio_source_instance.cc:37
void SetAutoRemove(bool isEnabled) noexcept
再生終了後に自動で削除するかの設定
Definition mgl_audio_source_instance.h:156
~SourceInstance() noexcept
デストラクタ
Definition mgl_audio_source_instance.h:40
bool Update(float &outDataL, float &outDataR) noexcept
ソースの更新処理
Definition mgl_audio_source_instance.cc:91
bool IsPlaying() const noexcept
再生中かどうかを取得
Definition mgl_audio_source_instance.h:133
SourceInstance(SharedVoice &voice, bool isAutoRemove) noexcept
コンストラクタ
Definition mgl_audio_source_instance.cc:20
bool IsPaused() const noexcept
一時停止の状態を取得
Definition mgl_audio_source_instance.h:66
constexpr bool IsFading() const noexcept
フェード中かどうかを取得
Definition mgl_audio_source_instance.h:145
float GetVolume() const noexcept
音量を取得
Definition mgl_audio_source_instance.h:121
void SetVolume(float volume) noexcept
音量の設定
Definition mgl_audio_source_instance.h:90
void Pause(bool isEnabled) noexcept
一時停止
Definition mgl_audio_source_instance.h:54
void SetVolume(float volume, float fadeTimeSec, float samplesPerSec, bool isAutoStop) noexcept
変化時間を指定して音量を設定
Definition mgl_audio_source_instance.h:108
void Remove() noexcept
削除要求
Definition mgl_audio_source_instance.h:76
LoopType
ループタイプ
Definition mgl_audio_defs.h:71
MGL フェード処理
std::weak_ptr< SourceInstance > WeakSourceInstance
弱参照のソースインスタンス
Definition mgl_audio_source_instance.h:190
std::shared_ptr< SourceInstance > SharedSourceInstance
共有ソースインスタンス
Definition mgl_audio_source_instance.h:187
MGL オーディオボイス
std::shared_ptr< Voice > SharedVoice
共有ボイスの型
Definition mgl_audio_voice.h:251
MGL 環境定義