public void Encode(OggStreamState oggStreamState, VorbisBlock block, Stream stream) { OggPacket packet = new OggPacket(); OggPage page = new OggPage(); /* vorbis does some data preanalysis, then divvies up blocks for * more involved (potentially parallel) processing. Get a single * block for encoding now */ while (BlockOut(block)) { /* analysis, assume we want to use bitrate management */ block.Analyze(); block.BitrateAddBlock(); while (BitrateFlushPacket(packet) != 0) { /* weld the packet into the bitstream */ NativeMethods.ogg_stream_packetin(ref oggStreamState.InternalStruct, ref packet.InternalStruct); /* write out pages (if any) */ bool eos = false; while (!eos) { int result = NativeMethods.ogg_stream_pageout(ref oggStreamState.InternalStruct, ref og); if (result == 0) { break; } page.Write(stream); /* this could be set above, but for illustrative purposes, I do * it here (to show that vorbis does know where the stream ends) */ if (xm.ogg_page_eos(ref page.InternalStruct) != 0) { eos = true; } } } } }
public bool BlockOut(VorbisBlock block) { return(NativeMethods.vorbis_analysis_blockout(ref InternalStruct, ref block.InternalStruct) == 1); }