Navigation

    Fuze Arena Logo
    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Users
    • Groups
    • Help
    • Discord

    Clipping Audio

    Coding
    3
    3
    210
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • pianofire
      pianofire Fuze Team last edited by pianofire

      I have been asked if it is possible to cut an audio track short and this is what I came up with:

      dealSound = loadaudio("Wild Forts/FX_Card_Deal_02")
      
      playingSound = false
      
      count = 0
      clipTime = 0.4
      
      loop
        clear()
        print(count)
        update()
        c = controls( 0 )
        if c.a then
          dealCard()
        endif
      repeat
      
      function dealCard()
        if !playingSound then
          playaudio(0, dealSound, 1.0, 0.5, 1, 1)
          playingSound = true
          timer1 = setTimer(clipTime, 1, stopChannel0())
        endif
      return void
      
      function stopChannel0()
        if playingSound then
          count += 1
          stopChannel(0)
          playingSound = false
        endif
      return void
      

      Basically at the same time as starting playing the audio you start a timer to trigger at a specified interval to stop it. If anyone can come up with a better/simpler solution please let me know!

      1 Reply Last reply Reply Quote 4
      • Dave
        Dave Fuze Team last edited by

        In the Ninja Scroll game I had to fade out multiple bits of audio and layer them to get the sword slash fx sounding right. If you don't want to hard clip a sound effect, a controllable fade is very helpful.

        I'm sure there is a much prettier way to do it, but I did something like:

        audio = loadAudio("David Silvera/chuckle_11")
        
        chanVol = 2
        fadeOut = 0.02
        
        sfxPlaying = false
        sfxFade = false
        
        loop
            clear()
            c = controls(0)
            if c.a then 
                playSfx()
            endif
            if sfxPlaying then
                fadeSfx()
            endif
            update()
        repeat
        
        function playSfx()
            if !sfxPlaying then
                chanVol = 2
                playAudio(0, audio, chanVol, 0.5, 1, 0)
                sfxPlaying = true
                sfxFade = true
            endif
        return void
        
        function fadeSfx()
            chanVol -= fadeOut
            setVolume(0, chanVol)
            if chanVol <= 0 then
                sfxFade = false
                sfxPlaying = false
            endif
        return void
        

        This doesn't use the setTimer() function and the fadeOut value can be adjusted very precisely to make the sound play for any length of time. I'm sure with a little bit of maths you could get a very nicely adjustable drop-off rate too.

        1 Reply Last reply Reply Quote 3
        • Jaywalker
          Jaywalker Donator last edited by

          Yep, used an audio fade for my AnimeJump Game as well

          1 Reply Last reply Reply Quote 0
          • First post
            Last post