Audio 模块
类: SoundBuffer、Sound、Music、SoundStream、SoundSource、SoundRecorder、SoundBufferRecorder、InputSoundFile、OutputSoundFile、SoundFileFactory / Reader / Writer、AudioResource
命名空间: Listener、PlaybackDevice(设备管理)
SoundBuffer / Sound
Section titled “SoundBuffer / Sound”sf::SoundBuffer buffer("shot.wav"); // 或 loadFromFilesf::Sound sound(buffer); // 无默认构造;必须绑定 buffersound.setLooping(true); // 原 setLoop/getLoop → setLooping/isLoopingsound.setVolume(50.f);sound.setPitch(1.2f);sound.play(); // pause / stop / setPlayingOffset(sf::seconds(2))- 格式:WAV、OGG/Vorbis、FLAC;MP3 解码支持、编码不支持
loadFromSamples等需 Channel Map(std::vector<sf::SoundChannel>)——相对 2.x 破坏性变更- 生命周期: Sound 只引用 SoundBuffer,buffer 必须活过 Sound
Music / SoundStream
Section titled “Music / SoundStream”sf::Music music("bgm.ogg"); // openFromFile(流式,非完整 load)music.setLoopPoints({sf::milliseconds(500), sf::seconds(4)});music.play();- Music 不可拷贝、可移动
- 流式播放时源文件 / 内存必须保持有效
SoundSource 空间化
Section titled “SoundSource 空间化”setPosition、setRelativeToListener、setMinDistance、setAttenuation、setSpatializationEnabled,以及 cone / velocity / doppler 等(见 SoundSource.hpp)。
Listener
Section titled “Listener”sf::Listener::setGlobalVolume、setPosition、setDirection、setUpVector、setVelocity、setCone …
PlaybackDevice(3.x / 3.1)
Section titled “PlaybackDevice(3.x / 3.1)”getAvailableDevices()、getDefaultDevice()、setDevice(name)、setDeviceToDefault()、setDeviceToNull()、getDevice()、getDeviceSampleRate() → optional<uint32_t>、setNotificationCallback
相关教程:Sounds。