Add fork changes (move instruments to their own audio group)

This commit is contained in:
Bottinator22 2024-01-02 23:08:51 -08:00
parent 9e605b182d
commit 91cf2d8251
8 changed files with 26 additions and 3 deletions

View File

@ -172,6 +172,7 @@ Mixer::Mixer(unsigned sampleRate, unsigned channels) {
m_groupVolumes[MixerGroup::Effects] = {1.0f, 1.0f, 0};
m_groupVolumes[MixerGroup::Music] = {1.0f, 1.0f, 0};
m_groupVolumes[MixerGroup::Cinematic] = {1.0f, 1.0f, 0};
m_groupVolumes[MixerGroup::Instruments] = {1.0f, 1.0f, 0};
m_speed = 1.0f;
}
@ -296,7 +297,7 @@ void Mixer::read(int16_t* outBuffer, size_t frameCount, ExtraMixFunction extraMi
? approach(audioInstance->m_pitchMultiplierTarget, audioInstance->m_pitchMultiplier, audioInstance->m_pitchMultiplierVelocity * time)
: audioInstance->m_pitchMultiplier;
if (audioInstance->m_mixerGroup == MixerGroup::Effects)
if (audioInstance->m_mixerGroup == MixerGroup::Effects || audioInstance->m_mixerGroup == MixerGroup::Instruments)
pitchMultiplier *= speed;
if (audioStopVolEnd == 0.0f && audioInstance->m_stopping)

View File

@ -23,7 +23,8 @@ struct RampedValue {
enum class MixerGroup : uint8_t {
Effects,
Music,
Cinematic
Cinematic,
Instruments
};
class AudioInstance {

View File

@ -44,6 +44,7 @@ Json const AdditionalDefaultConfiguration = Json::parseJson(R"JSON(
"audioChannelSeparation" : [-25, 25],
"sfxVol" : 100,
"instrumentVol" : 100,
"musicVol" : 70,
"windowedResolution" : [1000, 600],
"fullscreenResolution" : [1920, 1080],

View File

@ -47,6 +47,7 @@ void MainMixer::update(float dt, bool muteSfx, bool muteMusic) {
updateGroupVolume(MixerGroup::Effects, muteSfx, "sfxVol");
updateGroupVolume(MixerGroup::Music, muteMusic, "musicVol");
updateGroupVolume(MixerGroup::Cinematic, false, "sfxVol");
updateGroupVolume(MixerGroup::Instruments, muteSfx, "instrumentVol");
WorldClientPtr currentWorld;
if (m_universeClient)
@ -57,6 +58,10 @@ void MainMixer::update(float dt, bool muteSfx, bool muteMusic) {
audioInstance->setMixerGroup(MixerGroup::Effects);
m_mixer->play(audioInstance);
}
for (auto audioInstance : currentWorld->pullPendingInstrumentAudio()) {
audioInstance->setMixerGroup(MixerGroup::Instruments);
m_mixer->play(audioInstance);
}
for (auto audioInstance : currentWorld->pullPendingMusic()) {
audioInstance->setMixerGroup(MixerGroup::Music);
m_mixer->play(audioInstance);

View File

@ -22,6 +22,7 @@ public:
virtual void addDrawable(Drawable drawable, EntityRenderLayer renderLayer) = 0;
virtual void addLightSource(LightSource lightSource) = 0;
virtual void addParticle(Particle particle) = 0;
virtual void addInstrumentAudio(AudioInstancePtr audio) = 0;
virtual void addAudio(AudioInstancePtr audio) = 0;
virtual void addTilePreview(PreviewTile preview) = 0;
virtual void addOverheadBar(OverheadBar bar) = 0;
@ -31,6 +32,7 @@ public:
void addDrawables(List<Drawable> drawables, EntityRenderLayer renderLayer, Vec2F translate = Vec2F());
void addLightSources(List<LightSource> lightSources, Vec2F translate = Vec2F());
void addParticles(List<Particle> particles, Vec2F translate = Vec2F());
void addInstrumentAudios(List<AudioInstancePtr> audios, Vec2F translate = Vec2F());
void addAudios(List<AudioInstancePtr> audios, Vec2F translate = Vec2F());
void addTilePreviews(List<PreviewTile> previews);
void addOverheadBars(List<OverheadBar> bars, Vec2F translate = Vec2F());

View File

@ -153,7 +153,7 @@ void Songbook::playback() {
void Songbook::render(RenderCallback* renderCallback) {
for (auto& a : m_pendingAudio)
renderCallback->addAudio(a);
renderCallback->addInstrumentAudio(a);
m_pendingAudio.clear();
}

View File

@ -165,6 +165,7 @@ void WorldClient::removeEntity(EntityId entityId, bool andDie) {
m_particles->addParticles(move(renderCallback.particles));
m_samples.appendAll(move(renderCallback.audios));
m_instrumentSamples.appendAll(move(renderCallback.instrumentAudios));
}
if (auto version = m_masterEntitiesNetVersion.maybeTake(entity->entityId())) {
@ -545,6 +546,7 @@ void WorldClient::render(WorldRenderData& renderData, unsigned bufferTiles) {
m_particles->addParticles(move(renderCallback.particles));
m_samples.appendAll(move(renderCallback.audios));
m_instrumentSamples.appendAll(move(renderCallback.instrumentAudios));
previewTiles.appendAll(move(renderCallback.previewTiles));
renderData.overheadBars.appendAll(move(renderCallback.overheadBars));
@ -685,6 +687,9 @@ void WorldClient::render(WorldRenderData& renderData, unsigned bufferTiles) {
List<AudioInstancePtr> WorldClient::pullPendingAudio() {
return take(m_samples);
}
List<AudioInstancePtr> WorldClient::pullPendingInstrumentAudio() {
return take(m_instrumentSamples);
}
List<AudioInstancePtr> WorldClient::pullPendingMusic() {
return take(m_music);
@ -2137,6 +2142,10 @@ void WorldClient::ClientRenderCallback::addAudio(AudioInstancePtr audio) {
audios.append(move(audio));
}
void WorldClient::ClientRenderCallback::addInstrumentAudio(AudioInstancePtr audio) {
instrumentAudios.append(move(audio));
}
void WorldClient::ClientRenderCallback::addTilePreview(PreviewTile preview) {
previewTiles.append(move(preview));
}

View File

@ -149,6 +149,7 @@ public:
// calculations. It is not necessary on the light array.
void render(WorldRenderData& renderData, unsigned borderTiles);
List<AudioInstancePtr> pullPendingAudio();
List<AudioInstancePtr> pullPendingInstrumentAudio();
List<AudioInstancePtr> pullPendingMusic();
bool playerCanReachEntity(EntityId entityId, bool preferInteractive = true) const;
@ -182,6 +183,7 @@ private:
void addLightSource(LightSource lightSource) override;
void addParticle(Particle particle) override;
void addAudio(AudioInstancePtr audio) override;
void addInstrumentAudio(AudioInstancePtr audio) override;
void addTilePreview(PreviewTile preview) override;
void addOverheadBar(OverheadBar bar) override;
@ -189,6 +191,7 @@ private:
List<LightSource> lightSources;
List<Particle> particles;
List<AudioInstancePtr> audios;
List<AudioInstancePtr> instrumentAudios;
List<PreviewTile> previewTiles;
List<OverheadBar> overheadBars;
};
@ -308,6 +311,7 @@ private:
ParticleManagerPtr m_particles;
List<AudioInstancePtr> m_samples;
List<AudioInstancePtr> m_instrumentSamples;
List<AudioInstancePtr> m_music;
HashMap<EntityId, uint64_t> m_masterEntitiesNetVersion;