Vorbis を利用するコードを実装した時のメモ


1. 利用目的

 Vorbis とは、音を再生、録音する際に利用するデコードおよびエンコード機能を提供するライブラリです。
 コーデックライブラリと考えれば分かり易いと思います。

 換言すれば「音源出力」と「音源入力」は含まれていない訳です。 これはoggも同じです。

 つまりスピーカへの出力とマイクからの入力は、独自に実装する必要がある次第です。

 これを踏まえて、取り敢えず利用目的を音源再生だけに定めます。

2. 音源データを入力(デコード)

 添付のドキュメントに以下のような説明がありました。

Decoding workflow
Note: if you do not need to do anything more involved than just decoding the audio from an Ogg Vorbis file, you can use the far simpler libvorbisfile interface, which will take care of all of the demuxing and low-level decoding operations (and even the I/O, if you want) for you.
1. When reading the header packets of an Ogg stream, you can use vorbis_synthesis_idheader to check whether a stream might be Vorbis.
2. Initialize a vorbis_info and a vorbis_comment structure using the appropriate vorbis_*_init routines, then pass the first three packets from the stream (the Vorbis stream header packets) to vorbis_synthesis_headerin in order. At this point, you can see the comments and basic parameters of the Vorbis stream.
3. Initialize a vorbis_dsp_state for decoding based on the parameters in the vorbis_info by using vorbis_synthesis_init.
4. Initialize a vorbis_block structure using vorbis_block_init.
5. While there are more packets to decode:
5-1. Decode the next packet into a block using vorbis_synthesis.
5-2. Submit the block to the reassembly layer using vorbis_synthesis_blockin.
5-3. Obtain some decoded audio using vorbis_synthesis_pcmout and vorbis_synthesis_read. Any audio data returned but not marked as consumed using vorbis_synthesis_read carries over to the next call to vorbis_synthesis_pcmout.
6. Destroy the structures using the appropriate vorbis_*_clear routines.

 以下のような事柄と、初期化から終了までの主なルーチンの呼出順序が書いてある様子です。

 途中まで読んで断念しました。 サンプルを見た方が早そうでした。

 サンプルは「decoder_example.c」が一番シンプルな実装だと思われます。
 このサンプルは、stdin からVorbis ビットストリームを入力して、標準出力にPCM を出力する実装のようです。

 デコード部分は、簡単に実装できそうな感触ですが、先にPCM 再生機能を実装しておかないと意味がなさそうでした。

3. まとめ

 取り敢えず、先にWindows XP でPCM 再生する機能を実装することになりました。

 そちらが実装できたら、このページに加筆したいと考えております。


作成日:2010/11/12