Re: Error Reading Audio Bitrates
- From: jackroofman@xxxxxxxxx
- Date: 31 Oct 2005 09:25:45 -0800
Everything I've done so far continues to fail. I know where the bitrate
values are stored in the bytes, but the data that my program is getting
is not what Windows and Winamp are. I have no idea why it's this way. I
found some code through one of the links here, but it doesn't seem to
be working. In fact, it gets one value the first time, and the
consistantly returns 128 every time after that. I don't get it.
protected int sync(FileInputStream in) throws IOException {
int store = 0;
while (!finished) {
int skip = in.read();
while (skip != 255 && skip != -1)
skip = in.read();
if (skip == -1)
throw new IOException();
store = in.read();
if (store >= 224)
finished = true;
else if (store == -1)
throw new IOException();
else {}
}
return store;
}
private int getBit(int input, int bit) {
if ((input & (1 << bit)) > 0)
return 1;
else
return 0;
}
protected int convertMPEGLevel(int in) {
if (in == 1)
return 1;
else
return 2;
}
protected int convertLayer(int in1, int in2) {
if (in1 == 0 && in2 == 0)
return 1;
else
return(4 - ((in1 << 1) + in2));
}
protected int convertBitRate(int in1, int in2, int in3, int in4) {
int[][] convert = {
{ 0, 0, 0, 0, 0, 0 },
{ 32, 32, 32, 32, 32, 8 },
{ 64, 48, 40, 64, 48, 16 },
{ 96, 56, 48, 96, 56, 24 },
{ 128, 64, 56, 128, 64, 32 },
{ 160, 80, 64, 160, 80, 64 },
{ 192, 96, 80, 192, 96, 80 },
{ 224, 112, 96, 224, 112, 56 },
{ 256, 128, 112, 256, 128, 64 },
{ 288, 160, 128, 288, 160, 128 },
{ 320, 192, 160, 320, 192, 160 },
{ 352, 224, 192, 352, 224, 112 },
{ 384, 256, 224, 384, 256, 128 },
{ 416, 320, 256, 416, 320, 256 },
{ 448, 384, 320, 448, 384, 320 },
{ 0, 0, 0, 0, 0, 0 }
};
//System.out.println(in1 + ", " + in2 + ", " + in3 + ", " +
in4);
//System.out.println(layer + ", " + level);
int index1 = (in1 << 3) | (in2 << 2) | (in3 << 1) | in4;
int index2 = (level - 1) * 3 + layer - 1;
//System.out.println(index1 + ", " + index2);
return convert[index1][index2];
}
And then actually calling those...
protected int readProperties(File file) throws IOException {
FileInputStream in = new FileInputStream(file);
in.mark(15);
int second = sync(in);
int third = in.read();
in.close();
level = convertMPEGLevel(getBit(second, 3));
layer = convertLayer(getBit(second, 2), getBit(second, 1));
int bits = convertBitRate(getBit(third, 7), getBit(third, 6),
getBit(third, 5), getBit(third, 4));
return bits;
}
I just don't understand why it won't work with most of my files.
There's no way that 90% of them aren't encoded right. Any ideas?
.
- Prev by Date: Re: help please
- Next by Date: Re: How to compile a java program w/ another java programs which are w/o a main method
- Previous by thread: Re: Error Reading Audio Bitrates
- Next by thread: Re: Implementing a Controller Servlet: forward to another servlet without cluttering up web.xml
- Index(es):