Re: WebAudio question

2020-06-02 Thread AudioGames . net Forum — Developers room : camlorn via Audiogames-reflector


  


Re: WebAudio question

@13I used to be super familiar with it and it's like everything else that does what it does. I just haven't used it in long enough that I can't rattle off property names.The coordinate system is unitlesss.  That is to say that they assume that whatever the unit is is whatever you want it to be.  There's some properties for configuring the distance model, you'll want to set max distance to the absolute limit of where the sound can be heard and maybe ref distance to the radius of the object and that's basically it.  They have some defaults assuming meters, but as far as I know nothing in WebAudio mandates meters.  The only important thing is that the forward and up vectors need to be unit vectors (they specify a direction, not a distance) but the formulas in this thread already have you set for that.

URL: https://forum.audiogames.net/post/536282/#p536282




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: WebAudio question

2020-06-02 Thread AudioGames . net Forum — Developers room : chrisnorman7 via Audiogames-reflector


  


Re: WebAudio question

Collision detection is on my todo list. For now it's pretty basic, but works.As an aside, don't suppose you've got any pointers on setting how that distance interacts with my coordinate system do you? I mean, there should be a correlation between the two, so if I move 1 tile that's the equivalent of 2 metres for example, but I've no idea how to set it.No worries if not. I know you said above you're not too familiar with Web Audio.

URL: https://forum.audiogames.net/post/536259/#p536259




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: WebAudio question

2020-06-01 Thread AudioGames . net Forum — Developers room : camlorn via Audiogames-reflector


  


Re: WebAudio question

And not to double post, but properly working collision detection will protect you from that problem.

URL: https://forum.audiogames.net/post/535833/#p535833




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: WebAudio question

2020-06-01 Thread AudioGames . net Forum — Developers room : camlorn via Audiogames-reflector


  


Re: WebAudio question

Glad to hear it.The last part of this is going to be that you will want to make sure that you don't let objects get too close together--if you let a source get "inside" the player's head odd things will happen (usually it panning back and forth crazily).  By "inside" the player's head, I mean within the limits of the error for whatever physics you're using--let's say not closer than  10CM or so.  There's no defined value or anything, but what can happen is that as it gets closer to the head center, really tiny movements become more and more amplified when it tries to figure out the angle--if it's 0.2 mm from the head center and it moves 0.1mm to the right, well that's about 30 degrees of angle.  So in general not something you want to allow to happen.

URL: https://forum.audiogames.net/post/535832/#p535832




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: WebAudio question

2020-06-01 Thread AudioGames . net Forum — Developers room : chrisnorman7 via Audiogames-reflector


  


Re: WebAudio question

OK, after some stress testing, and a change to my list of directions so that directions look right, it's all working swimmingly. Thank you both so much for your help.

URL: https://forum.audiogames.net/post/535826/#p535826




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: WebAudio question

2020-06-01 Thread AudioGames . net Forum — Developers room : chrisnorman7 via Audiogames-reflector


  


Re: WebAudio question

@7I should have written I'm not letting the player tilt their head forward or backwards, rather than I'm not letting them turn it. I am going for FPS-style, so I do believe HRTF is what I want.Everything actually seems to be working now I've applied the formulas you gave me, and the stuff I put in @4.I set the up vector when I first instantiate the listener, so yes, it's getting done.Thank you both so much for your help. I do believe it mostly works now.

URL: https://forum.audiogames.net/post/535822/#p535822




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: WebAudio question

2020-06-01 Thread AudioGames . net Forum — Developers room : chrisnorman7 via Audiogames-reflector


  


Re: WebAudio question

@5Yes, I should have said that before. Here's how my panners look when I create them:final PannerNode panner = commandContext.sounds.audioContext.createPanner()
  ..positionX.value = coordinates.x
  ..positionY.value = coordinates.y
  ..panningModel = 'HRTF'
  ..connectNode(output);commandContext.sounds.audioContext is an AudioContext instance.

URL: https://forum.audiogames.net/post/535821/#p535821




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: WebAudio question

2020-06-01 Thread AudioGames . net Forum — Developers room : camlorn via Audiogames-reflector


  


Re: WebAudio question

@4Yeah, that's right now I think.  You made the change I proposed in 6.HRTf is terrible at in front/behind.  HRTF is also terrible if you're trying to just use it as a stereo panner.  I am 99% sure that your issue is that you have taken something that's intended to be a realistic simulation and tried to make it into something unrealistic--for example if you take a razor or something and pull it from in front straight toward your head in real life, the sound goes off to one side as well unless you perfectly center it at the nose.  If something is close to the head a few inches either way will show up and you *are* supposed to be able to hear it how you're describing, because that's what a real object would do.  Don't forget that in game land you're probably simulating the head and other objects as not having size; if you put the source very, very, very close to the center of the head it also gets weird because it's not meant for that either.If you aren't doing an FPS you may not want hrtf at all; two gain nodes and a channel merger can make a perfectly controllable panner for a sidescroller, and that plus a little work gets you Shadow Rine.  Some of what you're saying implies to me that HRTF is not the right tool for whatever sort of game you're trying to make; as impressive as it is, it's not the end-all of audiogaming and there are a bunch of projects I wouldn't use it for despite currently writing an implementation of it.

URL: https://forum.audiogames.net/post/535818/#p535818




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: WebAudio question

2020-06-01 Thread AudioGames . net Forum — Developers room : camlorn via Audiogames-reflector


  


Re: WebAudio question

I don't see you setting the up vector, only the at vector.  If you aren't, that's your problem, but you only need to do it once, so maybe it's just not in your code.Moving the listener's head is done in every first person game ever. If you're not doing first person stuff, then you won't have them move their head, otherwise at needs to be pointed in the direction the listener is facing.You will have a much easier time if you express your simulation as it actually is (i.e. properly position sources, properly position the listener, etc) than trying to hack things into what you're trying to hack them into without knowing all the underlying math.  Let the engine work for you.Your coordinatesInDirection function is expecting angles counterclockwise from east, not clockwise from north.  Replace cos with sin and sin with cos and I think it will do what you think; but if you just put start in listener.positionX, listener.positionY, you can use my formulas as-is and avoid all of this.  If you want angles counterclockwise from east (which is not at all unreasonable) then my formulas become (cos(theta), sin(theta)) and your function is right.  That said I'm not entirely sure what that function is supposed to do, I'm only guessing.It might be possible to just control azimuth and elevation directly, you might want to do that instead.  And if you're doing a side-scroller or something, you can just drop HRTF and use a couple gain nodes for your panning (if you're wondering where WebAudio put simple stereo panning, where it put simple stereo panning is in 2 gain nodes and a channel merger).  I think it's also worth mentioning that if your game isn't going to allow the listener to turn then you're losing 75% of HRTF or something--HRTF is terrible beyond all belief at telling you if something just went from in front to behind if you can't turn to face it and are trying to aim east while "facing" north.  That said it looks kinda like you're trying to turn the world instead of the listener, which is fine as far as it goes and gets the same thing, it's just kinda hacky.Aprone's trig works well enough for Swamp, but reading his tutorials I don't think he understands what he's doing and just beat on the formulas until he got the numbers to be right, and if I'd done it I'd have just pointed people at a transformation matrix library of some sort and gone through the trouble of explaining how to use it rather than trying to end up at the same place as that through what he did.  Transformation matrix libraries hide all of this from you and if you're sighted you can do all of what you're trying to do with about 0% of the required math knowledge, but the tutorials on their usage are very visual.  It's basically the example case of a picture is worth a thousand words.  Unfortunately I don't have the bandwidth to write a resource at this time and it can't be explained quickly.It's also worth noting that DirectX uses a left-handed coordinate system, and is the only thing that does to my knowledge; to figure out if this mattered I'd have to follow through all of his math and reasoning.  I don't think it does in the 2D case because either he used the x-z plane as horizontal which in DirectX works out to what you'd expect, or he used the x-y plane as horizontal which works out to what you'd expect until you try to add vertical stuff at which point you discover that positive z is down.Trig is hard enough that I might be doing this wrong too, though I've used the above formulas many times before, but either way I take his math with a grain of salt.  I'm not saying assume it's wrong, just check.  Take some numbers and put them into your functions and see if the functions spit out numbers that make sense for what you expect them to do.

URL: https://forum.audiogames.net/post/535816/#p535816




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: WebAudio question

2020-06-01 Thread AudioGames . net Forum — Developers room : magurp244 via Audiogames-reflector


  


Re: WebAudio question

Have you tried enabling [HRTF]?

URL: https://forum.audiogames.net/post/535810/#p535810




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: WebAudio question

2020-06-01 Thread AudioGames . net Forum — Developers room : chrisnorman7 via Audiogames-reflector


  


Re: WebAudio question

OK... After thinking about what you'd said, I adjusted my coordinatesInDirection to the following, which gives slightly better results:Point coordinatesInDirection(Point start, double direction, {double distance = 1.0}) {
  final double rads = direction / 180.0 * pi;
  final double x = start.x + (distance * sin(rads));
  final double y = start.y + (distance * cos(rads));
  return Point(x, y);
}is that any closer to the right answer?Things are to the left and right when they should be, but I can't tell if stuff is in front or behind. Not sure if that's my ears, or Webaudio's inherent limitations. Also, when I get close to stuff, even if I'm facing it directly, it seems to slew off to one side.Thanks much.

URL: https://forum.audiogames.net/post/535804/#p535804




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: WebAudio question

2020-06-01 Thread AudioGames . net Forum — Developers room : chrisnorman7 via Audiogames-reflector


  


Re: WebAudio question

@2Thanks so much for that.So the code I have now, which I believe to be right from your instructions is:  set theta(double value) {
_theta = value;
final double rads = value / 180.0 * pi;
sounds.listener
  ..forwardX.value = sin(rads)
  ..forwardY.value = cos(rads)
  ..forwardZ.value = 0;
  }Does that look OK to you? The double . is Dart's cascade notation. It's still not panning the way I'd expect. As I turn my virtual back to an object, it moves to the left. Ahead objects are to the right. It's like that no matter which direction I walk in.The other thing is, if Aprone's trig is wrong, does that mean my function for getting the coordinates in a particular direction is also wrong? That could account for the panning being off.Point coordinatesInDirection(Point start, double direction, {double distance = 1.0}) {
  final double x = start.x + (distance * cos((direction * pi) / 180));
  final double y = start.y + (distance * sin((direction * pi) / 180));
  return Point(x, y);
}Finally, I'm not planning to let the listener move their head. From what you're saying, that would blow my tiny mind in unimaginary ways.Thanks again, I really appreciate all the help.

URL: https://forum.audiogames.net/post/535800/#p535800




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: WebAudio question

2020-06-01 Thread AudioGames . net Forum — Developers room : camlorn via Audiogames-reflector


  


Re: WebAudio question

Aprone's trig is overcomplicated to the extreme and wrong in some places, followed by him making up for it by correcting before and/or after the fact.The AudioListener has 3 parameters: the position, the forward vector, and the up vector.  You're supposed to set the position to where the listener is at, the forward vector to where the listener is facing, and the up vector out the top of the listener's head.  You're not finding convenient formulas because it's not convenient, it's designed for full 3d space, not 2d space, and it's a kind of standard representation.The way this works is that at cross up gives right, then you can use at, up, right, and position to form a standard 3d transformation matrix.  This is the standard way of representing orientation in a  lot of stuff.  But I suspect that's not helpful to you, so the 2d shortcut:Set the forward vector to (0, 1, 0) and the up vector to (0, 0, 1)  Now positive y is forward, positive x is right, positive z is up.  As long as the up vector is (0, 0, 1), you can think of y as north/south and x as east/west, and those example values configured the listener to face north.Degrees to radians is angle / 180.0 * pi.  To get this to be clockwise from north instead of counterclockwise from east, you use the (cos(theta), sin(theta) formula but swap it to be (sin(theta), cos(theta)).  So to turn the listener leave the up vector alone after you set it the first time and then set the listener's forward vector to (sin(theta), cos(theta), 0).  Z will always be 0 unless you start playing with facing the listener up and/or down, at which point there isn't a shortcut and you'll need to understand spherical coordinates and unit vector stuff properly.Also note that in early-enough versions of Chrome you need to use the deprecated functions to set the orientation and position stuff instead of the new properties, because the new properties are broken.  So if it seems that things aren't moving at all try that.If you just want to pan a source (i.e. ui stuff, things that always follow the player), I believe there's a way to turn off the application of the listener's vectors, but in that case you'll need to deal with the coordinate system being flipped so that negative z is forward, positive x is right, and positive y is up.  I haven't done WebAudio enough that I don't remember how to do it, if it can be done; I got disenchanted by the limitations and started on synthizer instead.  But OpenAL and most other libs offer this as a function.

URL: https://forum.audiogames.net/post/535711/#p535711




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector