#pragma once #include #include 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; }; }