Audio amplitude data

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By CrazyM
:warning: Old Version Published before Godot 3 was released.

I have been looking through the source, trying to find where the audio processing code is that drives the amplitude meter in the top right corner of the editor. I want to read amplitude sample values for beat detection and audio-based interactions, but I can’t find this source. Ultimately, I’d like use it for reference and hopefully expose this type of audio data access to GDscript.

Thanks,
Michael

I just notice now the “amplitude meter in the top right corner of the editor” part of your question. I think this meter is just to track CPU usage and is not related to audio processing; I might be wrong though.

Akien | 2016-02-27 09:56

@Akien, I think it is for audio, as I was able to test it back on 1.1 (or some dev revision after it), and it did so.

Bojidar Marinov | 2016-02-27 12:45

The meter is definitely responding to audio amplitude when previewing sounds in the editor, so the code is already in there somewhere. I’m looking through these editor classes to see if I can track it down as well.

CrazyM | 2016-02-28 16:21

I think I might have found it in the bands.c/h class. I’m assuming godot uses celt as it’s internal codec.

/* Compute the amplitude (sqrt energy) in each of the bands */
void compute_band_energies(const CELTMode *m, const celt_sig *X, celt_ener *bandE, int end, int C, int M)

CrazyM | 2016-02-28 23:46

:bust_in_silhouette: Reply From: Akien

I haven’t done such work myself, but I’d have a look at the AudioServer API to see if it has what you need: AudioServer — Godot Engine (latest) documentation in English

Maybe the AudioStreamPlayback API would be useful too, though it seems more limited: AudioStreamPlayback — Godot Engine (latest) documentation in English

As for the code, you can check servers/audioand maybe scenes/audio and scenes/resources/{audio_stream,samples}.{cpp,h} to some extent

Thanks a lot Aklet, the AudioServer class seems to get me in the right direction.

CrazyM | 2016-02-28 16:18