Jump to content
Melody_Mike

createSoundSource on a random position (Solved)

Recommended Posts

Hello everyone!

Aim: I wish to create randomly located environmental noises within a large space.
 

Attempt: The createSoundSource command works fine on a given marker or trigger. In this example, "mytrigger":

envsound = createSoundSource ["hissing", position mytrigger, ["hissmarker","hissmarker_1","hissmarker_2","hissmarker_3","hissmarker_4","hissmarker_5","hissmarker_6","hissmarker_7","hissmarker_8"], 0];

But you'll see I've also included an array of (earlier created) markers. According to the BIKI: https://community.bistudio.com/wiki/createSoundSource
These can be used to create random locations for the sound. There's also an argument for "placement".
However, regardless of what amount of placement radius or marker arrays I enter, the sounds all exclusively originate from the second argument (above example: position mytrigger ).  

Question: What's a good way to randomize the location of createSoundSource sounds within a given space?

Share this post


Link to post
Share on other sites
1 hour ago, Melody_Mike said:

Hello everyone!

Aim: I wish to create randomly located environmental noises within a large space.
 

Attempt: The createSoundSource command works fine on a given marker or trigger. In this example, "mytrigger":


envsound = createSoundSource ["hissing", position mytrigger, ["hissmarker","hissmarker_1","hissmarker_2","hissmarker_3","hissmarker_4","hissmarker_5","hissmarker_6","hissmarker_7","hissmarker_8"], 0];

But you'll see I've also included an array of (earlier created) markers. According to the BIKI: https://community.bistudio.com/wiki/createSoundSource
These can be used to create random locations for the sound. There's also an argument for "placement".
However, regardless of what amount of placement radius or marker arrays I enter, the sounds all exclusively originate from the second argument (above example: position mytrigger ).  

Question: What's a good way to randomize the location of createSoundSource sounds within a given space?

 

 

i was looking at this the other day to help me with some of my sound issues..

I havent tried it yet but looks fairly straight foward.

 

 

  • Like 1

Share this post


Link to post
Share on other sites

I appreciate the link!

It seems someone scripted their own createSoundSource using playSound3D. If necessary I will use that. 

But, doesn't anyone in these forums have experience with using createSoundSource? And could they explain the syntax of the markers and placement?

Share this post


Link to post
Share on other sites

Try ”_envsound” instead of ”envsound”. Maybe the sound source gets garbage collected when referens is lost. Just speculation though.

 

But if it results in no sound at all you’re closing in. Then you must keep the reference.

Share this post


Link to post
Share on other sites

@engima I'm sorry; I don't understand your suggestion :down:.

Did as you suggested: kept everything the same, except changed the variable name to a local one (_envsound = ... instead of envsound =). Obviously I had to cut the code from my trigger to an external script file, and execute the external script file using null = execVM "scriptfile.sqf"; from the trigger. There was no change, unfortunately. 

As I understand things, the sound was always being created locally at least; I can hear it in singleplayer during my mission at the position mytrigger when it is intended. 

The markers ("hissmarker_1" et cetera) are created globally at mission start, before the script is executed.

My question has to do with a step earlier: the input arguments of createSoundSource. Two of them do work (the chosen CfgSFX sound and position), and the other two do not (array of markers for random placement, and the placement radius around the position the sound may originate from). I have set one or the other argument blank. Both arguments are always ignored. 

So I guess my first question is: how would making the resulting variable local, change how it accepts (global objects as) arguments?  

And the second question: Do you perhaps know an example in a BI mission (preferably a showcase) with a special environmental sound? Perhaps then I could pull it apart to see how they do it... I mean they coded this command with it's syntax for a purpose, I'm sure!

(ps pardon if I seem ungrateful; this puzzle has been keeping me for several evenings!)

Share this post


Link to post
Share on other sites

My first answer was a real longshot. But easy to try, so...

 

I have used the command quite recently, and had no problem with it. I’m quite sure the effect was global as wiki says.

 

Have you tried with one of the default sounds? Otherwise do that. Like ”Sound_Alarm”.

 

I have never used the last two arguments myself. I would rather first selectRandom a marker, and then create sound source with last args as default args ([], 0).

Share this post


Link to post
Share on other sites

Oh bother. I think we are talking past each other. 

The sounds are playing fine. Locally and Globally. It's the (not) random positioning feature that has me stumped.

7 hours ago, engima said:

I have never used the last two arguments myself. I would rather first selectRandom a marker, and then create sound source with last args as default args ([], 0).


^ This is what I meant. 
I have tried your suggestion:

_envsound = createSoundSource ["hissing", getMarkerPos [selectRandom ["hissmarker","hissmarker_1","hissmarker_2","hissmarker_3","hissmarker_4","hissmarker_5","hissmarker_6","hissmarker_7","hissmarker_8"], true] , [], 0];

But the sounds still only play at the trigger location. How do you implement it?
 

Share this post


Link to post
Share on other sites

Spelling errors? And the markers exist on the machine creating the sound source?

Share this post


Link to post
Share on other sites

It's the syntax i'm afraid (parenthesis instead of brackets):

_envsound = createSoundSource ["hissing", getMarkerPos (selectRandom ["hissmarker","hissmarker_1","hissmarker_2","hissmarker_3","hissmarker_4","hissmarker_5","hissmarker_6","hissmarker_7","hissmarker_8"]), [], 0];

 

Share this post


Link to post
Share on other sites
29 minutes ago, RCA3 said:

It's the syntax i'm afraid (parenthesis instead of brackets):


_envsound = createSoundSource ["hissing", getMarkerPos (selectRandom ["hissmarker","hissmarker_1","hissmarker_2","hissmarker_3","hissmarker_4","hissmarker_5","hissmarker_6","hissmarker_7","hissmarker_8"]), [], 0];

 

 

Have you tested it? He’s using the alternative syntax that captures the marker’s z level, so the syntax he’s using should work.

Share this post


Link to post
Share on other sites

Didn't...

 

I don't think you can _mPos2 = getMarkerPos ["markerTwo", true] with multiple markers.

 

He'll have to:

_mkr = selectRandom ["hissmarker","hissmarker_1","hissmarker_2","hissmarker_3","hissmarker_4","hissmarker_5","hissmarker_6","hissmarker_7","hissmarker_8"];

_mkrpos = getMarkerPos [_mkr, true];

 

or

 

_mkrpos = getMarkerPos [(selectRandom ["hissmarker","hissmarker_1","hissmarker_2","hissmarker_3","hissmarker_4","hissmarker_5","hissmarker_6","hissmarker_7","hissmarker_8"]), true];

 

...which was what he did 😄

I think the parenthesis will help though. Idk...

 

Edited by RCA3

Share this post


Link to post
Share on other sites

Argh :sigh:!

To clarify the aim: I am trying to get random factory noises to play inside of a building. The origin should change, in order to confuse players a bit. 

Which means I don't want them all to play from a single location that's pre-selected beforehand. Regardless of the syntax suggested before, it seems that the marker selection will only occur once if I execute createSoundSource only once. 

I suppose the most straightforward solution is to create several markers and run createSoundSource on each of them, with a long delay specified. 

Damned shame nobody on this forum knows how the last two arguments of the command work. Thanks for the help guys!

Share this post


Link to post
Share on other sites

We got the point you were going for, and to expand on that, there's no way the selected marker will always be the same. You'll just have to randomize it outside the createSoundSource command (assuming the syntax above doesn't work).

Share this post


Link to post
Share on other sites

OK, because I was confused about your proposed solutions. Please correct me if I'm wrong here... 

_mkr = selectRandom ["hissmarker","hissmarker_1","hissmarker_2","hissmarker_3","hissmarker_4","hissmarker_5","hissmarker_6","hissmarker_7","hissmarker_8"];

As I understand variable declaration in sqf, the above code will chose ONE marker. From here on out, variable _mrk will always be this ONE marker; never change. Unless you have some sort of conditional loop intended to repeat the variable declaration..

To extend the point:

envsound = createSoundSource ["hissing", getMarkerPos (selectRandom ["hissmarker","hissmarker_1","hissmarker_2","hissmarker_3","hissmarker_4","hissmarker_5","hissmarker_6","hissmarker_7","hissmarker_8"]), [], 0];

Even if I got the syntax to work, the result would be that the sound source will still come from ONE marker position. It seemed, therefore, a little unnecessary to try out random parentheses placement. 

Do you know a user mission with environmental sounds I could pull apart, by any chance?

Share this post


Link to post
Share on other sites
1 hour ago, Melody_Mike said:

some sort of conditional loop intended to repeat the variable declaration..

Yup, because if you wanted to randomize it on createSoundSource itself, you would need a loop as well, wouldn't you?

 

1 hour ago, Melody_Mike said:

still come from ONE marker position.

Yup, random one each time.

 

1 hour ago, Melody_Mike said:

Do you know a user mission with environmental sounds I could pull apart, by any chance?

I was hoping you already had your sounds defined and were testing this.

 

EDIT:
Well, just read this:

Note that the sound created by createSoundSource will always be looping.

 

So... I don't know how you wanna go with this.

 

EDIT2:

I guess that was your problem after all 😄 (my bad, sorry). The command runs once and you were expecting it to play randomly each time... I'm testing it right now...

Edited by RCA3

Share this post


Link to post
Share on other sites
12 minutes ago, RCA3 said:

Yup, because if you wanted to randomize it on createSoundSource itself, you would need a loop as well, wouldn't you?

Okay; we're on the same page. But what kind of conditional looping did you have in mind back there, that would be easier than creating separate sound sources and giving them each their own marker?
 

12 minutes ago, RCA3 said:
32 minutes ago, Melody_Mike said:

Do you know a user mission with environmental sounds I could pull apart, by any chance?

I was hoping you already had your sounds defined and were testing this.

No hope necessary :-). My declared CfgSFX and CfgVehicles work as intended. I asked, because we're moving away from my original question (how to use last two arguments of createSoundSource), and I hoped you might know a potential mission I could check out for inspiration.

Share this post


Link to post
Share on other sites
alarmSFX = createSoundSource ["Sound_Alarm", getMarkerPos "marker_0", ["marker_1","marker_2"], 0];

Randomization works as described, but it's selected only once when called. Then loops always on same position.

 

56 minutes ago, Melody_Mike said:

what kind of conditional looping did you have in mind

 

Example 2 from BIKI plus while loop:

[] spawn {
	while {true} do{

		_alarm = createSoundSource ["Sound_Alarm", position player, [], 0]; //starts alarm

		sleep 10;

		deleteVehicle _alarm; //stops alarm
	};
};

 

Share this post


Link to post
Share on other sites

Ok thanks. But it seems like we've come full circle in a way.

I am not seeing the practical difference between your code:

2 minutes ago, RCA3 said:

alarmSFX = createSoundSource ["Sound_Alarm", getMarkerPos "marker_0", ["marker_1","marker_2"], 0];

And the code from my opening post:

On 9/17/2020 at 7:03 AM, Melody_Mike said:

envsound = createSoundSource ["hissing", position mytrigger, ["hissmarker","hissmarker_1","hissmarker_2","hissmarker_3","hissmarker_4","hissmarker_5","hissmarker_6","hissmarker_7","hissmarker_8"], 0];

Which keeps the sound on only 1 location. 

I appreciate the demonstration of a "while" loop. Can't immediately think of an elegant use for repeatedly creating and deleting new sound sources, whenever a sound has played. 
Unless someone has experience with the command, or a new suggestion, I think I'm going to leave it here, and stick to workarounds.

Thanks for the help gents. 

Share this post


Link to post
Share on other sites
1 hour ago, Melody_Mike said:

I am not seeing the practical difference between your code:

There isn't, but you did say this:

 

On 9/17/2020 at 6:03 AM, Melody_Mike said:

regardless of what amount of placement radius or marker arrays I enter, the sounds all exclusively originate from the second argument (above example: position mytrigger ).  

Which is not accurate because the sounds are indeed chosen randomly from the given array (plus given position).

 

1 hour ago, Melody_Mike said:

Can't immediately think of an elegant use for repeatedly creating and deleting new sound sources, whenever a sound has played. 

I think the loop is quite elegant and if i'm not mistaken, even if you deleteVehicle the sound playing, it will still end playing so it won't cut abruptly. You could also simply count the time the sound takes and sleep the loop for that amount of time.

 

1 hour ago, Melody_Mike said:

I think I'm going to leave it here, and stick to workarounds

As you wish.

 

1 hour ago, Melody_Mike said:

Thanks for the help gents. 

You're welcome.

Edited by RCA3
(plus given position)

Share this post


Link to post
Share on other sites
1 minute ago, RCA3 said:

Which is not accurate because the sounds are indeed chosen randomly from the given array.

Did you get it to work? Because I did not. I might even consider sending cash via Paypal if you have got an example mission where it works!

Share this post


Link to post
Share on other sites

😄

Yes, I said I was testing it, and it worked everytime.

(But only ONCE, then loops on same position each time, therefore the mentioned while loop).

Edited by RCA3

Share this post


Link to post
Share on other sites

Hi.

Props where props are due; Engima's mission works as expected. Using that example, I now have the environmental sounds working. 

A couple of things were keeping me stuck:
- An overestimation of the positional sound effects of the game.
- Incorrectly scaling the distance and volume parameters. Both units a quite arbitrary when it comes to sound perception (especially if sound is above the player).

Result was that I was changing around classnames and syntax, when it was just a question of setting appropriate numbers. 

Thanks gents!

  • Like 1

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×