Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source/frontend/StarVoice.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/frontend/StarVoice.hpp')
-rw-r--r--source/frontend/StarVoice.hpp36
1 files changed, 28 insertions, 8 deletions
diff --git a/source/frontend/StarVoice.hpp b/source/frontend/StarVoice.hpp
index 0d485db..269adb4 100644
--- a/source/frontend/StarVoice.hpp
+++ b/source/frontend/StarVoice.hpp
@@ -5,6 +5,7 @@
#include "StarException.hpp"
#include "StarGameTypes.hpp"
#include "StarMaybe.hpp"
+#include "StarThread.hpp"
#include "StarApplicationController.hpp"
struct OpusDecoder;
@@ -23,6 +24,7 @@ enum class VoiceChannelMode: uint8_t { Mono = 1, Stereo = 2 };
extern EnumMap<VoiceChannelMode> const VoiceChannelModeNames;
STAR_CLASS(Voice);
+STAR_CLASS(VoiceAudioStream);
STAR_CLASS(ApplicationController);
class Voice {
@@ -30,7 +32,8 @@ public:
// Individual speakers are represented by their connection ID.
typedef ConnectionId SpeakerId;
- struct Speaker {
+ class Speaker {
+ public:
SpeakerId speakerId = 0;
EntityId entityId = 0;
@@ -39,10 +42,8 @@ public:
OpusDecoderPtr decoderMono;
OpusDecoderPtr decoderStereo;
-
- atomic<bool> active = false;
- atomic<float> currentLoudness = 0.0f;
- atomic<Array<float, 2>> channelVolumes = Array<float, 2>::filled(1.0f);
+ VoiceAudioStreamPtr audioStream;
+ Mutex mutex;
Speaker(SpeakerId speakerId);
};
@@ -63,19 +64,29 @@ public:
Voice(Voice const&) = delete;
Voice& operator=(Voice const&) = delete;
- void load(Json const& config);
- Json save() const;
-
+ void init();
+
+ void loadJson(Json const& config);
+ Json saveJson() const;
+
+ void save() const;
+ void scheduleSave();
+
// Sets the local speaker ID and returns the local speaker. Must be called upon loading into a world.
SpeakerPtr setLocalSpeaker(SpeakerId speakerId);
SpeakerPtr speaker(SpeakerId speakerId);
+ // Called when receiving input audio data from SDL, on its own thread.
+ void getAudioData(uint8_t* stream, int len);
+
// Called to mix voice audio with the game.
void mix(int16_t* buffer, size_t frames, unsigned channels);
typedef function<float(unsigned, Vec2F, float)> PositionalAttenuationFunction;
void update(PositionalAttenuationFunction positionalAttenuationFunction = {});
+ void setDeviceName(Maybe<String> device);
+
inline int encoderChannels() const {
return m_channelMode == VoiceChannelMode::Mono ? 1 : 2;
}
@@ -96,12 +107,21 @@ private:
OpusEncoderPtr m_encoder;
+ float m_outputVolume = 1.0f;
+ float m_inputVolume = 1.0f;
+ float m_threshold = -50.0f;
+
+ bool m_enabled = true;
+ bool m_inputEnabled = true;
+
bool m_deviceOpen = false;
Maybe<String> m_deviceName;
VoiceInputMode m_inputMode;
VoiceChannelMode m_channelMode;
ApplicationControllerPtr m_applicationController;
+
+ double nextSaveTime = 0.0f;
};
}