pcm_dsd: convert to C++

This commit is contained in:
Max Kellermann 2013-07-29 07:56:40 +02:00
parent 43166130b5
commit cac3c159bc
8 changed files with 60 additions and 70 deletions

View File

@ -307,8 +307,8 @@ libpcm_a_SOURCES = \
src/pcm/PcmExport.cxx src/pcm/PcmExport.hxx \
src/pcm/PcmConvert.cxx src/pcm/PcmConvert.hxx \
src/pcm/dsd2pcm/dsd2pcm.c src/pcm/dsd2pcm/dsd2pcm.h \
src/pcm/pcm_dsd.c src/pcm/pcm_dsd.h \
src/pcm/pcm_dsd_usb.c src/pcm/pcm_dsd_usb.h \
src/pcm/PcmDsd.cxx src/pcm/PcmDsd.hxx \
src/pcm/PcmDsdUsb.cxx src/pcm/PcmDsdUsb.hxx \
src/pcm/PcmVolume.cxx src/pcm/PcmVolume.hxx \
src/pcm/PcmMix.cxx src/pcm/PcmMix.hxx \
src/pcm/PcmChannels.cxx src/pcm/PcmChannels.hxx \

View File

@ -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");

View File

@ -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;

View File

@ -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);
}
PcmDsd::~PcmDsd()
{
pcm_buffer_deinit(&buffer);
for (unsigned i = 0; i < G_N_ELEMENTS(dsd2pcm); ++i)
if (dsd2pcm[i] != nullptr)
dsd2pcm_destroy(dsd2pcm[i]);
}
void
pcm_dsd_deinit(struct pcm_dsd *dsd)
PcmDsd::Reset()
{
pcm_buffer_deinit(&dsd->buffer);
for (unsigned i = 0; i < G_N_ELEMENTS(dsd->dsd2pcm); ++i)
if (dsd->dsd2pcm[i] != NULL)
dsd2pcm_destroy(dsd->dsd2pcm[i]);
}
void
pcm_dsd_reset(struct pcm_dsd *dsd)
{
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);
}

View File

@ -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];
PcmDsd();
~PcmDsd();
void Reset();
const float *ToFloat(unsigned channels, bool lsbfirst,
const uint8_t *src, size_t src_size,
size_t *dest_size_r);
};
void
pcm_dsd_init(struct pcm_dsd *dsd);
void
pcm_dsd_deinit(struct pcm_dsd *dsd);
void
pcm_dsd_reset(struct pcm_dsd *dsd);
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);
#endif

View File

@ -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) {

View File

@ -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>

View File

@ -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"
}