MPD 0.20.6

- Main Page
- Namespaces
- Data Structures
- Files

- File List
- Globals

Volume.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_VOLUME_HXX
21 #define MPD_PCM_VOLUME_HXX
22
23 #include "SampleFormat.hxx"
24 #include "PcmBuffer.hxx"
25 #include "PcmDither.hxx"
26
27 #ifndef NDEBUG
28 #include <assert.h>
29 #endif
30
31 template<typename T> struct ConstBuffer;
32
36 static constexpr unsigned PCM_VOLUME_BITS = 10;
37
41 static constexpr unsigned PCM_VOLUME_1 = 1024;
42 static constexpr int PCM_VOLUME_1S = PCM_VOLUME_1;
43
48 static inline int
49 pcm_float_to_volume(float volume)
50 {
51 return volume * PCM_VOLUME_1 + 0.5;
52 }
53
54 static inline float
55 pcm_volume_to_float(int volume)
56 {
57 return (float)volume / (float)PCM_VOLUME_1;
58 }
59
63 class PcmVolume {
64 SampleFormat format;
65
66 unsigned volume;
67
68 PcmBuffer buffer;
69 PcmDither dither;
70
71 public:
72 PcmVolume()
73 :volume(PCM_VOLUME_1) {
74 #ifndef NDEBUG
75 format = SampleFormat::UNDEFINED;
76 #endif
77 }
78
79 unsigned GetVolume() const {
80 return volume;
81 }
82
88 void SetVolume(unsigned _volume) {
89 volume = _volume;
90 }
91
99 void Open(SampleFormat format);
100
104 void Close() {
105 #ifndef NDEBUG
106 assert(format != SampleFormat::UNDEFINED);
107 format = SampleFormat::UNDEFINED;
108 #endif
109 }
110
114 gcc_pure
115 ConstBuffer<void> Apply(ConstBuffer<void> src);
116 };
117
118 #endif
ConstBuffer< void >
Definition: ConstBuffer.hxx:45
pcm_volume_to_float
static float pcm_volume_to_float(int volume)
Definition: Volume.hxx:55
PCM_VOLUME_1
static constexpr unsigned PCM_VOLUME_1
This value means "100% volume".
Definition: Volume.hxx:41
PcmBuffer.hxx
PcmVolume
A class that converts samples from one format to another.
Definition: Volume.hxx:63
PcmVolume::Open
void Open(SampleFormat format)
Opens the object, prepare for Apply().
PcmVolume::SetVolume
void SetVolume(unsigned _volume)
Definition: Volume.hxx:88
PcmVolume::PcmVolume
PcmVolume()
Definition: Volume.hxx:72
PcmVolume::GetVolume
unsigned GetVolume() const
Definition: Volume.hxx:79
PCM_VOLUME_BITS
static constexpr unsigned PCM_VOLUME_BITS
Number of fractional bits for a fixed-point volume value.
Definition: Volume.hxx:36
PCM_VOLUME_1S
static constexpr int PCM_VOLUME_1S
Definition: Volume.hxx:42
PcmBuffer
Manager for a temporary buffer which grows as needed.
Definition: PcmBuffer.hxx:33
SampleFormat
SampleFormat
Definition: SampleFormat.hxx:33
SampleFormat.hxx
ConstBuffer
A reference to a memory area that is read-only.
Definition: FlacPcm.hxx:29
pcm_float_to_volume
static int pcm_float_to_volume(float volume)
Converts a float value (0.0 = silence, 1.0 = 100% volume) to an integer volume value (1000 = 100%)...
Definition: Volume.hxx:49
SampleFormat::UNDEFINED
PcmVolume::Close
void Close()
Closes the object.
Definition: Volume.hxx:104
gcc_pure
#define gcc_pure
Definition: Compiler.h:116
PcmDither
Definition: PcmDither.hxx:27
PcmDither.hxx
PcmVolume::Apply
gcc_pure ConstBuffer< void > Apply(ConstBuffer< void > src)
Apply the volume level.