MPD  0.20.6
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<>
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<>
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<>
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<>
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<>
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<>
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
This template describes the specified SampleFormat.
Definition: PcmUtils.hxx:30
const value_type * const_pointer_type
Definition: Traits.hxx:150
const value_type * const_pointer_type
A read-only pointer.
Definition: Traits.hxx:52
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
const value_type * const_pointer_type
Definition: Traits.hxx:116
const value_type * const_pointer_type
Definition: Traits.hxx:166
int8_t value_type
The type used for one sample value.
Definition: Traits.hxx:42
const value_type * const_pointer_type
Definition: Traits.hxx:99
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
Direct Stream Digital.
SampleFormat
Signed 24 bit integer samples, packed in 32 bit integers (the most significant byte is filled with th...
32 bit floating point samples in the host's format.
const value_type * const_pointer_type
Definition: Traits.hxx:133
value_type * pointer_type
A writable pointer.
Definition: Traits.hxx:47