2
* Copyright (C) 2003-2013 The Music Player Daemon Project
3
* http://www.musicpd.org
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License along
16
* with this program; if not, write to the Free Software Foundation, Inc.,
17
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
#include "FlacPcm.hxx"
25
static void flac_convert_stereo16(int16_t *dest,
26
const FLAC__int32 * const buf[],
27
unsigned int position, unsigned int end)
29
for (; position < end; ++position) {
30
*dest++ = buf[0][position];
31
*dest++ = buf[1][position];
36
flac_convert_16(int16_t *dest,
37
unsigned int num_channels,
38
const FLAC__int32 * const buf[],
39
unsigned int position, unsigned int end)
43
for (; position < end; ++position)
44
for (c_chan = 0; c_chan < num_channels; c_chan++)
45
*dest++ = buf[c_chan][position];
49
* Note: this function also handles 24 bit files!
52
flac_convert_32(int32_t *dest,
53
unsigned int num_channels,
54
const FLAC__int32 * const buf[],
55
unsigned int position, unsigned int end)
59
for (; position < end; ++position)
60
for (c_chan = 0; c_chan < num_channels; c_chan++)
61
*dest++ = buf[c_chan][position];
65
flac_convert_8(int8_t *dest,
66
unsigned int num_channels,
67
const FLAC__int32 * const buf[],
68
unsigned int position, unsigned int end)
72
for (; position < end; ++position)
73
for (c_chan = 0; c_chan < num_channels; c_chan++)
74
*dest++ = buf[c_chan][position];
78
flac_convert(void *dest,
79
unsigned int num_channels, SampleFormat sample_format,
80
const FLAC__int32 *const buf[],
81
unsigned int position, unsigned int end)
83
switch (sample_format) {
84
case SampleFormat::S16:
85
if (num_channels == 2)
86
flac_convert_stereo16((int16_t*)dest, buf,
89
flac_convert_16((int16_t*)dest, num_channels, buf,
93
case SampleFormat::S24_P32:
94
case SampleFormat::S32:
95
flac_convert_32((int32_t*)dest, num_channels, buf,
99
case SampleFormat::S8:
100
flac_convert_8((int8_t*)dest, num_channels, buf,
104
case SampleFormat::FLOAT:
105
case SampleFormat::DSD:
106
case SampleFormat::UNDEFINED: