Playing sounds?


(mgt) #1

For a few days now i’m wondering about how to play a soundfile. I added a new entry in the cgs.media structure and i registered the sound.

cgs.media.mapload = trap_S_RegisterSound("sound/music/mapload.wav", qfalse);
if (!cgs.media.mapload) { msg = "^1ERROR loading mapload sound!^7"; }
else { msg = "^2mapload sound loaded successfully!^7"; }

I always get the msg that the sound is loaded successfully, so I think it is. But when I try to play it by using the trap_S_StartSound command, nothing happens:

trap_S_StartSound(NULL, 1, CHAN_AUTO, cgs.media.mapload);

What am I doing wrong?


(mgt) #2

sry :bump:


(h0nd) #3

Maybe something like this?
From g_referee.c >


G_globalSound("sound/osp/prepare.wav");


(mgt) #4

hmm sry, i need it for cgame … but thx anyway…


(nUllSkillZ) #5

Hi,

I’ve found a struct where all of the media (exactly: I think these are handles for the media) is stored.
File: cg_local.h
Struct: cgMedia_t
Line: 1175 - 1711

// all of the model, shader, and sound references that are
// loaded at gamestate time are stored in cgMedia_t
// Other media that can be tied to clients, weapons, or items are
// stored in the clientInfo_t, itemInfo_t, weaponInfo_t, and powerupInfo_t

May be you have to edit this struct (if you haven’t so far).


(mgt) #6

I have, i have! look at my first post … cgs.media.mapload = trap_S_RegisterSound(“sound/music/mapload.wav”, qfalse);
but i cant get that sound played …


(nUllSkillZ) #7

Yes I know, but you haven’t declared the variable “mapload”.
It would be useful if you post the changes that you have done.
(If you don’t like posting here just send me an email or pm with the changes.)

I think you have to add something like


sfxHandle_t mapload;

to the struct “cgMedia_t” I’ve mentioned above.

“cgs” is a struct of type “cgs_t”.
“media” (which is a variable in the struct “cgs_t”) is a struct of type “cgMedia_t”.
And in this struct there are several (sound) handles of type “sfxHandle_t” declared.

EDIT:
And as far as I can see “cgs.media.mapload” as return of the function “trap_S_RegisterSound()” has to be of type “sfxHandle_t”.


(mgt) #8

i had done everything you described here … and otherwise the compiler wouldn’t have compiled properly … and it did. but ok, here you go:

void mgt_loadSound( void ) {
	char * msg;
	cgs.media.mapload = trap_S_RegisterSound("sound/music/mapload.wav", qfalse);
	if (!cgs.media.mapload) { msg = "^1ERROR loading mapload sound!^7"; }
	else { msg = "^2mapload sound loaded successfully!^7"; }
	trap_Print(va("[mgt] %s
", msg));
}

void mgt_stdPlaySound( sfxHandle_t s ) {
	trap_S_StartSound(NULL, 1, CHAN_AUTO, s);
}

// [mgt] (cg_local.h in cgMedia_t)
	sfxHandle_t mapload;
// end

// declarations of new functions in cg_mgt.c
void mgt_loadSound( void );
void mgt_stdPlaySound( sfxHandle_t );

// [mgt] (cg_main.c in CG_init line 2580)
if (CG_Cvar_Get("mgt_playMusicOnMapLoad") == "1") {
	trap_Print("[mgt] ^Xinside cvar check^7
");
	mgt_loadSound();
	mgt_stdPlaySound(cgs.media.mapload);
}

on running et and loading a map, i always get “good” messages, which means mapload sound successfully and so. btw dont worry about the cvar, i added it correctly. (;
now there’s my problem: something seems to be missing so that ET doesnt play the sound - what is it?

btw i dont care about how to stop that sound by now, i just want it to be played. :slight_smile:

nullskillz … do u have icq or are you familiar to irc?


(nUllSkillZ) #9

I’ve sent you a pm.