Construct Time #0 : Audio analyser example

3

Features on these Courses

Stats

2,112 visits, 2,968 views

Tools

Translations

This tutorial hasn't been translated.

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Published on 2 Feb, 2020. Last updated 24 Feb, 2020
Subscribe to Construct videos now

Example file publicly available (for free, for everyone) on my Patreon:

patreon.com/posts/33686701

This example was requested to me by toto_e, a fellow construct user, and was inspired by this tweet: https://twitter.com/0x000002D7/status/1223948862513041408

The example was made in C2 and uses no 3rd party addon, so it should be compatible with C3 as well.

How it works

Initialisation

I start by initializing my variables, preloading the audio, and destroying the sprite object I used for the analyser (and for the center position)

Once the audio is preloaded, I play it and add the audio analyser effect.

Creating the circle

I create the circle by creating sprites in a for loop, and placing them using polar coordinates.

lerp(0, 360, unlerp(0, NBSPRITES, loopindex)) gives me the angle between 0 and 360 based on the progress of the loop.

Once that is done, I initialise the size of each sprite.

1.2 * (2 * pi * RADIUS) / NBSPRITES is the formula for the perimeter of the circle, divided by the number of sprites in the circle, and I multiply that by 1.2 so the sprites don't separate too quickly when they will animate.

And finally, I point every sprite at the center of the circle.

Animating the circle

While the music is playing, all I need to do is gather the audio analyser's frequency bin at the position of the sprite, and remap that to be a size value for my sprite

The timer

The timer is fairly easy to do. All you need to do is get the duration the track, and the playback time, and divide them in seconds and minutes. Then, we can display them properly using zeropad

Final look at the whole code

This example is very short and only 5 lines long, so it should be pretty easy to read and experiment with.

The file

Once again, the source file is publicly available on my patreon:

patreon.com/posts/33686701

Consider supporting me if you like what I do :)

  • 0 Comments

Want to leave a comment? Login or Register an account!