Forum

Help With Sound?

Discuss programming in the QuakeC language.

Moderator: InsideQC Admins

Help With Sound?

Postby MikeWoodham » Wed Nov 22, 2006 3:56 pm

In Quake1SP I have a sound file that plays at a constant volume. In-game I want to adjust the volume level of that sound file according to player action but I do not want to use another sound file.

If I adjust the volume and play the sound again then the sound file will simply play from the begining at the new volume level, and although this is easy to achieve, it is not the effect I am looking for.

Is it possible to affect the volume using qc whilst the sound is playing?

I am only trying to affect the volume of the one selected sound file that is playing, not the overall sound level of the game.
MikeWoodham
 
Posts: 4
Joined: Wed Nov 22, 2006 3:30 pm

Postby Spike » Wed Nov 22, 2006 6:48 pm

once a sound is started, there is no way for the gamecode to refer to that sound. You can overwrite the sound by starting a new one (possibly silent) on the same entity and channel.

Of course, because each sound is attached to an entity, by moving the entity you can change the volume of the sound.
Unfortunatly this will be rather awkward. Firstly, it'll only work properly with a single player on the server. Secondly, if the entity enters into a wall then the sound volume will be left unchanged. Thirdly, you will end up with different volumes in left/right speakers depending on the player's angles and direction of sound. Or I might be muddled and it won't work at all.
Spike
 
Posts: 2892
Joined: Fri Nov 05, 2004 3:12 am
Location: UK

Postby Urre » Wed Nov 22, 2006 8:03 pm

Other than the problems you just presented, that's actually a pretty cool idea for music fading in and out Spike. It would work great in a top/down game/mod, if you just move the entity playing the music on a forward axis so that stereo isn't bothered. Cool stuff mate.
I was once a Quake modder
User avatar
Urre
 
Posts: 1109
Joined: Fri Nov 05, 2004 2:36 am
Location: Moon

Postby FrikaC » Wed Nov 22, 2006 10:17 pm

Spike wrote:once a sound is started, there is no way for the gamecode to refer to that sound. You can overwrite the sound by starting a new one (possibly silent) on the same entity and channel.

Of course, because each sound is attached to an entity, by moving the entity you can change the volume of the sound.
Unfortunatly this will be rather awkward. Firstly, it'll only work properly with a single player on the server. Secondly, if the entity enters into a wall then the sound volume will be left unchanged. Thirdly, you will end up with different volumes in left/right speakers depending on the player's angles and direction of sound. Or I might be muddled and it won't work at all.


Obviously would require a custom engine because in standard Quake the sound is sent to a client with simply a vector location, it is not attached to an entity in any way, thus moving an entity has no effect on a playing sound. The only thing that could be done is to move the listener (the client) but that would also be changing the view.
FrikaC
Site Admin
 
Posts: 1026
Joined: Fri Oct 08, 2004 11:19 pm

Postby scar3crow » Wed Nov 22, 2006 10:33 pm

Obviously would require a custom engine


Yeah thats what I was about to say. IIRC doesnt Darkplaces have a decently more advanced sound system in it ? I believe it can crossfade and such, dont know about changing volume of an entity midgame, but I guess we could poke LordHavoc about it.
User avatar
scar3crow
InsideQC Staff
 
Posts: 1054
Joined: Tue Jan 18, 2005 8:54 pm
Location: Alabama

Postby LordHavoc » Wed Nov 22, 2006 11:03 pm

scar3crow wrote:Yeah thats what I was about to say. IIRC doesnt Darkplaces have a decently more advanced sound system in it ? I believe it can crossfade and such, dont know about changing volume of an entity midgame, but I guess we could poke LordHavoc about it.


I wish it had a more advanced sound system :P

Seriously though, the sound system in DP has a few fixes and changes in it, but no cross-fading (isn't that only useful for music?).

Someone ought to write up an EXT_SND_SOUNDVOLUME or something to add a builtin and svc_ to change volume of a playing sound, wouldn't hurt to add a EXT_SND_SOUNDSTOP extension as well.

Regarding the ability to change properties of a playing sound - anything on a specific channel (not CHAN_AUTO) can be found easily if you know the entity and the entity channel value that was used to play it; CHAN_VOICE, CHAN_BODY, etc, are just qc constants that correspond to one of 7 specific sound channels per entity, there can be only one sound per channel, except that there can be any number of sounds on CHAN_AUTO for each entity.
LordHavoc
 
Posts: 322
Joined: Fri Nov 05, 2004 3:12 am
Location: western Oregon, USA

Postby FrikaC » Thu Nov 23, 2006 2:39 pm

LordHavoc wrote:
scar3crow wrote:Yeah thats what I was about to say. IIRC doesnt Darkplaces have a decently more advanced sound system in it ? I believe it can crossfade and such, dont know about changing volume of an entity midgame, but I guess we could poke LordHavoc about it.


I wish it had a more advanced sound system :P

Seriously though, the sound system in DP has a few fixes and changes in it, but no cross-fading (isn't that only useful for music?).

Someone ought to write up an EXT_SND_SOUNDVOLUME or something to add a builtin and svc_ to change volume of a playing sound, wouldn't hurt to add a EXT_SND_SOUNDSTOP extension as well.

Regarding the ability to change properties of a playing sound - anything on a specific channel (not CHAN_AUTO) can be found easily if you know the entity and the entity channel value that was used to play it; CHAN_VOICE, CHAN_BODY, etc, are just qc constants that correspond to one of 7 specific sound channels per entity, there can be only one sound per channel, except that there can be any number of sounds on CHAN_AUTO for each entity.


Obviously would require a custom engine.
FrikaC
Site Admin
 
Posts: 1026
Joined: Fri Oct 08, 2004 11:19 pm

Postby Spike » Thu Nov 23, 2006 7:55 pm

FrikaC wrote:
Spike wrote:once a sound is started, there is no way for the gamecode to refer to that sound. You can overwrite the sound by starting a new one (possibly silent) on the same entity and channel.

Of course, because each sound is attached to an entity, by moving the entity you can change the volume of the sound.
Unfortunatly this will be rather awkward. Firstly, it'll only work properly with a single player on the server. Secondly, if the entity enters into a wall then the sound volume will be left unchanged. Thirdly, you will end up with different volumes in left/right speakers depending on the player's angles and direction of sound. Or I might be muddled and it won't work at all.


Obviously would require a custom engine because in standard Quake the sound is sent to a client with simply a vector location, it is not attached to an entity in any way, thus moving an entity has no effect on a playing sound. The only thing that could be done is to move the listener (the client) but that would also be changing the view.


Hrm...

So what's wrong with moving absolutly everything? :p

MWAA HA HA!!!


Yeah, quakeworld doesn't work quite the same way, instead it grabs the sound's origin from the entity that it's attached to. Probably still doesn't update it though. Damn, I should be able to remember this stuff.

LordHavoc: Maybe a flag to attach a sound to the entity, allowing audiable rockets, q3 style. But personally I'd only allow changing the volume in csqc, other stuff would be too clunky to work effectivly. Gives people motivation to use it. :p
Spike
 
Posts: 2892
Joined: Fri Nov 05, 2004 3:12 am
Location: UK

Postby MikeWoodham » Thu Nov 23, 2006 9:13 pm

OK, thanks for your replies: it is for a music fade.

Although I can stop the music easily enough, an abrupt stop at a random point in the music is a bit naff and a fade can imply s-o-m-e-t-h-i-n-g i-s a-b-o-u-t t-o h-a-p-p-e-n b-u-t y-o-u d-o-n-t k-n-o-w w-h-e-n.

I'll just have to stop the music and trigger the event at the same time.
MikeWoodham
 
Posts: 4
Joined: Wed Nov 22, 2006 3:30 pm

Postby HeadThump » Fri Nov 24, 2006 8:57 am

hey Mike,

I suspect you have good reasons not to add another sound file, but I'll ask just in case -- why not use the custent entity ambient_bgm (bgm is for back ground music). There is a good example in the custent test maps of background music where three wav files are 'spliced' together with an intro, body and fade out where the entity is used to organize the timing. I suspect you could trigger two of these events in seperate channels simultaneously, have one of these at a 'loud' volume and another at a soft -- have the loud end early and the soft one contain the fade out.

I would have to experiment to be certain -- its been a long time since I've used this QC set, but you may have to use the play_sound_triggered entity instead because it contains a key that allows you to specify the channel that is playing the sound.
HeadThump
 
Posts: 74
Joined: Sun May 14, 2006 3:21 pm
Location: Zin

Headthump

Postby MikeWoodham » Fri Nov 24, 2006 3:27 pm

I've had a quick look at Custents and although it could be used to fade the sound, it is not quite right.

To fade the music at the appropriate time means at any time during the music loop. It will be determined by the player's position in the map e.g. the player arrives at a 'battle' area after an unknown number of minutes. Therefore, I cannot know in advance where we will be in the music loop.

If I play another sound file (the one that fades) on the same channel, it will stop the original music loop but I cannot guarantee the fade will commence at the right place - I hope that reads OK, I know what I mean but I'm not sure if I am explaining it well.

The actual effect I am going for is: play music; just before an event determined unwittingly by the player, fade this tune; a couple of seconds later just as the event occurs, play the new music.

I can play the music, and I can stop one tune and start a new one. I just don't like the abruptness of stopping the first tune in the middle of a bar. I could wait untill the end of the loop and then change the tune but the player could have been long-gone (like turkey through the corn) and so spoil the (high drama) effect.

I am probably just trying to be too clever in a game that is too old :(
MikeWoodham
 
Posts: 4
Joined: Wed Nov 22, 2006 3:30 pm

Re: Headthump

Postby Dr. Shadowborg » Fri Nov 24, 2006 7:40 pm

MikeWoodham wrote:I am probably just trying to be too clever in a game that is too old :(


It's probably not so much that, as it is that while the sound system was perfectly adequate back in the olden days, it's pretty much ass today. It's probably the least touched (unfortunatly) bit in the entire history of the engine since it became open source. :/
User avatar
Dr. Shadowborg
InsideQC Staff
 
Posts: 1110
Joined: Sat Oct 16, 2004 3:34 pm

Postby scar3crow » Sat Nov 25, 2006 2:43 am

Honestly, sound is probably the least touched bit in games period. Of course you have exceptions such as Thief and Blood and apparently Doom3, but on the whole, sound is just something to please the audiocard manufacturers to some companies.
User avatar
scar3crow
InsideQC Staff
 
Posts: 1054
Joined: Tue Jan 18, 2005 8:54 pm
Location: Alabama

Postby Entar » Sat Nov 25, 2006 3:00 am

Yeah. Code-wise, there's not a whole lot you can do with sound - sure you can do fades, volume, 3D sound etc, but at some point you just run out of things to do. The coolest effects are those that you record in the first place.
User avatar
Entar
 
Posts: 439
Joined: Fri Nov 05, 2004 7:27 pm
Location: At my computer

Postby FrikaC » Sat Nov 25, 2006 6:28 am

I personally would like to see the ability to do DSP style effects on the sound in certain areas of the map (e.g. make a cave all echo-y).
FrikaC
Site Admin
 
Posts: 1026
Joined: Fri Oct 08, 2004 11:19 pm

Next

Return to QuakeC Programming

Who is online

Users browsing this forum: No registered users and 1 guest