dcerpc-nt: add UNION_ALIGN_TO... helpers
[wireshark-sm.git] / wsutil / mpeg-audio.c
blob8e80a13fa43a5207e33b8ff098b5ba8baa8a5a9a
1 /* mpeg-audio.c
3 * MPEG Audio header dissection
4 * Written by Shaun Jackman <sjackman@gmail.com>
5 * Copyright 2007 Shaun Jackman
7 * Wiretap Library
8 * SPDX-License-Identifier: GPL-2.0-or-later
9 */
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] = {
17 { 384, 1152, 1152 },
18 { 384, 1152, 576 },
19 { 384, 1152, 576 },
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 };
48 int
49 mpa_version(const struct mpa *mpa)
51 return mpa_versions[mpa->version];
54 int
55 mpa_layer(const struct mpa *mpa)
57 return mpa_layers[mpa->layer];
60 unsigned
61 mpa_samples(const struct mpa *mpa)
63 return mpa_samples_data[mpa_versions[mpa->version]][mpa_layer(mpa)];
66 unsigned
67 mpa_bitrate(const struct mpa *mpa)
69 return (1000 * (mpa_bitrates[mpa_versions[mpa->version]][mpa_layers[mpa->layer]][mpa->bitrate]));
72 unsigned
73 mpa_frequency(const struct mpa *mpa)
75 return(mpa_frequencies[mpa_versions[mpa->version]][mpa->frequency]);
78 unsigned
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.
87 uint32_t
88 decode_synchsafe_int(uint32_t input)
90 uint32_t value;
92 /* High-order byte */
93 value = (input >> 24) & 0x7f;
94 /* Shift the result left to make room for the next 7 bits */
95 value <<= 7;
97 /* Now OR in the 2nd byte */
98 value |= (input >> 16) & 0x7f;
99 value <<= 7;
101 /* ... and the 3rd */
102 value |= (input >> 8) & 0x7f;
103 value <<= 7;
105 /* For the 4th byte don't do the shift */
106 value |= input & 0x7f;
108 return value;
112 * Editor modelines - https://www.wireshark.org/tools/modelines.html
114 * Local variables:
115 * c-basic-offset: 8
116 * tab-width: 8
117 * indent-tabs-mode: t
118 * End:
120 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
121 * :indentSize=8:tabSize=8:noTabs=false: