decoder/dsf: use PackedLE64 instead of DsdUint64

This commit is contained in:
Max Kellermann 2023-03-12 20:26:09 +01:00
parent f3ebaf8bdd
commit 68c36c0d3f
2 changed files with 11 additions and 22 deletions

View File

@ -20,17 +20,6 @@ struct DsdId {
bool Equals(const char *s) const noexcept;
};
class DsdUint64 {
uint32_t lo;
uint32_t hi;
public:
constexpr uint64_t Read() const {
return (uint64_t(FromLE32(hi)) << 32) |
uint64_t(FromLE32(lo));
}
};
bool
dsdlib_skip_to(DecoderClient *client, InputStream &is,
offset_type offset);

View File

@ -38,11 +38,11 @@ struct DsfHeader {
/** DSF header id: "DSD " */
DsdId id;
/** DSD chunk size, including id = 28 */
DsdUint64 size;
PackedLE64 size;
/** total file size */
DsdUint64 fsize;
PackedLE64 fsize;
/** pointer to id3v2 metadata, should be at the end of the file */
DsdUint64 pmeta;
PackedLE64 pmeta;
};
/** DSF file fmt chunk */
@ -50,7 +50,7 @@ struct DsfFmtChunk {
/** id: "fmt " */
DsdId id;
/** fmt chunk size, including id, normally 52 */
DsdUint64 size;
PackedLE64 size;
/** version of this format = 1 */
uint32_t version;
/** 0: DSD raw */
@ -64,7 +64,7 @@ struct DsfFmtChunk {
/** bits per sample 1 or 8 */
uint32_t bitssample;
/** Sample count per channel in bytes */
DsdUint64 scnt;
PackedLE64 scnt;
/** block size per channel = 4096 */
uint32_t block_size;
/** reserved, should be all zero */
@ -74,7 +74,7 @@ struct DsfFmtChunk {
struct DsfDataChunk {
DsdId id;
/** "data" chunk size, includes header (id+size) */
DsdUint64 size;
PackedLE64 size;
};
/**
@ -89,12 +89,12 @@ dsf_read_metadata(DecoderClient *client, InputStream &is,
!dsf_header.id.Equals("DSD "))
return false;
const offset_type chunk_size = dsf_header.size.Read();
const offset_type chunk_size = dsf_header.size;
if (sizeof(dsf_header) != chunk_size)
return false;
#ifdef ENABLE_ID3TAG
const offset_type metadata_offset = dsf_header.pmeta.Read();
const offset_type metadata_offset = dsf_header.pmeta;
#endif
/* read the 'fmt ' chunk of the DSF file */
@ -104,7 +104,7 @@ dsf_read_metadata(DecoderClient *client, InputStream &is,
!dsf_fmt_chunk.id.Equals("fmt "))
return false;
const uint64_t fmt_chunk_size = dsf_fmt_chunk.size.Read();
const uint64_t fmt_chunk_size = dsf_fmt_chunk.size;
if (fmt_chunk_size != sizeof(dsf_fmt_chunk))
return false;
@ -134,7 +134,7 @@ dsf_read_metadata(DecoderClient *client, InputStream &is,
/* data size of DSF files are padded to multiple of 4096,
we use the actual data size as chunk size */
offset_type data_size = data_chunk.size.Read();
offset_type data_size = data_chunk.size;
if (data_size < sizeof(data_chunk))
return false;
@ -147,7 +147,7 @@ dsf_read_metadata(DecoderClient *client, InputStream &is,
/* use the sample count from the DSF header as the upper
bound, because some DSF files contain junk at the end of
the "data" chunk */
const uint64_t samplecnt = dsf_fmt_chunk.scnt.Read();
const uint64_t samplecnt = dsf_fmt_chunk.scnt;
const offset_type playable_size = samplecnt * channels / 8;
if (data_size > playable_size)
data_size = playable_size;