1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
|
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
int main()
{
FILE* pFile;
errno_t err;
unsigned int uiFrame = 0,
check = 0,
test = 0,
CheckFlag = 0,
cntSize = 0,
uiFrameCount = 1,
PrevoiusFrameSize = 0,
TotalFileSize = 0;
int bitrate[16] = {0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 0};
int samp_freq[4]= {44, 48, 32, 0};
if( 0 != (err = fopen_s( &pFile, "C:\\test.mp3", "rb" )) ) {
printf( "The input file was not opened\n" );
return 1;
}
fseek(pFile, 0, SEEK_END);
TotalFileSize = ftell(pFile);
fseek(pFile, 0, SEEK_SET);
while(cntSize < TotalFileSize/*10 > uiFrameCount*/)
{
// Check for the SynBits
do
{
uiFrame = getc(pFile);
if(EOF == uiFrame)
break;
cntSize++;
if(0xFF == uiFrame)
{
uiFrame = getc(pFile);
if(EOF == uiFrame)
break;
if((0xFA == uiFrame) || (0xFB == uiFrame))
{
if(1 != uiFrameCount)
printf("\nFrame Size is %d \n\n",cntSize - PrevoiusFrameSize);
printf("\nFrame Found at Byte %d", cntSize);
PrevoiusFrameSize = cntSize;
CheckFlag = 1;
uiFrameCount++;
}
cntSize++;
}
}while(1 != CheckFlag);
CheckFlag = 0;
//Check for MPEG Version
check = uiFrame & 0x08;
switch(check)
{
case 0x00:
printf("\nError");
break;
case 0x08:
printf("\nMPEG 1");
break;
}
//Check for Layer
check = uiFrame & 0x06;
switch(check)
{
case 0x00:
printf("\nReserved");
break;
case 0x02:
printf("\nLayer 3");
break;
case 0x04:
printf("\nLayer 2");
break;
case 0x06:
printf("\nLayer 1");
break;
}
//CRC Added or not
test = uiFrame & 0x01;
switch(test)
{
case 0x00:
printf("\nRedundancy Added");
break;
case 0x01:
printf("\nRedundancy Not Added");
break;
}
// get next byte
uiFrame = getc(pFile);
if(uiFrame == EOF)
break;
cntSize++;
// Check for Bit rate
check = uiFrame & 0xF0;
test = check >> 4;
printf("\nBitrate is %d\n",bitrate[test]);
// Check for Sampling Frequency
check = uiFrame & 0x0C;
test = check >> 2;
printf("Sampling Frequency is %d\n",samp_freq[test]);
// Check slot for bitrate change
check = uiFrame& 0x02;
switch(check)
{
case 0x00:
printf("No Slot to adjust bit rate");
break;
case 0x02:
printf("Slot to adjust bit rate");
break;
}
// Check private bit
check = uiFrame & 0x01;
printf("\nPrivate Bit is %d\n", check);
// Get next byte
uiFrame = getc(pFile);
if(uiFrame == EOF)
break;
cntSize++;
// Check for channel type
check = uiFrame & 0xC0;
switch(check)
{
case 0x00:
printf("Stereo");
break;
case 0x40:
printf("Joint Stereo");
break;
case 0x80:
printf("Dual Channel");
break;
case 0xC0:
printf("Single Channel");
break;
}
// Intensity and MS Stero Check
check = uiFrame & 0x30;
test = check >> 4;
switch(test)
{
case 0x00:
printf("\nIntensity Stereo-OFF MS Stereo-OFF");
break;
case 0x10:
printf("\nIntensity Stereo-ON MS Stereo-OFF");
break;
case 0x20:
printf("\nIntensity Stereo-OFF MS Stereo-ON");
break;
case 0x30:
printf("\nIntensity Stereo-ON MS Stereo-ON");
break;
}
// Check for Copyright
check = uiFrame& 0x08;
switch(check)
{
case 0x00:
printf("\nNo Copyright");
break;
case 0x08:
printf("\nCopyrighted");
break;
}
// Check for Original or Copy
check = uiFrame & 0x04;
switch(check)
{
case 0x00:
printf("\nCopy");
break;
case 0x04:
printf("\nOriginal");
break;
}
// Check for Emphasis
check = uiFrame& 0x03;
switch(check)
{
case 0:
printf("\nNo Emphasis");
break;
case 1:
printf("\n50/15 Micro seconds");
break;
case 2:
printf("\nReserved");
break;
case 3:
printf("\nCCITT J.17");
break;
}
_getch();
}
printf("\nTotal Number of Frames displayed is %d \n", uiFrameCount);
fclose(pFile);
}
|