use of org.jaudiotagger.audio.flac.metadatablock.MetadataBlockDataStreamInfo in project MusicDNA by harjot-oberai.
the class FlacInfoReader method read.
public FlacAudioHeader read(RandomAccessFile raf) throws CannotReadException, IOException {
FlacStreamReader flacStream = new FlacStreamReader(raf);
flacStream.findStream();
MetadataBlockDataStreamInfo mbdsi = null;
boolean isLastBlock = false;
//the bitrate
while (!isLastBlock) {
MetadataBlockHeader mbh = MetadataBlockHeader.readHeader(raf);
if (mbh.getBlockType() == BlockType.STREAMINFO) {
mbdsi = new MetadataBlockDataStreamInfo(mbh, raf);
if (!mbdsi.isValid()) {
throw new CannotReadException("FLAC StreamInfo not valid");
}
//TODO We have found streaminfo so do we need to continue checking, effects bitrate calc which is correct
//break;
} else {
raf.seek(raf.getFilePointer() + mbh.getDataLength());
}
isLastBlock = mbh.isLastBlock();
//Free memory
mbh = null;
}
if (mbdsi == null) {
throw new CannotReadException("Unable to find Flac StreamInfo");
}
FlacAudioHeader info = new FlacAudioHeader();
info.setLength(mbdsi.getSongLength());
info.setPreciseLength(mbdsi.getPreciseLength());
info.setChannelNumber(mbdsi.getChannelNumber());
info.setSamplingRate(mbdsi.getSamplingRate());
info.setBitsPerSample(mbdsi.getBitsPerSample());
info.setEncodingType(mbdsi.getEncodingType());
info.setExtraEncodingInfos("");
info.setBitrate(computeBitrate(mbdsi.getPreciseLength(), raf.length() - raf.getFilePointer()));
info.setLossless(true);
info.setMd5(mbdsi.getMD5Signature());
return info;
}
Aggregations