Fix sample rate decimal precision for bit-perfect playback (CRITICAL)
Problem: - sample_rate stored as INTEGER in DB and u32 in Rust - Fractional rates (44.1, 88.2, 176.4 kHz) stored as 44100, 88200, 176400 Hz - Integer division (44100 / 1000 = 44) lost decimals - DAC badge showed "resampling 44 → 44.1 kHz" false positive - Breaks bit-perfect guarantee - user requirement: "no es negociable" Root Cause: - DB schema: sample_rate INTEGER (44100 Hz) - Frontend: Math.round(44100 / 1000) = 44 kHz (lost .1) - Badge: Compared 44 kHz vs 44.1 kHz → false resampling warning Solution: 1. Changed LocalTrack.sample_rate from u32 to f64 (models.rs) 2. Changed AudioProperties.sample_rate from u32 to f64 (models.rs) 3. Changed DB schema from INTEGER to REAL (database.rs) 4. Added migration to convert existing data (database.rs) 5. Updated metadata extraction to cast to f64 (metadata.rs) 6. Fixed frontend to use float division without rounding (+page.svelte) Migration: - Checks if sample_rate is INTEGER - Creates temp table with REAL, copies data, drops old, renames - Preserves all data and indexes - Runs automatically on app start Result: - 44100 Hz stored as 44100.0 - Division: 44100.0 / 1000.0 = 44.1 kHz (exact) - Badge: 44.1 kHz = 44.1 kHz → no resampling (correct) - Bit-perfect guarantee restored Files modified: - src-tauri/src/library/models.rs - Changed sample_rate to f64 in structs - src-tauri/src/library/metadata.rs - Cast sample_rate to f64 - src-tauri/src/library/database.rs - Changed schema to REAL + migration - src/routes/+page.svelte - Fixed division to preserve decimals
This commit is contained in:
1 parent
61fa05da93
commit
1e7475e308
4 files changed
+84
-8
No files matched your search
@@ -268,7 +268,7 @@ impl MetadataExtractor {
|
||||
// Get audio properties
|
||||
let properties = tagged_file.properties();
|
||||
let duration_secs = properties.duration().as_secs();
|
||||
let sample_rate = properties.sample_rate().unwrap_or(44100);
|
||||
let sample_rate = properties.sample_rate().unwrap_or(44100) as f64; // Convert to f64 for decimal precision
|
||||
let bit_depth = properties.bit_depth().map(|b| b as u32);
|
||||
let channels = properties.channels().unwrap_or(2) as u8;
|
||||
|
||||
@@ -398,7 +398,7 @@ impl MetadataExtractor {
|
||||
Ok(AudioProperties {
|
||||
duration_secs: properties.duration().as_secs(),
|
||||
bit_depth: properties.bit_depth().map(|b| b as u32),
|
||||
sample_rate: properties.sample_rate().unwrap_or(44100),
|
||||
sample_rate: properties.sample_rate().unwrap_or(44100) as f64, // Convert to f64
|
||||
channels: properties.channels().unwrap_or(2) as u8,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user