> ## Documentation Index
> Fetch the complete documentation index at: https://docs.liv.tv/llms.txt
> Use this file to discover all available pages before exploring further.

# Unreal Audio

> How to use the LCKUnrealAudio plugin for native Unreal Engine game audio and microphone capture in the LIV Camera Kit (LCK) SDK, including FAudioCapture microphone integration, FLCKUnrealAudioListener submix capture, sample rate configuration, and Blueprint utility functions.

<Info>
  **Module:** LCKUnrealAudio | **Version:** 1.0 | **Platforms:** All
</Info>

## Overview

LCKUnrealAudio provides native Unreal Engine audio capture, supporting both game audio output and microphone input using Unreal's built-in audio systems. It uses `FAudioCapture` for microphone input and `FLCKUnrealAudioListener` for submix-based game audio capture.

## Supported Channels

| Channel      | Supported | Description                     |
| ------------ | --------- | ------------------------------- |
| `Game`       | Yes       | Unreal Audio submix capture     |
| `Microphone` | Yes       | Unreal Audio microphone capture |
| `VoiceChat`  | No        | Use LCKVivox for voice chat     |

## Dependencies

```csharp theme={null}
// Add to your .Build.cs
PublicDependencyModuleNames.AddRange(new string[] {
    "LCKUnrealAudio",
    "LCKAudio"
});
```

## Automatic Integration

The plugin automatically registers itself with the LCK audio system when the module loads. No manual initialization is required.

## Source Implementation

### FLCKUnrealAudioSource

The core audio source class that implements `ILCKAudioSource` for native Unreal Engine audio:

```cpp theme={null}
class FLCKUnrealAudioSource : public ILCKAudioSource
{
public:
    FLCKUnrealAudioSource();
    ~FLCKUnrealAudioSource();

    bool StartCapture() noexcept override;
    bool StartCapture(TLCKAudioChannelsMask Channels) noexcept override;
    void StopCapture() noexcept override;
    const FString& GetSourceName() const noexcept override;
    float GetVolume() const noexcept override;

private:
    TUniquePtr<Audio::FAudioCapture> MicrophoneCapture;
    TSharedPtr<FLCKUnrealAudioListener, ESPMode::ThreadSafe> GameAudioListener;
    bool bIsMicrophoneCapturing = false;
    int32 Samplerate = 48000;
    int32 ChannelsCount = 1;
};
```

| Member                   | Type                                                       | Description                                    |
| ------------------------ | ---------------------------------------------------------- | ---------------------------------------------- |
| `MicrophoneCapture`      | `TUniquePtr<Audio::FAudioCapture>`                         | Unreal's built-in microphone capture device    |
| `GameAudioListener`      | `TSharedPtr<FLCKUnrealAudioListener, ESPMode::ThreadSafe>` | Submix listener for game audio output capture  |
| `bIsMicrophoneCapturing` | `bool`                                                     | Whether microphone capture is currently active |
| `Samplerate`             | `int32`                                                    | Audio sample rate, defaults to 48000 Hz        |
| `ChannelsCount`          | `int32`                                                    | Number of audio channels (1 = mono mic input)  |

### Audio Capture Pipeline

```
┌─────────────────────────────────────────────────────┐
│              Unreal Audio Engine                     │
├──────────────────────┬──────────────────────────────┤
│   Master Submix      │      Audio Capture API       │
│   (Game Audio)       │      (Microphone)            │
│        ↓             │           ↓                  │
│  FLCKUnrealAudio     │    Audio::FAudioCapture      │
│     Listener         │                              │
└──────────┬───────────┴──────────────┬───────────────┘
           │                          │
           ▼                          ▼
┌────────────────────────────────────────────────────┐
│           FLCKUnrealAudioSource                     │
│   OnAudioDataDelegate (Game + Microphone)          │
└────────────────────────────────────────────────────┘
```

### FLCKUnrealAudioListener

Hooks into Unreal's submix system to capture the final game audio mix. Registered automatically on the master submix when game audio capture starts.

### FAudioCapture (Microphone)

Uses Unreal's `Audio::FAudioCapture` API for cross-platform microphone input. The microphone stream is captured at 48000 Hz mono and delivered through the same `OnAudioDataDelegate` with `ELCKAudioChannel::Microphone`.

## Blueprint Functions

### ULCKUnrealAudioBPL

A Blueprint function library exposing audio utilities to Blueprints:

<ResponseField name="GetUnrealAudioSamplerate" type="int32">
  Returns the current Unreal Audio sample rate. Use this to configure the encoder with the correct sample rate.

  ```cpp theme={null}
  UFUNCTION(BlueprintCallable, BlueprintPure, Category = "LCK")
  static int32 GetUnrealAudioSamplerate();
  ```
</ResponseField>

### Usage

```cpp theme={null}
#include "LCKUnrealAudioBPL.h"

// Get sample rate for encoder configuration
int32 SampleRate = ULCKUnrealAudioBPL::GetUnrealAudioSamplerate();

// Configure encoder with matching rate
FLCKRecorderParams Params;
Params.Samplerate = SampleRate;
```

<Tip>
  In Blueprints, search for **Get Unreal Audio Samplerate** under the **LCK** category.
</Tip>

## Configuration

### Sample Rate

The default sample rate is **48000 Hz**. This matches the LCK encoder's expected input rate. If your project uses a different audio sample rate, ensure the encoder is configured to match:

```cpp theme={null}
int32 ProjectSampleRate = ULCKUnrealAudioBPL::GetUnrealAudioSamplerate();
// Use this value when configuring FLCKRecorderParams::Samplerate
```

<Warning>
  Voice chat and game audio must match in sample rate, otherwise audio distortion will occur in recordings.
</Warning>

### Project Settings

Ensure audio capture is enabled in your project settings:

1. **Edit > Project Settings > Platforms > Windows/Android**
2. Enable "Audio Capture" in the Audio section

### Submix Setup

For game audio capture, the plugin hooks into Unreal's master submix. No additional configuration is needed for default behavior.

<Tip>
  For custom submix routing, create a custom submix and route game audio through it, then configure the plugin to capture from that submix.
</Tip>

## Microphone Permissions

### Windows

No special permissions required. Microphone access is granted at the OS level.

### Android

Add to your `AndroidManifest.xml`:

```xml theme={null}
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
```

<Warning>
  On Android, consider using `LCKOboe` for lower latency microphone capture instead of `LCKUnrealAudio`.
</Warning>

## Performance

| Metric  | Impact         |
| ------- | -------------- |
| CPU     | \< 1% overhead |
| Memory  | \~1MB buffer   |
| Latency | 1-2 frames     |

## Troubleshooting

<AccordionGroup>
  <Accordion title="No game audio captured">
    1. Verify audio is playing through Unreal's audio system (not FMOD/Wwise)
    2. Check that the master submix is not muted
    3. Check LogLCKUnrealAudio for errors
  </Accordion>

  <Accordion title="No microphone audio">
    1. Verify microphone permissions are granted
    2. Check that no other application is exclusively using the mic
    3. Confirm Audio Capture is enabled in Project Settings
    4. On Android, verify `RECORD_AUDIO` permission in manifest
  </Accordion>

  <Accordion title="Sample rate mismatch">
    1. Use `ULCKUnrealAudioBPL::GetUnrealAudioSamplerate()` to query the actual rate
    2. Ensure `FLCKRecorderParams::Samplerate` matches
    3. Check Project Settings audio sample rate configuration
  </Accordion>
</AccordionGroup>

## Log Category

```cpp theme={null}
DECLARE_LOG_CATEGORY_EXTERN(LogLCKUnrealAudio, Log, All);
```

## See Also

<CardGroup cols={2}>
  <Card title="Audio Overview" icon="volume-high" href="/unreal/audio/overview">
    Audio system architecture
  </Card>

  <Card title="LCKOboe" icon="android" href="/unreal/audio/oboe-android">
    Low-latency Android microphone
  </Card>
</CardGroup>
