diff options
author | Max Kellermann <max@duempel.org> | 2013-07-29 07:56:40 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2013-07-29 07:56:40 +0200 |
commit | cac3c159bc84d5163c87a40383d3eda64a4c9f69 (patch) | |
tree | 06e9e4f965ba69b1a415ec1941e238b8a11565cb /src | |
parent | 43166130b51e995ada4130f6400efbb5d38eeb47 (diff) | |
download | mpd-cac3c159bc84d5163c87a40383d3eda64a4c9f69.tar.gz mpd-cac3c159bc84d5163c87a40383d3eda64a4c9f69.tar.xz mpd-cac3c159bc84d5163c87a40383d3eda64a4c9f69.zip |
pcm_dsd: convert to C++
Diffstat (limited to 'src')
-rw-r--r-- | src/pcm/PcmConvert.cxx | 11 | ||||
-rw-r--r-- | src/pcm/PcmConvert.hxx | 4 | ||||
-rw-r--r-- | src/pcm/PcmDsd.cxx (renamed from src/pcm/pcm_dsd.c) | 56 | ||||
-rw-r--r-- | src/pcm/PcmDsd.hxx (renamed from src/pcm/pcm_dsd.h) | 28 | ||||
-rw-r--r-- | src/pcm/PcmDsdUsb.cxx (renamed from src/pcm/pcm_dsd_usb.c) | 6 | ||||
-rw-r--r-- | src/pcm/PcmDsdUsb.hxx (renamed from src/pcm/pcm_dsd_usb.h) | 7 | ||||
-rw-r--r-- | src/pcm/PcmExport.cxx | 2 |
7 files changed, 52 insertions, 62 deletions
diff --git a/src/pcm/PcmConvert.cxx b/src/pcm/PcmConvert.cxx index 9618b9642..383df9156 100644 --- a/src/pcm/PcmConvert.cxx +++ b/src/pcm/PcmConvert.cxx @@ -36,7 +36,6 @@ PcmConvert::PcmConvert() { memset(this, 0, sizeof(*this)); - pcm_dsd_init(&dsd); pcm_resample_init(&resample); pcm_buffer_init(&format_buffer); @@ -45,7 +44,6 @@ PcmConvert::PcmConvert() PcmConvert::~PcmConvert() { - pcm_dsd_deinit(&dsd); pcm_resample_deinit(&resample); pcm_buffer_deinit(&format_buffer); @@ -55,7 +53,7 @@ PcmConvert::~PcmConvert() void PcmConvert::Reset() { - pcm_dsd_reset(&dsd); + dsd.Reset(); pcm_resample_reset(&resample); } @@ -278,10 +276,9 @@ PcmConvert::Convert(const audio_format *src_format, struct audio_format float_format; if (src_format->format == SAMPLE_FORMAT_DSD) { size_t f_size; - const float *f = pcm_dsd_to_float(&dsd, - src_format->channels, - false, (const uint8_t *)src, - src_size, &f_size); + const float *f = dsd.ToFloat(src_format->channels, + false, (const uint8_t *)src, + src_size, &f_size); if (f == NULL) { g_set_error_literal(error_r, pcm_convert_quark(), 0, "DSD to PCM conversion failed"); diff --git a/src/pcm/PcmConvert.hxx b/src/pcm/PcmConvert.hxx index f08188a9c..62f67ed8e 100644 --- a/src/pcm/PcmConvert.hxx +++ b/src/pcm/PcmConvert.hxx @@ -21,9 +21,9 @@ #define PCM_CONVERT_HXX #include "PcmDither.hxx" +#include "PcmDsd.hxx" extern "C" { -#include "pcm_dsd.h" #include "pcm_resample.h" #include "pcm_buffer.h" } @@ -38,7 +38,7 @@ struct audio_format; * conversions. */ class PcmConvert { - struct pcm_dsd dsd; + PcmDsd dsd; struct pcm_resample_state resample; diff --git a/src/pcm/pcm_dsd.c b/src/pcm/PcmDsd.cxx index 76266b4cc..fb2dfd033 100644 --- a/src/pcm/pcm_dsd.c +++ b/src/pcm/PcmDsd.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2012 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,48 +18,48 @@ */ #include "config.h" -#include "pcm_dsd.h" +#include "PcmDsd.hxx" #include "dsd2pcm/dsd2pcm.h" #include <glib.h> + +#include <algorithm> + #include <string.h> -void -pcm_dsd_init(struct pcm_dsd *dsd) +PcmDsd::PcmDsd() { - pcm_buffer_init(&dsd->buffer); + pcm_buffer_init(&buffer); - memset(dsd->dsd2pcm, 0, sizeof(dsd->dsd2pcm)); + std::fill_n(dsd2pcm, G_N_ELEMENTS(dsd2pcm), nullptr); } -void -pcm_dsd_deinit(struct pcm_dsd *dsd) +PcmDsd::~PcmDsd() { - pcm_buffer_deinit(&dsd->buffer); + pcm_buffer_deinit(&buffer); - for (unsigned i = 0; i < G_N_ELEMENTS(dsd->dsd2pcm); ++i) - if (dsd->dsd2pcm[i] != NULL) - dsd2pcm_destroy(dsd->dsd2pcm[i]); + for (unsigned i = 0; i < G_N_ELEMENTS(dsd2pcm); ++i) + if (dsd2pcm[i] != nullptr) + dsd2pcm_destroy(dsd2pcm[i]); } void -pcm_dsd_reset(struct pcm_dsd *dsd) +PcmDsd::Reset() { - for (unsigned i = 0; i < G_N_ELEMENTS(dsd->dsd2pcm); ++i) - if (dsd->dsd2pcm[i] != NULL) - dsd2pcm_reset(dsd->dsd2pcm[i]); + for (unsigned i = 0; i < G_N_ELEMENTS(dsd2pcm); ++i) + if (dsd2pcm[i] != nullptr) + dsd2pcm_reset(dsd2pcm[i]); } const float * -pcm_dsd_to_float(struct pcm_dsd *dsd, unsigned channels, bool lsbfirst, - const uint8_t *src, size_t src_size, - size_t *dest_size_r) +PcmDsd::ToFloat(unsigned channels, bool lsbfirst, + const uint8_t *src, size_t src_size, + size_t *dest_size_r) { - assert(dsd != NULL); - assert(src != NULL); + assert(src != nullptr); assert(src_size > 0); assert(src_size % channels == 0); - assert(channels <= G_N_ELEMENTS(dsd->dsd2pcm)); + assert(channels <= G_N_ELEMENTS(dsd2pcm)); const unsigned num_samples = src_size; const unsigned num_frames = src_size / channels; @@ -67,16 +67,16 @@ pcm_dsd_to_float(struct pcm_dsd *dsd, unsigned channels, bool lsbfirst, float *dest; const size_t dest_size = num_samples * sizeof(*dest); *dest_size_r = dest_size; - dest = pcm_buffer_get(&dsd->buffer, dest_size); + dest = (float *)pcm_buffer_get(&buffer, dest_size); for (unsigned c = 0; c < channels; ++c) { - if (dsd->dsd2pcm[c] == NULL) { - dsd->dsd2pcm[c] = dsd2pcm_init(); - if (dsd->dsd2pcm[c] == NULL) - return NULL; + if (dsd2pcm[c] == nullptr) { + dsd2pcm[c] = dsd2pcm_init(); + if (dsd2pcm[c] == nullptr) + return nullptr; } - dsd2pcm_translate(dsd->dsd2pcm[c], num_frames, + dsd2pcm_translate(dsd2pcm[c], num_frames, src + c, channels, lsbfirst, dest + c, channels); } diff --git a/src/pcm/pcm_dsd.h b/src/pcm/PcmDsd.hxx index 85c2455aa..ef71411e9 100644 --- a/src/pcm/pcm_dsd.h +++ b/src/pcm/PcmDsd.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2012 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,36 +17,30 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#ifndef MPD_PCM_DSD_H -#define MPD_PCM_DSD_H +#ifndef MPD_PCM_DSD_HXX +#define MPD_PCM_DSD_HXX #include "check.h" #include "pcm_buffer.h" -#include <stdbool.h> #include <stdint.h> /** * Wrapper for the dsd2pcm library. */ -struct pcm_dsd { +struct PcmDsd { struct pcm_buffer buffer; struct dsd2pcm_ctx_s *dsd2pcm[32]; -}; - -void -pcm_dsd_init(struct pcm_dsd *dsd); -void -pcm_dsd_deinit(struct pcm_dsd *dsd); + PcmDsd(); + ~PcmDsd(); -void -pcm_dsd_reset(struct pcm_dsd *dsd); + void Reset(); -const float * -pcm_dsd_to_float(struct pcm_dsd *dsd, unsigned channels, bool lsbfirst, - const uint8_t *src, size_t src_size, - size_t *dest_size_r); + const float *ToFloat(unsigned channels, bool lsbfirst, + const uint8_t *src, size_t src_size, + size_t *dest_size_r); +}; #endif diff --git a/src/pcm/pcm_dsd_usb.c b/src/pcm/PcmDsdUsb.cxx index 4b5e39f39..30231e144 100644 --- a/src/pcm/pcm_dsd_usb.c +++ b/src/pcm/PcmDsdUsb.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2012 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_dsd_usb.h" +#include "PcmDsdUsb.hxx" #include "pcm_buffer.h" #include "audio_format.h" @@ -58,7 +58,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 = pcm_buffer_get(buffer, dest_size), + uint32_t *const dest0 = (uint32_t *)pcm_buffer_get(buffer, dest_size), *dest = dest0; for (unsigned i = num_frames / 2; i > 0; --i) { diff --git a/src/pcm/pcm_dsd_usb.h b/src/pcm/PcmDsdUsb.hxx index 389358459..d4b414324 100644 --- a/src/pcm/pcm_dsd_usb.h +++ b/src/pcm/PcmDsdUsb.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2012 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,12 +17,11 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#ifndef MPD_PCM_DSD_USB_H -#define MPD_PCM_DSD_USB_H +#ifndef MPD_PCM_DSD_USB_HXX +#define MPD_PCM_DSD_USB_HXX #include "check.h" -#include <stdbool.h> #include <stdint.h> #include <stddef.h> diff --git a/src/pcm/PcmExport.cxx b/src/pcm/PcmExport.cxx index 288b59ab4..a148e2873 100644 --- a/src/pcm/PcmExport.cxx +++ b/src/pcm/PcmExport.cxx @@ -19,9 +19,9 @@ #include "config.h" #include "PcmExport.hxx" +#include "PcmDsdUsb.hxx" extern "C" { -#include "pcm_dsd_usb.h" #include "pcm_pack.h" #include "util/byte_reverse.h" } |