2 Replies Latest reply on Sep 14, 2006 1:55 AM by mollin

    Decibels from a wav file to animate sprites

      I've been looking at how to get the current decibel value from a playing audio file, I've looked at Amplitude and asFFT and carnt work it out. Basically I want to know if there is audio present within the wav file (i.e. waveform) then depening on the value of this animate a character to speak. If someone can point me in the direction of some script just to get the current decibels from a wav file then that would be brilliant.
        • 1. Re: Decibels from a wav file to animate sprites
          Level 7
          What's the problem using the Amplitude Xtra? It should do the job
          perfectly, and their users guide has examples that should get you going
          pretty smoothly.
          You won't be able to do this without an xtra... Can you give some
          specific issues?

          • 2. Re: Decibels from a wav file to animate sprites
            mollin Level 1
            Hi Dave, I did try to use the Amplitude xtra this is what i got so far:

            global gAmpXtra

            if objectP(gAmpXtra) then -- if the instance exists then remove it
            gAmpXtra = 0
            end if
            gAmpXtra = new(xtra "Amplitude") -- create an instance of the xtra
            if not objectP(gAmpXtra) then -- error check
            alert gAmpXtra.ampGetError()
            end if
            -- set some xtra properties...
            gAmpXtra.smoothed = true -- smooth the amp data
            gAmpXtra.resolution = 12 -- calculate amp data 15 times per second
            gAmpXtra.scale = 128 -- scale the amp data from 0 to 128

            -- tell the xtra to scan the sound and target sound channel 1
            err = gAmpXtra.ampSetSound(1, member "s16_vo_jt_stickbrickchick")
            if err <> 0 then -- check for errors
            alert gAmpXtra.ampGetError()
            end if
            ampList = ampGetCurve(gAmpXtra)

            -- depending on the level (decibels) change the sprite
            repeat with loop = 1 to ampList.count
            if amplist[loop] = 0 then
            sprite(2).member = member(1,2)
            else if (amplist[loop] > 0 and amplist[loop] < 10) then
            sprite(2).member = member(2,2)
            else if (amplist[loop] > 9 and amplist[loop] < 20) then
            sprite(2).member = member(3,2)
            else if (amplist[loop] > 19 and amplist[loop] < 30) then
            sprite(2).member = member(4,2)
            else if (amplist[loop] > 29 and amplist[loop] < 41) then
            sprite(2).member = member(5,2)
            end if
            end repeat

            The problem is, this get the curve of the wav file before the wav file has actually played. What I need to do is constantly check the curve or decibels of the wave file and then change the sprite accordingly. This code kinda worked in that it did animate the sprite but all too quickly.