Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (AndrewAMD, alibaba, VoroneTZ), 916 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
How to preload sounds? #352324
01/02/11 21:46
01/02/11 21:46
Joined: Nov 2010
Posts: 96
Vienna
S
Schubido Offline OP
Junior Member
Schubido  Offline OP
Junior Member
S

Joined: Nov 2010
Posts: 96
Vienna
Hi,

I'm doing my first try with sound in 3DGS V8.10.
If the sound is played the first time the game jitters a bit. I guess that happens because the sound file is loaded at the first use.
Is there any possibility to automatically preload sounds?
Currently I'm doing a work-around by playing all sounds one time with sound level 0 before the game starts. That works fine, but does not seem to be a smart way to do it.
Any better ideas?

Re: How to preload sounds? [Re: Schubido] #352331
01/02/11 22:26
01/02/11 22:26
Joined: Dec 2008
Posts: 271
Saturnus Offline
Member
Saturnus  Offline
Member

Joined: Dec 2008
Posts: 271
Do you use media_play()?
As far as I know, you can't preload sounds for media_play().

You could use snd_play() as an alternative, though. It plays wav and ogg files. There shouldn't be any delay when using this function.
You can also create your sound objects to be played back by snd_play() during runtime (snd_create) and destroy them, when you don't need them anymore (ptr_remove).

Re: How to preload sounds? [Re: Saturnus] #352361
01/03/11 08:03
01/03/11 08:03
Joined: Nov 2010
Posts: 96
Vienna
S
Schubido Offline OP
Junior Member
Schubido  Offline OP
Junior Member
S

Joined: Nov 2010
Posts: 96
Vienna
Thanks for your reply.
I use snd_play and of course there is a delay at the first call of snd_play for each sound (~0.5 sec) regardless if the sound was defined as global <SOUND* = "filename.wav"> or created with snd_create.

Re: How to preload sounds? [Re: Schubido] #352365
01/03/11 08:12
01/03/11 08:12
Joined: Dec 2008
Posts: 271
Saturnus Offline
Member
Saturnus  Offline
Member

Joined: Dec 2008
Posts: 271
Hmm, according to the manual there shouldn't be a delay: "SOUND* name = "filename"; ... Defined sounds are permanently stored in memory and can be played or looped without initial delay."
I don't know why it doesn't work (for you? for all?), though.

Re: How to preload sounds? [Re: Saturnus] #352368
01/03/11 09:06
01/03/11 09:06
Joined: Nov 2007
Posts: 1,143
United Kingdom
DJBMASTER Offline
Serious User
DJBMASTER  Offline
Serious User

Joined: Nov 2007
Posts: 1,143
United Kingdom
hmm yes this is strange, I thought it was only streaming media that had a delay.
Is it all sounds that have a delay or a select few?

Re: How to preload sounds? [Re: DJBMASTER] #352373
01/03/11 10:17
01/03/11 10:17
Joined: Nov 2010
Posts: 96
Vienna
S
Schubido Offline OP
Junior Member
Schubido  Offline OP
Junior Member
S

Joined: Nov 2010
Posts: 96
Vienna
I reproduced the behaviour in a short example.
It uses "fisch1.mdl", "explo.wav", "explosin.wav", "explosion.wav" which I found in the 3DGS samples.
It does a simple animation of the model (could be any model) and plays a sound if you press a number key (1-3).
It turned out, that the delay is only the first time any sound is played, not for each sound. So it should not occur in the final version of the game, if a intro sound is played.

If you want to reproduce the effect, here is the code :


///////////////////////////////
#include <acknex.h>
#include <default.c>
#include <mtlFX.c>
///////////////////////////////

SOUND* Sound1 = "explo.wav";
SOUND* Sound2 = "explosin.wav";
SOUND* Sound3 = "explosion.wav";

// do some silly movements ...
action AnimateFish()
{
var degree = 0;
var movePercent = 0;

while (1)
{
degree+=time_step*5;
movePercent += time_step*30;
me.x = 100*sin(degree);
me.y = 100*cos(degree);
me.pan = -degree;
ent_animate(me,"",movePercent,ANM_CYCLE);
wait(1);
}
}

function Sound()
{
while(1)
{
if (key_1)
{
snd_play(Sound1,50,0);
}
if (key_2)
{
snd_play(Sound2,50,0);
}
if (key_3)
{
snd_play(Sound3,50,0);
}
wait(1);
}
}


function main()
{
video_screen = 1; // full screen
preload_mode = 3; // preload entities
level_load(NULL);
camera.x = -300;
camera.z = 100;
camera.tilt = -20;
ent_create("fisch1.mdl", vector(0,0,0), AnimateFish);
Sound();
}

Re: How to preload sounds? [Re: Schubido] #352374
01/03/11 11:23
01/03/11 11:23
Joined: Feb 2010
Posts: 320
TANA/Madagascar
3dgs_snake Offline
Senior Member
3dgs_snake  Offline
Senior Member

Joined: Feb 2010
Posts: 320
TANA/Madagascar
Hi!
I think that it's not a problem with the function. It is just that if the keys remain pressed, it will cause the sound to be played again and again until you release the keys. There are many solutions but one example is to wait for the release of a key to play the sound (or play the sound on key press and wait until the release of the key).

Code:
///////////////////////////////
#include <acknex.h>
#include <default.c>
#include <mtlFX.c>
///////////////////////////////

#define PRAGMA_PATH "C:\\Program Files\\GStudio7\\templates\\sounds";

SOUND* Sound1 = "explo.wav";
SOUND* Sound2 = "explosin.wav";
SOUND* Sound3 = "explosion.wav";

// do some silly movements ...
action AnimateFish()
{
	var degree = 0;
	var movePercent = 0;
	
	while (1)
	{
		degree+=time_step*5;
		movePercent += time_step*30;
		me.x = 100*sin(degree);
		me.y = 100*cos(degree);
		me.pan = -degree;
		ent_animate(me,"",movePercent,ANM_CYCLE);
		wait(1);
	}
}

function Sound()
{
	while(1)
	{
		// Play after a key was released
		if (key_1)
		{
			while (key_1) {wait(1);}
			snd_play(Sound1,50,0);
		}
		// Play on key press and wait until the key is released
		if (key_2)
		{
			snd_play(Sound2,50,0);
			while (key_2) {wait(1);}
		}
		if (key_3)
		{
			snd_play(Sound3,50,0);
		}
		wait(1);
	}
}


function main()
{
	//video_screen = 1;	 // full screen
	preload_mode = 3; // preload entities
	level_load(NULL);
	camera.x = -300;
	camera.z = 100;
	camera.tilt = -20;
	ent_create("fisch1.mdl", vector(0,0,0), AnimateFish);
	Sound();
}



Re: How to preload sounds? [Re: 3dgs_snake] #352394
01/03/11 13:25
01/03/11 13:25
Joined: Nov 2010
Posts: 96
Vienna
S
Schubido Offline OP
Junior Member
Schubido  Offline OP
Junior Member
S

Joined: Nov 2010
Posts: 96
Vienna
No, it does not matter if the sound is played several times in parallel. Even keepeng the key pressed for some seconds does not result in a further delay - it just creates an enoying sound ;-)
But there is still a delay at the first snd_play call.
The example was just created to show the effect. In the original code the sound is triggered by a hit event.
However - calling snd_play once before the game starts solves the problem.

Re: How to preload sounds? [Re: Schubido] #352395
01/03/11 13:41
01/03/11 13:41
Joined: Feb 2010
Posts: 320
TANA/Madagascar
3dgs_snake Offline
Senior Member
3dgs_snake  Offline
Senior Member

Joined: Feb 2010
Posts: 320
TANA/Madagascar
Oh! Sorry blush! But here, i think I don't have any delay.


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1