Skip to content

Repository files navigation


Binaural Audio Simulation

A Python-based simulation engine for spatial audio rendering and room acoustics.

Explore the Documentation »

Report Bug · Request Feature

Table of Contents
  1. About The Project
  2. Lessons Learned
  3. Getting Started
  4. Usage
  5. Contact
  6. Acknowledgments

About The Project

Simulation Layout

Spatial Configuration: Listener (O) and 8 Surround Sound Sources (S0-S7).

This repository contains Binaural Audio Simulation, an academic project developed from scratch for the Comunicação de Sinais Multimedia (currently known as Processamento de Sinais Multimedia - PSM) course at ISEL (Instituto Superior de Engenharia de Lisboa) in 2024.

The primary goal of this project is to simulate and synthesize audio fields within a horizontal room plane, exploring monaural propagation, binaural audition via HRTF, and multichannel sound reproduction using VBAP.

Understanding the Simulation

The image above illustrates the mathematical and spatial configuration used to compute the audio in this project:

  • The Room: The space is defined by boundaries (Biombos/walls) on a 2D Cartesian plane (8m width, 6m height). These boundaries are used to calculate the physical reflections and reverberation of the sound waves.
  • The Listener (O): The central point at coordinate (4,3) represents the listener's head.
  • The Sound Sources (S0 - S7): Eight virtual speakers are placed in a perfect circle around the listener at a distance of 2m, spaced every 45°.

The Python simulation calculates the exact acoustic path—including direct sound propagation delays and acoustic reflections on the walls—from each of these 8 sound sources to the listener. To make this simulation realistic, we rely on two major acoustic concepts:

  • HRTF (Head-Related Transfer Function): A mathematical filter that mimics how sound waves interact with human anatomy (head, shoulders, and outer ears) before reaching the eardrums. By applying HRTFs to audio signals, we trick the brain into pinpointing exactly where a sound is coming from in 3D space, creating a surround sound illusion using only standard stereo headphones.
  • VBAP (Vector Based Amplitude Panning): A technique used to position a virtual sound (like an instrument) anywhere in space by intelligently distributing its volume across multiple physical speakers. It calculates the exact amplitude (gain) that each speaker needs to play so that the listener perceives the sound coming from a specific direction.

🔊 Audio Results

The resulting calculation of this entire physical setup can be heard below. When you listen to this file with headphones, your brain interprets the HRTF filters and the simulated room reflections, allowing you to actually feel where the sound sources are positioned around you.

(Note: GitHub may require you to download the .wav file to play it, or you can run the notebook to generate and listen to it locally).

(back to top)


Built With

  • Python
  • Jupyter
  • NumPy
  • SciPy
  • Matplotlib

(back to top)


Features & Key Highlights

  • Monaural Propagation: Simulates direct sound fields, first-order reflections, and room reverberation at a specific point.
  • Binaural Audition with HRTF: Models how a listener perceives the orchestra using Head-Related Transfer Functions, adjusting for sound absorption.
  • VBAP Multichannel Playback: Uses Vector Based Amplitude Panning to position virtual sound sources across a multichannel speaker setup.
  • Audio DSP Pipelines: Built from scratch using mathematical models and Python libraries to filter, convolve, and synthesize .wav files.

(back to top)


Lessons Learned

  • Acoustic Modeling: Consolidated knowledge on the impact of room parameters like direct fields, absorption coefficients, and reverberation times.
  • Spatial Audio Techniques: Learned how to apply Head-Related Transfer Functions to create realistic 3D auditory illusions for headphones.
  • Vector Based Amplitude Panning: Understood the mathematics behind calculating speaker gains to pan a virtual sound source between physical speakers.
  • Digital Signal Processing: Improved practical skills in Python for audio signal manipulation, filtering, and wave generation.

(back to top)


Getting Started

Follow these instructions to set up a local copy of the project on your machine.

Prerequisites

  • Python 3.8+
  • Jupyter Notebook (or JupyterLab)
  • Standard DSP libraries: numpy, scipy, matplotlib

Installation & Running Locally

  1. Clone the repository:
    git clone https://github.com/GuilhermeGraca/python-binaural-audio-simulation.git
  2. Navigate to the project folder:
    cd python-binaural-audio-simulation
  3. Install the required packages:
    pip install numpy scipy matplotlib jupyter
  4. Run the Jupyter Notebook:
    jupyter notebook Trabalho2_CPS_A51736_A51827_A51829.ipynb

(back to top)


Usage

To use the simulation, simply run the cells inside the Jupyter Notebook sequentially. The code will read the input audio files, perform the digital signal processing calculations, and output newly synthesized .wav files corresponding to the monaural, binaural, and multichannel simulations.

You can also analyze the generated plots inside the notebook to visualize the waveforms and understand the sound field behavior.

Visualizations

Here is a glimpse of the digital signal processing visualizations generated by the notebook:

Signal Processing Plot 1   Signal Processing Plot 2

Generated files (inside audio/generated/) include:

  • somOndaDireta.wav
  • somFinalPrimeirasReflexões.wav
  • campo_total_RT60_*.wav
  • somFinalHRTFdosAltifalantes.wav

(back to top)


Contact

Guilherme Graça - LinkedIn - GitHub

(back to top)


Acknowledgments

  • ISEL (Instituto Superior de Engenharia de Lisboa) for providing the academic environment and resources.
  • Professor Joel Paulo for the guidance throughout the Comunicação de Sinais Multimedia (now PSM) course.
  • Martim Ramos and Rodrigo Monteiro for the collaboration on this project.

(back to top)

About

Python-based simulation engine for spatial audio rendering, room acoustics, binaural audition (HRTF), and multichannel sound reproduction (VBAP). Made using the python libraries matplotlib, scipy, numpy, wav.. Made in colaboration with Martim Ramos and Rodrigo Monteiro

Topics

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages