Files
Frostbite2D/Frostbite2D/include/frostbite2D/audio/audio_system.h
Lenheart 0171c9d22a refactor(core): 重构资源销毁流程,改为集中式管理
将各模块的析构函数中自动调用shutdown()的逻辑移除,改为在Application::shutdown()中统一手动调用
调整SDL初始化和退出流程,避免重复调用
添加测试用的1秒定时退出逻辑
清理主程序中的示例代码
2026-03-25 20:00:13 +08:00

64 lines
1.3 KiB
C++

#pragma once
#include <frostbite2D/types/type_alias.h>
#include <string>
namespace frostbite2D {
/**
* @brief 音频系统配置
*/
struct AudioConfig {
int frequency = 44100;
uint16_t format = 0x8010;
int channels = 2;
int chunksize = 4096;
int maxSoundChannels = 32;
};
/**
* @brief 音频系统(单例)
*
* 负责初始化和管理整个音频系统,包括音量控制和声道管理。
*/
class AudioSystem {
public:
static AudioSystem& get();
AudioSystem(const AudioSystem&) = delete;
AudioSystem& operator=(const AudioSystem&) = delete;
bool init(const AudioConfig& config = AudioConfig());
void shutdown();
bool isInitialized() const { return initialized_; }
void setMasterVolume(float volume);
float getMasterVolume() const;
void setSoundVolume(float volume);
float getSoundVolume() const;
void setMusicVolume(float volume);
float getMusicVolume() const;
void pauseAllSounds();
void resumeAllSounds();
void stopAllSounds();
int getMaxChannels() const { return maxChannels_; }
private:
AudioSystem() = default;
// ~AudioSystem() 在 shutdown() 中手动调用销毁
void updateVolumes();
bool initialized_ = false;
float masterVolume_ = 1.0f;
float soundVolume_ = 1.0f;
float musicVolume_ = 1.0f;
int maxChannels_ = 32;
};
}