MPD 0.20.6

- Main Page
- Namespaces
- Data Structures
- Files

- File List
- Globals

Traits.hxx
Go to the documentation of this file.
1 /*
2 * Copyright 2003-2017 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 #ifndef MPD_PCM_TRAITS_HXX
21 #define MPD_PCM_TRAITS_HXX
22
23 #include "check.h"
24 #include "SampleFormat.hxx"
25
26 #include <stdint.h>
27 #include <stddef.h>
28
34 template<SampleFormat F>
35 struct SampleTraits {};
36
37 template<>
38 struct SampleTraits<SampleFormat::S8> {
42 typedef int8_t value_type;
43
47 typedef value_type *pointer_type;
48
52 typedef const value_type *const_pointer_type;
53
59 typedef int sum_type;
60
66 typedef int_least32_t long_type;
67
71 static constexpr size_t SAMPLE_SIZE = sizeof(value_type);
72
77 static constexpr unsigned BITS = sizeof(value_type) * 8;
78
82 static constexpr value_type MIN = -(sum_type(1) << (BITS - 1));
83
87 static constexpr value_type MAX = (sum_type(1) << (BITS - 1)) - 1;
88
92 static constexpr value_type SILENCE = 0;
93 };
94
95 template<>
96 struct SampleTraits<SampleFormat::S16> {
97 typedef int16_t value_type;
98 typedef value_type *pointer_type;
99 typedef const value_type *const_pointer_type;
100
101 typedef int_least32_t sum_type;
102 typedef int_least32_t long_type;
103
104 static constexpr size_t SAMPLE_SIZE = sizeof(value_type);
105 static constexpr unsigned BITS = sizeof(value_type) * 8;
106
107 static constexpr value_type MIN = -(sum_type(1) << (BITS - 1));
108 static constexpr value_type MAX = (sum_type(1) << (BITS - 1)) - 1;
109 static constexpr value_type SILENCE = 0;
110 };
111
112 template<>
113 struct SampleTraits<SampleFormat::S32> {
114 typedef int32_t value_type;
115 typedef value_type *pointer_type;
116 typedef const value_type *const_pointer_type;
117
118 typedef int_least64_t sum_type;
119 typedef int_least64_t long_type;
120
121 static constexpr size_t SAMPLE_SIZE = sizeof(value_type);
122 static constexpr unsigned BITS = sizeof(value_type) * 8;
123
124 static constexpr value_type MIN = -(sum_type(1) << (BITS - 1));
125 static constexpr value_type MAX = (sum_type(1) << (BITS - 1)) - 1;
126 static constexpr value_type SILENCE = 0;
127 };
128
129 template<>
130 struct SampleTraits<SampleFormat::S24_P32> {
131 typedef int32_t value_type;
132 typedef value_type *pointer_type;
133 typedef const value_type *const_pointer_type;
134
135 typedef int_least32_t sum_type;
136 typedef int_least64_t long_type;
137
138 static constexpr size_t SAMPLE_SIZE = sizeof(value_type);
139 static constexpr unsigned BITS = 24;
140
141 static constexpr value_type MIN = -(sum_type(1) << (BITS - 1));
142 static constexpr value_type MAX = (sum_type(1) << (BITS - 1)) - 1;
143 static constexpr value_type SILENCE = 0;
144 };
145
146 template<>
147 struct SampleTraits<SampleFormat::FLOAT> {
148 typedef float value_type;
149 typedef value_type *pointer_type;
150 typedef const value_type *const_pointer_type;
151
152 typedef float sum_type;
153 typedef float long_type;
154
155 static constexpr size_t SAMPLE_SIZE = sizeof(value_type);
156
157 static constexpr value_type MIN = -1;
158 static constexpr value_type MAX = 1;
159 static constexpr value_type SILENCE = 0;
160 };
161
162 template<>
163 struct SampleTraits<SampleFormat::DSD> {
164 typedef uint8_t value_type;
165 typedef value_type *pointer_type;
166 typedef const value_type *const_pointer_type;
167
168 static constexpr size_t SAMPLE_SIZE = sizeof(value_type);
169
170 static constexpr value_type SILENCE = 0x69;
171 };
172
173 #endif
SampleTraits< SampleFormat::S16 >::pointer_type
value_type * pointer_type
Definition: Traits.hxx:98
check.h
ConfigOption::MAX
SampleTraits< SampleFormat::FLOAT >::value_type
float value_type
Definition: Traits.hxx:148
SampleTraits< SampleFormat::DSD >::value_type
uint8_t value_type
Definition: Traits.hxx:164
SampleFormat::S16
SampleTraits
This template describes the specified SampleFormat.
Definition: PcmUtils.hxx:30
SampleTraits< SampleFormat::FLOAT >::const_pointer_type
const value_type * const_pointer_type
Definition: Traits.hxx:150
SampleTraits< SampleFormat::S32 >::sum_type
int_least64_t sum_type
Definition: Traits.hxx:118
SampleTraits< SampleFormat::S8 >::const_pointer_type
const value_type * const_pointer_type
A read-only pointer.
Definition: Traits.hxx:52
SampleTraits< SampleFormat::S8 >::long_type
int_least32_t long_type
A "long" type that is large and accurate enough for arithmetic without risking an (integer) overflow ...
Definition: Traits.hxx:66
SampleTraits< SampleFormat::S24_P32 >::pointer_type
value_type * pointer_type
Definition: Traits.hxx:132
SampleTraits< SampleFormat::S24_P32 >::long_type
int_least64_t long_type
Definition: Traits.hxx:136
SampleTraits< SampleFormat::S32 >::const_pointer_type
const value_type * const_pointer_type
Definition: Traits.hxx:116
SampleTraits< SampleFormat::S16 >::value_type
int16_t value_type
Definition: Traits.hxx:97
SampleTraits< SampleFormat::S24_P32 >::value_type
int32_t value_type
Definition: Traits.hxx:131
SampleTraits< SampleFormat::DSD >::const_pointer_type
const value_type * const_pointer_type
Definition: Traits.hxx:166
SampleTraits< SampleFormat::S32 >::pointer_type
value_type * pointer_type
Definition: Traits.hxx:115
SampleTraits< SampleFormat::S8 >::value_type
int8_t value_type
The type used for one sample value.
Definition: Traits.hxx:42
SampleTraits< SampleFormat::S16 >::long_type
int_least32_t long_type
Definition: Traits.hxx:102
SampleTraits< SampleFormat::DSD >::pointer_type
value_type * pointer_type
Definition: Traits.hxx:165
SampleTraits< SampleFormat::FLOAT >::long_type
float long_type
Definition: Traits.hxx:153
SampleTraits< SampleFormat::S16 >::const_pointer_type
const value_type * const_pointer_type
Definition: Traits.hxx:99
SampleTraits< SampleFormat::S32 >::value_type
int32_t value_type
Definition: Traits.hxx:114
SampleTraits< SampleFormat::S8 >::sum_type
int sum_type
A "long" type that is large and accurate enough for adding two values without risking an (integer) ov...
Definition: Traits.hxx:59
SampleFormat::DSD
Direct Stream Digital.
SampleTraits< SampleFormat::FLOAT >::sum_type
float sum_type
Definition: Traits.hxx:152
SampleFormat
SampleFormat
Definition: SampleFormat.hxx:33
SampleFormat::S24_P32
Signed 24 bit integer samples, packed in 32 bit integers (the most significant byte is filled with th...
SampleFormat.hxx
SampleFormat::FLOAT
32 bit floating point samples in the host's format.
SampleTraits< SampleFormat::S24_P32 >::const_pointer_type
const value_type * const_pointer_type
Definition: Traits.hxx:133
SampleTraits< SampleFormat::S32 >::long_type
int_least64_t long_type
Definition: Traits.hxx:119
SampleTraits< SampleFormat::S16 >::sum_type
int_least32_t sum_type
Definition: Traits.hxx:101
SampleTraits< SampleFormat::S8 >::pointer_type
value_type * pointer_type
A writable pointer.
Definition: Traits.hxx:47
SampleFormat::S8
SampleTraits< SampleFormat::FLOAT >::pointer_type
value_type * pointer_type
Definition: Traits.hxx:149
SampleTraits< SampleFormat::S24_P32 >::sum_type
int_least32_t sum_type
Definition: Traits.hxx:135
SampleFormat::S32