pcm/PcmDsd: use struct ConstBuffer
This commit is contained in:
parent
6f47c1ca20
commit
413f7c64e5
@ -22,6 +22,7 @@
|
|||||||
#include "PcmChannels.hxx"
|
#include "PcmChannels.hxx"
|
||||||
#include "PcmFormat.hxx"
|
#include "PcmFormat.hxx"
|
||||||
#include "AudioFormat.hxx"
|
#include "AudioFormat.hxx"
|
||||||
|
#include "util/ConstBuffer.hxx"
|
||||||
#include "util/Error.hxx"
|
#include "util/Error.hxx"
|
||||||
#include "util/Domain.hxx"
|
#include "util/Domain.hxx"
|
||||||
|
|
||||||
@ -287,39 +288,39 @@ PcmConvert::Convert(const void *src, size_t src_size,
|
|||||||
size_t *dest_size_r,
|
size_t *dest_size_r,
|
||||||
Error &error)
|
Error &error)
|
||||||
{
|
{
|
||||||
|
ConstBuffer<void> buffer(src, src_size);
|
||||||
|
|
||||||
if (is_dsd) {
|
if (is_dsd) {
|
||||||
size_t f_size;
|
auto s = ConstBuffer<uint8_t>::FromVoid(buffer);
|
||||||
const float *f = dsd.ToFloat(src_format.channels,
|
auto d = dsd.ToFloat(src_format.channels,
|
||||||
false, (const uint8_t *)src,
|
false, s);
|
||||||
src_size, &f_size);
|
if (d.IsNull()) {
|
||||||
if (f == nullptr) {
|
|
||||||
error.Set(pcm_convert_domain,
|
error.Set(pcm_convert_domain,
|
||||||
"DSD to PCM conversion failed");
|
"DSD to PCM conversion failed");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
src = f;
|
buffer = d.ToVoid();
|
||||||
src_size = f_size;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (dest_format.format) {
|
switch (dest_format.format) {
|
||||||
case SampleFormat::S16:
|
case SampleFormat::S16:
|
||||||
return Convert16(src, src_size,
|
return Convert16(buffer.data, buffer.size,
|
||||||
dest_size_r,
|
dest_size_r,
|
||||||
error);
|
error);
|
||||||
|
|
||||||
case SampleFormat::S24_P32:
|
case SampleFormat::S24_P32:
|
||||||
return Convert24(src, src_size,
|
return Convert24(buffer.data, buffer.size,
|
||||||
dest_size_r,
|
dest_size_r,
|
||||||
error);
|
error);
|
||||||
|
|
||||||
case SampleFormat::S32:
|
case SampleFormat::S32:
|
||||||
return Convert32(src, src_size,
|
return Convert32(buffer.data, buffer.size,
|
||||||
dest_size_r,
|
dest_size_r,
|
||||||
error);
|
error);
|
||||||
|
|
||||||
case SampleFormat::FLOAT:
|
case SampleFormat::FLOAT:
|
||||||
return ConvertFloat(src, src_size,
|
return ConvertFloat(buffer.data, buffer.size,
|
||||||
dest_size_r,
|
dest_size_r,
|
||||||
error);
|
error);
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#include "PcmDsd.hxx"
|
#include "PcmDsd.hxx"
|
||||||
#include "dsd2pcm/dsd2pcm.h"
|
#include "dsd2pcm/dsd2pcm.h"
|
||||||
#include "util/Macros.hxx"
|
#include "util/Macros.hxx"
|
||||||
|
#include "util/ConstBuffer.hxx"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
@ -46,22 +47,20 @@ PcmDsd::Reset()
|
|||||||
dsd2pcm_reset(dsd2pcm[i]);
|
dsd2pcm_reset(dsd2pcm[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
const float *
|
ConstBuffer<float>
|
||||||
PcmDsd::ToFloat(unsigned channels, bool lsbfirst,
|
PcmDsd::ToFloat(unsigned channels, bool lsbfirst,
|
||||||
const uint8_t *src, size_t src_size,
|
ConstBuffer<uint8_t> src)
|
||||||
size_t *dest_size_r)
|
|
||||||
{
|
{
|
||||||
assert(src != nullptr);
|
assert(!src.IsNull());
|
||||||
assert(src_size > 0);
|
assert(!src.IsEmpty());
|
||||||
assert(src_size % channels == 0);
|
assert(src.size % channels == 0);
|
||||||
assert(channels <= ARRAY_SIZE(dsd2pcm));
|
assert(channels <= ARRAY_SIZE(dsd2pcm));
|
||||||
|
|
||||||
const unsigned num_samples = src_size;
|
const unsigned num_samples = src.size;
|
||||||
const unsigned num_frames = src_size / channels;
|
const unsigned num_frames = src.size / channels;
|
||||||
|
|
||||||
float *dest;
|
float *dest;
|
||||||
const size_t dest_size = num_samples * sizeof(*dest);
|
const size_t dest_size = num_samples * sizeof(*dest);
|
||||||
*dest_size_r = dest_size;
|
|
||||||
dest = (float *)buffer.Get(dest_size);
|
dest = (float *)buffer.Get(dest_size);
|
||||||
|
|
||||||
for (unsigned c = 0; c < channels; ++c) {
|
for (unsigned c = 0; c < channels; ++c) {
|
||||||
@ -72,9 +71,9 @@ PcmDsd::ToFloat(unsigned channels, bool lsbfirst,
|
|||||||
}
|
}
|
||||||
|
|
||||||
dsd2pcm_translate(dsd2pcm[c], num_frames,
|
dsd2pcm_translate(dsd2pcm[c], num_frames,
|
||||||
src + c, channels,
|
src.data + c, channels,
|
||||||
lsbfirst, dest + c, channels);
|
lsbfirst, dest + c, channels);
|
||||||
}
|
}
|
||||||
|
|
||||||
return dest;
|
return { dest, num_samples };
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,8 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
template<typename T> struct ConstBuffer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrapper for the dsd2pcm library.
|
* Wrapper for the dsd2pcm library.
|
||||||
*/
|
*/
|
||||||
@ -39,9 +41,8 @@ public:
|
|||||||
|
|
||||||
void Reset();
|
void Reset();
|
||||||
|
|
||||||
const float *ToFloat(unsigned channels, bool lsbfirst,
|
ConstBuffer<float> ToFloat(unsigned channels, bool lsbfirst,
|
||||||
const uint8_t *src, size_t src_size,
|
ConstBuffer<uint8_t> src);
|
||||||
size_t *dest_size_r);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user