strptime.c needs ctype.h.
[metze/wireshark/wip.git] / wsutil / mpeg-audio.c
1 /* mpeg-audio.c
2  *
3  * MPEG Audio header dissection
4  * Written by Shaun Jackman <sjackman@gmail.com>
5  * Copyright 2007 Shaun Jackman
6  *
7  * Wiretap Library
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.
12  *
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.
17  *
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.
21  */
22
23 #include "mpeg-audio.h"
24
25 static const int mpa_versions[4] = { 2, -1, 1, 0 };
26 static const int mpa_layers[4] = { -1, 2, 1, 0 };
27
28 static const unsigned int mpa_samples_data[3][3] = {
29         { 384, 1152, 1152 },
30         { 384, 1152, 576 },
31         { 384, 1152, 576 },
32 };
33
34 static const unsigned int mpa_bitrates[3][3][16] = { /* kb/s */
35         {
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 },
39         },
40         {
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 },
44         },
45         {
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 },
49         },
50 };
51
52 static const unsigned int mpa_frequencies[3][4] = {
53         { 44100, 48000, 32000 },
54         { 22050, 24000, 16000 },
55         { 11025, 12000, 8000 },
56 };
57
58 static const unsigned int mpa_padding_data[3] = { 4, 1, 1 };
59
60 int
61 mpa_version(const struct mpa *mpa)
62 {
63         return mpa_versions[mpa->version];
64 }
65
66 int
67 mpa_layer(const struct mpa *mpa)
68 {
69         return mpa_layers[mpa->layer];
70 }
71
72 unsigned
73 mpa_samples(const struct mpa *mpa)
74 {
75         return mpa_samples_data[mpa_versions[mpa->version]][mpa_layer(mpa)];
76 }
77
78 unsigned
79 mpa_bitrate(const struct mpa *mpa)
80 {
81         return (1000 * (mpa_bitrates[mpa_versions[mpa->version]][mpa_layers[mpa->layer]][mpa->bitrate]));
82 }
83
84 unsigned
85 mpa_frequency(const struct mpa *mpa)
86 {
87         return(mpa_frequencies[mpa_versions[mpa->version]][mpa->frequency]);
88 }
89
90 unsigned
91 mpa_padding(const struct mpa *mpa)
92 {
93         return(mpa->padding ? mpa_padding_data[mpa_layers[mpa->layer]] : 0);
94 }
95
96 /*
97  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
98  *
99  * Local variables:
100  * c-basic-offset: 8
101  * tab-width: 8
102  * indent-tabs-mode: t
103  * End:
104  *
105  * vi: set shiftwidth=8 tabstop=8 noexpandtab:
106  * :indentSize=8:tabSize=8:noTabs=false:
107  */