3 #include "../exceptions.h"
5 #include <c++utilities/conversion/stringbuilder.h>
6 #include <c++utilities/conversion/stringconversion.h>
7 #include <c++utilities/io/binaryreader.h>
19 switch (channelMode) {
20 case MpegChannelMode::Stereo:
21 return "2 channels: stereo";
22 case MpegChannelMode::JointStereo:
23 return "2 channels: joint stereo";
24 case MpegChannelMode::DualChannel:
25 return "2 channels: dual channel";
26 case MpegChannelMode::SingleChannel:
27 return "1 channel: single channel";
29 return std::string_view();
38 const std::uint16_t MpegAudioFrame::s_bitrateTable[0x2][0x3][0xF] = { { { 0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448 },
39 { 0, 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384 },
40 { 0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320 } },
41 { { 0, 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256 }, { 0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160 },
42 { 0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160 } } };
49 void MpegAudioFrame::parseHeader(BinaryReader &reader,
Diagnostics &diag)
52 m_header = reader.readUInt32BE();
54 diag.emplace_back(DiagLevel::Critical,
55 "Frame 0x" % numberToString(m_header, 16u) %
" at 0x" % numberToString<std::int64_t>(reader.stream()->tellg() - 4l, 16) +
" is invalid.",
56 "parsing MPEG audio frame header");
61 if (size() < s_xingHeaderOffset - 4 + 8) {
64 reader.stream()->seekg(s_xingHeaderOffset - 4, ios_base::cur);
65 m_xingHeader = reader.readUInt64BE();
66 if (isXingHeaderAvailable()) {
67 m_xingHeaderFlags =
static_cast<XingHeaderFlags>(m_xingHeader & 0xffffffffuL);
68 if (isXingFramefieldPresent()) {
69 m_xingFramefield = reader.readUInt32BE();
71 if (isXingBytesfieldPresent()) {
72 m_xingBytesfield = reader.readUInt32BE();
74 if (isXingTocFieldPresent()) {
75 reader.stream()->seekg(64, ios_base::cur);
77 if (isXingQualityIndicatorFieldPresent()) {
78 m_xingQualityIndicator = reader.readUInt32BE();
86 double MpegAudioFrame::mpegVersion()
const
88 switch (m_header & 0x180000u) {
103 int MpegAudioFrame::layer()
const
105 switch (m_header & 0x60000u) {
120 std::uint32_t MpegAudioFrame::samplingFrequency()
const
122 switch (m_header & 0xc00u) {
126 switch (m_header & 0x180000u) {
136 switch (m_header & 0x180000u) {
146 switch (m_header & 0x180000u) {
165 switch (m_header & 0xc0u) {
167 return MpegChannelMode::SingleChannel;
169 return MpegChannelMode::DualChannel;
171 return MpegChannelMode::JointStereo;
173 return MpegChannelMode::Stereo;
177 return MpegChannelMode::Unspecifed;
183 std::uint32_t MpegAudioFrame::sampleCount()
const
185 switch (m_header & 0x60000u) {
191 switch (m_header & 0x180000u) {
206 std::uint32_t MpegAudioFrame::size()
const
208 switch (m_header & 0x60000u) {
210 return static_cast<std::uint32_t
>(
211 ((
static_cast<double>(
bitrate()) * 1024.0 / 8.0) /
static_cast<double>(samplingFrequency())) *
static_cast<double>(sampleCount())
212 +
static_cast<double>(paddingSize()))
216 return static_cast<std::uint32_t
>(
217 ((
static_cast<double>(
bitrate()) * 1024.0 / 8.0) /
static_cast<double>(samplingFrequency())) *
static_cast<double>(sampleCount())
218 +
static_cast<double>(paddingSize()));
The Diagnostics class is a container for DiagMessage.
The exception that is thrown when the data to be parsed or to be made seems invalid and therefore can...
constexpr TAG_PARSER_EXPORT std::string_view bitrate()
The track's bit rate in bits per second.
Contains all classes and functions of the TagInfo library.
TAG_PARSER_EXPORT std::string_view mpegChannelModeString(MpegChannelMode channelMode)
Returns the string representation for the specified channelMode.
MpegChannelMode
Specifies the channel mode.