Closed swampthang closed 1 year ago
Thank you for the kind words! That is a very interesting question!
When I first built this, I saw it as just an html and css visualization of the data contained in the inputBuffer
data contained in an audioprocess event. With that mental model, it really wouldn't make sense to have an API for the internal data - it would probably be better to write a blog post on how to convert that buffer data to dB.
However, now that there's logic for true-peak metering there's a temporal component to this processing - so it might make sense to expose some of the internal data. Designing the API might be a bit tricky. For example, would you be interested in getting the true-peak data since n milliseconds ago (with n configurable in the options), since the last time getMeterData()
was called, or since the last time the peak was cleared?
This has me curious... what are you trying to build with this?
Thanks for the reply! I built a desktop app (electron) that auto edits various versions of a background music track to be added to a video or other audio (such as a podcast or anything that needs background music) It uses the web audio api for playing the track and the audio from a loaded video and one of the features I'm adding is the ability to add sidechain compression (ducking). I use ffmpeg's "sidechaincompress" to process the compression settings to a file but the webaudio api doesn't offer sidechain inputs for its dynamicscompressor so at this point, the user has to process the file to hear the compression settings. I've been working on a way to apply ducking like this - https://codepen.io/swampthang/pen/poWbMdK?editors=1010
It uses an animation library to turn the gain up and down. Problem is I'm not doing a very good job of finding the actual decibel levels in that codepen - guessing is really what I'm doing there based on the height of the tallest bar in the visualization. I thought it would be better to have a decibel-based meter that showed the real dB values in order to know a little better where to set the threshold.
I forked and added a rather clunky method for snagging the data -> https://github.com/swampthang/web-audio-peak-meter/commit/1373b5f89e72e514971d7f3fec2bed26531a95ee
Another thing I'm trying to do is get an array of amplitudes with timestamps every .x-seconds so I can loop through them and build an animation timeline for applying the ducking so it doesn't have to be calculated in real time.
@swampthang You could be interested in peaks.js, which offers offline and online calculation of waveform data. You could use these to trigger the compressor. See https://github.com/bbc/peaks.js/#generating-waveform-data for more information. They even provide a CLI tool that does it on a server for example.
Other than that I would suggest @esonderegger that for example the peak value (or even the running level value) could be output as simple event, every time it changes. This would help this use case.
My apologies for taking so long to get to this! I've recently released a new version of this library that uses audio worklets (so should be much more performant) and has a new (and cleaner in my opinion) API.
As a result of the rewrite, it made it much easier to write a getPeaks()
method that does exactly what you describe.
If you are still interested in this functionality, please take a look at https://esonderegger.github.io/web-audio-peak-meter/examples/nodom.html and let me know what you think. Thanks!
Thanks so much for the repy, esonderegger. I'll check that out. I haven't done much on that project over the past few months.
What a great library! Thanks so much for building this. Is there a way to snag the current true peak dB level? eg,
webAudioPeakMeter.getMeterData()
Something that would return the current data or just the current highest dB value.