rserota / wad

Web Audio DAW. Use the Web Audio API for dynamic sound synthesis. It's like jQuery for your ears.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add a .length attribute to a Wad sound

frastlin opened this issue · comments

Hello,
I would love a way to get the length of a sound, preferably through:

const sound = new Wad({source:soundFile})
console.log(sound.length)

There is a basic way of getting the length through sound.env.hold, but I'm not seeing any other way to get the sound. There is a way to get the length of the sound using AudioBuffer.duration
but I can't seem to find the buffer context in the Wad object.

I just added a duration property to wads, which is calculated based on the envelope, the sound file's actual duration, and the rate parameter. If you didn't manually change the offset, then sound.duration should accurately tell you how long a sound will play for.

If you want to access the audio buffer, you should be able to find it at sound.decodedBuffer.

perfect!
Can sound.decodedBuffer please be in the documentation?
(I love this library so much LOL, but finding some of the more advanced stuff is a little hard to figure out)

I just added a little note about that to the docs. Thanks for your kind words!