aboutsummaryrefslogtreecommitdiffstats
path: root/src/pcm
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-11-29 22:48:23 +0100
committerMax Kellermann <max@duempel.org>2013-11-29 22:48:23 +0100
commit3c0c939689e25b56462c12330003f1b5da7b9887 (patch)
treef72f026edcac170a39e32acd00040db32c286ec4 /src/pcm
parent413f7c64e5faa82083140bae856aaabff20c870c (diff)
downloadmpd-3c0c939689e25b56462c12330003f1b5da7b9887.tar.gz
mpd-3c0c939689e25b56462c12330003f1b5da7b9887.tar.xz
mpd-3c0c939689e25b56462c12330003f1b5da7b9887.zip
pcm/PcmConvert: use struct ConstBuffer internally
Diffstat (limited to '')
-rw-r--r--src/pcm/PcmConvert.cxx77
-rw-r--r--src/pcm/PcmConvert.hxx20
2 files changed, 36 insertions, 61 deletions
diff --git a/src/pcm/PcmConvert.cxx b/src/pcm/PcmConvert.cxx
index a350f4ad2..c405fc94f 100644
--- a/src/pcm/PcmConvert.cxx
+++ b/src/pcm/PcmConvert.cxx
@@ -82,10 +82,8 @@ PcmConvert::Close()
#endif
}
-inline const int16_t *
-PcmConvert::Convert16(const void *src_buffer, size_t src_size,
- size_t *dest_size_r,
- Error &error)
+inline ConstBuffer<int16_t>
+PcmConvert::Convert16(ConstBuffer<void> src, Error &error)
{
const int16_t *buf;
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,
src_format.format,
- src_buffer, src_size,
+ src.data, src.size,
&len);
if (buf == nullptr) {
error.Format(pcm_convert_domain,
@@ -127,14 +125,11 @@ PcmConvert::Convert16(const void *src_buffer, size_t src_size,
return nullptr;
}
- *dest_size_r = len;
- return buf;
+ return ConstBuffer<int16_t>::FromVoid({buf, len});
}
-inline const int32_t *
-PcmConvert::Convert24(const void *src_buffer, size_t src_size,
- size_t *dest_size_r,
- Error &error)
+inline ConstBuffer<int32_t>
+PcmConvert::Convert24(ConstBuffer<void> src, Error &error)
{
const int32_t *buf;
size_t len;
@@ -143,7 +138,7 @@ PcmConvert::Convert24(const void *src_buffer, size_t src_size,
buf = pcm_convert_to_24(format_buffer,
src_format.format,
- src_buffer, src_size, &len);
+ src.data, src.size, &len);
if (buf == nullptr) {
error.Format(pcm_convert_domain,
"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;
}
- *dest_size_r = len;
- return buf;
+ return ConstBuffer<int32_t>::FromVoid({buf, len});
}
-inline const int32_t *
-PcmConvert::Convert32(const void *src_buffer, size_t src_size,
- size_t *dest_size_r,
- Error &error)
+inline ConstBuffer<int32_t>
+PcmConvert::Convert32(ConstBuffer<void> src, Error &error)
{
const int32_t *buf;
size_t len;
@@ -191,7 +183,7 @@ PcmConvert::Convert32(const void *src_buffer, size_t src_size,
buf = pcm_convert_to_32(format_buffer,
src_format.format,
- src_buffer, src_size, &len);
+ src.data, src.size, &len);
if (buf == nullptr) {
error.Format(pcm_convert_domain,
"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,
error);
if (buf == nullptr)
- return buf;
+ return nullptr;
}
- *dest_size_r = len;
- return buf;
+ return ConstBuffer<int32_t>::FromVoid({buf, len});
}
-inline const float *
-PcmConvert::ConvertFloat(const void *src_buffer, size_t src_size,
- size_t *dest_size_r,
- Error &error)
+inline ConstBuffer<float>
+PcmConvert::ConvertFloat(ConstBuffer<void> src, Error &error)
{
- const float *buffer = (const float *)src_buffer;
- size_t size = src_size;
-
assert(dest_format.format == SampleFormat::FLOAT);
/* convert to float now */
- buffer = pcm_convert_to_float(format_buffer,
- src_format.format,
- buffer, size, &size);
+ size_t size;
+ const float *buffer = pcm_convert_to_float(format_buffer,
+ src_format.format,
+ src.data, src.size, &size);
if (buffer == nullptr) {
error.Format(pcm_convert_domain,
"Conversion from %s to float is not implemented",
@@ -279,8 +266,7 @@ PcmConvert::ConvertFloat(const void *src_buffer, size_t src_size,
return nullptr;
}
- *dest_size_r = size;
- return buffer;
+ return ConstBuffer<float>::FromVoid({buffer, size});
}
const void *
@@ -305,24 +291,20 @@ PcmConvert::Convert(const void *src, size_t src_size,
switch (dest_format.format) {
case SampleFormat::S16:
- return Convert16(buffer.data, buffer.size,
- dest_size_r,
- error);
+ buffer = Convert16(buffer, error).ToVoid();
+ break;
case SampleFormat::S24_P32:
- return Convert24(buffer.data, buffer.size,
- dest_size_r,
- error);
+ buffer = Convert24(buffer, error).ToVoid();
+ break;
case SampleFormat::S32:
- return Convert32(buffer.data, buffer.size,
- dest_size_r,
- error);
+ buffer = Convert32(buffer, error).ToVoid();
+ break;
case SampleFormat::FLOAT:
- return ConvertFloat(buffer.data, buffer.size,
- dest_size_r,
- error);
+ buffer = ConvertFloat(buffer, error).ToVoid();
+ break;
default:
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));
return nullptr;
}
+
+ *dest_size_r = buffer.size;
+ return buffer.data;
}
diff --git a/src/pcm/PcmConvert.hxx b/src/pcm/PcmConvert.hxx
index 2db24f87b..74f4e350c 100644
--- a/src/pcm/PcmConvert.hxx
+++ b/src/pcm/PcmConvert.hxx
@@ -28,6 +28,7 @@
#include <stddef.h>
+template<typename T> struct ConstBuffer;
class Error;
class Domain;
@@ -91,21 +92,10 @@ public:
Error &error);
private:
- const int16_t *Convert16(const void *src_buffer, size_t src_size,
- size_t *dest_size_r,
- 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);
+ ConstBuffer<int16_t> Convert16(ConstBuffer<void> src, Error &error);
+ ConstBuffer<int32_t> Convert24(ConstBuffer<void> src, Error &error);
+ ConstBuffer<int32_t> Convert32(ConstBuffer<void> src, Error &error);
+ ConstBuffer<float> ConvertFloat(ConstBuffer<void> src, Error &error);
};
extern const Domain pcm_convert_domain;