3
Created by SMF aka Antoine Laydier <laydier@usa.net>.
4
Minor modifications by Kai Vehmanen <k@eca.cx>.
6
This program is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2 of the License, or
9
(at your option) any later version.
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
GNU General Public License for more details.
16
You should have received a copy of the GNU General Public License
17
along with this program; if not, write to the Free Software
18
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22
/*=============================================================================
24
=============================================================================*/
31
/*=============================================================================
33
=============================================================================*/
35
const int Layer::MPG_MD_STEREO = 0;
36
const int Layer::MPG_MD_JOINT_STEREO = 1;
37
const int Layer::MPG_MD_DUAL_CHANNEL = 2;
38
const int Layer::MPG_MD_MONO = 3;
40
const int Layer::MPG_MD_LR_LR = 0;
41
const int Layer::MPG_MD_LR_I = 1;
42
const int Layer::MPG_MD_MS_LR = 2;
43
const int Layer::MPG_MD_MS_I = 3;
45
const char *Layer::mode_names[5] = {"stereo", "j-stereo", "dual-ch",
46
"single-ch", "multi-ch"};
47
const char *Layer::layer_names[3] = {"I", "II", "III"};
48
const char *Layer::version_names[3] = {"MPEG-1", "MPEG-2 LSF", "MPEG-2.5"};
49
const char *Layer::version_nums[3] = {"1", "2", "2.5"};
50
const unsigned int Layer::bitrates[3][3][15] =
53
{0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448},
54
{0, 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384},
55
{0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320}
58
{0, 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256},
59
{0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160},
60
{0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160}
63
{0, 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256},
64
{0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160},
65
{0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160}
69
const unsigned int Layer::s_freq[3][4] =
71
{44100, 48000, 32000, 0},
72
{22050, 24000, 16000, 0},
73
{11025, 8000, 8000, 0}
76
const char * Layer::mode_name(void) { return (Layer::mode_names[mode_rep]); }
77
const char * Layer::layer_name(void) { return (Layer::layer_names[lay_rep - 1]); }
78
const char * Layer::version_name(void) { return (Layer::version_names[version_rep]); }
79
const char * Layer::version_num(void) { return (Layer::version_nums[version_rep]); }
80
int Layer::mode(void) { return(mode_rep); }
81
unsigned int Layer::bitrate(void)
82
{ return (Layer::bitrates[version_rep][lay_rep - 1][bitrate_index_rep]); }
83
unsigned int Layer::sfreq(void)
84
{ return (Layer::s_freq[version_rep][sampling_frequency_rep]); }
85
unsigned long Layer::length(void) { return bitrate() ? (fileSize_rep / (unsigned long)bitrate() /125) : 0; }
86
unsigned int Layer::pcmPerFrame(void) { return pcm_rep; }
88
bool Layer::get(const char* filename)
90
unsigned char *buff = new unsigned char[1024];
91
unsigned char *buffer;
98
// 22.3.2000 - added the second parameter for getting
99
// around FILE* compatibility issues, k@eca.cx
101
stat(filename, &buf);
102
fileSize_rep = (unsigned long)buf.st_size;
104
/* Theoretically reading 1024 instead of just 4 means a performance hit
105
* if we transfer over net filesystems... However, no filesystem I know
106
* of uses block sizes under 1024 bytes.
108
file = fopen(filename,"r");
109
if (!file) return(false);
111
fseek(file, 0, SEEK_SET);
112
readsize = fread(buff, 1, 1024, file);
122
/* Scan through the block looking for a header */
125
temp = ((buffer[0] << 4) & 0xFF0) | ((buffer[1] >> 4) & 0xE);
126
} while ((temp != 0xFFE) && ((size_t)(buffer-buff)<readsize));
132
switch ((buffer[1] >> 3 & 0x3)) {
146
lay_rep = 4 - ((buffer[1] >> 1) & 0x3);
147
error_protection_rep = !(buffer[1] & 0x1);
148
bitrate_index_rep = (buffer[2] >> 4) & 0x0F;
149
sampling_frequency_rep = (buffer[2] >> 2) & 0x3;
150
padding_rep = (buffer[2] >> 1) & 0x01;
151
extension_rep = buffer[2] & 0x01;
152
mode_rep = (buffer[3] >> 6) & 0x3;
153
mode_ext_rep = (buffer[3] >> 4) & 0x03;
154
copyright_rep = (buffer[3] >> 3) & 0x01;
155
original_rep = (buffer[3] >> 2) & 0x1;
156
emphasis_rep = (buffer[3]) & 0x3;
157
stereo_rep = (mode_rep == Layer::MPG_MD_MONO) ? 1 : 2;
163
if (version_rep == 0)