MGL(Win32)
読み取り中…
検索中…
一致する文字列を見つけられません
mgl_audio_wave_loader.h
[詳解]
1// SPDX-License-Identifier: Zlib
2/* ------------------------------------------------------------------------- */
9/* ------------------------------------------------------------------------- */
10
11#ifndef INCGUARD_MGL_AUDIO_WAVE_LOADER_H_1611731366
12#define INCGUARD_MGL_AUDIO_WAVE_LOADER_H_1611731366
13
15
16namespace MGL::Audio
17{
20{
21public:
23 struct Format
24 {
25 uint16_t type;
26 uint16_t channelCount;
27 uint32_t samplesPerSec;
28 uint32_t bytesPerSec;
29 uint16_t blockSize;
30 uint16_t bitsPerSample;
31 };
32 static_assert(sizeof(Format) == 16);
33
34 /* ------------------------------------------------------------------------- */
40 /* ------------------------------------------------------------------------- */
41 [[nodiscard]] constexpr bool IsOpen() const noexcept
42 {
43 return _isOpen;
44 }
45
46 /* ------------------------------------------------------------------------- */
51 /* ------------------------------------------------------------------------- */
52 [[nodiscard]] constexpr const Format &GetFormat() const noexcept
53 {
54 return _format;
55 }
56
57 /* ------------------------------------------------------------------------- */
62 /* ------------------------------------------------------------------------- */
63 constexpr void Seek(uint32_t sampleFrame) noexcept
64 {
65 _currentDataOffset = static_cast<size_t>(sampleFrame) * _format.blockSize;
66 }
67
68 /* ------------------------------------------------------------------------- */
74 /* ------------------------------------------------------------------------- */
75 [[nodiscard]] constexpr bool IsFinished() const noexcept
76 {
77 return _currentDataOffset >= _dataSize;
78 }
79
80 /* ------------------------------------------------------------------------- */
85 /* ------------------------------------------------------------------------- */
86 [[nodiscard]] constexpr size_t GetDataSize() const noexcept
87 {
88 return _dataSize;
89 }
90
91 bool Open(const File::PathView &path) noexcept;
92 void Close() noexcept;
93
94 size_t GetSample(void *buffer, size_t bufferSize) noexcept;
95 size_t GetSampleWithConvert(float *buffer, size_t bufferSize) noexcept;
96
97private:
98 bool _isOpen{false};
99 Format _format{};
100 File::ThrowingHandle _file;
101 size_t _dataOffset{0};
102 size_t _dataSize{0};
103 size_t _currentDataOffset{0};
104};
105} // namespace MGL::Audio
106
107#endif // INCGUARD_MGL_AUDIO_WAVE_LOADER_H_1611731366
108
109// vim: et ts=4 sw=4 sts=4
WAVEローダークラス
Definition mgl_audio_wave_loader.h:20
constexpr bool IsOpen() const noexcept
WAVEファイルがオープンされているかを取得
Definition mgl_audio_wave_loader.h:41
constexpr void Seek(uint32_t sampleFrame) noexcept
読み込み位置を設定
Definition mgl_audio_wave_loader.h:63
constexpr size_t GetDataSize() const noexcept
データサイズを取得
Definition mgl_audio_wave_loader.h:86
size_t GetSampleWithConvert(float *buffer, size_t bufferSize) noexcept
サンプルをfloatに変換して取得
Definition mgl_audio_wave_loader.cc:199
size_t GetSample(void *buffer, size_t bufferSize) noexcept
サンプルの取得
Definition mgl_audio_wave_loader.cc:154
void Close() noexcept
WAVEファイルをクローズ
Definition mgl_audio_wave_loader.cc:137
bool Open(const File::PathView &path) noexcept
WAVEファイルをオープン
Definition mgl_audio_wave_loader.cc:36
constexpr bool IsFinished() const noexcept
読み込み位置が終端に達しているかを取得
Definition mgl_audio_wave_loader.h:75
constexpr const Format & GetFormat() const noexcept
フォーマットを取得
Definition mgl_audio_wave_loader.h:52
文字列の参照のみを行うファイルパスクラス
Definition mgl_file_path_view.h:20
MGL 例外を発生させるファイルハンドル
フォーマット
Definition mgl_audio_wave_loader.h:24
uint16_t type
データフォーマット(1でPCM)
Definition mgl_audio_wave_loader.h:25
uint16_t bitsPerSample
1サンプルあたりのビット数
Definition mgl_audio_wave_loader.h:30
uint32_t bytesPerSec
1秒あたりのバイト数
Definition mgl_audio_wave_loader.h:28
uint16_t blockSize
1サンプルのバイト数
Definition mgl_audio_wave_loader.h:29
uint32_t samplesPerSec
サンプリングレート
Definition mgl_audio_wave_loader.h:27
uint16_t channelCount
チャンネル数
Definition mgl_audio_wave_loader.h:26