Use of Playsample Under Multiple Given Animations

maxman

Well-known member
I know that using hitfx and sound work perfectly in any animation, but I want to make an alternative by putting a sound sample under any specific animation in scripts. The sound sample I'm talking about is playsample. However, every time I put playsample with a priority value of 1, it results with an annoying distortion as I adjusted some parameters in it. That sound distortion doesn't stop there until it goes back to anim idle.

C-like:
if(vAniID == openborconstant("ANI_FREESPECIAL")
    || vAniID == openborconstant("ANI_ATTACK3")
    || vAniID == openborconstant("ANI_FREESPECIAL6")){
        void MPSound = loadsample("data/sounds/common/punch1.wav");
        //unloadsample(MPSound);
        playsample(MPSound, 1, 43, 43, 10000000000, 0);
        //playsample(ID, priority, left_volume, right_volume, speed, loop);
    }

What I'm trying to do is to play like a regular sound like sound. How can I make the sound go natural without distortion?
 
This script has a couple of issues.
  1. Why in the world do you have such an absurdly high playback speed? I'm surprised you hear anything. The default value is 100.
  2. Use the right variable type. Sound indexes are integers.
  3. You're trying to load a sound and play it on demand. That's going to cause an occasional delay the first time your sound plays, because it's trying to load it from data. You need to preload the sound first, then play it by index. The engine's native playback does this automatically when a model loads.
C:
/*
* Somewhere else, like the load script
* or oncreate event of update script
*/

setglobalvar("reference_id", loadsample("data/sounds/common/punch1.wav"));

/*-----------*/

int MPSound;

if(vAniID == openborconstant("ANI_FREESPECIAL")
    || vAniID == openborconstant("ANI_ATTACK3")
    || vAniID == openborconstant("ANI_FREESPECIAL6")){
        MPSound = getglobalvar("reference_id");
        //unloadsample(MPSound);
        playsample(MPSound, 1, 43, 43, 100, 0);
        //playsample(ID, priority, left_volume, right_volume, speed, loop);
    }

Also, if you're going to mess with the volume, then I suggest you master sounds with 16bit depth. Otherwise you may get a pop introduced. That's an issue with the samples, not OpenBOR, so there's not a thing you can do about it in code if that happens - you must use 16bit depth for the sound file.


HTH,
DC
 
Back
Top Bottom