openal-soft icon indicating copy to clipboard operation
openal-soft copied to clipboard

Volume of sound buffer at point in time

Open hsdk123 opened this issue 5 years ago • 3 comments

Hi, I'd like to get some form of 'volume' intensity for the current point where the source is playing. What would be the best way to get the information?

I'm trying to implement one of those audio widgets that rise up and down depending on the volume at the current point in the audio piece.

hsdk123 avatar Jan 30 '20 01:01 hsdk123

You would need to keep a copy of the audio samples yourself since OpenAL doesn't currently allow reading back loaded samples. But you can call alGetSourcei(source, AL_SAMPLE_OFFSET, &offset); to get the current playback offset, then read the given sample from your copy to get its amplitude (or read a number of samples around the offset and take the peak, average, or rms value, depending on the kind of measurement you want).

kcat avatar Jan 30 '20 12:01 kcat

then read the given sample from your copy to get its amplitude

If I have an array of bytes, how would I calculate the amplitude from the particular offset?

hsdk123 avatar Dec 23 '20 02:12 hsdk123

depends on the format of the data. its PCM data so its pretty easy with some variation its a 16 (signed) or 8 bit unsigned value depending on exact format. see AL_FORMAT_MONO16 : AL_FORMAT_STEREO16, etc.

MenaceSan avatar Jun 08 '25 12:06 MenaceSan