3 * MPEG Audio header dissection
4 * Written by Shaun Jackman <sjackman@gmail.com>
5 * Copyright 2007 Shaun Jackman
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include "mpeg-audio.h"
25 static const int mpa_versions[4] = { 2, -1, 1, 0 };
26 static const int mpa_layers[4] = { -1, 2, 1, 0 };
28 static const unsigned int mpa_samples_data[3][3] = {
34 static const unsigned int mpa_bitrates[3][3][16] = { /* kb/s */
36 { 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 },
41 { 0, 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256 },
42 { 0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160 },
43 { 0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160 },
46 { 0, 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256 },
47 { 0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160 },
48 { 0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160 },
52 static const unsigned int mpa_frequencies[3][4] = {
53 { 44100, 48000, 32000 },
54 { 22050, 24000, 16000 },
55 { 11025, 12000, 8000 },
58 static const unsigned int mpa_padding_data[3] = { 4, 1, 1 };
61 mpa_version(const struct mpa *mpa)
63 return mpa_versions[mpa->version];
67 mpa_layer(const struct mpa *mpa)
69 return mpa_layers[mpa->layer];
73 mpa_samples(const struct mpa *mpa)
75 return mpa_samples_data[mpa_versions[mpa->version]][mpa_layer(mpa)];
79 mpa_bitrate(const struct mpa *mpa)
81 return (1000 * (mpa_bitrates[mpa_versions[mpa->version]][mpa_layers[mpa->layer]][mpa->bitrate]));
85 mpa_frequency(const struct mpa *mpa)
87 return(mpa_frequencies[mpa_versions[mpa->version]][mpa->frequency]);
91 mpa_padding(const struct mpa *mpa)
93 return(mpa->padding ? mpa_padding_data[mpa_layers[mpa->layer]] : 0);
97 * Editor modelines - http://www.wireshark.org/tools/modelines.html
102 * indent-tabs-mode: t
105 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
106 * :indentSize=8:tabSize=8:noTabs=false: