Code Monkey home page Code Monkey logo

spectral-visualizer's Introduction

Spectral Visualizer

This is a spectral visualizer that analyzes the frequencies of music and sound, written in Godot 3.1. The bar's length and intensity depend on the amplitude of its corresponding frequency.

demo

Here's a video of it in action.

Running

Important: this requires Godot 3.1 Alpha Mono edition. Older versions, such as Godot 3.0.x, will not work.

Additionally, you need to install some packages using nuget. You can do this by installing nuget if not yet installed and then running the following command in a terminal in the root of the project folder:

nuget restore

Then you can just open the project and run it as usual.

How it works

The program uses the new Godot 3.1 API which enables you to get the raw byte array from an AudioStream, containing the entire audio file. The byte array is converted to an array of pairs of floats (since the sound is stereo) and then analyzed using MathNet's fourier transform functions. This is the main reason the program uses C# and not GDScript, since currently Godot does not expose any FFT functions to GDScript. Additionally, GDScript would probably be too slow.

Since Godot does not expose the position of the playback head of the stream, the program estimates the playback position by measuring the amount of time spent since the stream started and multiplying that by the sample rate. This works reasonably well, unless the playback is started/stopped regularly, which will cause the visualization to drift off in time compared to what you're seeing on the screen.

In the future I'd like this to work with an actual callback so you can get the stream of bytes in real-time, unfortunately this is not implemented in Godot yet. That would also enable visualization of audio captured in real time from e.g. a microphone.

Music

The song is a cut-up version of Meterorite, a song that appears on my album Meteorite Soundtrack.

License

The code is licensed MIT. The song is released under the CC BY-SA 4.0 license.

spectral-visualizer's People

Contributors

bauxitedev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

spectral-visualizer's Issues

GDScript implementation with new 3.1.1 audio features

New audio features were announced for 3.2: https://godotengine.org/article/godot-32-will-get-new-audio-features

However, 3.1.1 RC1 was released and it seems like these features were backported to 3.1.1: https://godotengine.org/article/release-candidate-godot-3-1-1-rc-1 Although 3.1.1 is only a release candidate for now, the audio features seem to be fully functional.

It would take some work to completely re-write the project in GDScript, but I think it could be a great example of how to use the new spectrum analyzer.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.