PcmDsd.cxx 1.77 KB
Newer Older
1
/*
Max Kellermann's avatar
Max Kellermann committed
2
 * Copyright 2003-2017 The Music Player Daemon Project
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
 * http://www.musicpd.org
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#include "config.h"
Max Kellermann's avatar
Max Kellermann committed
21
#include "PcmDsd.hxx"
22
#include "dsd2pcm/dsd2pcm.h"
23
#include "util/ConstBuffer.hxx"
Max Kellermann's avatar
Max Kellermann committed
24

Max Kellermann's avatar
Max Kellermann committed
25
#include <assert.h>
26

Max Kellermann's avatar
Max Kellermann committed
27
PcmDsd::PcmDsd()
28
{
29
	dsd2pcm.fill(nullptr);
30 31
}

Max Kellermann's avatar
Max Kellermann committed
32
PcmDsd::~PcmDsd()
33
{
34 35 36
	for (auto i : dsd2pcm)
		if (i != nullptr)
			dsd2pcm_destroy(i);
37 38 39
}

void
Max Kellermann's avatar
Max Kellermann committed
40
PcmDsd::Reset()
41
{
42 43 44
	for (auto i : dsd2pcm)
		if (i != nullptr)
			dsd2pcm_reset(i);
45 46
}

47
ConstBuffer<float>
48
PcmDsd::ToFloat(unsigned channels, ConstBuffer<uint8_t> src)
49
{
50
	assert(!src.IsNull());
51
	assert(!src.empty());
52
	assert(src.size % channels == 0);
53
	assert(channels <= dsd2pcm.max_size());
54

55 56
	const unsigned num_samples = src.size;
	const unsigned num_frames = src.size / channels;
57

58
	float *dest = buffer.GetT<float>(num_samples);
59 60

	for (unsigned c = 0; c < channels; ++c) {
Max Kellermann's avatar
Max Kellermann committed
61 62 63 64
		if (dsd2pcm[c] == nullptr) {
			dsd2pcm[c] = dsd2pcm_init();
			if (dsd2pcm[c] == nullptr)
				return nullptr;
65 66
		}

Max Kellermann's avatar
Max Kellermann committed
67
		dsd2pcm_translate(dsd2pcm[c], num_frames,
68
				  src.data + c, channels,
69
				  false, dest + c, channels);
70 71
	}

72
	return { dest, num_samples };
73
}