pw-cat: fix DSD file reading

Now that the server asks for the right amount of samples for DSD, just
give it the right amount of samples without doing some weird scaling.

Make a method to calculate the size (stride) of one sample, which
depends on the interleave and channels of the stream.

See !2540
This commit is contained in:
Wim Taymans 2025-09-25 13:56:51 +02:00
parent f8389cbdb7
commit 19198d2982
5 changed files with 17 additions and 11 deletions

View file

@ -175,6 +175,11 @@ exit_free:
return NULL;
}
uint32_t dsf_layout_stride(const struct dsf_layout *layout)
{
return layout->channels * SPA_ABS(layout->interleave);
}
static const uint8_t bitrev[256] = {
0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0, 0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0,
0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8, 0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8,
@ -200,16 +205,12 @@ dsf_file_read(struct dsf_file *f, void *data, size_t samples, const struct dsf_l
uint8_t *d = data;
int step = SPA_ABS(layout->interleave);
bool rev = layout->lsb != f->info.lsb;
size_t total, block, offset, pos, scale;
size_t total, block, offset, pos;
size_t blocksize = f->info.blocksize * f->info.channels;
block = f->offset / f->info.blocksize;
offset = block * blocksize;
pos = f->offset % f->info.blocksize;
scale = SPA_CLAMP(f->info.rate / (44100u * 64u), 1u, 4u);
samples *= step;
samples *= scale;
for (total = 0; total < samples; total++) {
uint32_t i;