# Audio System

The Beyond includes a built-in PDM microphone array that appears to the PC as a USB Audio Class device named **"Bigscreen Beyond"** (changed from "Generic Stereo USB Microphone" in v0.2.5).

## PDM Microphone Capture

- Multi-channel PDM (Pulse Density Modulation) microphone interface using the SAMG55 PDC (Peripheral DMA Controller)
- Audio data uploaded to the host via USB Audio Class on a dedicated endpoint
- The USB audio endpoint is separate from the HID endpoint, enabled by using HID feature reports on EP0 instead of standard reports (saves an endpoint)

**Source files:** `src/Drivers/pdm_mics.c/h`, `src/config/conf_board.h`

## Mono / Stereo Switching

Controllable via HID command `S` (0x53):

| Value | Mode | Behavior |
|-------|------|----------|
| 0 | Mono | Mixer adds left + right channels; still appears as stereo to PC |
| 1 | Stereo | True stereo output from left and right microphones |

**Default:** Mono (v0.2.1+)

## Gain Control

Two independent gain controls, both set via HID:

### Integer Gain — HID command `G` (0x47)
- Range: 0–32767 (16-bit unsigned, big-endian)
- Values above 32767 are clipped
- Evolution across versions: 10x -> 7x -> 3x -> 2x (current default integral gain)

### Fractional Gain — HID command `g` (0x67)
- Range: -1.0 to +1.0 (16-bit signed fixed-point, big-endian)
- Conversion: multiply desired value by 32768 (e.g., 0.75 = 24576)
- Current default: 0.75x fractional gain
- Fixed in v0.2.7 — wasn't actually applied before that version

### Effective Gain History

| Version | Integer Gain | Fractional Gain | Effective |
|---------|-------------|-----------------|-----------|
| <= v0.2.11 | 10x | (not working) | ~10x |
| v0.2.12 | 7x | (not working) | ~7x |
| v0.2.13 | 3x | (not working) | ~3x |
| v0.2.14+ | 2x | 0.75x | ~1.5x |

## Audio Task Scheduling

The USB audio upload task is sensitive to scheduling latency. Key fixes:

- **v0.2.22:** Fixed microphone popping caused by bad buffer position update
- **v0.3.7D:** FreeRTOS scheduling was temporarily disabled during I2C to fix proximity glitches, but this corrupted the microphone audio
- **v0.3.7E:** I2C moved to interrupt-driven with FreeRTOS scheduling re-enabled, fixing both the proximity issue and the microphone corruption

## USB Audio Configuration

Configured in `src/config/conf_usb.h`:
- Part of a composite USB device (HID + Audio)
- Dedicated USB endpoint for audio isochronous transfers
- Audio class descriptors configured via `udi_audio_conf.h`
