13constexpr float kStepPitch = 0.08f;
14constexpr float kStepVolume = 0.3f;
15constexpr float kSkillPitch = 0.04f;
16constexpr float kSkillVolume = 0.1f;
19constexpr float kStepLevel = 0.6f;
24 std::optional<Samples> departure)
25 : skill_variety_(1, kSkillPitch, kSkillVolume) {
27 Takes& takes = steps_[ground];
28 for (
int take = 0; take <
kStepTakes; ++take) {
30 const auto seed =
static_cast<uint32_t
>(
31 static_cast<int>(ground) *
kStepTakes + take + 1);
32 takes.push_back(
Clip::Load(device, nanommo::Step(ground, seed), 4));
34 step_varieties_.emplace(ground,
Variety(
static_cast<uint32_t
>(ground),
35 kStepPitch, kStepVolume));
37 for (
const auto& [
id, skill] : skills.
by_id) {
38 if (skill.look().fx().empty()) {
41 for (
const bool target : {
false,
true}) {
45 SkillSound(skill.look(),
static_cast<uint32_t
>(take + 1), target),
52 if (departure &&
Peak(*departure) > 0.0f) {
54 made = *std::move(departure);
57 for (std::size_t land = 0; land <
kLandSounds.size(); ++land) {
63void Soundboard::Play(
const Takes& takes, Variety& variety, Heard heard) {
64 if (takes.empty() || heard.volume <= 0.0f) {
67 const Variety::Take take = variety.Next(
static_cast<int>(takes.size()));
68 takes[take.take]->Play(volume_ * heard.volume * take.volume, heard.pan,
73 heard.
volume *= kStepLevel;
74 Play(steps_.at(ground), step_varieties_.at(ground), heard);
78 const auto takes = skills_.find({skill, target});
79 if (takes != skills_.end()) {
80 Play(takes->second, skill_variety_, heard);
87 if (land >= 0 && land <
static_cast<int>(arrivals_.size())) {
88 arrivals_[land]->Play(volume_, 0.0f, 1.0f);
static std::unique_ptr< Clip > Load(const AudioDevice &device, const Samples &samples, int voices)
static constexpr int kStepTakes
Takes of each step, and of each skill.
Soundboard(const AudioDevice &device, const SkillTable &skills, std::optional< Samples > departure=std::nullopt)
static constexpr int kSkillTakes
void Arrival(int land)
Into the land, by its place in the lands.
void Skill(uint32_t skill, bool target, Heard heard)
void Step(Ground ground, Heard heard)
std::vector< float > Samples
One channel of sound, at kRate.
Samples SkillSound(const skills::Look &look, uint32_t seed, bool target)
Place Arrival(const Gate &gate, float yaw)
Ground
What a foot comes down on, which is how the step sounds.
constexpr std::array< Ground, 7 > kGrounds
float Peak(const Samples &samples)
The loudest sample, whichever way it goes.
constexpr std::array< LandSound, 3 > kLandSounds
void Normalize(Samples &samples, float peak)
Louder or quieter, so that the loudest sample is at the peak.
Samples Departure(uint32_t seed)
Going through a gate: a rush up, as the screen covers the world.
std::map< uint32_t, skills::Skill > by_id