Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- The function below uses teh maths to rotate a pair of sound files (sound_r and sound_l) along the Y axis, relative to the player's "ears" in an attempt to mimic playing a stereo audio file. However, rotating sound along the Y axis doesn't do anything to the audio; rotation along the X axis, however, will create a stereo effect.
- Imagine using a pair of stereo headphones, with only a left and right channel. A value in the -X will favor the left channel, and a value in the +X will favor the right channel. Moving a theoretical sound source into +Y or -Y will have no effect on the left or right channel in a stereo setup. So, setting sound_l to a -X will play it in the left speaker, and setting sound_r to a +X will play it in the right speaker. Keeping each at 0 or neutral will play them as if they were mono files, ie dead center.
- The function vector_rotate_y uses theory from a very advanced, but very niche way to handle audio called Ambisonics. https://en.wikipedia.org/wiki/Ambisonics
- Here is a related .pdf with a bunch of math in it I don't understand :D
- http://raffayhamid.com/ICIP_2004.pdf
- I essentially need something like this (shown below) that will have an effect on the X axis instead of the Y axis. Trouble is, I have no idea where this math came from and I have no idea how to relate it to the X axis.
- for Y axis (current function):
- function vector_rotate_y (v, angle)
- angle = angle * 0.017453292519943295769236907684886 (where did they get this shit from?)
- local c = math.cos (angle)
- local s = math.sin (angle)
- return vector ():set (v.x * c - v.z * s, v.y, v.x * s + v.z * c)
- end
- for X axis (new function I need help coding):
- function vector_rotate_x (v, angle)
- angle = angle * (some number)
- local c = (sin? cos?)
- local s = (sin? cos?)
- return vector ():set (formula goes here)
- end
- in the game, I will then use this code to tell the game how many degrees to rotate the two opposing sound sources (I'll choose +90 for the left channel, and -90 for the right):
- function action_sound2d:get_source_positions ()
- local actor = db.actor
- local dir = actor:direction ()
- dir.y = 0.0
- local dir_left = vector_rotate_y (dir, 90)
- local dir_right = vector_rotate_y (dir, -90)
- dir_left:normalize ()
- dir_right:normalize ()
- --ðàññ÷èòàåì âûñîòó
- local pos = actor:position ()
- pos.y = pos.y + 1.5 --íó íèçêîðîñëûé ó íàñ àêòåð...
- local pos_l = pos;
- return pos_l:add (dir_left:mul (1.5)), pos:add (dir_right:mul (1.5))
- end
- ------------------------------------------------------------------------------------
- ------------------------------------------------------------------------------------
- NEW CODE WITH NEW MATHS
- ------------------------------------------------------------------------------------
- ------------------------------------------------------------------------------------
- function action_sound2d:get_source_positions ()
- local actor = db.actor
- local dir = actor:direction ()
- dir.x = 0.0 --wtf does this mean
- local dir_left = vector_rotate_x (dir, -90) --this should rotate the sources by 90 degrees from center, respectively ...
- local dir_right = vector_rotate_x (dir, 90)
- dir_left:normalize ()
- dir_right:normalize ()
- local pos = actor:position ()
- pos.x = pos.x + 1.5 --wtf does this do
- local pos_l = pos;
- return pos_l:add (dir_left:mul (1.5)), pos:add (dir_right:mul (1.5))
- -I think pos_l = position of the left channel audio source and pos = right channel
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement