docs: update resources API docs
This commit is contained in:
36
docs/api/resources/audio-loader/canload.md
Normal file
36
docs/api/resources/audio-loader/canload.md
Normal file
@@ -0,0 +1,36 @@
|
||||
# AudioLoader::CanLoad
|
||||
|
||||
## 方法签名
|
||||
|
||||
```cpp
|
||||
bool CanLoad(const Containers::String& path) const override;
|
||||
```
|
||||
|
||||
## 详细描述
|
||||
|
||||
根据文件扩展名判断此加载器是否能处理指定路径的资源。检测时先提取路径扩展名(小写),再与支持列表逐一比对。
|
||||
|
||||
## 参数
|
||||
|
||||
| 参数 | 类型 | 描述 |
|
||||
|------|------|------|
|
||||
| `path` | `const Containers::String&` | 资源文件的完整或相对路径 |
|
||||
|
||||
## 返回值
|
||||
|
||||
`bool` - 如果扩展名在支持列表中返回 `true`,否则返回 `false`。
|
||||
|
||||
## 示例
|
||||
|
||||
```cpp
|
||||
AudioLoader loader;
|
||||
|
||||
// 正确识别支持的格式
|
||||
bool canLoad1 = loader.CanLoad("assets/audio/bgm.ogg"); // true
|
||||
bool canLoad2 = loader.CanLoad("sound_effect.wav"); // true
|
||||
bool canLoad3 = loader.CanLoad("music.mp3"); // true
|
||||
|
||||
// 识别不支持的格式
|
||||
bool canLoad4 = loader.CanLoad("video.avi"); // false
|
||||
bool canLoad5 = loader.CanLoad("document.pdf"); // false
|
||||
```
|
||||
27
docs/api/resources/audio-loader/getdefaultsettings.md
Normal file
27
docs/api/resources/audio-loader/getdefaultsettings.md
Normal file
@@ -0,0 +1,27 @@
|
||||
# AudioLoader::GetDefaultSettings
|
||||
|
||||
## 方法签名
|
||||
|
||||
```cpp
|
||||
ImportSettings* GetDefaultSettings() const override;
|
||||
```
|
||||
|
||||
## 详细描述
|
||||
|
||||
返回音频资源的默认导入设置。当前版本音频加载器不使用导入设置,始终返回 `nullptr`。
|
||||
|
||||
## 返回值
|
||||
|
||||
`ImportSettings*` - 始终返回 `nullptr`。
|
||||
|
||||
## 示例
|
||||
|
||||
```cpp
|
||||
AudioLoader loader;
|
||||
ImportSettings* settings = loader.GetDefaultSettings();
|
||||
|
||||
// 始终为 nullptr
|
||||
if (settings == nullptr) {
|
||||
printf("No default settings for AudioLoader\n");
|
||||
}
|
||||
```
|
||||
38
docs/api/resources/audio-loader/getsupportedextensions.md
Normal file
38
docs/api/resources/audio-loader/getsupportedextensions.md
Normal file
@@ -0,0 +1,38 @@
|
||||
# AudioLoader::GetSupportedExtensions
|
||||
|
||||
## 方法签名
|
||||
|
||||
```cpp
|
||||
Containers::Array<Containers::String> GetSupportedExtensions() const override;
|
||||
```
|
||||
|
||||
## 详细描述
|
||||
|
||||
返回此加载器支持的所有音频文件扩展名。扩展名列表用于 `ResourceManager` 确定给定文件应由哪个加载器处理。
|
||||
|
||||
## 返回值
|
||||
|
||||
返回 `Containers::Array<Containers::String>`,包含所有支持的扩展名小写形式。
|
||||
|
||||
**支持的格式:**
|
||||
|
||||
| 扩展名 | 格式 |
|
||||
|--------|------|
|
||||
| `wav` | WAV (Waveform Audio File Format) |
|
||||
| `ogg` | OGG (Ogg Vorbis) |
|
||||
| `mp3` | MP3 (MPEG-1 Audio Layer III) |
|
||||
| `flac` | FLAC (Free Lossless Audio Codec) |
|
||||
| `aiff` | AIFF (Audio Interchange File Format) |
|
||||
| `aif` | AIFF (旧版扩展名) |
|
||||
|
||||
## 示例
|
||||
|
||||
```cpp
|
||||
AudioLoader loader;
|
||||
Array<String> extensions = loader.GetSupportedExtensions();
|
||||
|
||||
for (const auto& ext : extensions) {
|
||||
printf("Supported: %s\n", ext.CStr());
|
||||
}
|
||||
// 输出: wav, ogg, mp3, flac, aiff, aif
|
||||
```
|
||||
56
docs/api/resources/audio-loader/index.md
Normal file
56
docs/api/resources/audio-loader/index.md
Normal file
@@ -0,0 +1,56 @@
|
||||
# AudioLoader
|
||||
|
||||
## 命名空间
|
||||
|
||||
`XCEngine::Resources`
|
||||
|
||||
## 类型
|
||||
|
||||
类 (Class)
|
||||
|
||||
## 描述
|
||||
|
||||
音频资源加载器,负责从文件系统加载音频文件并转换为 `AudioClip` 资源。支持 WAV、OGG、MP3、FLAC、AIFF 等常见音频格式。
|
||||
|
||||
## 概述
|
||||
|
||||
`AudioLoader` 继承自 `IResourceLoader` 接口,实现音频资源的异步加载与格式解析。内部通过文件扩展名和文件头数据双重检测确定音频格式,确保加载结果的准确性。
|
||||
|
||||
## 公共方法表格
|
||||
|
||||
| 方法 | 返回值 | 描述 |
|
||||
|------|--------|------|
|
||||
| `AudioLoader()` | - | 构造函数 |
|
||||
| `~AudioLoader()` | - | 析构函数 |
|
||||
| `GetResourceType()` | `ResourceType` | 返回资源类型 `AudioClip` |
|
||||
| `GetSupportedExtensions()` | `Array<String>` | 获取支持的扩展名列表 |
|
||||
| `CanLoad(path)` | `bool` | 检查是否能够加载指定路径的资源 |
|
||||
| `Load(path, settings)` | `LoadResult` | 加载音频资源 |
|
||||
| `GetDefaultSettings()` | `ImportSettings*` | 获取默认导入设置 |
|
||||
|
||||
## 使用示例
|
||||
|
||||
```cpp
|
||||
#include "Resources/AudioLoader.h"
|
||||
#include "Resources/ResourceManager.h"
|
||||
|
||||
using namespace XCEngine::Resources;
|
||||
|
||||
// 通过 ResourceManager 加载音频
|
||||
ResourceGUID guid = ResourceGUID::Generate("assets/audio/bgm_music.ogg");
|
||||
LoadResult result = ResourceManager::Get().Load(guid, "assets/audio/bgm_music.ogg");
|
||||
|
||||
if (result.IsSuccess()) {
|
||||
AudioClip* clip = result.GetResource<AudioClip>();
|
||||
// 使用音频片段
|
||||
}
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [GetSupportedExtensions](getsupportedextensions.md) - 获取支持的音频格式
|
||||
- [CanLoad](canload.md) - 检查资源可加载性
|
||||
- [Load](load.md) - 加载音频资源
|
||||
- [GetDefaultSettings](getdefaultsettings.md) - 获取默认导入设置
|
||||
- [IResourceLoader](../resource-loader/resource-loader.md) - 资源加载器基类
|
||||
- [AudioClip](../audioclip/audio-clip.md) - 音频资源类型
|
||||
58
docs/api/resources/audio-loader/load.md
Normal file
58
docs/api/resources/audio-loader/load.md
Normal file
@@ -0,0 +1,58 @@
|
||||
# AudioLoader::Load
|
||||
|
||||
## 方法签名
|
||||
|
||||
```cpp
|
||||
LoadResult Load(const Containers::String& path, const ImportSettings* settings = nullptr) override;
|
||||
```
|
||||
|
||||
## 详细描述
|
||||
|
||||
从指定路径加载音频文件,读取文件数据后自动检测音频格式,并创建包含完整音频数据的 `AudioClip` 对象。
|
||||
|
||||
**加载流程:**
|
||||
|
||||
1. 调用 `ReadFileData(path)` 读取文件数据
|
||||
2. 若读取失败,返回包含错误信息的 `LoadResult`
|
||||
3. 调用 `DetectAudioFormat()` 检测音频格式
|
||||
4. 创建 `AudioClip` 对象并设置路径、名称、GUID
|
||||
5. 调用 `SetAudioFormat()` 和 `SetAudioData()` 设置音频属性
|
||||
6. 计算内存占用并返回成功结果
|
||||
|
||||
## 参数
|
||||
|
||||
| 参数 | 类型 | 描述 |
|
||||
|------|------|------|
|
||||
| `path` | `const Containers::String&` | 音频文件的完整或相对路径 |
|
||||
| `settings` | `const ImportSettings*` | 导入设置(当前版本未使用,始终为 `nullptr`) |
|
||||
|
||||
## 返回值
|
||||
|
||||
`LoadResult` - 成功时包含 `AudioClip*` 指针,失败时包含错误信息字符串。
|
||||
|
||||
## 示例
|
||||
|
||||
```cpp
|
||||
#include "Resources/AudioLoader.h"
|
||||
#include "Resources/ResourceManager.h"
|
||||
|
||||
using namespace XCEngine::Resources;
|
||||
|
||||
AudioLoader loader;
|
||||
LoadResult result = loader.Load("assets/audio/bgm_music.ogg");
|
||||
|
||||
if (result.IsSuccess()) {
|
||||
AudioClip* audioClip = result.GetResource<AudioClip>();
|
||||
|
||||
printf("Loaded: %s\n", audioClip->m_name.CStr());
|
||||
printf("Format: %d\n", static_cast<int>(audioClip->GetAudioFormat()));
|
||||
printf("Size: %zu bytes\n", audioClip->m_memorySize);
|
||||
} else {
|
||||
printf("Error: %s\n", result.GetError().CStr());
|
||||
}
|
||||
```
|
||||
|
||||
## 注意事项
|
||||
|
||||
- 当前实现 `ParseWAVData()` 方法为空,WAV 格式解析逻辑尚未完成
|
||||
- `settings` 参数当前版本未使用,保留接口兼容性
|
||||
Reference in New Issue
Block a user