Fixed bad header reading for wav files
This commit is contained in:
parent
3afbf3a671
commit
ca8316892a
@ -6,6 +6,8 @@ import java.io.FileInputStream;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.security.InvalidParameterException;
|
import java.security.InvalidParameterException;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.Gdx;
|
||||||
|
|
||||||
public class WavInfo {
|
public class WavInfo {
|
||||||
private int channels;
|
private int channels;
|
||||||
private double sampleRate;
|
private double sampleRate;
|
||||||
@ -28,43 +30,48 @@ public class WavInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void getHeaderInfo() throws IOException {
|
protected void getHeaderInfo() throws IOException {
|
||||||
if (!readBytesToString(4).equals("RIFF")) { //4
|
if (!readBytesToString(4).equals("RIFF")) { //4 for RIFF tag
|
||||||
throw new InvalidParameterException("RIFF tag not found in header.");
|
throw new InvalidParameterException("RIFF tag not found in header.");
|
||||||
}
|
}
|
||||||
dataSize = littleEndianIntBytes(); //4
|
dataSize = littleEndianIntBytes(); //4 for Chunk size
|
||||||
|
|
||||||
if (!readBytesToString(4).equals("WAVE")) { //4
|
if (!readBytesToString(4).equals("WAVE")) { //4 for WAVE tag
|
||||||
throw new InvalidParameterException("WAVE format tag not found.");
|
throw new InvalidParameterException("WAVE format tag not found.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!readBytesToString(4).equals("fmt ")) { //4
|
if (!readBytesToString(4).equals("fmt ")) { //4 for 'fmt '
|
||||||
throw new InvalidParameterException("fmt header not found.");
|
throw new InvalidParameterException("fmt header not found.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (readStream.readByte() != 16) { //1
|
if (littleEndianIntBytes() != 16) { //subchunk1size (4 bytes)
|
||||||
throw new InvalidParameterException("Data not pcm?");
|
throw new InvalidParameterException("Data not pcm?");
|
||||||
}
|
}
|
||||||
|
|
||||||
readStream.skipBytes(3); //3
|
if (readStream.readByte() != 1) { //1 pcm
|
||||||
if (readStream.readByte() != 1) { //1
|
|
||||||
throw new InvalidParameterException("Data not pcm?");
|
throw new InvalidParameterException("Data not pcm?");
|
||||||
}
|
}
|
||||||
readStream.skipBytes(1); //1
|
readStream.skip(1); //1
|
||||||
|
|
||||||
channels = readStream.readByte(); //1
|
channels = readStream.readByte(); //1 channel count
|
||||||
readStream.skipBytes(1); //1
|
readStream.skip(1); //1
|
||||||
|
|
||||||
sampleRate = littleEndianIntBytes(); //4
|
sampleRate = littleEndianIntBytes(); //4 sample rate
|
||||||
|
|
||||||
byteRate = littleEndianIntBytes(); //4
|
byteRate = littleEndianIntBytes(); //4
|
||||||
|
|
||||||
readStream.skipBytes(38); //38
|
readStream.skip(4); //38
|
||||||
|
|
||||||
// System.out.println(readBytesToString(4).equals("data"));
|
// System.out.println(readBytesToString(4).equals("data"));
|
||||||
|
|
||||||
if (!readBytesToString(4).equals("data")) { // 4
|
if (!readBytesToString(4).equals("data")) { // 4
|
||||||
|
Gdx.app.debug("Audio", "sample rate: " + sampleRate);
|
||||||
|
Gdx.app.debug("Audio", "Data chunk size: " + dataSize);
|
||||||
|
Gdx.app.debug("Audio", "Channel count: " + channels);
|
||||||
|
|
||||||
throw new InvalidParameterException("initial data section tag not found on wav: " + fileName);
|
throw new InvalidParameterException("initial data section tag not found on wav: " + fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
readStream.skip(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void initDataStream() {
|
protected void initDataStream() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user