|
| 1 | +# 3D Audio Visualizer |
| 2 | + |
| 3 | +A stunning 3D waterfall spectrogram visualizer built with Three.js that creates interactive 3D representations of audio frequency data over time. |
| 4 | + |
| 5 | +## 🎯 Overview |
| 6 | + |
| 7 | +This application transforms audio input into beautiful 3D visualizations where: |
| 8 | +- **X-axis**: Time (newest data on the right) |
| 9 | +- **Y-axis**: Amplitude (height of the surface) |
| 10 | +- **Z-axis**: Frequency (low frequencies at front, high at back) |
| 11 | +- **Color**: Signal intensity using scientific colormaps |
| 12 | + |
| 13 | +## ✨ Features |
| 14 | + |
| 15 | +### 3D Visualization |
| 16 | +- **Interactive 3D Scene**: Orbit, zoom, and pan controls |
| 17 | +- **Real-time Updates**: Live audio stream processing |
| 18 | +- **Smooth Animation**: 60 FPS rendering with damping |
| 19 | +- **Dynamic Lighting**: Ambient and directional lighting |
| 20 | + |
| 21 | +### Audio Input Options |
| 22 | +- **Microphone**: Real-time capture from system microphone |
| 23 | +- **File Upload**: Playback of audio files (WAV, MP3, etc.) |
| 24 | +- **Automatic Detection**: Seamless switching between input sources |
| 25 | + |
| 26 | +### Visualization Controls |
| 27 | +- **Colormap Palettes**: |
| 28 | + - Turbo (Google's scientific colormap) |
| 29 | + - Viridis (perceptually uniform) |
| 30 | + - Inferno (high contrast) |
| 31 | + - Jet (classic rainbow) |
| 32 | +- **Gamma Correction**: Adjust color intensity mapping |
| 33 | +- **Intensity Scaling**: Control overall visualization brightness |
| 34 | +- **Frequency Range**: Limit displayed frequency range |
| 35 | + |
| 36 | +### Technical Features |
| 37 | +- **FFT Analysis**: Configurable FFT size (default 1024) |
| 38 | +- **Frequency Binning**: Downsampling for smooth visualization |
| 39 | +- **Time History**: Configurable history length (default 192 frames) |
| 40 | +- **DC Blocking**: Automatic DC component removal |
| 41 | +- **Smoothing**: Configurable time constant for smooth updates |
| 42 | + |
| 43 | +## 🚀 Quick Start |
| 44 | + |
| 45 | +### Prerequisites |
| 46 | +- Modern web browser with Web Audio API support |
| 47 | +- Node.js and npm (for development) |
| 48 | + |
| 49 | +### Installation |
| 50 | +```bash |
| 51 | +npm install |
| 52 | +``` |
| 53 | + |
| 54 | +### Development |
| 55 | +```bash |
| 56 | +npm run dev |
| 57 | +``` |
| 58 | + |
| 59 | +### Production Build |
| 60 | +```bash |
| 61 | +npm run build |
| 62 | +``` |
| 63 | + |
| 64 | +### Preview Build |
| 65 | +```bash |
| 66 | +npm run preview |
| 67 | +``` |
| 68 | + |
| 69 | +## 🎮 Usage |
| 70 | + |
| 71 | +### Basic Operation |
| 72 | +1. **Start the application** in your browser |
| 73 | +2. **Grant microphone permissions** when prompted |
| 74 | +3. **Speak or play audio** to see the 3D visualization |
| 75 | +4. **Use mouse controls** to navigate the 3D scene: |
| 76 | + - **Left click + drag**: Rotate view |
| 77 | + - **Right click + drag**: Pan view |
| 78 | + - **Scroll wheel**: Zoom in/out |
| 79 | + |
| 80 | +### File Playback |
| 81 | +1. **Click "Load Audio File"** button |
| 82 | +2. **Select an audio file** (WAV, MP3, etc.) |
| 83 | +3. **Visualization starts automatically** when playback begins |
| 84 | +4. **File continues playing** while visualization updates |
| 85 | + |
| 86 | +### Controls Panel |
| 87 | +- **Colormap**: Select visualization color scheme |
| 88 | +- **Gamma**: Adjust color intensity curve (0.5 - 2.0) |
| 89 | +- **Intensity**: Control overall brightness (0.1 - 3.0) |
| 90 | +- **Max Frequency**: Limit frequency range (Hz) |
| 91 | + |
| 92 | +## 🔧 Configuration |
| 93 | + |
| 94 | +### Default Settings |
| 95 | +```typescript |
| 96 | +{ |
| 97 | + fftSize: 1024, // FFT analysis size |
| 98 | + historyLength: 192, // Number of time frames |
| 99 | + displayBinCount: 256, // Frequency bins to display |
| 100 | + minDecibels: -90, // Minimum signal level |
| 101 | + maxDecibels: -10, // Maximum signal level |
| 102 | + heightScale: 0.018, // Vertical scaling factor |
| 103 | + palette: 'turbo', // Default colormap |
| 104 | + gamma: 1.0, // Color gamma correction |
| 105 | + intensity: 1.0, // Overall intensity |
| 106 | + maxFrequencyHz: 4000 // Maximum frequency to display |
| 107 | +} |
| 108 | +``` |
| 109 | + |
| 110 | +### Customization |
| 111 | +You can modify the visualization parameters by editing the `visualiser.ts` file or by creating a new instance with custom options: |
| 112 | + |
| 113 | +```typescript |
| 114 | +const visualizer = new WaterfallSpectrogram(canvas, { |
| 115 | + fftSize: 2048, |
| 116 | + historyLength: 256, |
| 117 | + palette: 'viridis', |
| 118 | + gamma: 1.5, |
| 119 | + intensity: 1.2, |
| 120 | + maxFrequencyHz: 8000 |
| 121 | +}); |
| 122 | +``` |
| 123 | + |
| 124 | +## 🎨 Colormap Details |
| 125 | + |
| 126 | +### Turbo |
| 127 | +- **Origin**: Google's scientific colormap |
| 128 | +- **Best for**: General purpose, high contrast |
| 129 | +- **Colors**: Blue → Green → Yellow → Red |
| 130 | + |
| 131 | +### Viridis |
| 132 | +- **Origin**: Perceptually uniform colormap |
| 133 | +- **Best for**: Scientific visualization |
| 134 | +- **Colors**: Purple → Blue → Green → Yellow |
| 135 | + |
| 136 | +### Inferno |
| 137 | +- **Origin**: High contrast colormap |
| 138 | +- **Best for**: Highlighting details |
| 139 | +- **Colors**: Black → Red → Yellow → White |
| 140 | + |
| 141 | +### Jet |
| 142 | +- **Origin**: Classic rainbow colormap |
| 143 | +- **Best for**: Traditional spectrograms |
| 144 | +- **Colors**: Blue → Green → Yellow → Red |
| 145 | + |
| 146 | +## 🔍 Technical Details |
| 147 | + |
| 148 | +### Audio Processing Pipeline |
| 149 | +1. **Audio Capture**: Web Audio API microphone or file input |
| 150 | +2. **FFT Analysis**: Real-time frequency domain analysis |
| 151 | +3. **Frequency Binning**: Downsample to display resolution |
| 152 | +4. **Time History**: Maintain rolling buffer of frequency data |
| 153 | +5. **3D Geometry**: Generate mesh vertices from frequency data |
| 154 | +6. **Color Mapping**: Apply colormap to signal intensity |
| 155 | +7. **Rendering**: Three.js WebGL rendering |
| 156 | + |
| 157 | +### Performance Optimization |
| 158 | +- **Efficient FFT**: Uses Web Audio API AnalyserNode |
| 159 | +- **GPU Rendering**: WebGL-based 3D rendering |
| 160 | +- **Memory Management**: Reuses geometry buffers |
| 161 | +- **Frame Rate Control**: RequestAnimationFrame for smooth updates |
| 162 | +- **Adaptive Quality**: Automatic pixel ratio adjustment |
| 163 | + |
| 164 | +### Browser Compatibility |
| 165 | +- **Chrome/Chromium**: Full support |
| 166 | +- **Firefox**: Full support |
| 167 | +- **Safari**: Full support |
| 168 | +- **Edge**: Full support |
| 169 | + |
| 170 | +## 🛠️ Development |
| 171 | + |
| 172 | +### Project Structure |
| 173 | +``` |
| 174 | +3d-visualiser/ |
| 175 | +├── src/ |
| 176 | +│ ├── visualiser.ts # Main visualization class |
| 177 | +│ ├── main.ts # Application entry point |
| 178 | +│ └── style.css # Styling |
| 179 | +├── index.html # HTML template |
| 180 | +├── package.json # Dependencies and scripts |
| 181 | +└── tsconfig.json # TypeScript configuration |
| 182 | +``` |
| 183 | + |
| 184 | +### Key Dependencies |
| 185 | +- **Three.js**: 3D graphics library |
| 186 | +- **TypeScript**: Type-safe JavaScript |
| 187 | +- **Vite**: Build tool and dev server |
| 188 | + |
| 189 | +### Adding New Features |
| 190 | +1. **New Colormaps**: Add to `sampleColormap()` method |
| 191 | +2. **Audio Effects**: Modify the audio processing pipeline |
| 192 | +3. **UI Controls**: Add to the HTML and wire up event handlers |
| 193 | +4. **3D Objects**: Add to the Three.js scene |
| 194 | + |
| 195 | +## 🐛 Troubleshooting |
| 196 | + |
| 197 | +### Common Issues |
| 198 | + |
| 199 | +1. **No audio input**: |
| 200 | + - Check microphone permissions |
| 201 | + - Verify audio device is working |
| 202 | + - Try refreshing the page |
| 203 | + |
| 204 | +2. **Poor performance**: |
| 205 | + - Reduce `historyLength` or `displayBinCount` |
| 206 | + - Lower `fftSize` for faster processing |
| 207 | + - Check browser hardware acceleration |
| 208 | + |
| 209 | +3. **Visualization not updating**: |
| 210 | + - Check browser console for errors |
| 211 | + - Verify Web Audio API support |
| 212 | + - Try different audio input source |
| 213 | + |
| 214 | +4. **3D controls not working**: |
| 215 | + - Ensure mouse events are not blocked |
| 216 | + - Check for conflicting JavaScript |
| 217 | + - Try different browser |
| 218 | + |
| 219 | +### Debug Mode |
| 220 | +Enable debug logging by opening browser developer tools and checking the console for detailed information about audio processing and rendering. |
| 221 | + |
| 222 | +## 📄 License |
| 223 | + |
| 224 | +This project is part of the microphone audio processing suite. See the main repository README for license information. |
| 225 | + |
| 226 | +## 🤝 Contributing |
| 227 | + |
| 228 | +Contributions are welcome! Areas for improvement: |
| 229 | +- Additional colormap options |
| 230 | +- Audio effect processing |
| 231 | +- Export functionality |
| 232 | +- Mobile device optimization |
| 233 | +- Performance enhancements |
0 commit comments