3 #include "../exceptions.h"
5 #include <c++utilities/io/binaryreader.h>
17 switch (channelMode) {
18 case MpegChannelMode::Stereo:
19 return "2 channels: stereo";
20 case MpegChannelMode::JointStereo:
21 return "2 channels: joint stereo";
22 case MpegChannelMode::DualChannel:
23 return "2 channels: dual channel";
24 case MpegChannelMode::SingleChannel:
25 return "1 channel: single channel";
36 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 },
37 { 0, 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384 },
38 { 0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320 } },
39 { { 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 },
40 { 0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160 } } };
47 void MpegAudioFrame::parseHeader(BinaryReader &reader,
Diagnostics &diag)
49 m_header = reader.readUInt32BE();
51 diag.emplace_back(DiagLevel::Critical,
"Header is invalid.",
"parsing MPEG audio frame header");
54 reader.stream()->seekg(s_xingHeaderOffset - 4, ios_base::cur);
55 m_xingHeader = reader.readUInt64BE();
56 m_xingHeaderFlags = static_cast<XingHeaderFlags>(m_xingHeader & 0xffffffffuL);
57 if (isXingHeaderAvailable()) {
58 if (isXingFramefieldPresent()) {
59 m_xingFramefield = reader.readUInt32BE();
61 if (isXingBytesfieldPresent()) {
62 m_xingBytesfield = reader.readUInt32BE();
64 if (isXingTocFieldPresent()) {
65 reader.stream()->seekg(64, ios_base::cur);
67 if (isXingQualityIndicatorFieldPresent()) {
68 m_xingQualityIndicator = reader.readUInt32BE();
76 double MpegAudioFrame::mpegVersion()
const
78 switch (m_header & 0x180000u) {
93 int MpegAudioFrame::layer()
const
95 switch (m_header & 0x60000u) {
110 std::uint32_t MpegAudioFrame::samplingFrequency()
const
112 switch (m_header & 0xc00u) {
116 switch (m_header & 0x180000u) {
126 switch (m_header & 0x180000u) {
136 switch (m_header & 0x180000u) {
155 switch (m_header & 0xc0u) {
157 return MpegChannelMode::SingleChannel;
159 return MpegChannelMode::DualChannel;
161 return MpegChannelMode::JointStereo;
163 return MpegChannelMode::Stereo;
167 return MpegChannelMode::Unspecifed;
173 std::uint32_t MpegAudioFrame::sampleCount()
const
175 switch (m_header & 0x60000u) {
181 switch (m_header & 0x180000u) {
196 std::uint32_t MpegAudioFrame::size()
const
198 switch (m_header & 0x60000u) {
200 return static_cast<std::uint32_t>(
201 ((static_cast<double>(
bitrate()) * 1024.0 / 8.0) / static_cast<double>(samplingFrequency())) * static_cast<double>(sampleCount())
202 + static_cast<double>(paddingSize()));
205 return static_cast<std::uint32_t>(
206 ((static_cast<double>(
bitrate()) * 1024.0 / 8.0) / static_cast<double>(samplingFrequency())) * static_cast<double>(sampleCount())
207 + static_cast<double>(paddingSize()));