# 6. DSP Module

## 6.1 Channel DSP Callback

Apply per-sample processing to channel output before it reaches the actuator:

```cpp
channels.applyDSP(1, [](uint8_t val) -> uint8_t {
    // Soft clipping: reduce values above 200
    if (val > 200) val = 200 + (val - 200) / 4;
    // Dead-zone removal: boost low values below threshold
    if (val > 127 && val < 140) val = 140;
    return val;
});
```

The callback receives each 8-bit sample (0–255, 127 = silence) and returns the processed value.

---

## 6.2 Audio Stream DSP

Apply DSP to the audio stream before buffering:

```cpp
audioStream.setAudioDSP([](uint8_t val) -> uint8_t {
    // Process each sample before it goes into the ring buffer
    return val;
});
```

---

## 6.3 Mixing Strategy

Control how primitives and audio/PCM mix on a channel:

```cpp
channel.setMixingStrategy(MixingStrategy::ADDITIVE_MIX);
audioStream.enableMixing(1, MixingStrategy::ADDITIVE_MIX);
```

| Strategy | Behavior |
|----------|----------|
| `NO_MIX` | Pass-through |
| `INTERRUPT_MIX` | Primitive overrides PCM |
| `LARGESTVAL_MIX` | `max(prim, pcm)` |
| `ADDITIVE_MIX` | Signed add + clamp |
| `CUSTOM_MIX` | PCM overrides primitive |
