Skip to content

RebeccaStankus/audio-xr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

24 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Audio XR

A spatial audio platform for creating and experiencing immersive 3D music mixes. Position individual stems in 3D space and let listeners experience your music with headphones-based HRTF spatial audio.

πŸ—οΈ Architecture

Frontend: SvelteKit + TypeScript + PixiJS + Resonance Audio Backend: Express + TypeScript + MongoDB + GridFS Auth: Auth.js with Google OAuth & Email/Password Deployment: Vercel (frontend) + Railway (backend)


✨ Features

Core Features

  • 🎡 Spatial Audio Editor - Position stems in 3D space using visual map interface
  • 🎧 HRTF Playback - Headphones-only binaural spatial audio using Google Resonance Audio
  • πŸ“Š Dual Coordinate Systems - Cartesian (meters) and Spherical (azimuth/elevation/radius)
  • 🎚️ Stem Management - Upload, position, adjust gain, and delete individual stems
  • ▢️ Real-time Preview - Play/pause/restart with synchronized spatial audio
  • πŸ”„ Audio Deduplication - Efficient GridFS storage with MD5 hash deduplication

Authentication & Security

  • πŸ” Multi-method Auth - Google OAuth or Email/Password via Auth.js
  • πŸ“± Phone Recovery - SMS-based password reset using Twilio
  • πŸ‘€ User Ownership - Songs tied to creators, edit permissions enforced
  • πŸ‘οΈ Public Listening - Anyone can listen, only owners can edit
  • πŸ›‘οΈ Protected Routes - JWT-like session validation on all write operations

User Experience

  • 🎨 Visual Feedback - Real-time waveform visualization during playback
  • 🎯 Interactive Map - Drag-and-drop stem positioning with visual guides
  • πŸ“ Scale Control - Zoom in/out on the spatial map
  • ⌨️ Keyboard Shortcuts - Play/pause (Space), coordinate mode toggle, etc.
  • πŸ”Š Per-stem Gain - Individual volume control for each stem

πŸš€ Setup

Prerequisites

  • Node.js 18+
  • MongoDB URI (MongoDB Atlas or local instance)
  • Google OAuth credentials (for sign-in)
  • Twilio account (for SMS password recovery)

Environment Variables

Client (.env in client/)

# Auth Configuration
AUTH_SECRET=your-random-secret-string-here
GOOGLE_CLIENT_ID=your-google-client-id
GOOGLE_CLIENT_SECRET=your-google-client-secret

# MongoDB
MONGODB_URI=mongodb://localhost:27017  # or your Atlas URI

# API
VITE_API_URL=http://localhost:3001

Server (.env in server/)

# MongoDB
MONGODB_URI=mongodb://localhost:27017  # or your Atlas URI

# Port
PORT=3001

Installation

# Install all dependencies
npm install

# Build shared package
npm run build:shared

# Run development servers (client + server)
npm run dev

The client will run on http://localhost:5173 and the server on http://localhost:3001.

Production Deployment

Frontend (Vercel):

  • Set VITE_API_URL to your Railway backend URL
  • Set Auth.js environment variables

Backend (Railway):

  • Set MONGODB_URI to your MongoDB Atlas connection string
  • Auto-deploys from GitHub pushes

πŸ›οΈ Project Structure

audio-xr/
β”œβ”€β”€ client/              # SvelteKit frontend
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ routes/      # Pages and API routes
β”‚   β”‚   β”‚   β”œβ”€β”€ +page.svelte           # Home page
β”‚   β”‚   β”‚   β”œβ”€β”€ songs/+page.svelte     # Songs list
β”‚   β”‚   β”‚   β”œβ”€β”€ songs/[id]/edit/       # Spatial audio editor
β”‚   β”‚   β”‚   └── auth/signin/           # Authentication
β”‚   β”‚   β”œβ”€β”€ lib/
β”‚   β”‚   β”‚   β”œβ”€β”€ components/            # Reusable UI components
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ MapEditor.svelte   # 3D positioning editor
β”‚   β”‚   β”‚   β”‚   └── UploadSongForm.svelte
β”‚   β”‚   β”‚   └── api.ts                 # API configuration
β”‚   β”‚   └── hooks.server.ts            # Auth.js configuration
β”‚   └── package.json
β”œβ”€β”€ server/              # Express backend API
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ routes/
β”‚   β”‚   β”‚   β”œβ”€β”€ songs.ts               # Song CRUD
β”‚   β”‚   β”‚   β”œβ”€β”€ stems.ts               # Stem streaming
β”‚   β”‚   β”‚   β”œβ”€β”€ stems-upload.ts        # Stem upload/update
β”‚   β”‚   β”‚   └── users.ts               # User registration/recovery
β”‚   β”‚   β”œβ”€β”€ middleware/
β”‚   β”‚   β”‚   └── auth.ts                # Authentication middleware
β”‚   β”‚   └── index.ts                   # Express server
β”‚   └── package.json
β”œβ”€β”€ shared/              # Shared TypeScript types
β”‚   └── src/types/song.ts
└── package.json         # Root workspace config

πŸ”§ Tech Stack

Frontend

  • SvelteKit - Full-stack framework with SSR
  • TypeScript - Type safety
  • PixiJS - 2D map canvas rendering
  • Resonance Audio - Google's spatial audio library (HRTF)
  • Auth.js - Authentication framework

Backend

  • Express - REST API server
  • MongoDB - Document database
  • GridFS - Audio file storage with deduplication
  • bcryptjs - Password hashing
  • Multer - File upload handling

Authentication

  • Auth.js (SvelteKit) - Session management
  • Google OAuth - One-click sign-in
  • Credentials Provider - Email/password auth
  • Twilio (optional) - SMS password recovery

🎯 How It Works

Spatial Audio Pipeline

  1. Upload: Creator uploads a song and individual stems (vocals, drums, bass, etc.)
  2. Position: Creator positions each stem in 3D space using the map editor
  3. Store: Stems stored in MongoDB GridFS with position metadata
  4. Listen: Listener loads the song, downloads stems, and hears spatial audio
  5. HRTF: Resonance Audio processes each stem based on its 3D position
  6. Output: Binaural audio played through headphones

Authentication Flow

  1. User clicks "Sign In to Create" or "Upload"
  2. Redirected to /auth/signin
  3. Choose Google OAuth or Email/Password
  4. If Email/Password signup, optionally add phone number for recovery
  5. Session created via Auth.js
  6. User ID attached to all created songs
  7. Edit actions check ownership before allowing changes

Password Recovery

  1. User clicks "Forgot Password"
  2. Enters phone number
  3. Receives 6-digit SMS code via Twilio
  4. Enters code + new password
  5. Password reset, can log in again

πŸ“š API Endpoints

Songs

  • GET /api/songs - List all songs (public)
  • GET /api/songs/:id - Get song details (public)
  • POST /api/songs - Create song (requires auth)

Stems

  • POST /api/songs/:id/stems - Upload stem (requires ownership)
  • PATCH /api/songs/:id/stems/:stemId - Update stem position (requires ownership)
  • DELETE /api/songs/:id/stems/:stemId - Delete stem (requires ownership)
  • GET /api/stems/:fileId - Stream stem audio (public)

Users

  • POST /api/users/register - Register new user
  • POST /api/users/reset-password/request - Request SMS reset code
  • POST /api/users/reset-password/verify - Verify code and reset password

🎧 User Guide

For Listeners:

  1. Browse songs at /songs
  2. Click any song to listen
  3. Put on headphones for full spatial effect
  4. Press play and experience 3D audio

For Creators:

  1. Sign in with Google or create account
  2. Click "Create New" to upload a song
  3. Add individual stems (vocals, drums, bass, etc.)
  4. Position stems on the 3D map
  5. Preview with play button
  6. Share the song URL with listeners

πŸ” Security Notes

  • Passwords hashed with bcryptjs (never stored plain)
  • Google OAuth users have no password stored
  • Sessions validated via Auth.js
  • API routes protected with ownership checks
  • CORS configured for production domains
  • Admin has MongoDB access for manual recovery

πŸ“ License

See LICENSE.txt for details.

About

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors