mirror of
https://github.com/open-goal/jak-project.git
synced 2024-10-20 11:26:18 -04:00
38 lines
742 B
C++
38 lines
742 B
C++
// Copyright: 2021 - 2022, Ziemas
|
|
// SPDX-License-Identifier: ISC
|
|
#include "synth.h"
|
|
|
|
#include <stdexcept>
|
|
|
|
namespace snd {
|
|
|
|
static s16 ApplyVolume(s16 sample, s32 volume) {
|
|
return (sample * volume) >> 15;
|
|
}
|
|
|
|
s16Output Synth::Tick() {
|
|
s16Output out{};
|
|
|
|
mVoices.remove_if([](std::shared_ptr<Voice>& v) { return v->Dead(); });
|
|
for (auto& v : mVoices) {
|
|
out += v->Run();
|
|
}
|
|
|
|
out.left = ApplyVolume(out.left, mVolume.left.Get());
|
|
out.right = ApplyVolume(out.right, mVolume.right.Get());
|
|
|
|
mVolume.Run();
|
|
|
|
return out;
|
|
}
|
|
|
|
void Synth::AddVoice(std::shared_ptr<Voice> voice) {
|
|
mVoices.emplace_front(voice);
|
|
}
|
|
|
|
void Synth::SetMasterVol(u32 volume) {
|
|
mVolume.left.Set(volume);
|
|
mVolume.right.Set(volume);
|
|
}
|
|
} // namespace snd
|