あなたはすべてをチェックする必要があります実際のサイズを確認するためのヘッダーデータ。 Broadcast Wave Formatファイルにはさらに大きな拡張サブチャンクが含まれます。 Pro ToolsのWAVファイルとAIFFファイルには、文書化されていない拡張チャンクとオーディオ後のデータがあります。サンプルデータの開始位置と終了位置を確認するには、データチャンク(WAVファイルの場合は 'data'、AIFFの場合は 'SSND')を実際に探す必要があります。レビューとして
、すべてのWAVサブチャンクは、次の形式に準拠:
Subchunk Descriptor (4 bytes)
Subchunk Size (4 byte integer, little endian)
Subchunk Data (size is Subchunk Size)
これは、プロセスが非常に簡単です。あなたが探しているものでない場合は、ディスクリプタを読み、データサイズを読み、次のものにスキップします。それを行うための単純なJavaルーチンは、次のようになります。ここで注目すべき
found 'RIFF' descriptor
found 'bext' descriptor
found 'fmt ' descriptor
found 'minf' descriptor
found 'elm1' descriptor
found 'data' descriptor
found 'regn' descriptor
found 'ovwf' descriptor
found 'umid' descriptor
end of file
、両方の「FMT」と「データ」は、合法的に表示されます。ここでは例えば
//
// Quick note for people who don't know Java well:
// 'in.read(...)' returns -1 when the stream reaches
// the end of the file, so 'if (in.read(...) < 0)'
// is checking for the end of file.
//
public static void printWaveDescriptors(File file)
throws IOException {
try (FileInputStream in = new FileInputStream(file)) {
byte[] bytes = new byte[4];
// read first 4 bytes
// should be RIFF descriptor
if (in.read(bytes) < 0) {
return;
}
printDescriptor(bytes);
// first subchunk will always be at byte 12
// there is no other dependable constant
in.skip(8);
for (;;) {
// read each chunk descriptor
if (in.read(bytes) < 0) {
break;
}
printDescriptor(bytes);
// read chunk length
if (in.read(bytes) < 0) {
break;
}
// skip the length of this chunk
// next bytes should be another descriptor or EOF
in.skip(
(bytes[0] & 0xFF)
| (bytes[1] & 0xFF) << 8
| (bytes[2] & 0xFF) << 16
| (bytes[3] & 0xFF) << 24
);
}
System.out.println("end of file");
}
}
private static void printDescriptor(byte[] bytes)
throws IOException {
String desc = new String(bytes, "US-ASCII");
System.out.println("found '" + desc + "' descriptor");
}
は私が持っていたランダムなWAVファイルでありますMicrosoft's RIFF specificationはサブチャンクがどのような順序でも出現できると述べているため、他のチャンクの間に配置します。私が知っているいくつかの主要なオーディオシステムでさえ、これは間違っていて、それを説明していません。
特定のチャンクを探したい場合は、探しているものが見つかるまで、各ディスクリプタをチェックしてファイルをループします。
私は、データが完全にどこかで始まる多くのWAVファイルを持っています。ファイルの先頭から何百ものバイトがあります。 WAVチャンクヘッダーは実際に解析が容易で、解析しないという言い訳はありません。 –
ヘッダーの解析には言い訳がありませんが、そうすることに関する誤った情報がたくさんあります。 Googleで "wav parser"を検索し、多くのトップヒットには議論のない44バイト長のコードが含まれています。 SOはもっと大きなものへのヒントしか含んでいませんでした。私は、次の欲求不満の人のためにこの問題に注意を向けようとしています。 –
私は、音楽音響研究所(スタンフォード)のウェブサイトの[WAVE PCM soundfile format](https://ccrma.stanford.edu/courses/422/projects/WaveFormat/)この種のものにとって有用なリソースとなります。 – Sheridan