0

次のFLACファイルから情報を抽出するパーサーを作成しようとしています。

$ hd audio.flac | head -n 6
00000000  66 4c 61 43 00 00 00 22  12 00 12 00 00 00 00 00  |fLaC..."........|
00000010  00 00 0a c4 42 f0 00 78  9f 30 00 00 00 00 00 00  |....B..x.0......|
00000020  00 00 00 00 00 00 00 00  00 00 84 00 02 64 1f 00  |.............d..|
00000030  00 00 47 53 74 72 65 61  6d 65 72 20 65 6e 63 6f  |..GStreamer enco|
00000040  64 65 64 20 76 6f 72 62  69 73 63 6f 6d 6d 65 6e  |ded vorbiscommen|
00000050  74 10 00 00 00 12 00 00  00 54 49 54 4c 45 3d 52  |t........TITLE=R|

ここで、仕様によると、フォーマットは次のようになります (数値はビット単位です)。

 <32>  "fLaC", the FLAC stream marker in ASCII
 <16>  The minimum block size (in samples) used in the stream.
 <16>  The maximum block size (in samples) used in the stream.
 <24>  The minimum frame size (in bytes) used in the stream.
 <24>  The maximum frame size (in bytes) used in the stream.
 <20>  Sample rate in Hz.
  <3>  (number of channels)-1. FLAC supports from 1 to 8 channels
  <5>  (bits per sample)-1. FLAC supports from 4 to 32 bits per sample.
 <36>  Total samples in stream.
<128>  MD5 signature of the unencoded audio data.

そこで、パーサーを書き始め、テスト中に非常に奇妙な結果が得られました。そこで、「実際の」メタデータ エクストラクタでテストします。

$ metaflac --list audio.flac 
METADATA block #0
  type: 0 (STREAMINFO)
  is last: false
  length: 34
  minimum blocksize: 4608 samples
  maximum blocksize: 4608 samples
  minimum framesize: 0 bytes
  maximum framesize: 0 bytes
  sample_rate: 44100 Hz
  channels: 2
  bits-per-sample: 16
  total samples: 7905072
  MD5 signature: 00000000000000000000000000000000

数字から、次のことが推測できます。

66 4c 61 43 00 00 00 22  12 00 12 00 00 00 00 00
~~~~~~~~~~~ ~~~~~~~~~~~  ~~~~~ ~~~~~ ~~~~~~~~ ~~
     ^           ^         ^     ^       ^    ^
     |           |         |     |       |    |
     |           |         |     |       |    + Etc.
     |           |         |     |       + Minimum frame size
     |           |         |     + Maximum block size
     |           |         + Minimum block size
     |           + What is that ?!?
     + FLAC stream marker

これらの 32 ビットはどこから来たのですか? それらはヘッダーの長さを表しているようですが、そこに置くのは標準に反していません(長さは既にわかっていることを考慮すると: (32+16+16+24+20+3+5+36+ 128)/8)?

4

1 に答える 1