Forum

A "Sound" Question

Discuss programming in the QuakeC language.

Moderator: InsideQC Admins

A "Sound" Question

Postby Junrall » Sat Feb 27, 2010 2:45 am

Is it possible to attach a sound to something like a rocket then have that sound repeated? It would be cool to hear a rocket hiss by as it passes you.
Good God! You shot my leg off!
User avatar
Junrall
 
Posts: 191
Joined: Mon Sep 21, 2009 12:27 am
Location: North West Oregon, USA

Postby Lardarse » Sat Feb 27, 2010 4:36 am

It's not possible for sounds to travel as they are ebing played. The only way would be the rocket retriggering the sound as it moves along...
Roaming status: Testing and documentation
User avatar
Lardarse
 
Posts: 266
Joined: Sat Nov 05, 2005 1:58 pm
Location: Bristol, UK

Postby Scrama » Sat Feb 27, 2010 4:38 am

Code: Select all
void(entity e, float chan, string samp, float vol, float atten) sound = #8;

As you can see, you can play sound at entity (rocket f.e.). Look at the plats.qc/plat_go_* code:
Code: Select all
void() plat_go_down =
{
   sound (self, CHAN_VOICE, self.noise, 1, ATTN_NORM);
   self.state = STATE_DOWN;
   SUB_CalcMove (self.pos2, self.speed, plat_hit_bottom);
};

void() plat_go_up =
{
   sound (self, CHAN_VOICE, self.noise, 1, ATTN_NORM);
   self.state = STATE_UP;
   SUB_CalcMove (self.pos1, self.speed, plat_hit_top);
};

May be you need start and stop markers in wav.
User avatar
Scrama
 
Posts: 20
Joined: Fri Aug 28, 2009 6:16 am
Location: Siberia, Omsk

Postby Junrall » Sat Feb 27, 2010 5:01 am

Lardarse wrote:It's not possible for sounds to travel as they are ebing played. The only way would be the rocket retriggering the sound as it moves along...


I suppose that immediately after the rocket is spawned I could spawn another entity in front of the rocket. As soon as the rocket touches this entity the rocket's touch function could be triggered and then I could do a sound update in the think function?

This would be similar to Scrama's plat_go_down/plat_go_up idea.
Good God! You shot my leg off!
User avatar
Junrall
 
Posts: 191
Joined: Mon Sep 21, 2009 12:27 am
Location: North West Oregon, USA

Postby ceriux » Sat Feb 27, 2010 5:13 am

why not spawn an invisible entity which plays the sound and give it a movetype_follow or something?
User avatar
ceriux
 
Posts: 2223
Joined: Sat Sep 06, 2008 3:30 pm
Location: Indiana, USA

Postby Junrall » Sat Feb 27, 2010 5:26 am

ceriux wrote:why not spawn an invisible entity which plays the sound and give it a movetype_follow or something?


Is movetype_follow a DP movetype?
At the moment I'm focusing on only using standard Quake code.
A part of me wants to stick with the standard stuff as everyone can play a mod using standard QC... the other part of me is starting to lean towards learning to mod for DP.
I'm finding myself torn.
Good God! You shot my leg off!
User avatar
Junrall
 
Posts: 191
Joined: Mon Sep 21, 2009 12:27 am
Location: North West Oregon, USA

Postby Orion » Sat Feb 27, 2010 10:46 am

That's only possible on darkplaces, which actually make all sounds follow the entity's origin when played.

On darkplaces you only play the looping sound once, don't need to re-trigger it many times.

You'll need set a think function to your rocket to play the sound, as sound (missile, CHAN_VOICE, "weapons/whatever.wav", 1, ATTN_IDLE); (calling the sound function in W_FireRocket when the missile just spawned) won't work at all.

You can set the rocket's nextthink to something less than 0.1, I recommend just set to time, which will call a function on the next frame.

Also, you'll need to precache and call misc/null.wav on T_MissileTouch(), otherwise when the rocket explodes, the looping sound will still play. Use CHAN_VOICE(or whatever channel you used the looping sound to play, can't be CHAN_AUTO) too, which will make the sound stop, as misc/null.wav on the same channel of the looping sound will override it.

Now on a regular Quake engine, you'll need to create a very short non-looping sound and make the rocket re-trigger it every 0.2 seconds or so(depending on the duration of the sound).
User avatar
Orion
 
Posts: 476
Joined: Fri Jan 12, 2007 6:32 pm
Location: Brazil

Re: A "Sound" Question

Postby Teiman » Sat Feb 27, 2010 3:36 pm

Junrall wrote:Is it possible to attach a sound to something like a rocket then have that sound repeated? It would be cool to hear a rocket hiss by as it passes you.


What you want can be emulated as oposed to simulated:

You can make a think function that calculate distance (from player to the rocket). If the distance is lowering, then do nothing, continue. But If the distance is getting bigger, make a FOOOOOOSH sound, and stop thinking (so only one FOOOSH sound is generated).

This will look like is phisics what are creating the FOOOSH sound, withouth the need to use complicated math, or proper phisics.
Teiman
 
Posts: 309
Joined: Sun Jun 03, 2007 9:39 am

Postby goldenboy » Sat Feb 27, 2010 4:37 pm

CSQC can do moving sound (which is one reason I really, really want it).
User avatar
goldenboy
 
Posts: 924
Joined: Fri Sep 05, 2008 11:04 pm
Location: Kiel

Postby Lardarse » Sat Feb 27, 2010 7:44 pm

Junrall wrote:
Lardarse wrote:It's not possible for sounds to travel as they are ebing played. The only way would be the rocket retriggering the sound as it moves along...

I suppose that immediately after the rocket is spawned I could spawn another entity in front of the rocket. As soon as the rocket touches this entity the rocket's touch function could be triggered and then I could do a sound update in the think function?

Even easier: have the rocket think every 0.2 seconds or so (a lot depends on the sound being used), and in that think function, check how how long the rocket has been flying for (I think it's something like 5 seconds before it's removed), and if it isn't time for it to disappear then play the sound again.
Roaming status: Testing and documentation
User avatar
Lardarse
 
Posts: 266
Joined: Sat Nov 05, 2005 1:58 pm
Location: Bristol, UK

Postby ceriux » Sat Feb 27, 2010 8:24 pm

couldnt you call a seperate trace that shoots out the x cordinants and if it hits the player play your wizzz sound? or w.e?
User avatar
ceriux
 
Posts: 2223
Joined: Sat Sep 06, 2008 3:30 pm
Location: Indiana, USA

Postby Junrall » Sat Feb 27, 2010 10:04 pm

Alright, I've got it to work... very easy as Lardarse said it was.
Code: Select all
void() RocketThink =
{
   if (self.attack_finished < time)
   {
      remove(self);
      return;
   }

   sound (self, CHAN_VOICE, "weapons/ricofly.wav",1, ATTN_IDLE);

   self.nextthink = time + 0.48;
};

And as Lardarse mentioned...
(a lot depends on the sound being used)

If your sound is short or long you'll have to adjust self.nextthink accordingly. If you don't, you'll hear sputtering/warbling which could mean thet self.nextthink is too short for the sound's play length... or you may hear sound, a pause, then sound again which means self.nextthink is too long for the sound's play length.
Also, if the sound file fades in or out, you'll hear weird things as well.
The sound file I'm using is about one second long. I clipped the start and end parts off as one was fading in and the other was fading out. Now I just have to find a better sound clip... one that has a slight hiss and buzz sound... should be great for those spikes!
Good God! You shot my leg off!
User avatar
Junrall
 
Posts: 191
Joined: Mon Sep 21, 2009 12:27 am
Location: North West Oregon, USA

Postby Lardarse » Sun Feb 28, 2010 10:55 pm

Something you could try is have the rocket play the sound on a different channel each time. This would make the sounds overlap a little but, and then you'd also avoid the horrible noise of the sound being retriggered.
Roaming status: Testing and documentation
User avatar
Lardarse
 
Posts: 266
Joined: Sat Nov 05, 2005 1:58 pm
Location: Bristol, UK

Postby Junrall » Sun Feb 28, 2010 11:06 pm

Lardarse wrote:Something you could try is have the rocket play the sound on a different channel each time. This would make the sounds overlap a little but, and then you'd also avoid the horrible noise of the sound being retriggered.

I was wondering about that. :)

I also figured out that the sounds I was using would only work in DP and not standard Quake. Turns out that the sounds were stereo and not mono... easy fix... deleted one channel and converted the other channel to mono.
This tells me that DP has revamped sound code (What hasn't been revamped in DP!? I really need to read DP's documentation!).
Does DP make use of the stereo output?
Good God! You shot my leg off!
User avatar
Junrall
 
Posts: 191
Joined: Mon Sep 21, 2009 12:27 am
Location: North West Oregon, USA

Postby Team Xlink » Sun Feb 28, 2010 11:59 pm

Orion wrote:That's only possible on darkplaces, which actually make all sounds follow the entity's origin when played.

On darkplaces you only play the looping sound once, don't need to re-trigger it many times.

You'll need set a think function to your rocket to play the sound, as sound (missile, CHAN_VOICE, "weapons/whatever.wav", 1, ATTN_IDLE); (calling the sound function in W_FireRocket when the missile just spawned) won't work at all.

You can set the rocket's nextthink to something less than 0.1, I recommend just set to time, which will call a function on the next frame.

Also, you'll need to precache and call misc/null.wav on T_MissileTouch(), otherwise when the rocket explodes, the looping sound will still play. Use CHAN_VOICE(or whatever channel you used the looping sound to play, can't be CHAN_AUTO) too, which will make the sound stop, as misc/null.wav on the same channel of the looping sound will override it.

Now on a regular Quake engine, you'll need to create a very short non-looping sound and make the rocket re-trigger it every 0.2 seconds or so(depending on the duration of the sound).


MOVETYPE_FOLLOW isn't a DarkPlaces only feature, it is in more engines such as TomazQuake and is very easy to implement from TomazQuake into other engines, everything in TomazQuake is commented very well.

I suppose you could do it like this:

Find all players x units away from where the rocket was aimed and then play the sound for them.
Team Xlink
 
Posts: 368
Joined: Thu Jun 25, 2009 4:45 am
Location: Michigan

Next

Return to QuakeC Programming

Who is online

Users browsing this forum: No registered users and 1 guest