3 * MPEG Audio header dissection
4 * Written by Shaun Jackman <sjackman@gmail.com>
5 * Copyright 2007 Shaun Jackman
8 * SPDX-License-Identifier: GPL-2.0-or-later
11 #include "mpeg-audio.h"
13 static const int mpa_versions
[4] = { 2, -1, 1, 0 };
14 static const int mpa_layers
[4] = { -1, 2, 1, 0 };
16 static const unsigned int mpa_samples_data
[3][3] = {
22 static const unsigned int mpa_bitrates
[3][3][16] = { /* kb/s */
24 { 0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448 },
25 { 0, 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384 },
26 { 0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320 },
29 { 0, 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256 },
30 { 0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160 },
31 { 0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160 },
34 { 0, 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256 },
35 { 0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160 },
36 { 0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160 },
40 static const unsigned int mpa_frequencies
[3][4] = {
41 { 44100, 48000, 32000 },
42 { 22050, 24000, 16000 },
43 { 11025, 12000, 8000 },
46 static const unsigned int mpa_padding_data
[3] = { 4, 1, 1 };
49 mpa_version(const struct mpa
*mpa
)
51 return mpa_versions
[mpa
->version
];
55 mpa_layer(const struct mpa
*mpa
)
57 return mpa_layers
[mpa
->layer
];
61 mpa_samples(const struct mpa
*mpa
)
63 return mpa_samples_data
[mpa_versions
[mpa
->version
]][mpa_layer(mpa
)];
67 mpa_bitrate(const struct mpa
*mpa
)
69 return (1000 * (mpa_bitrates
[mpa_versions
[mpa
->version
]][mpa_layers
[mpa
->layer
]][mpa
->bitrate
]));
73 mpa_frequency(const struct mpa
*mpa
)
75 return(mpa_frequencies
[mpa_versions
[mpa
->version
]][mpa
->frequency
]);
79 mpa_padding(const struct mpa
*mpa
)
81 return(mpa
->padding
? mpa_padding_data
[mpa_layers
[mpa
->layer
]] : 0);
84 /* Decode an ID3v2 synchsafe integer.
85 * See https://id3.org/id3v2.4.0-structure section 6.2.
88 decode_synchsafe_int(uint32_t input
)
93 value
= (input
>> 24) & 0x7f;
94 /* Shift the result left to make room for the next 7 bits */
97 /* Now OR in the 2nd byte */
98 value
|= (input
>> 16) & 0x7f;
101 /* ... and the 3rd */
102 value
|= (input
>> 8) & 0x7f;
105 /* For the 4th byte don't do the shift */
106 value
|= input
& 0x7f;
112 * Editor modelines - https://www.wireshark.org/tools/modelines.html
117 * indent-tabs-mode: t
120 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
121 * :indentSize=8:tabSize=8:noTabs=false: