Sound for FireArm (SSC)

Ask questions, discuss ideas, get answers
Post Reply
User avatar
Swaffy
Posts: 1715
Joined: Sun Aug 29, 2010 9:25 pm
Location: Cibolo, Texas

Sound for FireArm (SSC)

Post by Swaffy »

So far, I only know two methods the game will play a sound file when firing a gun:
- The game plays the full sound and loops the sound. The sound must finish before it plays again, which results in the sound not accurately matching the weapon's fire rate.
- The game plays the sound every time a shot is fired from the weapon. This is bad for automatic weapons since the sounds can "stack up" if the gun fires faster than the sound's length (The sounds can pile up and begin to sound glitchy).

Is there a way to do the second method, but the previous sound stops when a new shot is fired and "restarts" the sound? This way, the sounds won't overlap on each other and stuff the game up with a bunch of sounds. So if a gun fires faster than the sound (especially if the sound resonates, being around 2 to 4 seconds long instead of 0.2 seconds for looping sounds), then the game will stop the previous one and play a new one.
(Forum Thread|Download) Swaffy'sMod v0.34 | Download link to come Soon™
User avatar
Apache Thunder
Posts: 1210
Joined: Mon Oct 19, 2009 2:48 am
Location: Levelland Texas, USA
Contact:

Re: Sound for FireArm (SSC)

Post by Apache Thunder »

I believe what you may be looking for is something like this:

Code: Select all

###########################################################################################################
### Fire Loop ###
#################
newPatch
load @ROOT/Sound/@RTD/GB_LMG_Lewis_Fire.wav
minDistance 15
loop
stop Immediate
dopplerOff
priority 10

beginEffect
	controlDestination Volume
	controlSource Distance
	envelope Ramp
	param 15
	param 300
	param 1
	param -1
endEffect
The line that is of importance is this:

Code: Select all

stop Immediate

That defines the "stop" type. As I recall this stop type isn't used often in the vanilla files (if at all) and I discovered it while taking a look at an old sound script creator/editing app.

I use this in most of my weapons in my BFH'42 mod due to the nature of how BFH/BF2 sound file are structured. So I decided it was best to have the gun play the sound, but if the next shot comes before the sound ends, it immediately stops the sound and restarts it. That way, the length of the sound won't have to always coincide with the fire rate of the sound. Also, a lot of guns in BFH don't fire at the fire rate that their sound effects play at. Thus using BF42's normal system for stop type would produce undesirable results.

I also used the end of the BF2/BFH sound effect as the "Release" sound effect. So that the release sound can be isolated and played only when the gun stops firing.

Here's the complete coding to the stationary MG on my tanks for example:

Code: Select all

newPatch
load @ROOT/Sound/@RTD/silence.wav
volume 0

newPatch
load @ROOT/Sound/@RTD/silence.wav
volume 0

newPatch
load @ROOT/Sound/@RTD/silence.wav
volume 0

newPatch
load @ROOT/Sound/@RTD/West_SFX_Weapon_GB_LMG_M249_Release.wav
dopplerOff
priority 10
minDistance 5

beginEffect
	controlDestination Volume
	controlSource Distance
	envelope Ramp
	param 15
	param 300
	param 1
	param -1
endEffect

newPatch
load @ROOT/Sound/@RTD/silence.wav
volume 0

newPatch
load @ROOT/Sound/@RTD/West_SFX_Weapon_GB_LMG_M249_Fire1.wav
randomStartPitch 0.01 / 0.01
minDistance 15
loop
stop Immediate
dopplerOff
priority 10

beginEffect
	controlDestination Volume
	controlSource Distance
	envelope Ramp
	param 15
	param 300
	param 1
	param -1
endEffect

load @ROOT/Sound/@RTD/West_SFX_Weapon_GB_LMG_M249_Fire2.wav
randomStartPitch 0.01 / 0.01
minDistance 15
loop
stop Immediate
dopplerOff
priority 10

beginEffect
	controlDestination Volume
	controlSource Distance
	envelope Ramp
	param 15
	param 300
	param 1
	param -1
endEffect

randomPlay 1
This one is simplified compared to the vanilla sound scripts and ones used in most other mods. I got rid of the "distance" sound effects and used the same sound effect at all distances. Mostly because BFH lacks alternate sound effects for alternate distances.
ImageImageImage
I have cameras in your head!
User avatar
Swaffy
Posts: 1715
Joined: Sun Aug 29, 2010 9:25 pm
Location: Cibolo, Texas

Re: Sound for FireArm (SSC)

Post by Swaffy »

Apache Thunder wrote:

Code: Select all

stop Immediate
I had a strong feeling it had to do with this line. I saw stop FinishSample and thought "If there is a space after stop, there has to be one or more functions other than FinishSample."

I will try this right now.

[Edit] It doesn't seem to be working the way you explained it to work. The sound is stopping when I release my finger off the fire button. So it is, basically, acting like a normal looped sound that instantly stops when the trigger is released. My audio file is about 1.7 seconds long, and the "release" part of the sound is not separate (you can hear it in the video below). You hear the gunshot and it has the reverb sound in the same audio file. I just want the sound file to end and restart once the gun fires a new round, without me releasing the trigger.

I used my Thompson as a test gun for this, because it is fully-automatic and has a fairly fast fire rate.

Code: Select all

load @ROOT/Sound/@RTD/ThomLRLP.wav
minDistance 6
stereo
loop
stop Immediate
priority 10
randomStartPitch 0.05 / 0.0

*** Distance Volume ***
beginEffect
	controlDestination Volume
	controlSource Distance
	envelope Ramp
	param 1
	param 1
	param 1
	param -1
endEffect

*** Distance Volume ***
beginEffect
	controlDestination Volume
	controlSource Distance
	envelope Ramp
	param 1
	param 1
	param 1
	param -1
endEffect
Video: http://www.youtube.com/watch?v=6GbOhQyg_3g
(Forum Thread|Download) Swaffy'sMod v0.34 | Download link to come Soon™
User avatar
Apache Thunder
Posts: 1210
Joined: Mon Oct 19, 2009 2:48 am
Location: Levelland Texas, USA
Contact:

Re: Sound for FireArm (SSC)

Post by Apache Thunder »

There are only 3 stop types I know of. I don't remember what the third one was other then this one and the FinishSample one, but I do recall it wouldn't help in this case. So as far as I know there is no function that would have the stop after the next round fires. the Immediate type has the sound end as soon as the gun stops firing. So you will need to separate the "release" sound so that it is always played after the gun stops firing. That way it will sound better. That's how my BFH'42 guns are setup and haven't had issues with it.
ImageImageImage
I have cameras in your head!
User avatar
Swaffy
Posts: 1715
Joined: Sun Aug 29, 2010 9:25 pm
Location: Cibolo, Texas

Re: Sound for FireArm (SSC)

Post by Swaffy »

Okay, I guess it's another mod beyond the game engine's abilities. I am already aware of the sound setup you noted previously, I use it on some weapons. But still, thanks for trying to help.
(Forum Thread|Download) Swaffy'sMod v0.34 | Download link to come Soon™
User avatar
Sarge31FR
Posts: 25
Joined: Sun Dec 16, 2012 5:55 pm
Location: Germany
Contact:

Re: Sound for FireArm (SSC)

Post by Sarge31FR »

That's a problem i've been having for ten years now. Making an automatic gun/cannon use a proper single shot in a perfect loop.

And i can tell you this: It won't work. The Bf42 engine simply doesn't allow it. You can either use VERY short sounds for loops, or long, "complete" single shots for automatic weapons which fire very slowly.
And since there aren't much weapons of that kind... well... :?
User avatar
Swaffy
Posts: 1715
Joined: Sun Aug 29, 2010 9:25 pm
Location: Cibolo, Texas

Re: Sound for FireArm (SSC)

Post by Swaffy »

Well, I have made sounds for my guns in the game that have nearly perfect timing with the actual fire rate in the game, so I'll just stick to that plan. One thing that really bothered me when it came to sound was Battlegroup's sounds, how some guns sound like they are shooting three times faster than they really are.
(Forum Thread|Download) Swaffy'sMod v0.34 | Download link to come Soon™
Post Reply