MPD 0.20.6

- Main Page
- Namespaces
- Data Structures
- Files

- File List
- Globals

SampleFormat.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_SAMPLE_FORMAT_HXX
21 #define MPD_PCM_SAMPLE_FORMAT_HXX
22
23 #include "Compiler.h"
24
25 #include <stdint.h>
26
27 #if defined(WIN32) && GCC_CHECK_VERSION(4,6)
28 /* on WIN32, "FLOAT" is already defined, and this triggers -Wshadow */
29 #pragma GCC diagnostic push
30 #pragma GCC diagnostic ignored "-Wshadow"
31 #endif
32
33 enum class SampleFormat : uint8_t {
34 UNDEFINED = 0,
35
36 S8,
37 S16,
38
43 S24_P32,
44
45 S32,
46
51 FLOAT,
52
57 DSD,
58 };
59
60 #if defined(WIN32) && GCC_CHECK_VERSION(4,6)
61 #pragma GCC diagnostic pop
62 #endif
63
67 #if !GCC_OLDER_THAN(5,0)
68 constexpr
69 #endif
70 static inline bool
71 audio_valid_sample_format(SampleFormat format)
72 {
73 switch (format) {
74 case SampleFormat::S8:
75 case SampleFormat::S16:
76 case SampleFormat::S24_P32:
77 case SampleFormat::S32:
78 case SampleFormat::FLOAT:
79 case SampleFormat::DSD:
80 return true;
81
82 case SampleFormat::UNDEFINED:
83 break;
84 }
85
86 return false;
87 }
88
89 #if !GCC_OLDER_THAN(5,0)
90 constexpr
91 #endif
92 static inline unsigned
93 sample_format_size(SampleFormat format)
94 {
95 switch (format) {
96 case SampleFormat::S8:
97 return 1;
98
99 case SampleFormat::S16:
100 return 2;
101
102 case SampleFormat::S24_P32:
103 case SampleFormat::S32:
104 case SampleFormat::FLOAT:
105 return 4;
106
107 case SampleFormat::DSD:
108 /* each frame has 8 samples per channel */
109 return 1;
110
111 case SampleFormat::UNDEFINED:
112 return 0;
113 }
114
115 gcc_unreachable();
116 }
117
125 gcc_pure gcc_malloc
126 const char *
127 sample_format_to_string(SampleFormat format);
128
129 #endif
SampleFormat::S16
audio_valid_sample_format
static constexpr bool audio_valid_sample_format(SampleFormat format)
Checks whether the sample format is valid.
Definition: SampleFormat.hxx:71
gcc_malloc
#define gcc_malloc
Definition: Compiler.h:112
sample_format_to_string
gcc_pure gcc_malloc const char * sample_format_to_string(SampleFormat format)
Renders a SampleFormat enum into a string, e.g.
gcc_unreachable
#define gcc_unreachable()
Definition: Compiler.h:177
Compiler.h
SampleFormat::DSD
Direct Stream Digital.
sample_format_size
static constexpr unsigned sample_format_size(SampleFormat format)
Definition: SampleFormat.hxx:93
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::UNDEFINED
gcc_pure
#define gcc_pure
Definition: Compiler.h:116
SampleFormat::FLOAT
32 bit floating point samples in the host's format.
SampleFormat::S8
SampleFormat::S32