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

« back to all changes in this revision

Viewing changes to src/pcm/PcmDsdUsb.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 "PcmDsdUsb.hxx"
 
22
#include "PcmBuffer.hxx"
 
23
#include "AudioFormat.hxx"
 
24
 
 
25
constexpr
 
26
static inline uint32_t
 
27
pcm_two_dsd_to_usb_marker1(uint8_t a, uint8_t b)
 
28
{
 
29
        return 0xff050000 | (a << 8) | b;
 
30
}
 
31
 
 
32
constexpr
 
33
static inline uint32_t
 
34
pcm_two_dsd_to_usb_marker2(uint8_t a, uint8_t b)
 
35
{
 
36
        return 0xfffa0000 | (a << 8) | b;
 
37
}
 
38
 
 
39
 
 
40
const uint32_t *
 
41
pcm_dsd_to_usb(PcmBuffer &buffer, unsigned channels,
 
42
               const uint8_t *src, size_t src_size,
 
43
               size_t *dest_size_r)
 
44
{
 
45
        assert(audio_valid_channel_count(channels));
 
46
        assert(src != NULL);
 
47
        assert(src_size > 0);
 
48
        assert(src_size % channels == 0);
 
49
 
 
50
        const unsigned num_src_samples = src_size;
 
51
        const unsigned num_src_frames = num_src_samples / channels;
 
52
 
 
53
        /* this rounds down and discards the last odd frame; not
 
54
           elegant, but good enough for now */
 
55
        const unsigned num_frames = num_src_frames / 2;
 
56
        const unsigned num_samples = num_frames * channels;
 
57
 
 
58
        const size_t dest_size = num_samples * 4;
 
59
        *dest_size_r = dest_size;
 
60
        uint32_t *const dest0 = (uint32_t *)buffer.Get(dest_size),
 
61
                *dest = dest0;
 
62
 
 
63
        for (unsigned i = num_frames / 2; i > 0; --i) {
 
64
                for (unsigned c = channels; c > 0; --c) {
 
65
                        /* each 24 bit sample has 16 DSD sample bits
 
66
                           plus the magic 0x05 marker */
 
67
 
 
68
                        *dest++ = pcm_two_dsd_to_usb_marker1(src[0], src[channels]);
 
69
 
 
70
                        /* seek the source pointer to the next
 
71
                           channel */
 
72
                        ++src;
 
73
                }
 
74
 
 
75
                /* skip the second byte of each channel, because we
 
76
                   have already copied it */
 
77
                src += channels;
 
78
 
 
79
                for (unsigned c = channels; c > 0; --c) {
 
80
                        /* each 24 bit sample has 16 DSD sample bits
 
81
                           plus the magic 0xfa marker */
 
82
 
 
83
                        *dest++ = pcm_two_dsd_to_usb_marker2(src[0], src[channels]);
 
84
 
 
85
                        /* seek the source pointer to the next
 
86
                           channel */
 
87
                        ++src;
 
88
                }
 
89
 
 
90
                /* skip the second byte of each channel, because we
 
91
                   have already copied it */
 
92
                src += channels;
 
93
        }
 
94
 
 
95
        return dest0;
 
96
}