Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ set(Impacto_Src
src/audio/audiosystem.cpp
src/audio/audiochannel.cpp
src/audio/audiostream.cpp
src/audio/controlleraudio.cpp
src/audio/vorbisaudiostream.cpp
src/audio/atrac9audiostream.cpp
src/audio/adxaudiostream.cpp
Expand Down Expand Up @@ -768,6 +769,7 @@ set(Impacto_Header
src/audio/audiocommon.h
src/audio/audiochannel.h
src/audio/audiostream.h
src/audio/controlleraudio.h
src/audio/buffering.h
src/audio/ffmpegaudioplayer.h
src/audio/vorbisaudiostream.h
Expand Down
2 changes: 2 additions & 0 deletions profiles/cclcc/configsystem.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ root.ConfigSystem = {
SkipRead = true;
SyncVoice = true;
SkipVoice = false;
UseSpeaker = true;
SpeakerVolume = 0.5;

VoiceCount = 13;
VoiceMuted = {};
Expand Down
4 changes: 3 additions & 1 deletion profiles/cclcc/game.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ root.GameFeatures = GameFeature.Sc3VirtualMachine |
GameFeature.Subtitles |
GameFeature.DebugMenu |
GameFeature.Achievements |
GameFeature.Overlay;
GameFeature.Overlay |
GameFeature.ControllerSpeaker;
root.DesignWidth = 1920;
root.DesignHeight = 1080;

Expand Down Expand Up @@ -64,6 +65,7 @@ include(root.BasePaths.RootProfilesDir .. '/cclcc/gamespecific.lua');
include(root.BasePaths.RootProfilesDir .. '/cclcc/font.lua');
include(root.BasePaths.RootProfilesDir .. '/cclcc/dialogue.lua');
include(root.BasePaths.RootProfilesDir .. '/cclcc/configsystem.lua');
include(root.BasePaths.RootProfilesDir .. '/cclcc/speakervoicelines.lua');
include(root.BasePaths.RootProfilesDir .. '/cclcc/bgeff.lua');
include(root.BasePaths.RootProfilesDir .. '/cclcc/waveeffects.lua');
include(root.BasePaths.RootProfilesDir .. '/cclcc/hud/saveicon.lua');
Expand Down
4 changes: 2 additions & 2 deletions profiles/cclcc/hud/optionsmenu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,9 @@ end
-- Rearange the labels in the array so they're in order of appearance
labelIndices = {5, 6, 7, 1,
2, 3, 8,
9, 10, 11, 12, 13, 4};
9, 10, 11, 12, 13, 4, 15, 14};
height = 52;
for i = 0, 12 do
for i = 0, 14 do
offset = ((i > 11) and {104} or {0})[1];

root.Sprites["OptionsLabel" .. i] = {
Expand Down
13 changes: 13 additions & 0 deletions profiles/cclcc/speakervoicelines.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
root.SpeakerVoiceLines = {
5631, 5632, 5633, 5634, 5818, 5819, 5820, 5821, 5822, 5823,
5824, 5825, 5826, 4863, 4864, 4865, 4866, 4867, 4868, 4869,
4870, 4871, 4872, 4873, 4874, 4875, 4876, 4877, 4878, 4879,
4880, 4881, 4882, 4883, 4884, 4885, 6618, 6619, 9411, 9412,
9413, 9414, 9415, 9416, 4827, 4828, 4829, 4830, 4831, 4832,
4833, 4834, 4835, 4836, 4837, 4838, 4839, 4840, 4841, 4842,
4843, 4844, 4845, 4846, 4847, 4848, 4849, 4850, 4851, 4852,
4853, 6460, 6461, 6462, 6463, 6464, 6465, 6466, 6467, 6468,
6469, 6470, 6471, 6472, 6473, 6474, 6475, 6476, 6498, 6499,
6500, 6501, 6502, 6503, 6504, 6505, 6506, 6507, 6508, 6509,
6510, 6511, 2420, 2421, 2422, 2423
};
6 changes: 6 additions & 0 deletions src/audio/audiochannel.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ class AudioChannel {
float GetVolume() const { return Volume; }
void SetVolume(float volume) { Volume = volume; }

AudioOutputId GetOutput() const { return Output; }
virtual void SetOutput(AudioOutputId output) = 0;

const AudioStream* GetStream() const { return Stream.get(); }

// may be negative for no fixed duration, 0 for no audio
Expand All @@ -52,6 +55,7 @@ class AudioChannel {
AudioChannelId Id;
AudioChannelGroup Group;
AudioChannelState State = ACS_Stopped;
AudioOutputId Output = AO_Main;

float Volume = 1.0f;
bool Looping = false;
Expand Down Expand Up @@ -85,6 +89,8 @@ class EmptyAudioChannel : public AudioChannel {

void Reinit() override {}

void SetOutput(AudioOutputId output) override { Output = output; }

void Update(float dt) override {}

float PositionInSeconds() const override { return 0; }
Expand Down
2 changes: 2 additions & 0 deletions src/audio/audiocommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ enum AudioChannelId {
AC_Count
};

enum AudioOutputId { AO_Main, AO_Controller };

enum AudioChannelState {
ACS_Stopped,
ACS_Playing,
Expand Down
41 changes: 41 additions & 0 deletions src/audio/audiosystem.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "audiosystem.h"
#include "controlleraudio.h"
#include "../userconfig.h"
#include "../log.h"
#include "../profile/game.h"
Expand All @@ -10,6 +11,7 @@
#include "openal/audiobackend.h"
#endif

#include <algorithm>
#include <utility>

namespace Impacto {
Expand Down Expand Up @@ -148,11 +150,42 @@ void ResumeChannelGroup(AudioChannelGroup group) {
}
}

static bool ShouldPlayOnController(AudioChannel const* channel) {
if (!Profile::ConfigSystem::UseSpeaker || !channel ||
channel->GetState() == ACS_Stopped) {
return false;
}

AudioStream const* stream = channel->GetStream();
if (!stream) return false;

Io::Stream const* baseStream = stream->GetBaseStream();
if (!baseStream || baseStream->Meta.ArchiveMountPoint != "voice") {
return false;
}

return std::ranges::find(Profile::Game::SpeakerVoiceLines,
baseStream->Meta.Id) !=
Profile::Game::SpeakerVoiceLines.end();
}

static void UpdateControllerChannelOutput() {
AudioChannel* channel = Channels[AC_VOICE0].get();
if (!channel) return;

const AudioOutputId output =
(ControllerAudio::IsAvailable() && ShouldPlayOnController(channel))
? AO_Controller
: AO_Main;
if (channel->GetOutput() != output) channel->SetOutput(output);
}

void AudioShutdown() {
for (int i = 0; i < AC_Count; i++) {
Channels[i] = nullptr;
}
IsInit = false;
ControllerAudio::Shutdown();
Backend->Shutdown();
}

Expand All @@ -176,6 +209,9 @@ void AudioInit() {
}

if (!Backend->Init()) return;
if (+Profile::Game::GameFeatures & +GameFeature::ControllerSpeaker) {
ControllerAudio::Init();
}
for (int i = AC_SE0; i <= AC_SE2; i++)
Channels[i] = AudioChannel::Create((AudioChannelId)i, ACG_SE);
for (int i = AC_VOICE0; i <= AC_REV; i++)
Expand Down Expand Up @@ -251,6 +287,11 @@ void PlayInGroup(AudioChannelGroup group, std::string const& mountpoint,
}

void AudioUpdate(float dt) {
if (+Profile::Game::GameFeatures & +GameFeature::ControllerSpeaker) {
ControllerAudio::Update(Profile::ConfigSystem::UseSpeaker);
UpdateControllerChannelOutput();
}

// Set voice modifier for each voice channel
for (int i = AC_VOICE0; i <= AC_VOICE2; i++) {
const int charId = DialoguePages[i - AC_VOICE0].CurrentVoiceCharacterId;
Expand Down
Loading
Loading