MPD  0.20.6
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
72 {
73  switch (format) {
74  case SampleFormat::S8:
75  case SampleFormat::S16:
77  case SampleFormat::S32:
79  case SampleFormat::DSD:
80  return true;
81 
83  break;
84  }
85 
86  return false;
87 }
88 
89 #if !GCC_OLDER_THAN(5,0)
90 constexpr
91 #endif
92 static inline unsigned
94 {
95  switch (format) {
96  case SampleFormat::S8:
97  return 1;
98 
99  case SampleFormat::S16:
100  return 2;
101 
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 
112  return 0;
113  }
114 
115  gcc_unreachable();
116 }
117 
126 const char *
128 
129 #endif
static constexpr bool audio_valid_sample_format(SampleFormat format)
Checks whether the sample format is valid.
#define gcc_malloc
Definition: Compiler.h:112
gcc_pure gcc_malloc const char * sample_format_to_string(SampleFormat format)
Renders a SampleFormat enum into a string, e.g.
#define gcc_unreachable()
Definition: Compiler.h:177
Direct Stream Digital.
static constexpr unsigned sample_format_size(SampleFormat format)
SampleFormat
Signed 24 bit integer samples, packed in 32 bit integers (the most significant byte is filled with th...
#define gcc_pure
Definition: Compiler.h:116
32 bit floating point samples in the host's format.