pcm/PcmConvert: use struct ConstBuffer internally
This commit is contained in:
parent
413f7c64e5
commit
3c0c939689
@ -82,10 +82,8 @@ PcmConvert::Close()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const int16_t *
|
inline ConstBuffer<int16_t>
|
||||||
PcmConvert::Convert16(const void *src_buffer, size_t src_size,
|
PcmConvert::Convert16(ConstBuffer<void> src, Error &error)
|
||||||
size_t *dest_size_r,
|
|
||||||
Error &error)
|
|
||||||
{
|
{
|
||||||
const int16_t *buf;
|
const int16_t *buf;
|
||||||
size_t len;
|
size_t len;
|
||||||
@ -94,7 +92,7 @@ PcmConvert::Convert16(const void *src_buffer, size_t src_size,
|
|||||||
|
|
||||||
buf = pcm_convert_to_16(format_buffer, dither,
|
buf = pcm_convert_to_16(format_buffer, dither,
|
||||||
src_format.format,
|
src_format.format,
|
||||||
src_buffer, src_size,
|
src.data, src.size,
|
||||||
&len);
|
&len);
|
||||||
if (buf == nullptr) {
|
if (buf == nullptr) {
|
||||||
error.Format(pcm_convert_domain,
|
error.Format(pcm_convert_domain,
|
||||||
@ -127,14 +125,11 @@ PcmConvert::Convert16(const void *src_buffer, size_t src_size,
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
*dest_size_r = len;
|
return ConstBuffer<int16_t>::FromVoid({buf, len});
|
||||||
return buf;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const int32_t *
|
inline ConstBuffer<int32_t>
|
||||||
PcmConvert::Convert24(const void *src_buffer, size_t src_size,
|
PcmConvert::Convert24(ConstBuffer<void> src, Error &error)
|
||||||
size_t *dest_size_r,
|
|
||||||
Error &error)
|
|
||||||
{
|
{
|
||||||
const int32_t *buf;
|
const int32_t *buf;
|
||||||
size_t len;
|
size_t len;
|
||||||
@ -143,7 +138,7 @@ PcmConvert::Convert24(const void *src_buffer, size_t src_size,
|
|||||||
|
|
||||||
buf = pcm_convert_to_24(format_buffer,
|
buf = pcm_convert_to_24(format_buffer,
|
||||||
src_format.format,
|
src_format.format,
|
||||||
src_buffer, src_size, &len);
|
src.data, src.size, &len);
|
||||||
if (buf == nullptr) {
|
if (buf == nullptr) {
|
||||||
error.Format(pcm_convert_domain,
|
error.Format(pcm_convert_domain,
|
||||||
"Conversion from %s to 24 bit is not implemented",
|
"Conversion from %s to 24 bit is not implemented",
|
||||||
@ -175,14 +170,11 @@ PcmConvert::Convert24(const void *src_buffer, size_t src_size,
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
*dest_size_r = len;
|
return ConstBuffer<int32_t>::FromVoid({buf, len});
|
||||||
return buf;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const int32_t *
|
inline ConstBuffer<int32_t>
|
||||||
PcmConvert::Convert32(const void *src_buffer, size_t src_size,
|
PcmConvert::Convert32(ConstBuffer<void> src, Error &error)
|
||||||
size_t *dest_size_r,
|
|
||||||
Error &error)
|
|
||||||
{
|
{
|
||||||
const int32_t *buf;
|
const int32_t *buf;
|
||||||
size_t len;
|
size_t len;
|
||||||
@ -191,7 +183,7 @@ PcmConvert::Convert32(const void *src_buffer, size_t src_size,
|
|||||||
|
|
||||||
buf = pcm_convert_to_32(format_buffer,
|
buf = pcm_convert_to_32(format_buffer,
|
||||||
src_format.format,
|
src_format.format,
|
||||||
src_buffer, src_size, &len);
|
src.data, src.size, &len);
|
||||||
if (buf == nullptr) {
|
if (buf == nullptr) {
|
||||||
error.Format(pcm_convert_domain,
|
error.Format(pcm_convert_domain,
|
||||||
"Conversion from %s to 32 bit is not implemented",
|
"Conversion from %s to 32 bit is not implemented",
|
||||||
@ -220,28 +212,23 @@ PcmConvert::Convert32(const void *src_buffer, size_t src_size,
|
|||||||
dest_format.sample_rate, &len,
|
dest_format.sample_rate, &len,
|
||||||
error);
|
error);
|
||||||
if (buf == nullptr)
|
if (buf == nullptr)
|
||||||
return buf;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
*dest_size_r = len;
|
return ConstBuffer<int32_t>::FromVoid({buf, len});
|
||||||
return buf;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const float *
|
inline ConstBuffer<float>
|
||||||
PcmConvert::ConvertFloat(const void *src_buffer, size_t src_size,
|
PcmConvert::ConvertFloat(ConstBuffer<void> src, Error &error)
|
||||||
size_t *dest_size_r,
|
|
||||||
Error &error)
|
|
||||||
{
|
{
|
||||||
const float *buffer = (const float *)src_buffer;
|
|
||||||
size_t size = src_size;
|
|
||||||
|
|
||||||
assert(dest_format.format == SampleFormat::FLOAT);
|
assert(dest_format.format == SampleFormat::FLOAT);
|
||||||
|
|
||||||
/* convert to float now */
|
/* convert to float now */
|
||||||
|
|
||||||
buffer = pcm_convert_to_float(format_buffer,
|
size_t size;
|
||||||
|
const float *buffer = pcm_convert_to_float(format_buffer,
|
||||||
src_format.format,
|
src_format.format,
|
||||||
buffer, size, &size);
|
src.data, src.size, &size);
|
||||||
if (buffer == nullptr) {
|
if (buffer == nullptr) {
|
||||||
error.Format(pcm_convert_domain,
|
error.Format(pcm_convert_domain,
|
||||||
"Conversion from %s to float is not implemented",
|
"Conversion from %s to float is not implemented",
|
||||||
@ -279,8 +266,7 @@ PcmConvert::ConvertFloat(const void *src_buffer, size_t src_size,
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
*dest_size_r = size;
|
return ConstBuffer<float>::FromVoid({buffer, size});
|
||||||
return buffer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const void *
|
const void *
|
||||||
@ -305,24 +291,20 @@ PcmConvert::Convert(const void *src, size_t src_size,
|
|||||||
|
|
||||||
switch (dest_format.format) {
|
switch (dest_format.format) {
|
||||||
case SampleFormat::S16:
|
case SampleFormat::S16:
|
||||||
return Convert16(buffer.data, buffer.size,
|
buffer = Convert16(buffer, error).ToVoid();
|
||||||
dest_size_r,
|
break;
|
||||||
error);
|
|
||||||
|
|
||||||
case SampleFormat::S24_P32:
|
case SampleFormat::S24_P32:
|
||||||
return Convert24(buffer.data, buffer.size,
|
buffer = Convert24(buffer, error).ToVoid();
|
||||||
dest_size_r,
|
break;
|
||||||
error);
|
|
||||||
|
|
||||||
case SampleFormat::S32:
|
case SampleFormat::S32:
|
||||||
return Convert32(buffer.data, buffer.size,
|
buffer = Convert32(buffer, error).ToVoid();
|
||||||
dest_size_r,
|
break;
|
||||||
error);
|
|
||||||
|
|
||||||
case SampleFormat::FLOAT:
|
case SampleFormat::FLOAT:
|
||||||
return ConvertFloat(buffer.data, buffer.size,
|
buffer = ConvertFloat(buffer, error).ToVoid();
|
||||||
dest_size_r,
|
break;
|
||||||
error);
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
error.Format(pcm_convert_domain,
|
error.Format(pcm_convert_domain,
|
||||||
@ -330,4 +312,7 @@ PcmConvert::Convert(const void *src, size_t src_size,
|
|||||||
sample_format_to_string(dest_format.format));
|
sample_format_to_string(dest_format.format));
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*dest_size_r = buffer.size;
|
||||||
|
return buffer.data;
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
|
template<typename T> struct ConstBuffer;
|
||||||
class Error;
|
class Error;
|
||||||
class Domain;
|
class Domain;
|
||||||
|
|
||||||
@ -91,21 +92,10 @@ public:
|
|||||||
Error &error);
|
Error &error);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const int16_t *Convert16(const void *src_buffer, size_t src_size,
|
ConstBuffer<int16_t> Convert16(ConstBuffer<void> src, Error &error);
|
||||||
size_t *dest_size_r,
|
ConstBuffer<int32_t> Convert24(ConstBuffer<void> src, Error &error);
|
||||||
Error &error);
|
ConstBuffer<int32_t> Convert32(ConstBuffer<void> src, Error &error);
|
||||||
|
ConstBuffer<float> ConvertFloat(ConstBuffer<void> src, Error &error);
|
||||||
const int32_t *Convert24(const void *src_buffer, size_t src_size,
|
|
||||||
size_t *dest_size_r,
|
|
||||||
Error &error);
|
|
||||||
|
|
||||||
const int32_t *Convert32(const void *src_buffer, size_t src_size,
|
|
||||||
size_t *dest_size_r,
|
|
||||||
Error &error);
|
|
||||||
|
|
||||||
const float *ConvertFloat(const void *src_buffer, size_t src_size,
|
|
||||||
size_t *dest_size_r,
|
|
||||||
Error &error);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
extern const Domain pcm_convert_domain;
|
extern const Domain pcm_convert_domain;
|
||||||
|
Loading…
Reference in New Issue
Block a user