Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Audio Need Help Improving Glitchy Audio for a Puzzle Game

Discussion in 'Audio & Video' started by Fatamos, Oct 24, 2023.

  1. Fatamos

    Fatamos

    Joined:
    May 27, 2020
    Posts:
    12
    I'm working on a puzzle where each letter triggers a short audio, aiming for a smooth mechanical keyboard sound effect (sort of). How can I make this sound more smooth? I wanted to get sort of a mechanical keyboard sound effect. Any suggestions on how to make the sound more seamless and less glitchy?

    Code (CSharp):
    1. private IEnumerator PlayAnimation()
    2.       {
    3.             animating = true;
    4.             animating = true;
    5.             int itemsIncluded = 4;
    6.  
    7.             for (int i = 0; i < _cipherSlotList.Count; i++)
    8.             {
    9.                   if (i >= itemsIncluded)
    10.                   {
    11.                         _cipherSlotList[i - itemsIncluded].StartSparkleAnimation(false);
    12.                   }
    13.                   _cipherSlotList[i].StartSparkleAnimation(true);
    14.                   _cipherSlotList[i].StartLetterAnimation(true);
    15.  
    16.                   if (i % 2 == 0)
    17.                         _cipherSlotList[i].PlaySound(); //play sound
    18.  
    19.                   yield return new WaitForSeconds(_timeBla);
    20.             }
    21.             for (int i = _cipherSlotList.Count - itemsIncluded; i < _cipherSlotList.Count; i++)
    22.             {
    23.                   _cipherSlotList[i].StartSparkleAnimation(false);
    24.             }
    25.  
    26.             animating = false;
    27.       }
    Code (CSharp):
    1.  internal void PlaySound()
    2.       {
    3.             _soundController.PlaySound();
    4.             _soundController.audioSource.pitch = UnityEngine.Random.Range(0.9f, 1.1f);
    5.       }
    I tried playing the sound of every second item, but that didn't work. Also, audioSource.PlayOneShot doesn't make difference. The only way I could smooth out things a little bit, is with pitching the audio with random values.

     
    Last edited: Oct 24, 2023
  2. PeachyPixels

    PeachyPixels

    Joined:
    Feb 17, 2018
    Posts:
    715
    I've encountered this issue before (playing many short back to back audio clips) and there's no one solution.

    One possible approach could be to pool a few of the clips and play them async (so they overlap, rather than one cancelling another out)

    Failing that (or on-top of)...

    Better adjusting the animation speed to the audio. As a rough guess, each letter animation is about 80ms but the audio is nearly 250ms. So maybe slow the animation and trim some audio whitespace (as the animation\audio lag seems noticeable)

    Just some ideas anyway :)
     
  3. Fatamos

    Fatamos

    Joined:
    May 27, 2020
    Posts:
    12
    Thanks! Will try it out today and let you know :)
     
    PeachyPixels likes this.
  4. KalUnity3D

    KalUnity3D

    Unity Technologies

    Joined:
    Jul 17, 2020
    Posts:
    17
    Do you get the intended effect if you repeatedly press play in editor (without the pitch of course)?

    @PeachyPixels idea would be mine as well, trim any unused audio space in your file to allow you to play it "quicker".

    Their advice on pooling is good too, when you type fast it might sound like you're hitting multiple buttons async, otherwise it'll sound glithy because the next clip wants to be played before the first one finishes naturally.

    Another way around this is to record a longer clip of typing and using that longer audio clip, with modifiers, for the duration of the in game typing.
     
    PeachyPixels likes this.