Skip to content

ayushmaanbhav/ColorfulSound

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

17 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

ColorfulSound

Real-Time Audio Visualization for RGB LEDs

MIT License Java Arduino Platform Processing GitHub Sponsors PRs Welcome

Transform your music into a mesmerizing light show with real-time FFT audio analysis and Arduino-controlled RGB LEDs

Features β€’ Demo β€’ Quick Start β€’ Architecture β€’ API β€’ Contributing


ColorfulSound Logo

Overview

ColorfulSound is a sophisticated audio visualization system that bridges digital sound with physical RGB lighting. Using Fast Fourier Transform (FFT) analysis and beat detection algorithms, it maps audio frequencies to a rainbow color spectrum in real-time, creating immersive lighting experiences synchronized to your music.

Whether you're building an ambient lighting setup, enhancing your music room, or creating a DJ booth visualization, ColorfulSound provides the software foundation to bring audio to life through color.

Demo

Live Demo Beat Detection
Demo 1 Demo 2
RGB LEDs in action Frequency visualization

Features

Core Capabilities

Feature Description
Real-Time FFT Analysis 2048-sample buffer FFT processing using the Minim audio library
Beat Detection Dual-mode detection: overall energy onset + frequency-range beats
Dynamic Range Mapping Automatically adapts to the frequency content of your music
Rainbow Color Blending Maps 7 rainbow colors (ROYGBIV) to frequency bands with smooth blending
Cross-Platform Windows, Linux, macOS, and Raspberry Pi support
System Tray Control Lightweight tray icon with full feature control
Visual Debugging Optional Processing-based visualization window

Control Options

  • Enable/Disable - Toggle LED output on/off
  • Color Change Mode - Switch between dynamic colors and fixed color
  • Default Color Picker - Choose your preferred static color with alpha
  • Sensitivity Modes - High/Low sensitivity for different music types
  • Rainbow Shuffle - Randomize the color-to-frequency mapping

Architecture

System Overview

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                         ColorfulSound System                            β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                                         β”‚
β”‚   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚   β”‚ Audio Input  │────▢│  Beat Detection &    │────▢│   Arduino    β”‚   β”‚
β”‚   β”‚   (Minim)    β”‚     β”‚   FFT Analysis       β”‚     β”‚  Connector   β”‚   β”‚
β”‚   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β”‚          β”‚                       β”‚                          β”‚          β”‚
β”‚          β”‚                       β–Ό                          β”‚          β”‚
β”‚          β”‚             β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                 β”‚          β”‚
β”‚          β”‚             β”‚  Color Mapping   β”‚                 β”‚          β”‚
β”‚          β”‚             β”‚  (Rainbow Blend) β”‚                 β”‚          β”‚
β”‚          β”‚             β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                 β”‚          β”‚
β”‚          β”‚                       β”‚                          β”‚          β”‚
β”‚          β–Ό                       β–Ό                          β–Ό          β”‚
β”‚   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚   β”‚  System Tray β”‚     β”‚   Visualization  β”‚     β”‚    RGB LEDs      β”‚   β”‚
β”‚   β”‚     UI       β”‚     β”‚   (Processing)   β”‚     β”‚   (Hardware)     β”‚   β”‚
β”‚   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β”‚                                                                         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Component Design

com.ayush.colorfulsound
β”œβ”€β”€ SoundEnergyBeatDetection.java    # Main application & audio processing
β”‚   β”œβ”€β”€ BeatListener                  # AudioListener implementation
β”‚   β”œβ”€β”€ setup()                       # Initialize audio, UI, Arduino
β”‚   β”œβ”€β”€ draw()                        # Main loop: FFT + color calculation
β”‚   β”œβ”€β”€ sendToArduino()               # Queue RGB values to serial port
β”‚   └── blend()                       # Multi-color weighted averaging
β”‚
β”œβ”€β”€ SoundEnergyBeatDetectionGUI.java # Processing visualization mode
β”‚   β”œβ”€β”€ PApplet extension             # Processing application base
β”‚   └── Visual beat feedback          # Animated circles on beat
β”‚
└── ArduinoConnector.java            # Serial communication handler
    β”œβ”€β”€ Platform detection            # Auto-detect serial ports
    β”œβ”€β”€ RXTX integration              # Cross-platform serial I/O
    └── Event handling                # Bidirectional communication

Threading Model

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Audio Thread  β”‚   β”‚  Queue Worker   β”‚   β”‚  Update Thread  β”‚
β”‚    (Minim)      β”‚   β”‚   (Executor)    β”‚   β”‚   (15ms loop)   β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€   β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€   β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ β€’ Sample captureβ”‚   β”‚ β€’ Process queue β”‚   β”‚ β€’ Decay radius  β”‚
β”‚ β€’ Beat detectionβ”‚   β”‚ β€’ Serial write  β”‚   β”‚ β€’ Refresh LEDs  β”‚
β”‚ β€’ Color calc    β”‚   β”‚ β€’ Order guaranteeβ”‚  β”‚ β€’ State sync    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚                    β–²                      β”‚
         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                    BlockingQueue<Runnable>

Audio Processing Pipeline

Audio Input (Stereo, 2048 samples)
          β”‚
          β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚      BeatDetect (Energy)        β”‚  ──▢  Onset Detection (eRadius = 500)
β”‚      Sensitivity: 100ms         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
          β”‚
          β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚    BeatDetect (Frequency)       β”‚  ──▢  Per-band beat detection
β”‚    Full spectrum analysis       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
          β”‚
          β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚     Dynamic Range Tracking      β”‚  ──▢  Exponential smoothing (0.97)
β”‚   Identify active frequencies   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
          β”‚
          β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚      Rainbow Color Mapping      β”‚  ──▢  7 colors: R-O-Y-G-B-I-V
β”‚   Blend matching frequencies    β”‚       High freq β†’ Violet
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜       Low freq  β†’ Red
          β”‚
          β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚       Amplitude Scaling         β”‚  ──▢  RGB * (radius / 500)
β”‚    Based on beat intensity      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
          β”‚
          β–Ό
      Serial Output (R, G, B)

Quick Start

Prerequisites

  • Java 8+ - Download
  • Arduino IDE - Download
  • RGB LED Strip or Module - Common cathode or anode
  • Arduino Board - Uno, Nano, or compatible

Hardware Setup

Circuit Diagram

                    Arduino Uno
                   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                   β”‚           β”‚
    RGB LED        β”‚    D11 ───┼──▢ Red (with resistor)
   (Common         β”‚    D10 ───┼──▢ Green (with resistor)
   Cathode)        β”‚    D9  ───┼──▢ Blue (with resistor)
                   β”‚    GND ───┼──▢ Common Cathode
                   β”‚           β”‚
                   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

    Note: Use 220Ξ©-330Ξ© current limiting resistors

For 12V LED Strips

Warning: Arduino is a 5V device! For 12V LED strips, you must use transistors (TIP120/IRLZ44N) or a MOSFET driver. See this guide for proper wiring.

Installation

Step 1: Upload Arduino Firmware

// Arduino/colorfulsound/colorfulsound.ino
// Pin configuration:
int redPin = 11;    // PWM pin for red
int greenPin = 10;  // PWM pin for green
int bluePin = 9;    // PWM pin for blue
  1. Open Arduino/colorfulsound/colorfulsound.ino in Arduino IDE
  2. For common anode LEDs, uncomment: #define COMMON_ANODE
  3. Upload to your Arduino board

Step 2: Install RXTX Drivers (Windows Only)

Copy the appropriate DLL to your system:

Architecture Source Destination
64-bit libraries/rxtx-2.2pre2-bins/win64/rxtxSerial.dll C:\Windows\System32\
32-bit libraries/rxtx-2.2pre2-bins/win32/rxtxSerial.dll C:\Windows\SysWOW64\

Step 3: Configure Audio Input

Important: ColorfulSound listens to your system's audio output via "Stereo Mix" or "What U Hear"

Windows:

  1. Right-click speaker icon β†’ Sounds β†’ Recording tab
  2. Right-click β†’ Show Disabled Devices
  3. Enable Stereo Mix β†’ Set as Default Device
  4. Start ColorfulSound, then switch back to Microphone if desired

Linux:

# Use PulseAudio monitor
pactl load-module module-loopback

macOS:

Step 4: Run the Application

Option A: Pre-built Executable (Windows)

exe/ColorfulSound.exe

Option B: Java JAR (Cross-platform)

java -jar exe/ColorfulSound.jar

Option C: With Visualization (Development)

# Run from IDE: SoundEnergyBeatDetectionGUI.main()

Testing the Connection

  1. Test Serial Port:

    # Run ArduinoConnector standalone
    java -cp "exe/ColorfulSound.jar" com.ayush.colorfulsound.ArduinoConnector
    
    # Type RGB values (0-255) to test LED response
    255    # Red full
    0      # Green off
    0      # Blue off
  2. Verify Detection:

    • Check console output for detected COM port
    • LEDs should respond to typed values

API Reference

SoundEnergyBeatDetection

The main application class managing audio processing and LED control.

Configuration Fields

Field Type Default Description
enabled volatile boolean true Master on/off for LED output
colorEnabled volatile boolean true Dynamic colors vs fixed color
defaultColor volatile Color RED Static color when dynamic disabled
threshold1 volatile boolean false High sensitivity mode
threshold2 volatile boolean false Low sensitivity mode
eRadius volatile float 500 Beat intensity (decays to 50)

Key Methods

// Initialize audio, UI, and Arduino connection
public void setup()

// Main audio processing loop (called per sample buffer)
public void draw()

// Queue RGB values to Arduino (thread-safe)
private synchronized void sendToArduino(int r, int g, int b, float a)

// Blend multiple colors with weighted averaging
public static Color blend(List<Color> colors)

ArduinoConnector

Cross-platform serial communication handler.

Supported Platforms

Platform Port Pattern
macOS /dev/tty.usbserial-*
Linux /dev/ttyUSB0, /dev/ttyACM0
Windows COM3 (configurable)
Raspberry Pi /dev/ttyACM0

Serial Configuration

BAUD_RATE = 9600
DATA_BITS = 8
STOP_BITS = 1
PARITY = NONE
TIMEOUT = 2000ms

Arduino Protocol

The Arduino expects 3 consecutive bytes per frame:

Byte Range Description
1 0-255 Red intensity
2 0-255 Green intensity
3 0-255 Blue intensity
// Arduino receives RGB in sequence
void loop() {
    if (Serial.available() > 0) {
        // Reads R, G, B sequentially
        // Calls setColor(r, g, b) when complete
    }
}

Technology Stack

Component Technology Purpose
Java Java 8 Core application
Arduino Arduino C Firmware
Processing Processing Visualization

Dependencies

Library Version License Purpose
Minim Latest LGPL Audio input, FFT, beat detection
Processing Core Latest LGPL Graphics framework
RXTX 2.2pre2 LGPL Serial communication
JOGL Latest BSD OpenGL for Processing

Project Structure

ColorfulSound/
β”œβ”€β”€ Arduino/
β”‚   └── colorfulsound/
β”‚       └── colorfulsound.ino      # Arduino firmware
β”œβ”€β”€ src/
β”‚   └── com/ayush/colorfulsound/
β”‚       β”œβ”€β”€ SoundEnergyBeatDetection.java      # Main app (449 lines)
β”‚       β”œβ”€β”€ SoundEnergyBeatDetectionGUI.java   # Visual mode (133 lines)
β”‚       └── ArduinoConnector.java              # Serial handler (134 lines)
β”œβ”€β”€ libraries/
β”‚   β”œβ”€β”€ minim/                     # Audio processing
β”‚   β”œβ”€β”€ processing/                # Graphics + OpenGL natives
β”‚   └── rxtx-2.2pre2-bins/         # Serial natives (Win/Linux/Mac)
β”œβ”€β”€ exe/
β”‚   β”œβ”€β”€ ColorfulSound.jar          # Compiled JAR
β”‚   └── ColorfulSound.exe          # Windows executable
β”œβ”€β”€ images/
β”‚   β”œβ”€β”€ icon.png                   # Application icon (legacy)
β”‚   └── icon.svg                   # Application icon (scalable)
β”œβ”€β”€ launch4j/
β”‚   └── config.xml                 # EXE wrapper config
└── docs/
    └── ...                        # Documentation

Building from Source

Eclipse IDE

  1. Import as existing project (Eclipse metadata included)
  2. Libraries are pre-configured in .classpath
  3. Run SoundEnergyBeatDetection.main()

Creating Executable JAR

# From Eclipse: Export β†’ Runnable JAR File
# Main class: com.ayush.colorfulsound.SoundEnergyBeatDetection
# Library handling: Package required libraries into JAR

Creating Windows EXE

  1. Install Launch4j
  2. Open launch4j/config.xml
  3. Build β†’ Creates exe/ColorfulSound.exe

Troubleshooting

Common Issues

Issue Solution
"Could not find COM port" Check Arduino connection, verify drivers installed
No audio response Enable Stereo Mix in Recording devices
LEDs always off Check common anode/cathode setting in Arduino code
Colors inverted Toggle COMMON_ANODE define in Arduino sketch
Port locked (Linux) Run sudo chmod 666 /dev/ttyUSB0 or add user to dialout group

Debug Mode

Run the GUI version for visual debugging:

// Shows real-time beat visualization
SoundEnergyBeatDetectionGUI.main()

Contributing

Contributions are welcome! Please see our Contributing Guidelines for details.

Development Setup

  1. Fork the repository
  2. Clone your fork
  3. Import into Eclipse or your preferred IDE
  4. Make changes and test thoroughly
  5. Submit a pull request

Areas for Contribution

  • Maven/Gradle build system
  • Additional color mapping algorithms
  • Web-based configuration interface
  • Support for addressable LED strips (WS2812B)
  • Audio file input mode
  • Network streaming support

Acknowledgments

License

This project is licensed under the MIT License - see the LICENSE file for details.

MIT License

Copyright (c) 2016 Ayush Jain

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software...

Support the Project

If you find ColorfulSound useful, consider supporting its development:

GitHub Sponsors

UPI (India): 8544130924@pthdfc


Made with by Ayush Jain

Star History Follow

About

🎡 🌈 Real-time LED strip music visualization using Arduino and Minim (Java)

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •