-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathspatialisation.py
42 lines (36 loc) · 1.36 KB
/
spatialisation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# -*- coding: utf-8 -*-
#
# Copyright 2016 Holger Ballweg
#
# This file is part of chison.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# spatialisation
import math
from numpy import linalg
halfpi = (0.5 * math.pi)
def angle2d(x1, y1,x2, y2):
return halfpi - math.atan2(y1 - y2, x1 - x2)
def elevation(eye, point):
return angle2d(eye[1], eye[2],
point[1],point[2])
def azimuth(eye, point):
return angle2d(eye[0], eye[2],
point[0],point[2])
def calculate_position(eye, point,distance_offset=0):
# distance shouldn't become 0 for ambisonics
distance = max(0.01, linalg.norm(point-eye) + distance_offset)
az = azimuth(eye, point)
ele = elevation(eye, point)
return distance, az, ele