MGL(Win32)
読み取り中…
検索中…
一致する文字列を見つけられません
mgl_audio_voice.h
[詳解]
1// SPDX-License-Identifier: Zlib
2/* ------------------------------------------------------------------------- */
9/* ------------------------------------------------------------------------- */
10
11#ifndef INCGUARD_MGL_AUDIO_VOICE_H_1610732115
12#define INCGUARD_MGL_AUDIO_VOICE_H_1610732115
13
15#include <mgl/mgl_environment.h>
17
18#include <atomic>
19
20namespace MGL::Audio
21{
23class Voice
24{
25public:
27 enum class Status : uint8_t
28 {
29 None,
30 Loading,
31 Error,
32 Ready,
33 Remove
34 };
35
37 enum class Type : uint8_t
38 {
39 Static,
40 Dynamic
41 };
42
43 /* ------------------------------------------------------------------------- */
49 /* ------------------------------------------------------------------------- */
50 constexpr Voice(VoiceKey key, Type type) noexcept
51 : _key(key)
52 , _type(type)
53 , _status(Status::None)
54 , _volume(1.0f)
55 {
56 }
57
58 virtual ~Voice() noexcept = default;
59
60 /* ------------------------------------------------------------------------- */
66 /* ------------------------------------------------------------------------- */
67 virtual bool Load() noexcept = 0;
68
69 /* ------------------------------------------------------------------------- */
79 /* ------------------------------------------------------------------------- */
80 virtual bool GetSample([[maybe_unused]] float &outDataL, [[maybe_unused]] float &outDataR, [[maybe_unused]] uint32_t trackIndex, [[maybe_unused]] size_t sampleFrame) const noexcept
81 {
82 return false;
83 }
84
85 /* ------------------------------------------------------------------------- */
93 /* ------------------------------------------------------------------------- */
94 virtual bool GetSample([[maybe_unused]] float &outDataL, [[maybe_unused]] float &outDataR) noexcept
95 {
96 return false;
97 }
98
99 /* ------------------------------------------------------------------------- */
107 /* ------------------------------------------------------------------------- */
108 virtual bool Start([[maybe_unused]] uint32_t trackIndex, [[maybe_unused]] LoopType loopType) noexcept
109 {
110 return true;
111 }
112
113 /* ------------------------------------------------------------------------- */
117 /* ------------------------------------------------------------------------- */
118 virtual void Stop() noexcept
119 {
120 }
121
122 /* ------------------------------------------------------------------------- */
128 /* ------------------------------------------------------------------------- */
129 [[nodiscard]] virtual uint32_t GetTotalFrame(uint32_t trackIndex) const noexcept = 0;
130
131 /* ------------------------------------------------------------------------- */
138 /* ------------------------------------------------------------------------- */
139 [[nodiscard]] virtual bool IsLoop(uint32_t trackIndex) const noexcept = 0;
140
141 /* ------------------------------------------------------------------------- */
147 /* ------------------------------------------------------------------------- */
148 [[nodiscard]] virtual uint32_t GetLoopFrame(uint32_t trackIndex) const noexcept = 0;
149
150 /* ------------------------------------------------------------------------- */
155 /* ------------------------------------------------------------------------- */
156 [[nodiscard]] constexpr VoiceKey GetKey() const noexcept
157 {
158 return _key;
159 }
160
161 /* ------------------------------------------------------------------------- */
165 /* ------------------------------------------------------------------------- */
166 void RemoveRequests() noexcept
167 {
168 switch (_status)
169 {
170 case Status::Ready:
171 _status = Status::Remove;
172 break;
173
174 default:
175 break;
176 }
177 }
178
179 /* ------------------------------------------------------------------------- */
184 /* ------------------------------------------------------------------------- */
185 [[nodiscard]] Status GetStatus() const noexcept
186 {
187 return _status;
188 }
189
190 /* ------------------------------------------------------------------------- */
195 /* ------------------------------------------------------------------------- */
196 [[nodiscard]] constexpr Type GetType() const noexcept
197 {
198 return _type;
199 }
200
201 /* ------------------------------------------------------------------------- */
206 /* ------------------------------------------------------------------------- */
207 [[nodiscard]] virtual uint32_t GetTrackCount() const noexcept = 0;
208
209 /* ------------------------------------------------------------------------- */
214 /* ------------------------------------------------------------------------- */
215 void SetVolume(float volume) noexcept
216 {
217 _volume = volume;
218 }
219
220 /* ------------------------------------------------------------------------- */
225 /* ------------------------------------------------------------------------- */
226 [[nodiscard]] float GetVolume() const noexcept
227 {
228 return _volume;
229 }
230
231protected:
232 /* ------------------------------------------------------------------------- */
237 /* ------------------------------------------------------------------------- */
238 void SetStatus(Status status) noexcept
239 {
240 _status = status;
241 }
242
243private:
244 VoiceKey _key;
245 Type _type;
246 std::atomic<Status> _status;
247 std::atomic<float> _volume;
248};
249
251using SharedVoice = std::shared_ptr<Voice>;
252
253} // namespace MGL::Audio
254#endif // INCGUARD_MGL_AUDIO_VOICE_H_1610732115
255
256// vim: et ts=4 sw=4 sts=4
MGL オーディオボイス
Definition mgl_audio_voice.h:24
void SetStatus(Status status) noexcept
ボイスのステータスを設定
Definition mgl_audio_voice.h:238
virtual uint32_t GetTrackCount() const noexcept=0
ボイスが持つトラックの数を取得
virtual uint32_t GetTotalFrame(uint32_t trackIndex) const noexcept=0
ボイスの最大フレーム数を取得
virtual uint32_t GetLoopFrame(uint32_t trackIndex) const noexcept=0
指定したトラックのループフレームを取得
void SetVolume(float volume) noexcept
ボイスのボリュームを設定
Definition mgl_audio_voice.h:215
constexpr Voice(VoiceKey key, Type type) noexcept
コンストラクタ
Definition mgl_audio_voice.h:50
virtual bool Load() noexcept=0
ボイスの読み込み処理
virtual void Stop() noexcept
ボイスの停止処理
Definition mgl_audio_voice.h:118
virtual bool GetSample(float &outDataL, float &outDataR, uint32_t trackIndex, size_t sampleFrame) const noexcept
スタティックボイスのサンプルの取得
Definition mgl_audio_voice.h:80
virtual bool Start(uint32_t trackIndex, LoopType loopType) noexcept
ボイスの開始処理
Definition mgl_audio_voice.h:108
virtual bool GetSample(float &outDataL, float &outDataR) noexcept
ダイナミックボイスのサンプルの取得
Definition mgl_audio_voice.h:94
Type
ボイスのタイプ
Definition mgl_audio_voice.h:38
@ Static
スタティック: 読み込み後は内部状態が変化しない.同時再生可能
@ Dynamic
ダイナミック: 再生中に内部状態が変化する.同時再生不可能.ストリーム再生など
float GetVolume() const noexcept
ボイスのボリュームを取得
Definition mgl_audio_voice.h:226
Status
ボイスの状態
Definition mgl_audio_voice.h:28
@ Remove
削除要求済み
@ Loading
読み込み中
@ None
状態なし(初期状態)
@ Error
エラー発生
virtual bool IsLoop(uint32_t trackIndex) const noexcept=0
指定したトラックのループ設定を取得
constexpr Type GetType() const noexcept
ボイスの種類を取得
Definition mgl_audio_voice.h:196
Status GetStatus() const noexcept
ボイスのステータスを取得
Definition mgl_audio_voice.h:185
void RemoveRequests() noexcept
削除を要求
Definition mgl_audio_voice.h:166
constexpr VoiceKey GetKey() const noexcept
ボイスキーを取得
Definition mgl_audio_voice.h:156
MGL オーディオ関連定義
VoiceKey
ボイスキー
Definition mgl_audio_defs.h:22
LoopType
ループタイプ
Definition mgl_audio_defs.h:71
std::shared_ptr< Voice > SharedVoice
共有ボイスの型
Definition mgl_audio_voice.h:251
MGL 環境定義
MGL STLのメモリ関連の代替