Voice Pipeline
The VoicePipeline class is the orchestrator for all audio data within the HoloMIT SDK. It inherits from BasePipeline and sets up the necessary worker threads and queues depending on whether the voice is local (microphone) or remote (network).
Pipeline Flow
Local Voice (Producer)
When the SourceType is Self, the pipeline captures local microphone input and prepares it for transmission.
- Queue Initialization: Allocates
encoderQueueandsenderQueue. - Microphone Check: Verifies that a valid microphone is available in the user's data.
- Codec Loading: Instantiates either an
NSpeexEncoderorOpusEncoderdepending on the globalConfig.AudioCodecsettings. - VoiceReader: Initializes the
VoiceReaderworker to capture hardware microphone data and push it to the encoder queue. - AudioWriter: Pushes the encoded packets from the sender queue out to the network orchestrator.
Remote Voice (Consumer)
When the SourceType is Remote, the pipeline receives audio packets from the network and plays them back.
- Queue Initialization: Allocates
decoderQueueandpreparerQueue. - AudioSource Configuration: Spawns an
AudioSourcecomponent on the target GameObject, configuring it for loop and 3D spatialization. - AudioReader: Initializes the
AudioReaderworker to pull packets from the network into the decoder queue. - VoiceDecoder: Decompresses the network packets back into raw audio buffers.
- AudioPreparer: Prepares the raw buffers for playback.
- Playback: The pipeline intercepts Unity's audio DSP via the
OnAudioFilterReadcallback, extracting audio from theAudioPreparerand mixing it directly into the Unity audio stream.
Key Worker Scripts
While orchestrated by VoicePipeline, the heavy lifting is done by specialized workers located in Assets\UserRepresentation\Voice\Scripts\Workers\:
- VoiceReader: Interacts directly with microphone hardware to capture PCM data.
- VoiceEncoder / VoiceDecoder: Wrappers for Opus and Speex implementations.
- AudioPreparer: A bridge between the asynchronous decoder threads and Unity's synchronous audio DSP loop.