2
* Asterisk -- A telephony toolkit for Linux.
4
* MP3 Header Analysis Routines. Thanks to Robert Kaye for the logic!
6
* Copyright (C) 1999, Mark Spencer
8
* Mark Spencer <markster@linux-support.net>
10
* This program is free software, distributed under the terms of
11
* the GNU General Public License
14
static int bitrates1[] = { 0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320 };
15
static int bitrates2[] = { 0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160 };
17
static int samplerates1[] = { 44100, 48000, 32000 };
18
static int samplerates2[] = { 22050, 24000, 16000 };
20
static int outputsamples[] = { 576, 1152 };
22
static int mp3_samples(unsigned char *header)
24
int ver = (header[1] & 0x8) >> 3;
25
return outputsamples[ver];
28
static int mp3_bitrate(unsigned char *header)
30
int ver = (header[1] & 0x8) >> 3;
31
int br = (header[2] >> 4);
34
ast_log(LOG_WARNING, "Invalid bit rate\n");
44
static int mp3_samplerate(unsigned char *header)
46
int ver = (header[1] & 0x8) >> 3;
47
int sr = (header[2] >> 2) & 0x3;
50
ast_log(LOG_WARNING, "Invalid sample rate\n");
55
return samplerates1[sr];
57
return samplerates2[sr];
60
static int mp3_padding(unsigned char *header)
62
return (header[2] >> 1) & 0x1;
65
static int mp3_badheader(unsigned char *header)
67
if ((header[0] != 0xFF) || ((header[1] & 0xF0) != 0xF0))
72
static int mp3_framelen(unsigned char *header)
74
int br = mp3_bitrate(header);
75
int sr = mp3_samplerate(header);
78
if ((br < 0) || (sr < 0))
80
size = 144000 * br / sr + mp3_padding(header);