aboutsummaryrefslogtreecommitdiffstats
path: root/src
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
parentcd1bb2bafa2653e5d4c7c9abf6f464bcdec693c5 (diff)
downloadmpd-c75cb67c4406648314ce2a15daf8b632374d7913.tar.gz
mpd-c75cb67c4406648314ce2a15daf8b632374d7913.tar.xz
mpd-c75cb67c4406648314ce2a15daf8b632374d7913.zip
pcm_buffer: convert to C++
Diffstat (limited to 'src')
-rw-r--r--src/OutputFinish.cxx2
-rw-r--r--src/OutputInit.cxx2
-rw-r--r--src/OutputInternal.hxx4
-rw-r--r--src/OutputThread.cxx3
-rw-r--r--src/decoder/FlacCommon.cxx5
-rw-r--r--src/decoder/FlacCommon.hxx7
-rw-r--r--src/encoder/FlacEncoderPlugin.cxx12
-rw-r--r--src/filter/NormalizeFilterPlugin.cxx9
-rw-r--r--src/filter/ReplayGainFilterPlugin.cxx12
-rw-r--r--src/filter/RouteFilterPlugin.cxx13
-rw-r--r--src/filter/VolumeFilterPlugin.cxx9
-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
30 files changed, 172 insertions, 276 deletions
diff --git a/src/OutputFinish.cxx b/src/OutputFinish.cxx
index d36538a4e..2346161aa 100644
--- a/src/OutputFinish.cxx
+++ b/src/OutputFinish.cxx
@@ -38,8 +38,6 @@ ao_base_finish(struct audio_output *ao)
delete ao->replay_gain_filter;
delete ao->other_replay_gain_filter;
delete ao->filter;
-
- pcm_buffer_deinit(&ao->cross_fade_buffer);
}
void
diff --git a/src/OutputInit.cxx b/src/OutputInit.cxx
index 8d8e034e7..8fb8e5b54 100644
--- a/src/OutputInit.cxx
+++ b/src/OutputInit.cxx
@@ -176,8 +176,6 @@ ao_base_init(struct audio_output *ao,
ao->allow_play = true;
ao->fail_timer = NULL;
- pcm_buffer_init(&ao->cross_fade_buffer);
-
/* set up the filter chain */
ao->filter = filter_chain_new();
diff --git a/src/OutputInternal.hxx b/src/OutputInternal.hxx
index f3b23d8f5..a0d376827 100644
--- a/src/OutputInternal.hxx
+++ b/src/OutputInternal.hxx
@@ -21,7 +21,7 @@
#define MPD_OUTPUT_INTERNAL_HXX
#include "audio_format.h"
-#include "pcm/pcm_buffer.h"
+#include "pcm/PcmBuffer.hxx"
#include "thread/Mutex.hxx"
#include "thread/Cond.hxx"
@@ -153,7 +153,7 @@ struct audio_output {
/**
* The buffer used to allocate the cross-fading result.
*/
- struct pcm_buffer cross_fade_buffer;
+ PcmBuffer cross_fade_buffer;
/**
* The filter object of this audio output. This is an
diff --git a/src/OutputThread.cxx b/src/OutputThread.cxx
index d072b50cd..1f6a21654 100644
--- a/src/OutputThread.cxx
+++ b/src/OutputThread.cxx
@@ -395,8 +395,7 @@ ao_filter_chunk(struct audio_output *ao, const struct music_chunk *chunk,
if (length > other_length)
length = other_length;
- void *dest = pcm_buffer_get(&ao->cross_fade_buffer,
- other_length);
+ void *dest = ao->cross_fade_buffer.Get(other_length);
memcpy(dest, other_data, other_length);
if (!pcm_mix(dest, data, length,
sample_format(ao->in_audio_format.format),
diff --git a/src/decoder/FlacCommon.cxx b/src/decoder/FlacCommon.cxx
index 07a377055..74a0347f2 100644
--- a/src/decoder/FlacCommon.cxx
+++ b/src/decoder/FlacCommon.cxx
@@ -39,13 +39,10 @@ flac_data::flac_data(struct decoder *_decoder,
decoder(_decoder), input_stream(_input_stream),
tag(nullptr)
{
- pcm_buffer_init(&buffer);
}
flac_data::~flac_data()
{
- pcm_buffer_deinit(&buffer);
-
if (tag != nullptr)
tag_free(tag);
}
@@ -178,7 +175,7 @@ flac_common_write(struct flac_data *data, const FLAC__Frame * frame,
return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
size_t buffer_size = frame->header.blocksize * data->frame_size;
- buffer = pcm_buffer_get(&data->buffer, buffer_size);
+ buffer = data->buffer.Get(buffer_size);
flac_convert(buffer, frame->header.channels,
(enum sample_format)data->audio_format.format, buf,
diff --git a/src/decoder/FlacCommon.hxx b/src/decoder/FlacCommon.hxx
index 78982e308..ca6c9a8f9 100644
--- a/src/decoder/FlacCommon.hxx
+++ b/src/decoder/FlacCommon.hxx
@@ -26,10 +26,7 @@
#include "FlacInput.hxx"
#include "DecoderAPI.hxx"
-
-extern "C" {
-#include "pcm/pcm_buffer.h"
-}
+#include "pcm/PcmBuffer.hxx"
#include <FLAC/stream_decoder.h>
#include <FLAC/metadata.h>
@@ -38,7 +35,7 @@ extern "C" {
#define G_LOG_DOMAIN "flac"
struct flac_data : public FlacInput {
- struct pcm_buffer buffer;
+ PcmBuffer buffer;
/**
* The size of one frame in the output buffer.
diff --git a/src/encoder/FlacEncoderPlugin.cxx b/src/encoder/FlacEncoderPlugin.cxx
index 3694c5327..a7f551422 100644
--- a/src/encoder/FlacEncoderPlugin.cxx
+++ b/src/encoder/FlacEncoderPlugin.cxx
@@ -22,7 +22,7 @@
#include "encoder_api.h"
#include "encoder_plugin.h"
#include "audio_format.h"
-#include "pcm/pcm_buffer.h"
+#include "pcm/PcmBuffer.hxx"
#include "util/fifo_buffer.h"
extern "C" {
@@ -46,7 +46,7 @@ struct flac_encoder {
FLAC__StreamEncoder *fse;
- struct pcm_buffer expand_buffer;
+ PcmBuffer expand_buffer;
/**
* This buffer will hold encoded data from libFLAC until it is
@@ -160,7 +160,7 @@ flac_encoder_close(struct encoder *_encoder)
FLAC__stream_encoder_delete(encoder->fse);
- pcm_buffer_deinit(&encoder->expand_buffer);
+ encoder->expand_buffer.Clear();
fifo_buffer_free(encoder->output_buffer);
}
@@ -205,8 +205,6 @@ flac_encoder_open(struct encoder *_encoder, struct audio_format *audio_format,
return false;
}
- pcm_buffer_init(&encoder->expand_buffer);
-
encoder->output_buffer = growing_fifo_new();
/* this immediately outputs data through callback */
@@ -275,14 +273,14 @@ flac_encoder_write(struct encoder *_encoder,
switch (encoder->audio_format.format) {
case SAMPLE_FORMAT_S8:
- exbuffer = pcm_buffer_get(&encoder->expand_buffer, length*4);
+ exbuffer = encoder->expand_buffer.Get(length * 4);
pcm8_to_flac((int32_t *)exbuffer, (const int8_t *)data,
num_samples);
buffer = exbuffer;
break;
case SAMPLE_FORMAT_S16:
- exbuffer = pcm_buffer_get(&encoder->expand_buffer, length*2);
+ exbuffer = encoder->expand_buffer.Get(length * 2);
pcm16_to_flac((int32_t *)exbuffer, (const int16_t *)data,
num_samples);
buffer = exbuffer;
diff --git a/src/filter/NormalizeFilterPlugin.cxx b/src/filter/NormalizeFilterPlugin.cxx
index 082d6fc94..f4e2963cc 100644
--- a/src/filter/NormalizeFilterPlugin.cxx
+++ b/src/filter/NormalizeFilterPlugin.cxx
@@ -21,7 +21,7 @@
#include "FilterPlugin.hxx"
#include "FilterInternal.hxx"
#include "FilterRegistry.hxx"
-#include "pcm/pcm_buffer.h"
+#include "pcm/PcmBuffer.hxx"
#include "audio_format.h"
#include "AudioCompress/compress.h"
@@ -31,7 +31,7 @@
class NormalizeFilter final : public Filter {
struct Compressor *compressor;
- struct pcm_buffer buffer;
+ PcmBuffer buffer;
public:
virtual const audio_format *Open(audio_format &af, GError **error_r);
@@ -53,7 +53,6 @@ NormalizeFilter::Open(audio_format &audio_format, gcc_unused GError **error_r)
audio_format.format = SAMPLE_FORMAT_S16;
compressor = Compressor_new(0);
- pcm_buffer_init(&buffer);
return &audio_format;
}
@@ -61,7 +60,7 @@ NormalizeFilter::Open(audio_format &audio_format, gcc_unused GError **error_r)
void
NormalizeFilter::Close()
{
- pcm_buffer_deinit(&buffer);
+ buffer.Clear();
Compressor_delete(compressor);
}
@@ -69,7 +68,7 @@ const void *
NormalizeFilter::FilterPCM(const void *src, size_t src_size,
size_t *dest_size_r, gcc_unused GError **error_r)
{
- int16_t *dest = (int16_t *)pcm_buffer_get(&buffer, src_size);
+ int16_t *dest = (int16_t *)buffer.Get(src_size);
memcpy(dest, src, src_size);
Compressor_Process_int16(compressor, dest, src_size / 2);
diff --git a/src/filter/ReplayGainFilterPlugin.cxx b/src/filter/ReplayGainFilterPlugin.cxx
index f590d57f5..d736c910f 100644
--- a/src/filter/ReplayGainFilterPlugin.cxx
+++ b/src/filter/ReplayGainFilterPlugin.cxx
@@ -27,10 +27,7 @@
#include "replay_gain_config.h"
#include "MixerControl.hxx"
#include "pcm/PcmVolume.hxx"
-
-extern "C" {
-#include "pcm/pcm_buffer.h"
-}
+#include "pcm/PcmBuffer.hxx"
#include <assert.h>
#include <string.h>
@@ -71,7 +68,7 @@ class ReplayGainFilter final : public Filter {
struct audio_format format;
- struct pcm_buffer buffer;
+ PcmBuffer buffer;
public:
ReplayGainFilter()
@@ -166,7 +163,6 @@ const audio_format *
ReplayGainFilter::Open(audio_format &af, gcc_unused GError **error_r)
{
format = af;
- pcm_buffer_init(&buffer);
return &format;
}
@@ -174,7 +170,7 @@ ReplayGainFilter::Open(audio_format &af, gcc_unused GError **error_r)
void
ReplayGainFilter::Close()
{
- pcm_buffer_deinit(&buffer);
+ buffer.Clear();
}
const void *
@@ -188,7 +184,7 @@ ReplayGainFilter::FilterPCM(const void *src, size_t src_size,
/* optimized special case: 100% volume = no-op */
return src;
- void *dest = pcm_buffer_get(&buffer, src_size);
+ void *dest = buffer.Get(src_size);
if (volume <= 0) {
/* optimized special case: 0% volume = memset(0) */
/* XXX is this valid for all sample formats? What
diff --git a/src/filter/RouteFilterPlugin.cxx b/src/filter/RouteFilterPlugin.cxx
index 85db7e9ea..3dc0991f9 100644
--- a/src/filter/RouteFilterPlugin.cxx
+++ b/src/filter/RouteFilterPlugin.cxx
@@ -47,7 +47,7 @@
#include "FilterPlugin.hxx"
#include "FilterInternal.hxx"
#include "FilterRegistry.hxx"
-#include "pcm/pcm_buffer.h"
+#include "pcm/PcmBuffer.hxx"
#include <assert.h>
#include <string.h>
@@ -101,7 +101,7 @@ class RouteFilter final : public Filter {
/**
* The output buffer used last time around, can be reused if the size doesn't differ.
*/
- struct pcm_buffer output_buffer;
+ PcmBuffer output_buffer;
public:
RouteFilter():sources(nullptr) {}
@@ -256,16 +256,13 @@ RouteFilter::Open(audio_format &audio_format, gcc_unused GError **error_r)
// Precalculate this simple value, to speed up allocation later
output_frame_size = audio_format_frame_size(&output_format);
- // This buffer grows as needed
- pcm_buffer_init(&output_buffer);
-
return &output_format;
}
void
RouteFilter::Close()
{
- pcm_buffer_deinit(&output_buffer);
+ output_buffer.Clear();
}
const void *
@@ -285,9 +282,7 @@ RouteFilter::FilterPCM(const void *src, size_t src_size,
// Grow our reusable buffer, if needed, and set the moving pointer
*dest_size_r = number_of_frames * output_frame_size;
- chan_destination = (uint8_t *)
- pcm_buffer_get(&output_buffer, *dest_size_r);
-
+ chan_destination = (uint8_t *)output_buffer.Get(*dest_size_r);
// Perform our copy operations, with N input channels and M output channels
for (unsigned int s=0; s<number_of_frames; ++s) {
diff --git a/src/filter/VolumeFilterPlugin.cxx b/src/filter/VolumeFilterPlugin.cxx
index 660ad260e..824ad0ab4 100644
--- a/src/filter/VolumeFilterPlugin.cxx
+++ b/src/filter/VolumeFilterPlugin.cxx
@@ -23,8 +23,8 @@
#include "FilterInternal.hxx"
#include "FilterRegistry.hxx"
#include "conf.h"
-#include "pcm/pcm_buffer.h"
#include "pcm/PcmVolume.hxx"
+#include "pcm/PcmBuffer.hxx"
#include "audio_format.h"
#include <assert.h>
@@ -38,7 +38,7 @@ class VolumeFilter final : public Filter {
struct audio_format format;
- struct pcm_buffer buffer;
+ PcmBuffer buffer;
public:
VolumeFilter()
@@ -79,7 +79,6 @@ const struct audio_format *
VolumeFilter::Open(audio_format &audio_format, gcc_unused GError **error_r)
{
format = audio_format;
- pcm_buffer_init(&buffer);
return &format;
}
@@ -87,7 +86,7 @@ VolumeFilter::Open(audio_format &audio_format, gcc_unused GError **error_r)
void
VolumeFilter::Close()
{
- pcm_buffer_deinit(&buffer);
+ buffer.Clear();
}
const void *
@@ -100,7 +99,7 @@ VolumeFilter::FilterPCM(const void *src, size_t src_size,
/* optimized special case: 100% volume = no-op */
return src;
- void *dest = pcm_buffer_get(&buffer, src_size);
+ void *dest = buffer.Get(src_size);
if (volume <= 0) {
/* optimized special case: 0% volume = memset(0) */
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);