// The Vorbis header is in three packets; the initial small packet in // the first page that identifies basic parameters, a second packet // with bitstream comments and a third packet that holds the // codebook. public int SynthesisHeaderIn(Comment Comment, Packet Packet) { var Buffer = new NVorbis.Ogg.BBuffer(); if (Packet != null) { Buffer.ReadInit(Packet.packet_base, Packet.packet, Packet.bytes); // Which of the three types of header is this? // Also verify header-ness, vorbis { byte[] buffer = new byte[6]; int packtype = Buffer.Read(8); Buffer.Read(buffer, 6); if (buffer[0] != 'v' || buffer[1] != 'o' || buffer[2] != 'r' || buffer[3] != 'b' || buffer[4] != 'i' || buffer[5] != 's') { // not a vorbis header return (-1); } switch (packtype) { case 0x01: // least significant *bit* is read first if (Packet.b_o_s == 0) { // Not the initial packet return (-1); } if (Rate != 0) { // previously initialized info header return (-1); } return (UnpackInfo(Buffer)); case 0x03: // least significant *bit* is read first if (Rate == 0) { // um... we didn't get the initial header return (-1); } return (Comment.unpack(Buffer)); case 0x05: // least significant *bit* is read first if (Rate == 0 || Comment.vendor == null) { // um... we didn;t get the initial header or comments yet return (-1); } return (UnpackBooks(Buffer)); default: // Not a valid vorbis header type //return(-1); break; } } } return (-1); }
private void DecodeInit() { convbuffer = new byte[convsize]; // take 8k out of the data segment, not the stack SyncState = new SyncState(); // sync and verify incoming physical bitstream StreamState = new StreamState(); // take physical pages, weld into a logical stream of packets Page = new Page(); // one Ogg bitstream page. Vorbis packets are inside Packet = new Packet(); // one raw packet of data for decode Info = new Info(); // struct that stores all the static vorbis bitstream settings Comment = new Comment(); // struct that stores all the bitstream user comments DspState = new DspState(); // central working state for the packet->PCM decoder Block = new Block(DspState); // local working space for packet->PCM decode bytes = 0; }