172 lines
4.4 KiB
Markdown
172 lines
4.4 KiB
Markdown
# 🎵 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**
|
|
|
|
1. **Right-click** on `TheNoiseClock` folder
|
|
2. **Select "New Group"** and name it `Ambient.bundle`
|
|
3. **Add audio files** to the bundle
|
|
4. **Repeat** for other categories
|
|
|
|
### **Step 2: Update JSON Configuration**
|
|
|
|
```json
|
|
{
|
|
"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**
|
|
|
|
1. **"all"** - Load all sounds at startup
|
|
- ✅ Fast switching between sounds
|
|
- ❌ High memory usage
|
|
- ❌ Slow startup
|
|
|
|
2. **"category"** - Load sounds by category
|
|
- ✅ Balanced memory usage
|
|
- ✅ Fast category switching
|
|
- ⚠️ Slight delay when switching categories
|
|
|
|
3. **"none"** - Load sounds on demand
|
|
- ✅ Minimal memory usage
|
|
- ✅ Fast startup
|
|
- ❌ Delay when playing new sounds
|
|
|
|
### **Memory Management**
|
|
|
|
```swift
|
|
// 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**
|
|
|
|
1. **Keep current setup working** ✅
|
|
2. **Create bundles** for new sounds
|
|
3. **Update JSON** to use bundle names
|
|
4. **Test thoroughly** before removing old files
|
|
5. **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**
|
|
|
|
1. **Compress audio files** - Use AAC format
|
|
2. **Optimize bitrates** - 128kbps is usually sufficient
|
|
3. **Consider dynamic downloads** - For very large collections
|
|
4. **Use bundles** - Better organization and loading
|
|
|
|
## 🎯 **Recommendation for Your Use Case**
|
|
|
|
Based on your current setup, I recommend:
|
|
|
|
1. **Keep current setup** for now (it works!)
|
|
2. **Use bundles** for new sound categories
|
|
3. **Implement category-based preloading**
|
|
4. **Consider dynamic downloads** if you exceed 100+ files
|
|
|
|
The code is already prepared for this migration path! 🚀
|