Chaingun makes two sounds firing single bullet

From DoomWiki.org

The chaingun in the Doom games, like its predecessor in Wolfenstein 3D, normally fires an even number of bullets each time the firing key or button is pressed. When only one bullet remains in the player's supply, that bullet is deducted and a single shot is fired, as expected — but as the engine does not check whether the ammunition has run out when producing the necessary pair of firing noises (which are DSPISTOL), the sound is still played twice as if two shots had been fired.

Some source ports have fixed this bug. However, some DM players pointed out that this changes the gameplay, because you can tell if your opponent has run out of ammo if his/her chaingun emits an odd number of shot sounds.

The cause of the bug can be found in A_FireCGun. The function starts the chaingun sound and immediately after, checks if the player has no ammo. It can simply be fixed by moving the S_StartSound line under the return, so the sound is started only after this check.

   void A_FireCGun ( player_t* player, pspdef_t* psp ) 
   {
       S_StartSound (player->mo, sfx_pistol);
   
       if (!player->ammo[weaponinfo[player->readyweapon].ammo])
           return;
   
       P_SetMobjState (player->mo, S_PLAY_ATK2);
       player->ammo[weaponinfo[player->readyweapon].ammo]--;
   
       P_SetPsprite (player,
                     ps_flash,
                     weaponinfo[player->readyweapon].flashstate
                     + psp->state
                     - &states[S_CHAIN1] );
   
       P_BulletSlope (player->mo);
   	
       P_GunShot (player->mo, !player->refire);
   }

Demo files[edit]