Skip to content

feat: add DSF (DSD Stream File) format support#638

Open
TianfangChang wants to merge 2 commits intoSerial-ATA:mainfrom
TianfangChang:feat/dsf-format-support
Open

feat: add DSF (DSD Stream File) format support#638
TianfangChang wants to merge 2 commits intoSerial-ATA:mainfrom
TianfangChang:feat/dsf-format-support

Conversation

@TianfangChang
Copy link
Copy Markdown

Summary

Add read/write support for Sony's DSF container format — a common container for DSD (Direct Stream Digital) audio that stores 1-bit samples with an optional ID3v2 tag appended after the audio data.

  • Parse DSD chunk header, fmt chunk, and locate the ID3v2 metadata offset
  • Write ID3v2 tag at end of audio data and update the DSD chunk header pointer
  • Map DSF channel types (mono through 5.1) to ChannelMask
  • Compute duration and bitrate from DSD sample count and rate
  • Register FileType::Dsf with extension detection ("dsf") and magic byte detection (b"DSD ")

Supported DSD sample rates: DSD64 (2.8 MHz), DSD128 (5.6 MHz), DSD256 (11.2 MHz), DSD512 (22.5 MHz).

Files

New files Purpose
lofty/src/dsf/mod.rs DsfFile struct with LoftyFile derive
lofty/src/dsf/read.rs DSF container parsing + ID3v2 tag reading
lofty/src/dsf/properties.rs DsfProperties audio properties
lofty/src/dsf/write_impl.rs ID3v2 write to DSF (called from id3/v2/write)
lofty/tests/dsf_quick_test.rs 5 tests: properties, ID3v2, probe, roundtrip

Test plan

  • cargo test -p lofty --lib — 239 existing tests pass, zero regressions
  • cargo test -p lofty --test dsf_quick_test — 5 DSF-specific tests pass
  • Verified against real-world DSF files (DSD64/128/256) with ID3v2.3 tags and embedded cover art

Add read/write support for Sony's DSF container format, which stores
1-bit DSD audio with an optional ID3v2 tag appended after the audio data.

Implementation:
- Parse DSD chunk header (magic, file size, metadata offset)
- Parse fmt chunk (sample rate, channels, bits per sample, sample count)
- Read ID3v2 tag by seeking to the metadata offset
- Write ID3v2 tag at end of audio data and update header pointer
- Map DSF channel types (mono through 5.1) to ChannelMask
- Compute duration and bitrate from DSD sample count and rate

Supported DSD sample rates: DSD64 (2.8MHz), DSD128 (5.6MHz),
DSD256 (11.2MHz), DSD512 (22.5MHz).

Tests cover property reading, ID3v2 tag reading, probe detection
(both from buffer magic and file extension), and full roundtrip.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant