简体   繁体   English

在3D空间中获得声音的“声像”

[英]Get the “pan” of the sound in 3d space

I am currently writing a simple 3d sound system, but I got stuck. 我目前正在编写一个简单的3d声音系统,但遇到了麻烦。

The problem is: I have a point in the space, where the sound comes from, and of course I have the listener, with his point and orientation. 问题是:我在空间中有一个点,声音来自哪里,当然还有听众,他的观点和方向。

The distance was not the problem, it works perfectly, but when I want to calculate the pan of the sound (how much left/right), well it is a total disaster. 距离不是问题,它可以完美工作,但是当我要计算声音的声像(左/右)时,那完全是一场灾难。

I have searched it on the internet, but I can't find any usable solution, and then I tried to calculate it by myself with triangles and stuff, but you don't want to know what the result was. 我已经在互联网上搜索了它,但是找不到任何可用的解决方案,然后我尝试自己用三角形和其他东西来计算它,但是您不想知道结果是什么。

I won't show code, because I have written it three times, and each version was unusable. 我不会显示代码,因为我已经编写了三遍,并且每个版本都不可用。

I don't want you to necessarily give me code, I will happy if I get a mathematical solution for that. 我不希望您一定要给我代码,如果能得到数学上的解决方案,我会很高兴。 I would like to get if the sound is how much left or right from the camera. 我想知道声音是从摄像机左移还是向右移。

I work in c++ 11 and the sound library is Audiere. 我在c ++ 11中工作,声音库是Audiere。

Edit: Thanks to willywonkadailyblah I figured out some solution. 编辑:感谢willywonkadailyblah,我想出了一些解决方案。 You can watch it here: Get x position of sound from camera 您可以在此处观看: 从摄像机获取声音的x位置

with the dot product I can get the cos alpha of the triangle then with a simple pitagoras theorem I can get the distance (A). 用点积,我可以得到三角形的cosα,然后用一个简单的pitagoras定理,我可以得到距离(A)。

And in the end I divide the pandistance with the heardistance and multiply with the sound distance. 最后,我将听觉距离除以听觉范围,再将声音距离乘以。

You could calculate the dot product of the camera direction and the vector joining the camera and the sound source. 您可以计算摄像头方向与连接摄像头和声源的矢量的积。 This gives the cosine of the angle between the vectors. 这给出了向量之间角度的余弦值。 If the dot product is closer to zero than one, the sound source is more "to the side" than "in front". 如果点积比零更接近于零,则声源更“靠近侧面”而不是“前面”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM