MPD: MusicChunk.hxx Source File

MPD 0.20.18

MusicChunk.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_MUSIC_CHUNK_HXX
21 #define MPD_MUSIC_CHUNK_HXX
22
23 #include "Chrono.hxx"
24 #include "ReplayGainInfo.hxx"
25 #include "util/WritableBuffer.hxx"
26
27 #ifndef NDEBUG
28 #include "AudioFormat.hxx"
29 #endif
30
31 #include <stdint.h>
32 #include <stddef.h>
33
34 static constexpr size_t CHUNK_SIZE = 4096;
35
36 struct AudioFormat;
37 struct Tag;
38
43 struct MusicChunk {
45 MusicChunk *next;
46
51 MusicChunk *other = nullptr;
52
57 float mix_ratio;
58
60 uint16_t length = 0;
61
63 uint16_t bit_rate;
64
66 SignedSongTime time;
67
74 Tag *tag = nullptr;
75
80 ReplayGainInfo replay_gain_info;
81
88 static constexpr unsigned IGNORE_REPLAY_GAIN = ~0u;
89
95 unsigned replay_gain_serial;
96
98 uint8_t data[CHUNK_SIZE];
99
100 #ifndef NDEBUG
101 AudioFormat audio_format;
102 #endif
103
104 MusicChunk() = default;
105
106 MusicChunk(const MusicChunk &) = delete;
107
108 ~MusicChunk();
109
110 MusicChunk &operator=(const MusicChunk &) = delete;
111
112 bool IsEmpty() const {
113 return length == 0 && tag == nullptr;
114 }
115
116 #ifndef NDEBUG
117
121 gcc_pure
122 bool CheckFormat(AudioFormat audio_format) const noexcept;
123 #endif
124
136 WritableBuffer<void> Write(AudioFormat af,
137 SongTime data_time,
138 uint16_t bit_rate) noexcept;
139
149 bool Expand(AudioFormat af, size_t length) noexcept;
150 };
151
152 #endif
WritableBuffer.hxx
MusicChunk::IsEmpty
bool IsEmpty() const
Definition: MusicChunk.hxx:112
AudioFormat
This structure describes the format of a raw PCM stream.
Definition: AudioFormat.hxx:37
Chrono.hxx
Tag
The meta information about a song file.
Definition: Tag.hxx:34
AudioFormat.hxx
SongTime
A time stamp within a song.
Definition: Chrono.hxx:31
MusicChunk::CheckFormat
gcc_pure bool CheckFormat(AudioFormat audio_format) const noexcept
Checks if the audio format if the chunk is equal to the specified audio_format.
MusicChunk::Expand
bool Expand(AudioFormat af, size_t length) noexcept
Increases the length of the chunk after the caller has written to the buffer returned by Write()...
MusicChunk::tag
Tag * tag
An optional tag associated with this chunk (and the following chunks); appears at song boundaries...
Definition: MusicChunk.hxx:74
MusicChunk::mix_ratio
float mix_ratio
The current mix ratio for cross-fading: 1.0 means play 100% of this chunk, 0.0 means play 100% of the...
Definition: MusicChunk.hxx:57
MusicChunk
A chunk of music data.
Definition: MusicChunk.hxx:43
MusicChunk::length
uint16_t length
number of bytes stored in this chunk
Definition: MusicChunk.hxx:60
MusicChunk::other
MusicChunk * other
An optional chunk which should be mixed into this chunk.
Definition: MusicChunk.hxx:51
WritableBuffer< void >
Definition: WritableBuffer.hxx:45
MusicChunk::replay_gain_serial
unsigned replay_gain_serial
A serial number for checking if replay gain info has changed since the last chunk.
Definition: MusicChunk.hxx:95
CHUNK_SIZE
static constexpr size_t CHUNK_SIZE
Definition: MusicChunk.hxx:34
MusicChunk::IGNORE_REPLAY_GAIN
static constexpr unsigned IGNORE_REPLAY_GAIN
A magic value for replay_gain_serial which omits updating the #ReplayGainFilter.
Definition: MusicChunk.hxx:88
ReplayGainInfo
Definition: ReplayGainInfo.hxx:46
MusicChunk::data
uint8_t data[CHUNK_SIZE]
the data (probably PCM)
Definition: MusicChunk.hxx:98
MusicChunk::time
SignedSongTime time
the time stamp within the song
Definition: MusicChunk.hxx:66
ReplayGainInfo.hxx
MusicChunk::replay_gain_info
ReplayGainInfo replay_gain_info
Replay gain information associated with this chunk.
Definition: MusicChunk.hxx:80
SignedSongTime
A variant of SongTime that is based on a signed integer.
Definition: Chrono.hxx:115
MusicChunk::next
MusicChunk * next
the next chunk in a linked list
Definition: MusicChunk.hxx:45
MusicChunk::operator=
MusicChunk & operator=(const MusicChunk &)=delete
MusicChunk::bit_rate
uint16_t bit_rate
current bit rate of the source file
Definition: MusicChunk.hxx:63
gcc_pure
#define gcc_pure
Definition: Compiler.h:116
MusicChunk::MusicChunk
MusicChunk()=default
MusicChunk::Write
WritableBuffer< void > Write(AudioFormat af, SongTime data_time, uint16_t bit_rate) noexcept
Prepares appending to the music chunk.
MusicChunk::~MusicChunk
~MusicChunk()
MusicChunk::audio_format
AudioFormat audio_format
Definition: MusicChunk.hxx:101