# Spherel

> Binaural panner for headphones: places the input around the listener's head by azimuth, elevation and distance, with the time and level differences between the ears, the head's shadow, a pinna cue for height and softer highs from behind and far away.

- Engine id: `org.sournd.utility.spherel`
- Category: Utility
- Licence: paid: £2.99 an effect or £4.99 a synth, once (owned for good, with updates), or included in the Everything plan (£14.99 a month)
- Version: 1.0.0
- Latency: 0 samples
- Tail: 0.05 s
- Sidechain input: no
- Channels: mono or stereo
- Audio demo: https://sournd.com/static/preview/demos/spherel.mp3 (plucked chords, default settings)

## Parameters

The id is the C ABI parameter id and the JUCE parameter id (as a decimal string).

| Id | Key | Name | Min | Max | Default | Unit | Taper |
|---|---|---|---|---|---|---|---|
| 0 | `azimuth_deg` | Azimuth | -180 | 180 | 0 | deg | linear |
| 1 | `elevation_deg` | Elevation | -45 | 90 | 0 | deg | linear |
| 2 | `distance_m` | Distance | 0.3 | 20 | 1 | m | log |
| 3 | `head_radius_cm` | Head radius | 7 | 11 | 8.75 | cm | linear |
| 4 | `output_db` | Output | -12 | 12 | 0 | dB | linear |

## Use it in JUCE

CMake ([quick start](/docs/juce/index.md)):

```cmake
juce_add_module(path/to/sournd_engine)
target_include_directories(MyPlugin PRIVATE path/to/include)
target_link_libraries(MyPlugin PRIVATE sournd_engine path/to/libsournd_cabi.a)
```

C++:

```cpp
#include <sournd_engine/sournd_engine.h>

sournd::SourndEngine engine { "org.sournd.utility.spherel" };
juce::AudioProcessorValueTreeState parameters { *this, nullptr, "Parameters",
    sournd::SourndEngineParameters::createLayout (engine) };
sournd::SourndEngineParameters bridge { engine, parameters };

// prepareToPlay
engine.prepare ({ sampleRate, (juce::uint32) maximumBlock, 2 });
bridge.prepare (sampleRate);
setLatencySamples ((int) engine.latency());

// processBlock
bridge.apply ((uint32_t) buffer.getNumSamples());
juce::dsp::AudioBlock<float> block { buffer };
engine.process (juce::dsp::ProcessContextReplacing<float> { block });

// get/setStateInformation: hold getCallbackLock() around saveState / loadState,
// so state work never overlaps processBlock (full example: /docs/juce/)
```

Plain C:

```c
sournd_engine *e = NULL;
if (sournd_engine_create("org.sournd.utility.spherel", &e) == SOURND_OK) {
    sournd_engine_prepare(e, 48000.0, 512);
    sournd_engine_set_param(e, 0, 0); /* Azimuth */
    sournd_engine_process(e, in, out, 2, frames);
    sournd_engine_destroy(e);
}
```

## How it is made

Original sOURnd design blending general, published techniques: the spherical-head model (per-ear travel-time difference from the head radius and a first-order head-shadow filter whose high-frequency gain follows the angle to the ear), an elevation-dependent pinna notch, a rear shading shelf, inverse-distance gain and air absorption.

## Ask your AI

Paste this into your coding assistant:

```text
Add the sournd engine org.sournd.utility.spherel to my JUCE plugin. Follow https://sournd.com/docs/juce/index.md
and the engine reference at https://sournd.com/engines/spherel/index.md. Expose every parameter through APVTS.
```
