aboutsummaryrefslogtreecommitdiffstats
path: root/src/pcm
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-07-29 08:10:10 +0200
committerMax Kellermann <max@duempel.org>2013-07-30 08:31:02 +0200
commitc75cb67c4406648314ce2a15daf8b632374d7913 (patch)
tree5e27b73f2c90e878631bfac5b60070505b094717 /src/pcm
parentcd1bb2bafa2653e5d4c7c9abf6f464bcdec693c5 (diff)
downloadmpd-c75cb67c4406648314ce2a15daf8b632374d7913.tar.gz
mpd-c75cb67c4406648314ce2a15daf8b632374d7913.tar.xz
mpd-c75cb67c4406648314ce2a15daf8b632374d7913.zip
pcm_buffer: convert to C++
Diffstat (limited to 'src/pcm')
-rw-r--r--src/pcm/PcmBuffer.cxx (renamed from src/pcm/pcm_buffer.c)26
-rw-r--r--src/pcm/PcmBuffer.hxx (renamed from src/pcm/pcm_buffer.h)76
-rw-r--r--src/pcm/PcmChannels.cxx18
-rw-r--r--src/pcm/PcmChannels.hxx10
-rw-r--r--src/pcm/PcmConvert.cxx20
-rw-r--r--src/pcm/PcmConvert.hxx9
-rw-r--r--src/pcm/PcmDsd.cxx6
-rw-r--r--src/pcm/PcmDsd.hxx4
-rw-r--r--src/pcm/PcmDsdUsb.cxx7
-rw-r--r--src/pcm/PcmDsdUsb.hxx4
-rw-r--r--src/pcm/PcmExport.cxx11
-rw-r--r--src/pcm/PcmExport.hxx20
-rw-r--r--src/pcm/PcmFormat.cxx80
-rw-r--r--src/pcm/PcmFormat.hxx18
-rw-r--r--src/pcm/PcmResample.cxx4
-rw-r--r--src/pcm/PcmResample.hxx6
-rw-r--r--src/pcm/PcmResampleFallback.cxx18
-rw-r--r--src/pcm/PcmResampleInternal.hxx6
-rw-r--r--src/pcm/PcmResampleLibsamplerate.cxx27
19 files changed, 145 insertions, 225 deletions
diff --git a/src/pcm/pcm_buffer.c b/src/pcm/PcmBuffer.cxx
index 4b1eb875a..a70888080 100644
--- a/src/pcm/pcm_buffer.c
+++ b/src/pcm/PcmBuffer.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2011 The Music Player Daemon Project
+ * Copyright (C) 2003-2013 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -18,7 +18,7 @@
*/
#include "config.h"
-#include "pcm_buffer.h"
+#include "PcmBuffer.hxx"
#include "poison.h"
/**
@@ -32,27 +32,25 @@ align_8k(size_t size)
}
void *
-pcm_buffer_get(struct pcm_buffer *buffer, size_t size)
+PcmBuffer::Get(size_t new_size)
{
- assert(buffer != NULL);
-
- if (size == 0)
+ if (new_size == 0)
/* never return NULL, because NULL would be assumed to
be an error condition */
- size = 1;
+ new_size = 1;
- if (buffer->size < size) {
+ if (size < new_size) {
/* free the old buffer */
- g_free(buffer->buffer);
+ g_free(buffer);
- buffer->size = align_8k(size);
- buffer->buffer = g_malloc(buffer->size);
+ size = align_8k(new_size);
+ buffer = g_malloc(size);
} else {
/* discard old buffer contents */
- poison_undefined(buffer->buffer, buffer->size);
+ poison_undefined(buffer, size);
}
- assert(buffer->size >= size);
+ assert(size >= new_size);
- return buffer->buffer;
+ return buffer;
}
diff --git a/src/pcm/pcm_buffer.h b/src/pcm/PcmBuffer.hxx
index 5d6382d5e..260960726 100644
--- a/src/pcm/pcm_buffer.h
+++ b/src/pcm/PcmBuffer.hxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2011 The Music Player Daemon Project
+ * Copyright (C) 2003-2013 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -17,10 +17,11 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#ifndef PCM_BUFFER_H
-#define PCM_BUFFER_H
+#ifndef PCM_BUFFER_HXX
+#define PCM_BUFFER_HXX
#include "check.h"
+#include "gcc.h"
#include <glib.h>
@@ -31,55 +32,32 @@
* allocate a new buffer every time pcm_convert() is called, but that
* would put too much stress on the allocator.
*/
-struct pcm_buffer {
+struct PcmBuffer {
void *buffer;
size_t size;
-};
-
-/**
- * Initialize the buffer, but don't allocate anything yet.
- */
-static inline void
-pcm_buffer_init(struct pcm_buffer *buffer)
-{
- assert(buffer != NULL);
-
- buffer->buffer = NULL;
- buffer->size = 0;
-}
-
-/**
- * Free resources. This function may be called more than once.
- */
-static inline void
-pcm_buffer_deinit(struct pcm_buffer *buffer)
-{
- assert(buffer != NULL);
-
- g_free(buffer->buffer);
- buffer->buffer = NULL;
-}
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * Get the buffer, and guarantee a minimum size. This buffer becomes
- * invalid with the next pcm_buffer_get() call.
- *
- * This function will never return NULL, even if size is zero, because
- * the PCM library uses the NULL return value to signal "error". An
- * empty destination buffer is not always an error.
- */
-G_GNUC_MALLOC
-void *
-pcm_buffer_get(struct pcm_buffer *buffer, size_t size);
-
-#ifdef __cplusplus
-}
-#endif
+ PcmBuffer():buffer(nullptr), size(0) {}
+
+ ~PcmBuffer() {
+ g_free(buffer);
+ }
+
+ void Clear() {
+ g_free(buffer);
+ buffer = nullptr;
+ }
+
+ /**
+ * Get the buffer, and guarantee a minimum size. This buffer becomes
+ * invalid with the next pcm_buffer_get() call.
+ *
+ * This function will never return NULL, even if size is zero, because
+ * the PCM library uses the NULL return value to signal "error". An
+ * empty destination buffer is not always an error.
+ */
+ gcc_malloc
+ void *Get(size_t size);
+};
#endif
diff --git a/src/pcm/PcmChannels.cxx b/src/pcm/PcmChannels.cxx
index eca6b2506..27a155063 100644
--- a/src/pcm/PcmChannels.cxx
+++ b/src/pcm/PcmChannels.cxx
@@ -19,7 +19,7 @@
#include "config.h"
#include "PcmChannels.hxx"
-#include "pcm_buffer.h"
+#include "PcmBuffer.hxx"
#include "PcmUtils.hxx"
#include <assert.h>
@@ -74,7 +74,7 @@ pcm_convert_channels_16_n_to_2(int16_t *restrict dest,
}
const int16_t *
-pcm_convert_channels_16(struct pcm_buffer *buffer,
+pcm_convert_channels_16(PcmBuffer &buffer,
unsigned dest_channels,
unsigned src_channels, const int16_t *src,
size_t src_size, size_t *dest_size_r)
@@ -84,7 +84,7 @@ pcm_convert_channels_16(struct pcm_buffer *buffer,
size_t dest_size = src_size / src_channels * dest_channels;
*dest_size_r = dest_size;
- int16_t *dest = (int16_t *)pcm_buffer_get(buffer, dest_size);
+ int16_t *dest = (int16_t *)buffer.Get(dest_size);
const int16_t *src_end = pcm_end_pointer(src, src_size);
if (src_channels == 1 && dest_channels == 2)
@@ -137,7 +137,7 @@ pcm_convert_channels_24_n_to_2(int32_t *restrict dest,
}
const int32_t *
-pcm_convert_channels_24(struct pcm_buffer *buffer,
+pcm_convert_channels_24(PcmBuffer &buffer,
unsigned dest_channels,
unsigned src_channels, const int32_t *src,
size_t src_size, size_t *dest_size_r)
@@ -147,7 +147,7 @@ pcm_convert_channels_24(struct pcm_buffer *buffer,
size_t dest_size = src_size / src_channels * dest_channels;
*dest_size_r = dest_size;
- int32_t *dest = (int32_t *)pcm_buffer_get(buffer, dest_size);
+ int32_t *dest = (int32_t *)buffer.Get(dest_size);
const int32_t *src_end = (const int32_t *)
pcm_end_pointer(src, src_size);
@@ -200,7 +200,7 @@ pcm_convert_channels_32_n_to_2(int32_t *dest,
}
const int32_t *
-pcm_convert_channels_32(struct pcm_buffer *buffer,
+pcm_convert_channels_32(PcmBuffer &buffer,
unsigned dest_channels,
unsigned src_channels, const int32_t *src,
size_t src_size, size_t *dest_size_r)
@@ -210,7 +210,7 @@ pcm_convert_channels_32(struct pcm_buffer *buffer,
size_t dest_size = src_size / src_channels * dest_channels;
*dest_size_r = dest_size;
- int32_t *dest = (int32_t *)pcm_buffer_get(buffer, dest_size);
+ int32_t *dest = (int32_t *)buffer.Get(dest_size);
const int32_t *src_end = (const int32_t *)
pcm_end_pointer(src, src_size);
@@ -263,7 +263,7 @@ pcm_convert_channels_float_n_to_2(float *dest,
}
const float *
-pcm_convert_channels_float(struct pcm_buffer *buffer,
+pcm_convert_channels_float(PcmBuffer &buffer,
unsigned dest_channels,
unsigned src_channels, const float *src,
size_t src_size, size_t *dest_size_r)
@@ -273,7 +273,7 @@ pcm_convert_channels_float(struct pcm_buffer *buffer,
size_t dest_size = src_size / src_channels * dest_channels;
*dest_size_r = dest_size;
- float *dest = (float *)pcm_buffer_get(buffer, dest_size);
+ float *dest = (float *)buffer.Get(dest_size);
const float *src_end = (const float *)pcm_end_pointer(src, src_size);
if (src_channels == 1 && dest_channels == 2)
diff --git a/src/pcm/PcmChannels.hxx b/src/pcm/PcmChannels.hxx
index ede49cd81..889a14a60 100644
--- a/src/pcm/PcmChannels.hxx
+++ b/src/pcm/PcmChannels.hxx
@@ -23,7 +23,7 @@
#include <stdint.h>
#include <stddef.h>
-struct pcm_buffer;
+struct PcmBuffer;
/**
* Changes the number of channels in 16 bit PCM data.
@@ -37,7 +37,7 @@ struct pcm_buffer;
* @return the destination buffer
*/
const int16_t *
-pcm_convert_channels_16(struct pcm_buffer *buffer,
+pcm_convert_channels_16(PcmBuffer &buffer,
unsigned dest_channels,
unsigned src_channels, const int16_t *src,
size_t src_size, size_t *dest_size_r);
@@ -55,7 +55,7 @@ pcm_convert_channels_16(struct pcm_buffer *buffer,
* @return the destination buffer
*/
const int32_t *
-pcm_convert_channels_24(struct pcm_buffer *buffer,
+pcm_convert_channels_24(PcmBuffer &buffer,
unsigned dest_channels,
unsigned src_channels, const int32_t *src,
size_t src_size, size_t *dest_size_r);
@@ -72,7 +72,7 @@ pcm_convert_channels_24(struct pcm_buffer *buffer,
* @return the destination buffer
*/
const int32_t *
-pcm_convert_channels_32(struct pcm_buffer *buffer,
+pcm_convert_channels_32(PcmBuffer &buffer,
unsigned dest_channels,
unsigned src_channels, const int32_t *src,
size_t src_size, size_t *dest_size_r);
@@ -89,7 +89,7 @@ pcm_convert_channels_32(struct pcm_buffer *buffer,
* @return the destination buffer
*/
const float *
-pcm_convert_channels_float(struct pcm_buffer *buffer,
+pcm_convert_channels_float(PcmBuffer &buffer,
unsigned dest_channels,
unsigned src_channels, const float *src,
size_t src_size, size_t *dest_size_r);
diff --git a/src/pcm/PcmConvert.cxx b/src/pcm/PcmConvert.cxx
index d280101b5..69e1c5d04 100644
--- a/src/pcm/PcmConvert.cxx
+++ b/src/pcm/PcmConvert.cxx
@@ -34,14 +34,10 @@
PcmConvert::PcmConvert()
{
- pcm_buffer_init(&format_buffer);
- pcm_buffer_init(&channels_buffer);
}
PcmConvert::~PcmConvert()
{
- pcm_buffer_deinit(&format_buffer);
- pcm_buffer_deinit(&channels_buffer);
}
void
@@ -62,7 +58,7 @@ PcmConvert::Convert16(const audio_format *src_format,
assert(dest_format->format == SAMPLE_FORMAT_S16);
- buf = pcm_convert_to_16(&format_buffer, dither,
+ buf = pcm_convert_to_16(format_buffer, dither,
sample_format(src_format->format),
src_buffer, src_size,
&len);
@@ -74,7 +70,7 @@ PcmConvert::Convert16(const audio_format *src_format,
}
if (src_format->channels != dest_format->channels) {
- buf = pcm_convert_channels_16(&channels_buffer,
+ buf = pcm_convert_channels_16(channels_buffer,
dest_format->channels,
src_format->channels,
buf, len, &len);
@@ -112,7 +108,7 @@ PcmConvert::Convert24(const audio_format *src_format,
assert(dest_format->format == SAMPLE_FORMAT_S24_P32);
- buf = pcm_convert_to_24(&format_buffer,
+ buf = pcm_convert_to_24(format_buffer,
sample_format(src_format->format),
src_buffer, src_size, &len);
if (buf == NULL) {
@@ -123,7 +119,7 @@ PcmConvert::Convert24(const audio_format *src_format,
}
if (src_format->channels != dest_format->channels) {
- buf = pcm_convert_channels_24(&channels_buffer,
+ buf = pcm_convert_channels_24(channels_buffer,
dest_format->channels,
src_format->channels,
buf, len, &len);
@@ -161,7 +157,7 @@ PcmConvert::Convert32(const audio_format *src_format,
assert(dest_format->format == SAMPLE_FORMAT_S32);
- buf = pcm_convert_to_32(&format_buffer,
+ buf = pcm_convert_to_32(format_buffer,
sample_format(src_format->format),
src_buffer, src_size, &len);
if (buf == NULL) {
@@ -172,7 +168,7 @@ PcmConvert::Convert32(const audio_format *src_format,
}
if (src_format->channels != dest_format->channels) {
- buf = pcm_convert_channels_32(&channels_buffer,
+ buf = pcm_convert_channels_32(channels_buffer,
dest_format->channels,
src_format->channels,
buf, len, &len);
@@ -212,7 +208,7 @@ PcmConvert::ConvertFloat(const audio_format *src_format,
/* convert to float now */
- buffer = pcm_convert_to_float(&format_buffer,
+ buffer = pcm_convert_to_float(format_buffer,
sample_format(src_format->format),
buffer, size, &size);
if (buffer == NULL) {
@@ -225,7 +221,7 @@ PcmConvert::ConvertFloat(const audio_format *src_format,
/* convert channels */
if (src_format->channels != dest_format->channels) {
- buffer = pcm_convert_channels_float(&channels_buffer,
+ buffer = pcm_convert_channels_float(channels_buffer,
dest_format->channels,
src_format->channels,
buffer, size, &size);
diff --git a/src/pcm/PcmConvert.hxx b/src/pcm/PcmConvert.hxx
index 1635a90c3..f4503f5aa 100644
--- a/src/pcm/PcmConvert.hxx
+++ b/src/pcm/PcmConvert.hxx
@@ -23,10 +23,7 @@
#include "PcmDither.hxx"
#include "PcmDsd.hxx"
#include "PcmResample.hxx"
-
-extern "C" {
-#include "pcm_buffer.h"
-}
+#include "PcmBuffer.hxx"
#include <glib.h>
@@ -45,10 +42,10 @@ class PcmConvert {
PcmDither dither;
/** the buffer for converting the sample format */
- struct pcm_buffer format_buffer;
+ PcmBuffer format_buffer;
/** the buffer for converting the channel count */
- struct pcm_buffer channels_buffer;
+ PcmBuffer channels_buffer;
public:
PcmConvert();
diff --git a/src/pcm/PcmDsd.cxx b/src/pcm/PcmDsd.cxx
index fb2dfd033..e2f5aac20 100644
--- a/src/pcm/PcmDsd.cxx
+++ b/src/pcm/PcmDsd.cxx
@@ -29,15 +29,11 @@
PcmDsd::PcmDsd()
{
- pcm_buffer_init(&buffer);
-
std::fill_n(dsd2pcm, G_N_ELEMENTS(dsd2pcm), nullptr);
}
PcmDsd::~PcmDsd()
{
- pcm_buffer_deinit(&buffer);
-
for (unsigned i = 0; i < G_N_ELEMENTS(dsd2pcm); ++i)
if (dsd2pcm[i] != nullptr)
dsd2pcm_destroy(dsd2pcm[i]);
@@ -67,7 +63,7 @@ PcmDsd::ToFloat(unsigned channels, bool lsbfirst,
float *dest;
const size_t dest_size = num_samples * sizeof(*dest);
*dest_size_r = dest_size;
- dest = (float *)pcm_buffer_get(&buffer, dest_size);
+ dest = (float *)buffer.Get(dest_size);
for (unsigned c = 0; c < channels; ++c) {
if (dsd2pcm[c] == nullptr) {
diff --git a/src/pcm/PcmDsd.hxx b/src/pcm/PcmDsd.hxx
index ef71411e9..26ee11b13 100644
--- a/src/pcm/PcmDsd.hxx
+++ b/src/pcm/PcmDsd.hxx
@@ -21,7 +21,7 @@
#define MPD_PCM_DSD_HXX
#include "check.h"
-#include "pcm_buffer.h"
+#include "PcmBuffer.hxx"
#include <stdint.h>
@@ -29,7 +29,7 @@
* Wrapper for the dsd2pcm library.
*/
struct PcmDsd {
- struct pcm_buffer buffer;
+ PcmBuffer buffer;
struct dsd2pcm_ctx_s *dsd2pcm[32];
diff --git a/src/pcm/PcmDsdUsb.cxx b/src/pcm/PcmDsdUsb.cxx
index 30231e144..ef267e724 100644
--- a/src/pcm/PcmDsdUsb.cxx
+++ b/src/pcm/PcmDsdUsb.cxx
@@ -19,7 +19,7 @@
#include "config.h"
#include "PcmDsdUsb.hxx"
-#include "pcm_buffer.h"
+#include "PcmBuffer.hxx"
#include "audio_format.h"
G_GNUC_CONST
@@ -38,11 +38,10 @@ pcm_two_dsd_to_usb_marker2(uint8_t a, uint8_t b)
const uint32_t *
-pcm_dsd_to_usb(struct pcm_buffer *buffer, unsigned channels,
+pcm_dsd_to_usb(PcmBuffer &buffer, unsigned channels,
const uint8_t *src, size_t src_size,
size_t *dest_size_r)
{
- assert(buffer != NULL);
assert(audio_valid_channel_count(channels));
assert(src != NULL);
assert(src_size > 0);
@@ -58,7 +57,7 @@ pcm_dsd_to_usb(struct pcm_buffer *buffer, unsigned channels,
const size_t dest_size = num_samples * 4;
*dest_size_r = dest_size;
- uint32_t *const dest0 = (uint32_t *)pcm_buffer_get(buffer, dest_size),
+ uint32_t *const dest0 = (uint32_t *)buffer.Get(dest_size),
*dest = dest0;
for (unsigned i = num_frames / 2; i > 0; --i) {
diff --git a/src/pcm/PcmDsdUsb.hxx b/src/pcm/PcmDsdUsb.hxx
index d4b414324..2cf8bfbba 100644
--- a/src/pcm/PcmDsdUsb.hxx
+++ b/src/pcm/PcmDsdUsb.hxx
@@ -25,7 +25,7 @@
#include <stdint.h>
#include <stddef.h>
-struct pcm_buffer;
+struct PcmBuffer;
/**
* Pack DSD 1 bit samples into (padded) 24 bit PCM samples for
@@ -34,7 +34,7 @@ struct pcm_buffer;
* http://www.sonore.us/DoP_openStandard_1v1.pdf
*/
const uint32_t *
-pcm_dsd_to_usb(struct pcm_buffer *buffer, unsigned channels,
+pcm_dsd_to_usb(PcmBuffer &buffer, unsigned channels,
const uint8_t *src, size_t src_size,
size_t *dest_size_r);
diff --git a/src/pcm/PcmExport.cxx b/src/pcm/PcmExport.cxx
index a148e2873..8840dc865 100644
--- a/src/pcm/PcmExport.cxx
+++ b/src/pcm/PcmExport.cxx
@@ -78,7 +78,7 @@ const void *
PcmExport::Export(const void *data, size_t size, size_t &dest_size_r)
{
if (dsd_usb)
- data = pcm_dsd_to_usb(&dsd_buffer, channels,
+ data = pcm_dsd_to_usb(dsd_buffer, channels,
(const uint8_t *)data, size, &size);
if (pack24) {
@@ -89,8 +89,7 @@ PcmExport::Export(const void *data, size_t size, size_t &dest_size_r)
const uint8_t *src8 = (const uint8_t *)data;
const uint8_t *src_end8 = src8 + size;
- uint8_t *dest = (uint8_t *)
- pcm_buffer_get(&pack_buffer, dest_size);
+ uint8_t *dest = (uint8_t *)pack_buffer.Get(dest_size);
assert(dest != NULL);
pcm_pack_24(dest, (const int32_t *)src8,
@@ -106,8 +105,7 @@ PcmExport::Export(const void *data, size_t size, size_t &dest_size_r)
const uint32_t *src = (const uint32_t *)src8;
const uint32_t *const src_end = (const uint32_t *)src_end8;
- uint32_t *dest = (uint32_t *)
- pcm_buffer_get(&pack_buffer, size);
+ uint32_t *dest = (uint32_t *)pack_buffer.Get(size);
data = dest;
while (src < src_end)
@@ -118,8 +116,7 @@ PcmExport::Export(const void *data, size_t size, size_t &dest_size_r)
if (reverse_endian > 0) {
assert(reverse_endian >= 2);
- uint8_t *dest = (uint8_t *)
- pcm_buffer_get(&reverse_buffer, size);
+ uint8_t *dest = (uint8_t *)reverse_buffer.Get(size);
assert(dest != NULL);
const uint8_t *src = (const uint8_t *)data;
diff --git a/src/pcm/PcmExport.hxx b/src/pcm/PcmExport.hxx
index 4fb5cc9fc..e420493f0 100644
--- a/src/pcm/PcmExport.hxx
+++ b/src/pcm/PcmExport.hxx
@@ -21,7 +21,7 @@
#define PCM_EXPORT_HXX
#include "check.h"
-#include "pcm_buffer.h"
+#include "PcmBuffer.hxx"
#include "audio_format.h"
struct audio_format;
@@ -38,21 +38,21 @@ struct PcmExport {
*
* @see #dsd_usb
*/
- struct pcm_buffer dsd_buffer;
+ PcmBuffer dsd_buffer;
/**
* The buffer is used to pack samples, removing padding.
*
* @see #pack24
*/
- struct pcm_buffer pack_buffer;
+ PcmBuffer pack_buffer;
/**
* The buffer is used to reverse the byte order.
*
* @see #reverse_endian
*/
- struct pcm_buffer reverse_buffer;
+ PcmBuffer reverse_buffer;
/**
* The number of channels.
@@ -84,18 +84,6 @@ struct PcmExport {
*/
uint8_t reverse_endian;
- PcmExport() {
- pcm_buffer_init(&reverse_buffer);
- pcm_buffer_init(&pack_buffer);
- pcm_buffer_init(&dsd_buffer);
- }
-
- ~PcmExport() {
- pcm_buffer_deinit(&reverse_buffer);
- pcm_buffer_deinit(&pack_buffer);
- pcm_buffer_deinit(&dsd_buffer);
- }
-
/**
* Open the #pcm_export_state object.
*
diff --git a/src/pcm/PcmFormat.cxx b/src/pcm/PcmFormat.cxx
index 1385d161b..2dea09d2c 100644
--- a/src/pcm/PcmFormat.cxx
+++ b/src/pcm/PcmFormat.cxx
@@ -20,7 +20,7 @@
#include "config.h"
#include "PcmFormat.hxx"
#include "PcmDither.hxx"
-#include "pcm_buffer.h"
+#include "PcmBuffer.hxx"
#include "pcm_pack.h"
#include "PcmUtils.hxx"
@@ -80,7 +80,7 @@ ConvertFromFloat(S dest, const float *src, size_t size)
template<typename S, unsigned bits=sizeof(S)*8>
static S *
-AllocateFromFloat(pcm_buffer &buffer, const float *src, size_t src_size,
+AllocateFromFloat(PcmBuffer &buffer, const float *src, size_t src_size,
size_t *dest_size_r)
{
constexpr size_t src_sample_size = sizeof(*src);
@@ -88,60 +88,60 @@ AllocateFromFloat(pcm_buffer &buffer, const float *src, size_t src_size,
const size_t num_samples = src_size / src_sample_size;
*dest_size_r = num_samples * sizeof(S);
- S *dest = (S *)pcm_buffer_get(&buffer, *dest_size_r);
+ S *dest = (S *)buffer.Get(*dest_size_r);
ConvertFromFloat<S *, bits>(dest, src, src_size);
return dest;
}
static int16_t *
-pcm_allocate_8_to_16(struct pcm_buffer *buffer,
+pcm_allocate_8_to_16(PcmBuffer &buffer,
const int8_t *src, size_t src_size, size_t *dest_size_r)
{
int16_t *dest;
*dest_size_r = src_size / sizeof(*src) * sizeof(*dest);
- dest = (int16_t *)pcm_buffer_get(buffer, *dest_size_r);
+ dest = (int16_t *)buffer.Get(*dest_size_r);
pcm_convert_8_to_16(dest, src, pcm_end_pointer(src, src_size));
return dest;
}
static int16_t *
-pcm_allocate_24p32_to_16(struct pcm_buffer *buffer, PcmDither &dither,
+pcm_allocate_24p32_to_16(PcmBuffer &buffer, PcmDither &dither,
const int32_t *src, size_t src_size,
size_t *dest_size_r)
{
int16_t *dest;
*dest_size_r = src_size / 2;
assert(*dest_size_r == src_size / sizeof(*src) * sizeof(*dest));
- dest = (int16_t *)pcm_buffer_get(buffer, *dest_size_r);
+ dest = (int16_t *)buffer.Get(*dest_size_r);
pcm_convert_24_to_16(dither, dest, src,
pcm_end_pointer(src, src_size));
return dest;
}
static int16_t *
-pcm_allocate_32_to_16(struct pcm_buffer *buffer, PcmDither &dither,
+pcm_allocate_32_to_16(PcmBuffer &buffer, PcmDither &dither,
const int32_t *src, size_t src_size,
size_t *dest_size_r)
{
int16_t *dest;
*dest_size_r = src_size / 2;
assert(*dest_size_r == src_size / sizeof(*src) * sizeof(*dest));
- dest = (int16_t *)pcm_buffer_get(buffer, *dest_size_r);
+ dest = (int16_t *)buffer.Get(*dest_size_r);
pcm_convert_32_to_16(dither, dest, src,
pcm_end_pointer(src, src_size));
return dest;
}
static int16_t *
-pcm_allocate_float_to_16(struct pcm_buffer *buffer,
+pcm_allocate_float_to_16(PcmBuffer &buffer,
const float *src, size_t src_size,
size_t *dest_size_r)
{
- return AllocateFromFloat<int16_t>(*buffer, src, src_size, dest_size_r);
+ return AllocateFromFloat<int16_t>(buffer, src, src_size, dest_size_r);
}
const int16_t *
-pcm_convert_to_16(struct pcm_buffer *buffer, PcmDither &dither,
+pcm_convert_to_16(PcmBuffer &buffer, PcmDither &dither,
enum sample_format src_format, const void *src,
size_t src_size, size_t *dest_size_r)
{
@@ -204,49 +204,49 @@ pcm_convert_32_to_24(int32_t *restrict out,
}
static int32_t *
-pcm_allocate_8_to_24(struct pcm_buffer *buffer,
+pcm_allocate_8_to_24(PcmBuffer &buffer,
const int8_t *src, size_t src_size, size_t *dest_size_r)
{
int32_t *dest;
*dest_size_r = src_size / sizeof(*src) * sizeof(*dest);
- dest = (int32_t *)pcm_buffer_get(buffer, *dest_size_r);
+ dest = (int32_t *)buffer.Get(*dest_size_r);
pcm_convert_8_to_24(dest, src, pcm_end_pointer(src, src_size));
return dest;
}
static int32_t *
-pcm_allocate_16_to_24(struct pcm_buffer *buffer,
+pcm_allocate_16_to_24(PcmBuffer &buffer,
const int16_t *src, size_t src_size, size_t *dest_size_r)
{
int32_t *dest;
*dest_size_r = src_size * 2;
assert(*dest_size_r == src_size / sizeof(*src) * sizeof(*dest));
- dest = (int32_t *)pcm_buffer_get(buffer, *dest_size_r);
+ dest = (int32_t *)buffer.Get(*dest_size_r);
pcm_convert_16_to_24(dest, src, pcm_end_pointer(src, src_size));
return dest;
}
static int32_t *
-pcm_allocate_32_to_24(struct pcm_buffer *buffer,
+pcm_allocate_32_to_24(PcmBuffer &buffer,
const int32_t *src, size_t src_size, size_t *dest_size_r)
{
*dest_size_r = src_size;
- int32_t *dest = (int32_t *)pcm_buffer_get(buffer, *dest_size_r);
+ int32_t *dest = (int32_t *)buffer.Get(*dest_size_r);
pcm_convert_32_to_24(dest, src, pcm_end_pointer(src, src_size));
return dest;
}
static int32_t *
-pcm_allocate_float_to_24(struct pcm_buffer *buffer,
+pcm_allocate_float_to_24(PcmBuffer &buffer,
const float *src, size_t src_size,
size_t *dest_size_r)
{
- return AllocateFromFloat<int32_t, 24>(*buffer, src, src_size,
+ return AllocateFromFloat<int32_t, 24>(buffer, src, src_size,
dest_size_r);
}
const int32_t *
-pcm_convert_to_24(struct pcm_buffer *buffer,
+pcm_convert_to_24(PcmBuffer &buffer,
enum sample_format src_format, const void *src,
size_t src_size, size_t *dest_size_r)
{
@@ -309,41 +309,41 @@ pcm_convert_24_to_32(int32_t *restrict out,
}
static int32_t *
-pcm_allocate_8_to_32(struct pcm_buffer *buffer,
+pcm_allocate_8_to_32(PcmBuffer &buffer,
const int8_t *src, size_t src_size, size_t *dest_size_r)
{
int32_t *dest;
*dest_size_r = src_size / sizeof(*src) * sizeof(*dest);
- dest = (int32_t *)pcm_buffer_get(buffer, *dest_size_r);
+ dest = (int32_t *)buffer.Get(*dest_size_r);
pcm_convert_8_to_32(dest, src, pcm_end_pointer(src, src_size));
return dest;
}
static int32_t *
-pcm_allocate_16_to_32(struct pcm_buffer *buffer,
+pcm_allocate_16_to_32(PcmBuffer &buffer,
const int16_t *src, size_t src_size, size_t *dest_size_r)
{
int32_t *dest;
*dest_size_r = src_size * 2;
assert(*dest_size_r == src_size / sizeof(*src) * sizeof(*dest));
- dest = (int32_t *)pcm_buffer_get(buffer, *dest_size_r);
+ dest = (int32_t *)buffer.Get(*dest_size_r);
pcm_convert_16_to_32(dest, src, pcm_end_pointer(src, src_size));
return dest;
}
static int32_t *
-pcm_allocate_24p32_to_32(struct pcm_buffer *buffer,
+pcm_allocate_24p32_to_32(PcmBuffer &buffer,
const int32_t *src, size_t src_size,
size_t *dest_size_r)
{
*dest_size_r = src_size;
- int32_t *dest = (int32_t *)pcm_buffer_get(buffer, *dest_size_r);
+ int32_t *dest = (int32_t *)buffer.Get(*dest_size_r);
pcm_convert_24_to_32(dest, src, pcm_end_pointer(src, src_size));
return dest;
}
static int32_t *
-pcm_allocate_float_to_32(struct pcm_buffer *buffer,
+pcm_allocate_float_to_32(PcmBuffer &buffer,
const float *src, size_t src_size,
size_t *dest_size_r)
{
@@ -357,7 +357,7 @@ pcm_allocate_float_to_32(struct pcm_buffer *buffer,
}
const int32_t *
-pcm_convert_to_32(struct pcm_buffer *buffer,
+pcm_convert_to_32(PcmBuffer &buffer,
enum sample_format src_format, const void *src,
size_t src_size, size_t *dest_size_r)
{
@@ -415,7 +415,7 @@ ConvertToFloat(float *dest, S src, size_t size)
template<typename S, unsigned bits=DefaultSampleBits<S>::value>
static float *
-AllocateToFloat(pcm_buffer &buffer, S src, size_t src_size,
+AllocateToFloat(PcmBuffer &buffer, S src, size_t src_size,
size_t *dest_size_r)
{
constexpr size_t src_sample_size = sizeof(*S());
@@ -423,46 +423,46 @@ AllocateToFloat(pcm_buffer &buffer, S src, size_t src_size,
const size_t num_samples = src_size / src_sample_size;
*dest_size_r = num_samples * sizeof(float);
- float *dest = (float *)pcm_buffer_get(&buffer, *dest_size_r);
+ float *dest = (float *)buffer.Get(*dest_size_r);
ConvertToFloat<S, bits>(dest, src, src_size);
return dest;
}
static float *
-pcm_allocate_8_to_float(struct pcm_buffer *buffer,
+pcm_allocate_8_to_float(PcmBuffer &buffer,
const int8_t *src, size_t src_size,
size_t *dest_size_r)
{
- return AllocateToFloat(*buffer, src, src_size, dest_size_r);
+ return AllocateToFloat(buffer, src, src_size, dest_size_r);
}
static float *
-pcm_allocate_16_to_float(struct pcm_buffer *buffer,
+pcm_allocate_16_to_float(PcmBuffer &buffer,
const int16_t *src, size_t src_size,
size_t *dest_size_r)
{
- return AllocateToFloat(*buffer, src, src_size, dest_size_r);
+ return AllocateToFloat(buffer, src, src_size, dest_size_r);
}
static float *
-pcm_allocate_24p32_to_float(struct pcm_buffer *buffer,
+pcm_allocate_24p32_to_float(PcmBuffer &buffer,
const int32_t *src, size_t src_size,
size_t *dest_size_r)
{
return AllocateToFloat<decltype(src), 24>
- (*buffer, src, src_size, dest_size_r);
+ (buffer, src, src_size, dest_size_r);
}
static float *
-pcm_allocate_32_to_float(struct pcm_buffer *buffer,
+pcm_allocate_32_to_float(PcmBuffer &buffer,
const int32_t *src, size_t src_size,
size_t *dest_size_r)
{
- return AllocateToFloat(*buffer, src, src_size, dest_size_r);
+ return AllocateToFloat(buffer, src, src_size, dest_size_r);
}
const float *
-pcm_convert_to_float(struct pcm_buffer *buffer,
+pcm_convert_to_float(PcmBuffer &buffer,
enum sample_format src_format, const void *src,
size_t src_size, size_t *dest_size_r)
{
diff --git a/src/pcm/PcmFormat.hxx b/src/pcm/PcmFormat.hxx
index a5970b2d2..bb5ad49ae 100644
--- a/src/pcm/PcmFormat.hxx
+++ b/src/pcm/PcmFormat.hxx
@@ -25,14 +25,14 @@
#include <stdint.h>
#include <stddef.h>
-struct pcm_buffer;
+struct PcmBuffer;
class PcmDither;
/**
* Converts PCM samples to 16 bit. If the source format is 24 bit,
* then dithering is applied.
*
- * @param buffer a pcm_buffer object
+ * @param buffer a PcmBuffer object
* @param dither a pcm_dither object for 24-to-16 conversion
* @param bits the number of in the source buffer
* @param src the source PCM buffer
@@ -41,14 +41,14 @@ class PcmDither;
* @return the destination buffer
*/
const int16_t *
-pcm_convert_to_16(struct pcm_buffer *buffer, PcmDither &dither,
+pcm_convert_to_16(PcmBuffer &buffer, PcmDither &dither,
enum sample_format src_format, const void *src,
size_t src_size, size_t *dest_size_r);
/**
* Converts PCM samples to 24 bit (32 bit alignment).
*
- * @param buffer a pcm_buffer object
+ * @param buffer a PcmBuffer object
* @param bits the number of in the source buffer
* @param src the source PCM buffer
* @param src_size the size of #src in bytes
@@ -56,14 +56,14 @@ pcm_convert_to_16(struct pcm_buffer *buffer, PcmDither &dither,
* @return the destination buffer
*/
const int32_t *
-pcm_convert_to_24(struct pcm_buffer *buffer,
+pcm_convert_to_24(PcmBuffer &buffer,
enum sample_format src_format, const void *src,
size_t src_size, size_t *dest_size_r);
/**
* Converts PCM samples to 32 bit.
*
- * @param buffer a pcm_buffer object
+ * @param buffer a PcmBuffer object
* @param bits the number of in the source buffer
* @param src the source PCM buffer
* @param src_size the size of #src in bytes
@@ -71,14 +71,14 @@ pcm_convert_to_24(struct pcm_buffer *buffer,
* @return the destination buffer
*/
const int32_t *
-pcm_convert_to_32(struct pcm_buffer *buffer,
+pcm_convert_to_32(PcmBuffer &buffer,
enum sample_format src_format, const void *src,
size_t src_size, size_t *dest_size_r);
/**
* Converts PCM samples to 32 bit floating point.
*
- * @param buffer a pcm_buffer object
+ * @param buffer a PcmBuffer object
* @param bits the number of in the source buffer
* @param src the source PCM buffer
* @param src_size the size of #src in bytes
@@ -86,7 +86,7 @@ pcm_convert_to_32(struct pcm_buffer *buffer,
* @return the destination buffer
*/
const float *
-pcm_convert_to_float(struct pcm_buffer *buffer,
+pcm_convert_to_float(PcmBuffer &buffer,
enum sample_format src_format, const void *src,
size_t src_size, size_t *dest_size_r);
diff --git a/src/pcm/PcmResample.cxx b/src/pcm/PcmResample.cxx
index 60265380e..423e3d442 100644
--- a/src/pcm/PcmResample.cxx
+++ b/src/pcm/PcmResample.cxx
@@ -61,9 +61,7 @@ PcmResampler::PcmResampler()
#ifdef HAVE_LIBSAMPLERATE
if (pcm_resample_lsr_enabled())
pcm_resample_lsr_init(this);
- else
#endif
- pcm_resample_fallback_init(this);
}
PcmResampler::~PcmResampler()
@@ -71,9 +69,7 @@ PcmResampler::~PcmResampler()
#ifdef HAVE_LIBSAMPLERATE
if (pcm_resample_lsr_enabled())
pcm_resample_lsr_deinit(this);
- else
#endif
- pcm_resample_fallback_deinit(this);
}
void
diff --git a/src/pcm/PcmResample.hxx b/src/pcm/PcmResample.hxx
index 6aaa75014..790055486 100644
--- a/src/pcm/PcmResample.hxx
+++ b/src/pcm/PcmResample.hxx
@@ -21,7 +21,7 @@
#define MPD_PCM_RESAMPLE_HXX
#include "check.h"
-#include "pcm_buffer.h"
+#include "PcmBuffer.hxx"
#include <stdint.h>
#include <stddef.h>
@@ -40,7 +40,7 @@ struct PcmResampler {
SRC_STATE *state;
SRC_DATA data;
- struct pcm_buffer in, out;
+ PcmBuffer in, out;
struct {
unsigned src_rate;
@@ -51,7 +51,7 @@ struct PcmResampler {
int error;
#endif
- struct pcm_buffer buffer;
+ PcmBuffer buffer;
PcmResampler();
~PcmResampler();
diff --git a/src/pcm/PcmResampleFallback.cxx b/src/pcm/PcmResampleFallback.cxx
index 724894366..a62cd64f7 100644
--- a/src/pcm/PcmResampleFallback.cxx
+++ b/src/pcm/PcmResampleFallback.cxx
@@ -22,18 +22,6 @@
#include <assert.h>
-void
-pcm_resample_fallback_init(PcmResampler *state)
-{
- pcm_buffer_init(&state->buffer);
-}
-
-void
-pcm_resample_fallback_deinit(PcmResampler *state)
-{
- pcm_buffer_deinit(&state->buffer);
-}
-
/* resampling code blatantly ripped from ESD */
const int16_t *
pcm_resample_fallback_16(PcmResampler *state,
@@ -49,8 +37,7 @@ pcm_resample_fallback_16(PcmResampler *state,
(src_frames * dest_rate + src_rate - 1) / src_rate;
unsigned dest_samples = dest_frames * channels;
size_t dest_size = dest_samples * sizeof(*src_buffer);
- int16_t *dest_buffer = (int16_t *)
- pcm_buffer_get(&state->buffer, dest_size);
+ int16_t *dest_buffer = (int16_t *)state->buffer.Get(dest_size);
assert((src_size % (sizeof(*src_buffer) * channels)) == 0);
@@ -91,8 +78,7 @@ pcm_resample_fallback_32(PcmResampler *state,
(src_frames * dest_rate + src_rate - 1) / src_rate;
unsigned dest_samples = dest_frames * channels;
size_t dest_size = dest_samples * sizeof(*src_buffer);
- int32_t *dest_buffer = (int32_t *)
- pcm_buffer_get(&state->buffer, dest_size);
+ int32_t *dest_buffer = (int32_t *)state->buffer.Get(dest_size);
assert((src_size % (sizeof(*src_buffer) * channels)) == 0);
diff --git a/src/pcm/PcmResampleInternal.hxx b/src/pcm/PcmResampleInternal.hxx
index bae69fab4..4ea96daea 100644
--- a/src/pcm/PcmResampleInternal.hxx
+++ b/src/pcm/PcmResampleInternal.hxx
@@ -71,12 +71,6 @@ pcm_resample_lsr_32(PcmResampler *state,
#endif
-void
-pcm_resample_fallback_init(PcmResampler *state);
-
-void
-pcm_resample_fallback_deinit(PcmResampler *state);
-
const int16_t *
pcm_resample_fallback_16(PcmResampler *state,
unsigned channels,
diff --git a/src/pcm/PcmResampleLibsamplerate.cxx b/src/pcm/PcmResampleLibsamplerate.cxx
index 532c79c8d..d8dde62e9 100644
--- a/src/pcm/PcmResampleLibsamplerate.cxx
+++ b/src/pcm/PcmResampleLibsamplerate.cxx
@@ -86,11 +86,10 @@ pcm_resample_lsr_global_init(const char *converter, GError **error_r)
void
pcm_resample_lsr_init(PcmResampler *state)
{
- memset(state, 0, sizeof(*state));
-
- pcm_buffer_init(&state->in);
- pcm_buffer_init(&state->out);
- pcm_buffer_init(&state->buffer);
+ state->state = nullptr;
+ memset(&state->data, 0, sizeof(state->data));
+ memset(&state->prev, 0, sizeof(state->prev));
+ state->error = 0;
}
void
@@ -98,10 +97,6 @@ pcm_resample_lsr_deinit(PcmResampler *state)
{
if (state->state != nullptr)
state->state = src_delete(state->state);
-
- pcm_buffer_deinit(&state->in);
- pcm_buffer_deinit(&state->out);
- pcm_buffer_deinit(&state->buffer);
}
void
@@ -184,7 +179,7 @@ pcm_resample_lsr_float(PcmResampler *state,
data->output_frames = (src_size * dest_rate + src_rate - 1) / src_rate;
size_t data_out_size = data->output_frames * sizeof(float) * channels;
- data->data_out = (float *)pcm_buffer_get(&state->out, data_out_size);
+ data->data_out = (float *)state->out.Get(data_out_size);
if (!lsr_process(state, error_r))
return nullptr;
@@ -212,11 +207,11 @@ pcm_resample_lsr_16(PcmResampler *state,
data->input_frames = src_size / sizeof(*src_buffer) / channels;
size_t data_in_size = data->input_frames * sizeof(float) * channels;
- data->data_in = (float *)pcm_buffer_get(&state->in, data_in_size);
+ data->data_in = (float *)state->in.Get(data_in_size);
data->output_frames = (src_size * dest_rate + src_rate - 1) / src_rate;
size_t data_out_size = data->output_frames * sizeof(float) * channels;
- data->data_out = (float *)pcm_buffer_get(&state->out, data_out_size);
+ data->data_out = (float *)state->out.Get(data_out_size);
src_short_to_float_array(src_buffer, data->data_in,
data->input_frames * channels);
@@ -227,7 +222,7 @@ pcm_resample_lsr_16(PcmResampler *state,
int16_t *dest_buffer;
*dest_size_r = data->output_frames_gen *
sizeof(*dest_buffer) * channels;
- dest_buffer = (int16_t *)pcm_buffer_get(&state->buffer, *dest_size_r);
+ dest_buffer = (int16_t *)state->buffer.Get(*dest_size_r);
src_float_to_short_array(data->data_out, dest_buffer,
data->output_frames_gen * channels);
@@ -272,11 +267,11 @@ pcm_resample_lsr_32(PcmResampler *state,
data->input_frames = src_size / sizeof(*src_buffer) / channels;
size_t data_in_size = data->input_frames * sizeof(float) * channels;
- data->data_in = (float *)pcm_buffer_get(&state->in, data_in_size);
+ data->data_in = (float *)state->in.Get(data_in_size);
data->output_frames = (src_size * dest_rate + src_rate - 1) / src_rate;
size_t data_out_size = data->output_frames * sizeof(float) * channels;
- data->data_out = (float *)pcm_buffer_get(&state->out, data_out_size);
+ data->data_out = (float *)state->out.Get(data_out_size);
src_int_to_float_array(src_buffer, data->data_in,
data->input_frames * channels);
@@ -287,7 +282,7 @@ pcm_resample_lsr_32(PcmResampler *state,
int32_t *dest_buffer;
*dest_size_r = data->output_frames_gen *
sizeof(*dest_buffer) * channels;
- dest_buffer = (int32_t *)pcm_buffer_get(&state->buffer, *dest_size_r);
+ dest_buffer = (int32_t *)state->buffer.Get(*dest_size_r);
src_float_to_int_array(data->data_out, dest_buffer,
data->output_frames_gen * channels);