https://github.com/mrdimas/hrir_sphere_builder
Tool to create sphere from IRCAM HRIR database
https://github.com/mrdimas/hrir_sphere_builder
auralization hrir hrtf ircam
Last synced: 3 months ago
JSON representation
Tool to create sphere from IRCAM HRIR database
- Host: GitHub
- URL: https://github.com/mrdimas/hrir_sphere_builder
- Owner: mrDIMAS
- License: mit
- Created: 2019-12-24T09:28:18.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2021-11-17T17:55:00.000Z (over 4 years ago)
- Last Synced: 2025-04-11T20:05:51.139Z (about 1 year ago)
- Topics: auralization, hrir, hrtf, ircam
- Language: C++
- Size: 83.5 MB
- Stars: 11
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# HRIR Sphere Builder
Special tool to make HRIR sphere mesh from IRCAM http://recherche.ircam.fr/equipes/salles/listen/download.html base.
## Pre-built database
I already converted all IRCAM database entries, you can find them in `hrtf_base/IRCAM` - just pick any of `*.bin` files. Description of each can be found in link up above.
## Usage
`hrir_sphere_builder `
Output file will have this name: `directory_name.bin` and will be placed in parent directory of `directory_path`.
## Why it is needed?
HRIR database sampled at fixed angles - in case of IRCAM it has 15 degress azimuthal resolution and variable elavation resolution. Such fact gives annoying "jumping" effect of sound source spatial positioning. Resolution can be effectively increased by interpolation of HRIR's from three closest points for given source's azimuth and elevation. Working in spherical coordinates is error prone and may lead to various bugs, to bypass this we can use cartesian coordinate system. To be able to work in cartesian coordinates we need to know triangulated surface of a HRIR sphere so we can find a triangle which is intersected by ray from listener to sound source position. Once we have a triangle, we can use barycentric coordinates of a ray's intersection point to get weights for interpolation.
## How it works?
The tool reads file-by-file from database and extracts azimuth and elevation from file name, then tool translates spherical coordinates to cartesion and adds hrir point to point cloud. Each file contains head-related impulse response for left and right ears. Each channel gets converted into array of floats in [0; 1] range (normalized range). After all points were created, tool creates convex hull using these points. Finally, triangulated hrir sphere saved to disk.
## File format
The tool produces binary file, first goes header:
| Field | Size | Type | Value |
|--------------|------|----------|-------|
| magic | 4 | uint32_t | HRIR |
| sample_rate | 4 | uint32_t | |
| length | 4 | uint32_t | |
| vertex_count | 4 | uint32_t | |
| index_count | 4 | uint32_t | |
Then goes indices:
| Field | Size | Type |
|---------|-----------------|----------|
| Indices | 4 * index_count | uint32_t |
Finally goes `vertex_count` vertices, each vertex has this format:
| Field | Size | Type |
|------------|------------|-------|
| X | 4 | float |
| Y | 4 | float |
| Z | 4 | float |
| Left HRIR | 4 * length | float |
| Right HRIR | 4 * length | float |
## How to use produced sphere?
- Translate vector from listener position to sound source position into listener coordinate system (by multiplying vector with listener view matrix)
- Use this vector to find an intersection point and intersected triangle with sphere mesh
- Calculate barycentric coordinates of intersection point
- Use barycentric coordinates as weights for HRTF samples (as reference you can use this paper - http://www02.smt.ufrj.br/~diniz/conf/confi117.pdf)
## How to build the tool?
`g++ -std=c++17 -o hrir_sphere_builder ./src/hrtf_builder.cpp`