[][src]Module rg3d_sound::hrtf

Head-Related Transfer Function (HRTF) module. Provides all needed types and methods for HRTF rendering.

Overview

HRTF stands for Head-Related Transfer Function and can work only with spatial sounds. For each of such sound source after it was processed by HRTF you can defininitely tell from which locationsound came from. In other words HRTF improves perception of sound to the level of real life.

HRIR Spheres

This library uses Head-Related Impulse Response (HRIR) spheres to create HRTF spheres. HRTF sphere is a set of points in 3D space which are connected into a mesh forming triangulated sphere. Each point contains spectrum for left and right ears which will be used to modify samples from each spatial sound source to create binaural sound. HRIR spheres can be found here

Usage

To use HRTF you need to change default renderer to HRTF renderer like so:

use rg3d_sound::context::Context;
use rg3d_sound::hrtf::{HrtfSphere, HrtfRenderer};
use rg3d_sound::renderer::Renderer;
use std::path::Path;

fn use_hrtf(context: &mut Context) {
    // IRC_1002_C.bin is HRIR sphere in binary format, can be any valid HRIR sphere
    // from base mentioned above.
    let hrtf = HrtfSphere::new(Path::new("IRC_1002_C.bin")).unwrap();

    context.set_renderer(Renderer::HrtfRenderer(HrtfRenderer::new(hrtf)));
}

Performance

HRTF is heavy. Usually it 4-5 slower than default renderer, this is essential because HRTF requires some heavy math (fast Fourier transform, convolution, etc.). On Ryzen 1700 it takes 400-450 μs (0.4 - 0.45 ms) per source. In most cases this is ok, engine works in separate thread and it has around 100 ms to prepare new portion of samples for output device.

Known problems

This renderer still suffers from small audible clicks in very fast moving sounds, clicks sounds more like "buzzing" - it is due the fact that hrtf is different from frame to frame which gives "bumps" in amplitude of signal because of phase shift each impulse response have. This can be fixed by short cross fade between small amount of samples from previous frame with same amount of frames of current as proposed in here

Clicks can be reproduced by using clean sine wave of 440 Hz on some source moving around listener.

Structs

HrtfPoint

Single point of HRTF sphere. See module docs for more info.

HrtfRenderer

See module docs.

HrtfSphere

See module docs.

Enums

HrtfError

All possible error that can occur during HRIR sphere loading.