2019-05-01 00:33:38 (edited by amerikranian 2019-05-05 22:50:18)

I'm posting this in here because this is not a game. No, this is a set of scripts that should make your life a bit easier when it comes to multiple sound managing.
When I started with python I had an interesting time figuring out sounds. I was a bit annoyed that there was no sound_pool module for it and I had an idea. Let's convert BGT sound_pool to python!
And so here we are.
Before I give out the links, I want to say one thing: I didn't write it myself. Yes, I translated the entire file from BGT to python, but what made it possible was Carter Tem's sound class. He also figured out why the pan wasn't working as it should and was kind enough to give me the sound positioning functions and his permission for me to release the two files here publicly on the forum.
As well as Carter, I would like to thank Sam Tupy for releasing his 3D sound pool which this conversion is based on. Without Sam, the pool would only have 2D functionality, and without Carter, the pool would still have been broken in terms of pan. Thank you both.
So what do you need to run this?
First, you will need sound_lib, which I will link to after this post. That or you can go check out Carter's Github and find it yourself.
Then you need to import the sound_pool within your project. It comes with an instantiated object of size 100 named p, which you can find at the bottom of the sound_pool.py file. Previously, you were required to change the sound pool values, but that is changed. Though you still may do so, the sound pool defaults are sufficient enough.
There is no read me. If you really need one, go check out the BGT manual or Sam's package, though that one still assumes you worked with the sound_pool before.
Lastly, the links.
Tiny upload link, guaranteed to stay
Dropbox link, not guaranteed to stay forever but should work for a while
Sam's 3D sound pool, this is what I converted to python
The sound_lib, this is what you need in order for the sound class to function properly
Again, thanks goes to Carter and Sam for making this possible.
A quick note: Some of this has not been tested well, so if you find an error do let me know so I can fix it. Seems to work fine when I messed around with it. Also, optimizations and performance improvements tips are greatly appreciated.
Quick note 2:  The sound pool already assumes that you are in your sounds folder. So for example, if I had the folder named steps within my sounds and I want the sample to play step one, I would do steps/step1.ogg as a function parameter. I tried to come up with a way to change this, but I haven’t found an easy solution.

Coding is not hard. No, not at all.
What is hard is making code that accepts different and sometimes unexpected types of input and still works.
This is what truly takes a large amount of effort on a developer's part.

Thumbs up +3

2019-05-01 16:38:53

This sounds neat!
Thanks.

My tactical battle scripts: https://www.dropbox.com/s/dzsmqv2pgqvu1 … h.zip?dl=1
Currently, one of my favorite games is Trimps.
So I'm the Trimper Trooper!

Thumbs up

2019-05-02 02:36:24

... There is so much wrong with this. So many times, you refer to handle.handle ... That doesn't exist. Your play_extended_3d function doesn't have all the requirements ... Reserving slots is broken because of the handle.handle thing ... Oh man.

Follow on twitter! @masonasons_me
Thanks, enjoy, thumbs up, share, like, hate, exist, do what ya do,
my website: masonasons.me
If this post is of any use, why not thumb it up?

2019-05-02 02:37:10

Oh and also, please do not assume where the sounds are in a player's system. I had to completely remove the pack thing because no my sounds aren't in sounds/.

Follow on twitter! @masonasons_me
Thanks, enjoy, thumbs up, share, like, hate, exist, do what ya do,
my website: masonasons.me
If this post is of any use, why not thumb it up?

2019-05-02 20:22:25 (edited by amerikranian 2019-05-02 20:24:40)

@3/4, I am open to suggestions and or improvements like I said. As for handle.handle, try printing it when the sound is loaded into it and when it isn't. If it isn't, you will get None as your value. Saying that the pool is broken and not offering suggestions isn't exactly helpful.
If you know the same function as sound.is_active for BGT sound object in python/sound lib, let me know.
My play_extended_3d is missing arguments? I'll check over it but it shouldn't, I'm not sure what are you talking about. Please explain further if you can.

Coding is not hard. No, not at all.
What is hard is making code that accepts different and sometimes unexpected types of input and still works.
This is what truly takes a large amount of effort on a developer's part.

Thumbs up

2019-05-03 01:49:26 (edited by amerikranian 2019-05-03 01:51:06)

Right. So, I have made some changes to the sound pool, but I can't really debug the thing because I don't know exactly what is broken. Mason, can you tell me what to do in order to make it behave weirdly? I.e, illustrate how the slots get cleaned up incorrectly so I can make sure I fixed the issue.
On another note, I will also remove the packname thing since only I am sane and keep my sounds in sounds/, though that will be an issue if I ever figure out how to encrypt folders.

Coding is not hard. No, not at all.
What is hard is making code that accepts different and sometimes unexpected types of input and still works.
This is what truly takes a large amount of effort on a developer's part.

Thumbs up

2019-05-03 10:45:53 (edited by cmerry 2019-05-03 10:47:34)

I think part of the problem with this thing was it was sort of originally made for more private projects, and then wasn't really optimized for public consumption. I haven't tryed reserving slots as of yet, I usually just use sound_lib and sound_positioning for moving sounds. Although, I used to do the same thing with bgt minefield, with the sound object, and that didn't turn out so good.

Use the below link to get about 500 or so mb of extra dropbox space when you create an account.
https://db.tt/dDngEzFLo7

2019-05-03 20:20:30

I figured out why we might be having issues reserving and cleaning slots, but again, I have no way of testing it. I can release the version that I have which really doesn't change a lot, but again, I would like to know what breaks so I can make sure that I fixed it.
As for public usage, you're right and not at the same time. I assumed that most people keep their sounds in sounds/, see oh shit. I have removed some bits of code in the try/except statements that basically alerted you that the lib couldn't find a file in the public version, but I just thought most folks keep their stuff in sounds/

Coding is not hard. No, not at all.
What is hard is making code that accepts different and sometimes unexpected types of input and still works.
This is what truly takes a large amount of effort on a developer's part.

Thumbs up

2019-05-03 22:03:22

In my current sound class, I have packing support, so my sounds won't be in sounds/.

Follow on twitter! @masonasons_me
Thanks, enjoy, thumbs up, share, like, hate, exist, do what ya do,
my website: masonasons.me
If this post is of any use, why not thumb it up?

2019-05-05 22:55:09

I've just updated sound pool, let me know if things are broken again. Thanks goes to Carter again for helping with figuring some stuff out, seems like we never stop learning...
The slot reservation shouldn't be a thing anymore, the sound pool does not have a limit on the amount of sounds it can play. That doesn't impact your ability of using the update_sound_range and update_sound values. Things might still be broken, and yes, the pack is still a thing, sorry Mason. I'll remove it, I promise, sometime. I'm just tired right now.

Coding is not hard. No, not at all.
What is hard is making code that accepts different and sometimes unexpected types of input and still works.
This is what truly takes a large amount of effort on a developer's part.

Thumbs up

2019-05-06 09:53:40

Hi, thanks for this sound pool. does it support all file formats? or just ogvorbius?

best regards
never give up on what ever you are doing.

2019-05-06 20:57:15

It supports all the file formats sound_lib does. I have tried .ogg and .wav, it should also work with .mp3.

Coding is not hard. No, not at all.
What is hard is making code that accepts different and sometimes unexpected types of input and still works.
This is what truly takes a large amount of effort on a developer's part.

Thumbs up

2019-05-16 20:01:31

Hello. You might want to consider adding orientation support for the player as well.

Add me on skype: kianoosh.shakeri2
Or follow me on twitter @kianoosh shakeri

2019-05-16 20:21:58

I am not sure what you mean. Are you talking about 3D rotation? If so, that can be done by adding a single parameter and changing the 0 in the position_sound_3d function to that param. One thing, though. I never worked with 3D rotation, and thus am unable to verify that it actually works.

Coding is not hard. No, not at all.
What is hard is making code that accepts different and sometimes unexpected types of input and still works.
This is what truly takes a large amount of effort on a developer's part.

Thumbs up

2019-05-17 16:14:05

I exactly meant what You mentioned. Yeah it should work fine. I added that in your sound pool and things should run smovely, At least I hope big_smile

Add me on skype: kianoosh.shakeri2
Or follow me on twitter @kianoosh shakeri

2019-05-17 20:16:31

Cool. I'll do that when I get home and hopefully upload the versions

Coding is not hard. No, not at all.
What is hard is making code that accepts different and sometimes unexpected types of input and still works.
This is what truly takes a large amount of effort on a developer's part.

Thumbs up

2019-05-20 11:06:42

Hey neat. Very awesome.

My name is Inigo Montoya. You killed my space bar. Prepare to die!

http://l-works.net

2019-05-20 14:51:35

There's just a problem. I'm not sure if it's my code, or your code, or bass itself. Update sound range 3d seem to break the correct panning when the sound is to your right.

Add me on skype: kianoosh.shakeri2
Or follow me on twitter @kianoosh shakeri

2019-05-20 20:24:23

In what way does it break the pan? Can you post a recording of it doing so as well as the params you're passing along to the update_sound_range function?

Coding is not hard. No, not at all.
What is hard is making code that accepts different and sometimes unexpected types of input and still works.
This is what truly takes a large amount of effort on a developer's part.

Thumbs up

2019-05-27 16:19:16

Ok. It looks like my problem with update range 3d was from my own code. Butt there's a problem with setting of pan in the sound class. It looks like that the set pan formula isn't calculated correctly. Because when I use the theta value in position sound custom 3d function,fails It's like if I'm facing 15 or 16 degrees the sound is to my left just like i'm facing 90 degrees

Add me on skype: kianoosh.shakeri2
Or follow me on twitter @kianoosh shakeri

2019-05-27 18:38:06 (edited by amerikranian 2019-05-28 01:23:37)

I am not too sure as to how to go about fixing that problem. I do not believe it is the pans fault, it might be your theta, Are you sure you are calculating it correctly?  I will see what I can do. Also, sorry for not updating the sound pool, I will do so hopefully this week.

Coding is not hard. No, not at all.
What is hard is making code that accepts different and sometimes unexpected types of input and still works.
This is what truly takes a large amount of effort on a developer's part.

Thumbs up

2019-05-28 15:38:11

Yeah i'm sure I'm calculating it correctly. I'm doing the same in bgt and it works fine there. It is a wrong calculation of pan which I think is so hard to fix

Add me on skype: kianoosh.shakeri2
Or follow me on twitter @kianoosh shakeri

2019-05-28 20:26:27

Can you post the formula that BGT uses here by any chance?

Coding is not hard. No, not at all.
What is hard is making code that accepts different and sometimes unexpected types of input and still works.
This is what truly takes a large amount of effort on a developer's part.

Thumbs up

2019-05-29 15:48:50

Sure. Here's the custom sound positioning 3d function:
void position_sound_custom_3d([email protected] handle, float listener_x, float listener_y, float listener_z, float source_x, float source_y, float source_z, double theta, float pan_step, float volume_step, float behind_pitch_decrease, float start_pan, float start_volume, float start_pitch)
{
float delta_x=0;
float delta_y=0;
float delta_z=0;
float final_pan=start_pan;
float final_volume=start_volume;
float final_pitch=start_pitch;
float rotational_source_x=source_x;
float rotational_source_y=source_y;
// First, we calculate the x and y based on the theta the listener is facing.
if(theta > 0.0)
{
rotational_source_x = (cosine(theta) * (source_x-listener_x)) - (sine(theta) * (source_y-listener_y)) + listener_x;
rotational_source_y = (sine(theta) * (source_x-listener_x)) + (cosine(theta) * (source_y-listener_y)) + listener_y;
source_x=rotational_source_x;
source_y=rotational_source_y;
}
// Next, we calculate the delta between the listener and the source.
if(source_x<listener_x)
{
delta_x=listener_x-source_x;
final_pan-=(delta_x*pan_step);
final_volume-=(delta_x*volume_step);
}
if(source_x>listener_x)
{
delta_x=source_x-listener_x;
final_pan+=(delta_x*pan_step);
final_volume-=(delta_x*volume_step);
}
if(source_y<listener_y)
{
final_pitch-=absolute(behind_pitch_decrease);
delta_y=listener_y-source_y;
final_volume-=(delta_y*volume_step);
}
if(source_y>listener_y)
{
delta_y=source_y-listener_y;
final_volume-=(delta_y*volume_step);
}
if(source_z<listener_z)
{
final_pitch-=absolute(behind_pitch_decrease);
delta_z=listener_z-source_z;
final_volume-=(delta_z*volume_step);
}
if(source_z>listener_z)
{
delta_z=source_z-listener_z;
final_volume-=(delta_z*volume_step);
}
// Then we check if the calculated values are out of range, and fix them if that's the case.
if(final_pan<-100)
{
final_pan=-100;
}
if(final_pan>100)
{
final_pan=100;
}
if(final_volume<-100)
{
final_volume=-100;
}
if(final_pitch<handle.pitch_lower_limit)
{
final_pitch=handle.pitch_lower_limit;
}
// We don't check for the highest possible pitch as it is hard to determine.

// Now we set the properties on the sound, provided that they are not already correct.
if(handle.pan!=final_pan)
handle.pan=final_pan;
if(handle.volume!=final_volume)
handle.volume=final_volume;
if(handle.pitch!=final_pitch)
handle.pitch=final_pitch;
}

Add me on skype: kianoosh.shakeri2
Or follow me on twitter @kianoosh shakeri

2019-05-29 21:07:51

I am not really sure, unfortunately. The formulas look exactly the same, hell I replaced bgt sin and cosine functions and checked the equality of strings in python and it showed it to be true. I'm sorry. I'd like to help, I just dono how.

Coding is not hard. No, not at all.
What is hard is making code that accepts different and sometimes unexpected types of input and still works.
This is what truly takes a large amount of effort on a developer's part.

Thumbs up