~ubuntu-branches/ubuntu/utopic/mpd/utopic-proposed

« back to all changes in this revision

Viewing changes to src/decoder/FlacPcm.cxx

  • Committer: Package Import Robot
  • Author(s): Steve Kowalik
  • Date: 2013-11-12 18:17:40 UTC
  • mfrom: (2.2.36 sid)
  • Revision ID: package-import@ubuntu.com-20131112181740-72aa4zihehoobedp
Tags: 0.18.3-1ubuntu1
* Merge from Debian unstable.  Remaining changes:
  - Add libmp3lame-dev to Build-Depends, and enable LAME.
  - Read the user for the daemon from the config file in the init script.
  - Move avahi-daemon from Suggests to Recommends.
  - Added apport hook to include user configuration file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2003-2013 The Music Player Daemon Project
 
3
 * http://www.musicpd.org
 
4
 *
 
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.
 
9
 *
 
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.
 
14
 *
 
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.
 
18
 */
 
19
 
 
20
#include "config.h"
 
21
#include "FlacPcm.hxx"
 
22
 
 
23
#include <assert.h>
 
24
 
 
25
static void flac_convert_stereo16(int16_t *dest,
 
26
                                  const FLAC__int32 * const buf[],
 
27
                                  unsigned int position, unsigned int end)
 
28
{
 
29
        for (; position < end; ++position) {
 
30
                *dest++ = buf[0][position];
 
31
                *dest++ = buf[1][position];
 
32
        }
 
33
}
 
34
 
 
35
static void
 
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)
 
40
{
 
41
        unsigned int c_chan;
 
42
 
 
43
        for (; position < end; ++position)
 
44
                for (c_chan = 0; c_chan < num_channels; c_chan++)
 
45
                        *dest++ = buf[c_chan][position];
 
46
}
 
47
 
 
48
/**
 
49
 * Note: this function also handles 24 bit files!
 
50
 */
 
51
static void
 
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)
 
56
{
 
57
        unsigned int c_chan;
 
58
 
 
59
        for (; position < end; ++position)
 
60
                for (c_chan = 0; c_chan < num_channels; c_chan++)
 
61
                        *dest++ = buf[c_chan][position];
 
62
}
 
63
 
 
64
static void
 
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)
 
69
{
 
70
        unsigned int c_chan;
 
71
 
 
72
        for (; position < end; ++position)
 
73
                for (c_chan = 0; c_chan < num_channels; c_chan++)
 
74
                        *dest++ = buf[c_chan][position];
 
75
}
 
76
 
 
77
void
 
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)
 
82
{
 
83
        switch (sample_format) {
 
84
        case SampleFormat::S16:
 
85
                if (num_channels == 2)
 
86
                        flac_convert_stereo16((int16_t*)dest, buf,
 
87
                                              position, end);
 
88
                else
 
89
                        flac_convert_16((int16_t*)dest, num_channels, buf,
 
90
                                        position, end);
 
91
                break;
 
92
 
 
93
        case SampleFormat::S24_P32:
 
94
        case SampleFormat::S32:
 
95
                flac_convert_32((int32_t*)dest, num_channels, buf,
 
96
                                position, end);
 
97
                break;
 
98
 
 
99
        case SampleFormat::S8:
 
100
                flac_convert_8((int8_t*)dest, num_channels, buf,
 
101
                               position, end);
 
102
                break;
 
103
 
 
104
        case SampleFormat::FLOAT:
 
105
        case SampleFormat::DSD:
 
106
        case SampleFormat::UNDEFINED:
 
107
                assert(false);
 
108
                gcc_unreachable();
 
109
        }
 
110
}