4.4 KiB
4.4 KiB
🎵 Audio File Management Guide
📊 Scale Considerations
Small Scale (1-10 files)
- ✅ Current approach works fine
- ✅ Keep files in root bundle
- ✅ Simple JSON configuration
Medium Scale (10-50 files)
- ⚠️ Consider bundles for organization
- ⚠️ Group by category (Ambient, Nature, Mechanical)
- ⚠️ Use preload strategy: "category"
Large Scale (50+ files)
- 🚨 Definitely use bundles
- 🚨 Implement lazy loading
- 🚨 Consider dynamic downloads
🎯 Recommended Approaches
Option 1: Category-Based Bundles (Recommended)
TheNoiseClock/
├── Resources/
│ ├── sounds.json
│ ├── Ambient.bundle/
│ │ ├── white-noise.mp3
│ │ ├── pink-noise.mp3
│ │ └── brown-noise.mp3
│ ├── Nature.bundle/
│ │ ├── rain.mp3
│ │ ├── ocean.mp3
│ │ └── forest.mp3
│ └── Mechanical.bundle/
│ ├── fan.mp3
│ ├── air-conditioner.mp3
│ └── washing-machine.mp3
Benefits:
- ✅ Organized by category - Easy to manage
- ✅ Faster loading - Only load sounds from active category
- ✅ Smaller memory footprint - Don't preload everything
- ✅ Easy to add new categories - Just create new bundle
- ✅ Clean project structure - No file clutter
Option 2: Single Bundle with Subfolders
TheNoiseClock/
├── Resources/
│ ├── sounds.json
│ └── Sounds.bundle/
│ ├── Ambient/
│ ├── Nature/
│ └── Mechanical/
Benefits:
- ✅ Single bundle - Easier to manage as one unit
- ✅ Organized structure - Still categorized
- ✅ All sounds in one place - Simpler distribution
🚀 Implementation Steps
Step 1: Create Bundles in Xcode
- Right-click on
TheNoiseClockfolder - Select "New Group" and name it
Ambient.bundle - Add audio files to the bundle
- Repeat for other categories
Step 2: Update JSON Configuration
{
"sounds": [
{
"id": "white-noise",
"name": "White Noise",
"fileName": "white-noise.mp3",
"category": "ambient",
"bundleName": "Ambient"
}
],
"settings": {
"preloadStrategy": "category"
}
}
Step 3: Update Code (Already Done)
The code has been updated to support:
- ✅ Bundle-based file loading
- ✅ Category-based preloading
- ✅ Fallback to direct files
📈 Performance Optimizations
Preload Strategies
-
"all" - Load all sounds at startup
- ✅ Fast switching between sounds
- ❌ High memory usage
- ❌ Slow startup
-
"category" - Load sounds by category
- ✅ Balanced memory usage
- ✅ Fast category switching
- ⚠️ Slight delay when switching categories
-
"none" - Load sounds on demand
- ✅ Minimal memory usage
- ✅ Fast startup
- ❌ Delay when playing new sounds
Memory Management
// Example: Load only active category
func loadCategory(_ categoryId: String) {
let sounds = SoundConfigurationService.shared.getSoundsByCategory(categoryId)
// Preload only these sounds
}
🔄 Migration Path
From Current Setup to Bundles
- Keep current setup working ✅
- Create bundles for new sounds
- Update JSON to use bundle names
- Test thoroughly before removing old files
- Gradually migrate existing sounds
Backward Compatibility
The code supports both approaches:
- ✅ Direct files (current setup)
- ✅ Bundle files (new approach)
- ✅ Mixed approach (during migration)
📱 App Store Considerations
Bundle Size Limits
- iOS App Store: 4GB limit
- TestFlight: 4GB limit
- Enterprise: No limit
Best Practices
- Compress audio files - Use AAC format
- Optimize bitrates - 128kbps is usually sufficient
- Consider dynamic downloads - For very large collections
- Use bundles - Better organization and loading
🎯 Recommendation for Your Use Case
Based on your current setup, I recommend:
- Keep current setup for now (it works!)
- Use bundles for new sound categories
- Implement category-based preloading
- Consider dynamic downloads if you exceed 100+ files
The code is already prepared for this migration path! 🚀