Mercurial > mplayer.hg
annotate libmpdemux/mp3_hdr.c @ 7482:1056d2dc4f3a
changed 'detected fileformat' messages to a message with %s
author | jaf |
---|---|
date | Sun, 22 Sep 2002 14:28:29 +0000 |
parents | e29f95ed5d36 |
children | 5a276890cec4 |
rev | line source |
---|---|
2588 | 1 #include <stdio.h> |
2 | |
3 #include "config.h" | |
4694
a21735031d6a
Audio file demuxer. Extended version for demuxer info.
albeu
parents:
2589
diff
changeset
|
4 #include "../mp_msg.h" |
2588 | 5 |
6 //----------------------- mp3 audio frame header parser ----------------------- | |
7 | |
8 static int tabsel_123[2][3][16] = { | |
9 { {0,32,64,96,128,160,192,224,256,288,320,352,384,416,448,}, | |
10 {0,32,48,56, 64, 80, 96,112,128,160,192,224,256,320,384,}, | |
11 {0,32,40,48, 56, 64, 80, 96,112,128,160,192,224,256,320,} }, | |
12 | |
13 { {0,32,48,56,64,80,96,112,128,144,160,176,192,224,256,}, | |
14 {0,8,16,24,32,40,48,56,64,80,96,112,128,144,160,}, | |
15 {0,8,16,24,32,40,48,56,64,80,96,112,128,144,160,} } | |
16 }; | |
17 static long freqs[9] = { 44100, 48000, 32000, 22050, 24000, 16000 , 11025 , 12000 , 8000 }; | |
18 | |
5806 | 19 int mp_mp3_get_lsf(unsigned char* hbuf){ |
20 unsigned long newhead = | |
21 hbuf[0] << 24 | | |
22 hbuf[1] << 16 | | |
23 hbuf[2] << 8 | | |
24 hbuf[3]; | |
25 if( newhead & ((long)1<<20) ) { | |
26 return (newhead & ((long)1<<19)) ? 0x0 : 0x1; | |
27 } | |
28 return 1; | |
29 } | |
30 | |
2588 | 31 /* |
32 * return frame size or -1 (bad frame) | |
33 */ | |
6763 | 34 int mp_get_mp3_header(unsigned char* hbuf,int* chans, int* srate){ |
2588 | 35 int stereo,ssize,crc,lsf,mpeg25,framesize,padding,bitrate_index,sampling_frequency; |
36 unsigned long newhead = | |
37 hbuf[0] << 24 | | |
38 hbuf[1] << 16 | | |
39 hbuf[2] << 8 | | |
40 hbuf[3]; | |
41 | |
42 // printf("head=0x%08X\n",newhead); | |
43 | |
44 #if 1 | |
45 // head_check: | |
46 if( (newhead & 0xffe00000) != 0xffe00000 || | |
47 (newhead & 0x0000fc00) == 0x0000fc00){ | |
4694
a21735031d6a
Audio file demuxer. Extended version for demuxer info.
albeu
parents:
2589
diff
changeset
|
48 mp_msg(MSGT_DEMUXER,MSGL_DBG2,"head_check failed\n"); |
2588 | 49 return -1; |
50 } | |
51 #endif | |
52 | |
4694
a21735031d6a
Audio file demuxer. Extended version for demuxer info.
albeu
parents:
2589
diff
changeset
|
53 if((4-((newhead>>17)&3))!=3){ |
a21735031d6a
Audio file demuxer. Extended version for demuxer info.
albeu
parents:
2589
diff
changeset
|
54 mp_msg(MSGT_DEMUXER,MSGL_DBG2,"not layer-3\n"); |
a21735031d6a
Audio file demuxer. Extended version for demuxer info.
albeu
parents:
2589
diff
changeset
|
55 return -1; |
a21735031d6a
Audio file demuxer. Extended version for demuxer info.
albeu
parents:
2589
diff
changeset
|
56 } |
2588 | 57 |
58 if( newhead & ((long)1<<20) ) { | |
59 lsf = (newhead & ((long)1<<19)) ? 0x0 : 0x1; | |
60 mpeg25 = 0; | |
61 } else { | |
62 lsf = 1; | |
63 mpeg25 = 1; | |
64 } | |
65 | |
66 if(mpeg25) | |
67 sampling_frequency = 6 + ((newhead>>10)&0x3); | |
68 else | |
69 sampling_frequency = ((newhead>>10)&0x3) + (lsf*3); | |
70 | |
71 if(sampling_frequency>8){ | |
4694
a21735031d6a
Audio file demuxer. Extended version for demuxer info.
albeu
parents:
2589
diff
changeset
|
72 mp_msg(MSGT_DEMUXER,MSGL_DBG2,"invalid sampling_frequency\n"); |
2588 | 73 return -1; // valid: 0..8 |
74 } | |
75 | |
76 crc = ((newhead>>16)&0x1)^0x1; | |
77 bitrate_index = ((newhead>>12)&0xf); | |
78 padding = ((newhead>>9)&0x1); | |
79 // fr->extension = ((newhead>>8)&0x1); | |
80 // fr->mode = ((newhead>>6)&0x3); | |
81 // fr->mode_ext = ((newhead>>4)&0x3); | |
82 // fr->copyright = ((newhead>>3)&0x1); | |
83 // fr->original = ((newhead>>2)&0x1); | |
84 // fr->emphasis = newhead & 0x3; | |
85 | |
86 stereo = ( (((newhead>>6)&0x3)) == 3) ? 1 : 2; | |
87 | |
88 if(!bitrate_index){ | |
4694
a21735031d6a
Audio file demuxer. Extended version for demuxer info.
albeu
parents:
2589
diff
changeset
|
89 mp_msg(MSGT_DEMUXER,MSGL_DBG2,"Free format not supported.\n"); |
2588 | 90 return -1; |
91 } | |
92 | |
93 if(lsf) | |
94 ssize = (stereo == 1) ? 9 : 17; | |
95 else | |
96 ssize = (stereo == 1) ? 17 : 32; | |
97 if(crc) ssize += 2; | |
98 | |
99 framesize = (long) tabsel_123[lsf][2][bitrate_index] * 144000; | |
100 framesize /= freqs[sampling_frequency]<<lsf; | |
101 framesize += padding; | |
102 | |
103 // if(framesize<=0 || framesize>MAXFRAMESIZE) return FALSE; | |
6763 | 104 if(srate) *srate = freqs[sampling_frequency]; |
105 if(chans) *chans = stereo; | |
2588 | 106 |
107 return framesize; | |
108 } | |
109 |