Files
psysonic/src-tauri/patches/symphonia-format-isomp4/src/fp.rs
T
Psychotoxical a4c400cc69 fix(audio): correctly parse iTunSMPB gapless info from older iTunes M4A files
M4A files store the iTunSMPB value behind a 16-byte binary 'data' atom
header. The previous parser took bytes directly after the ASCII key,
landing in the binary header and producing a corrupted parts array
(total_valid=348 instead of ~13M samples), which caused take_duration
to exhaust the source in ~8ms — silent no-playback.

Fix: search for the " 00000000 " sentinel within 128 bytes of the key
to locate the actual value string, falling back to the old offset for
ID3v2/MP3 files where no binary header exists.

Also patches symphonia-format-isomp4 (local crate under patches/) to:
- Tolerate SL descriptor predefined=0x01 (older iTunes M4A)
- Convert descriptor.unwrap() panic to a proper decode error
- Gracefully skip malformed trak atoms (e.g. MJPEG cover-art streams)
  instead of failing the entire probe

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-07 18:54:10 +02:00

79 lines
1.6 KiB
Rust

// Symphonia
// Copyright (c) 2019-2022 The Project Symphonia Developers.
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
/// An unsigned 16.16-bit fixed point value.
#[derive(Copy, Clone, Debug, Default)]
pub struct FpU16(u32);
impl FpU16 {
pub fn new(val: u16) -> Self {
Self(u32::from(val) << 16)
}
pub fn parse_raw(val: u32) -> Self {
Self(val)
}
}
impl From<FpU16> for f64 {
fn from(fp: FpU16) -> Self {
f64::from(fp.0) / f64::from(1u32 << 16)
}
}
/// An unsigned 8.8-bit fixed point value.
#[derive(Copy, Clone, Debug, Default)]
pub struct FpU8(u16);
impl FpU8 {
pub fn new(val: u8) -> Self {
Self(u16::from(val) << 8)
}
pub fn parse_raw(val: u16) -> Self {
Self(val)
}
}
impl From<FpU8> for f64 {
fn from(fp: FpU8) -> Self {
f64::from(fp.0) / f64::from(1u16 << 8)
}
}
impl From<FpU8> for f32 {
fn from(fp: FpU8) -> Self {
f32::from(fp.0) / f32::from(1u16 << 8)
}
}
/// An unsigned 8.8-bit fixed point value.
#[derive(Copy, Clone, Debug, Default)]
pub struct FpI8(i16);
impl FpI8 {
pub fn new(val: i8) -> Self {
Self(i16::from(val) * 0x100)
}
pub fn parse_raw(val: i16) -> Self {
Self(val)
}
}
impl From<FpI8> for f64 {
fn from(fp: FpI8) -> Self {
f64::from(fp.0) / f64::from(1u16 << 8)
}
}
impl From<FpI8> for f32 {
fn from(fp: FpI8) -> Self {
f32::from(fp.0) / f32::from(1u16 << 8)
}
}