2019-07-22 14:47:07

I'm trying to play a sound using the sound_pool_item class that came with bgt. I understand all of the variables, except for this first thing...

class sound_pool_item
{
sound@ handle;
string filename;
string packname;
int x;
int y;

how the hell do I use the sound@handle to play my sound?

2019-07-22 14:57:01 (edited by ivan_soto 2019-07-22 14:59:35)

just do this.

handle=pool.play_2d("sound.ogg",listener_x,listener_y,sound_x,sound_y,loop);

Now if you wanna do things like kill the sound, you can do so by doing this.

pool.destroy_sound(handle);

Ivan M. Soto.
Feel free to check out my work and services.
http://ims-productions.com

2019-07-22 16:29:04

I tried to do the following

sound_pool_item v;
v.start_volume=0;
v.looping=true;
v.stationary=false;
void main()
{
v.filename="sounds/music1.ogg";
v.handle=p.play_stationary("sounds/music1.ogg",false);
}

Error: Can't implicitly convert from 'int' to 'const sound&'.

2019-07-22 16:59:43

the sound_pool_item is a lowerlevel class managed by the sound_pool
And you're getting that error, because the handle espects a sound handle, while the sound_pool play functions return an integer, which is the id of the item.
You should do something like the following, and use the sound_pool class instead.
#include "sound_pool.bgt";

sound_pool p; // define the variable p of type sound_pool
void main()
{
// the sound pool is nice, and you do not need to load the sound at all, but just pass the name to the play function
p.play_stationary("sounds/music1.ogg", false);
// if instead you wish to retrieve the id of the sound, you can do something like:
int sound_id = p.playstationary("sounds/music1.ogg", false);
}
Hope I was of help.

Paul

2019-07-22 17:18:51

You're not supposed to use sound_pool_item directly, but to let sound_pool manage it.
Having said that, if you really want to use sound_pool_item, look for the method that loads the sound (handle.stream, I think?).
The thing to be aware of is that handle may or may not be null. So if you want to use it directly, you need to be sure that it is not null.
It's not in the manual, but you can check if two handles are the same (null is effectively a handle for these purposes), like so:
if (handle is null) {do something}
But assigning values to handles is more annoying (you need the @ and such). Hence, sound_pool is more convenient.

看過來!
"If you want utopia but reality gives you Lovecraft, you don't give up, you carve your utopia out of the corpses of dead gods."
MaxAngor wrote:
    George... Don't do that.

2019-07-25 08:28:55

I just want to be able to set a volume for the sound. And I didn't think sound_pool could do that. I noticed sound_pool_item has start_volue which is what I need. So how can I use sound_pool to set a starting volume?

2019-07-25 08:39:58

You'll have to use play_extended_1d.

Look in the documentation for usage. You can pass 0 to left_range and right_range if you don't care. If you'd like an example of how this might be invoked, check the source for sound_pool.bgt. play_1d, play_2d and play_3d all use the extended functions to perform their magic under the hood.

2019-07-25 09:59:20 (edited by Zarvox 2019-07-25 10:00:25)

can I have the extended 1d loop? I am trying to use the sound_pool to play music rather than the sound function so I can set a volume and have it keep the volume when the music track changes. Currently with the sound function every time the track changes I have to write:
svolume=music.volume;
music.stream("music2.ogg");
music.volume=music.volume-svolume;

I would like to set the volume once and keep it when the track changes. As far as I know the sound function will not save volume so that's why I am attempting to use sound_pool instead
Perhaps I should have named this topic how to keep volume level when changes music tracks.

2019-07-25 10:43:05 (edited by haily_merry 2019-07-25 10:44:49)

Actually doing this sort of thing with the sound object would be much easier, provided you don't need to position the sound, but even then we have sound positioning. Here's a little example.
sound music;
void main()
{
show_game_window("Music player");
music.load("music.ogg");
music.volume=-10;
music.play_looped();
while(true)
{
wait(5);
if(key_pressed(KEY_UP))
{
music.volume++;
}
if(key_pressed(KEY_DOWN))
{
music.volume--;
}
if(key_pressed(KEY_ESCAPE))
{
exit();
}
}
}
Note that this code isn't tested, but I see no reason why it shouldn't work.

2019-07-25 13:35:13

but I would like the volume to keep where it is when I load a different sound. It always resets. And I am streaming not loading. I will switch to loading if it means it can do it better than streaming can. I have a way to do it, it is just a pain.

2019-07-25 14:44:40

What I would do is make a function that just streams a file and if there is one playing just get the volume and set it to the other one. Here is the function I wrote for ya.

Untested code so here you go.

bool play_sound(string soundname) {
bool oldvol=false;
int prev_volume=0;
if(music.playing==true) {
prev_volume=music.volume;
oldvol=true;
}
music.stop();
music.stream(soundname);
if(oldvol==true) music.volume=prev_volume;
music.play_looped();
}

Ivan M. Soto.
Feel free to check out my work and services.
http://ims-productions.com

2019-07-25 19:26:37

You'd need to specify the volume for every track. My approach has been to have a playsong function that takes care of this. It may or may not be in the includes I uploaded last year (stdlib.bgt, which also has updatebgm() for fading and crossfading).

看過來!
"If you want utopia but reality gives you Lovecraft, you don't give up, you carve your utopia out of the corpses of dead gods."
MaxAngor wrote:
    George... Don't do that.

2019-07-26 01:57:16

@12 expired links.

2019-07-26 05:43:41

can someone please make a working link for stdlib.bgt?

2019-07-26 13:29:47

Just use the function that I gave you. Hold on, let me upload sdlib.bgt to db.

https://www.dropbox.com/s/8db3lm1l7j10t … s.zip?dl=1

Ivan M. Soto.
Feel free to check out my work and services.
http://ims-productions.com