// 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); }
public int BlockSize(Packet Packet) { //codec_setup_info var Buffer = new NVorbis.Ogg.BBuffer(); int mode; Buffer.ReadInit(Packet.packet_base, Packet.packet, Packet.bytes); /* Check the packet type */ if (Buffer.Read(1) != 0) { /* Oops. This is not an audio data packet */ return(OV_ENOTAUDIO); } { int modebits = 0; uint v = (uint)Modes; while (v > 1) { modebits++; v >>= 1; } /* read our mode and pre/post windowsize */ mode = Buffer.Read(modebits); } if (mode == -1) { return(OV_EBADPACKET); } return(blocksizes[ModeParam[mode].blockflag]); }
/// <summary> /// Header packing/unpacking /// </summary> /// <param name="Buffer"></param> /// <returns></returns> int UnpackInfo(NVorbis.Ogg.BBuffer Buffer) { version = Buffer.Read(32); if (version != 0) { return(-1); } Channels = Buffer.Read(8); Rate = Buffer.Read(32); bitrate_upper = Buffer.Read(32); bitrate_nominal = Buffer.Read(32); bitrate_lower = Buffer.Read(32); blocksizes[0] = 1 << Buffer.Read(4); blocksizes[1] = 1 << Buffer.Read(4); if ((Rate < 1) || (Channels < 1) || (blocksizes[0] < 8) || (blocksizes[1] < blocksizes[0]) || (Buffer.Read(1) != 1)) { Clear(); return(-1); } return(0); }
/// <summary> /// All of the real encoding details are here. The modes, books, everything. /// </summary> /// <param name="Buffer"></param> /// <returns></returns> int UnpackBooks(NVorbis.Ogg.BBuffer Buffer) { Books = Buffer.Read(8) + 1; if (BookParam == null || BookParam.Length != Books) { BookParam = new StaticCodeBook[Books]; } for (int i = 0; i < Books; i++) { BookParam[i] = new StaticCodeBook(); if (BookParam[i].unpack(Buffer) != 0) { Clear(); return(-1); } } // time backend settings Times = Buffer.Read(6) + 1; if (TimeType == null || TimeType.Length != Times) { TimeType = new int[Times]; } if (TimeParam == null || TimeParam.Length != Times) { TimeParam = new Object[Times]; } for (int i = 0; i < Times; i++) { TimeType[i] = Buffer.Read(16); if (TimeType[i] < 0 || TimeType[i] >= VI_TIMEB) { Clear(); return(-1); } TimeParam[i] = FuncTime.time_P[TimeType[i]].unpack(this, Buffer); if (TimeParam[i] == null) { Clear(); return(-1); } } // floor backend settings floors = Buffer.Read(6) + 1; if (FloorType == null || FloorType.Length != floors) { FloorType = new int[floors]; } if (FloorParam == null || FloorParam.Length != floors) { FloorParam = new Object[floors]; } for (int i = 0; i < floors; i++) { FloorType[i] = Buffer.Read(16); if (FloorType[i] < 0 || FloorType[i] >= VI_FLOORB) { Clear(); return(-1); } FloorParam[i] = FuncFloor.floor_P[FloorType[i]].unpack(this, Buffer); if (FloorParam[i] == null) { Clear(); return(-1); } } // residue backend settings residues = Buffer.Read(6) + 1; if (residue_type == null || residue_type.Length != residues) { residue_type = new int[residues]; } if (ResidueParam == null || ResidueParam.Length != residues) { ResidueParam = new Object[residues]; } for (int i = 0; i < residues; i++) { residue_type[i] = Buffer.Read(16); if (residue_type[i] < 0 || residue_type[i] >= VI_RESB) { Clear(); return(-1); } ResidueParam[i] = FuncResidue.residue_P[residue_type[i]].unpack(this, Buffer); if (ResidueParam[i] == null) { Clear(); return(-1); } } // map backend settings maps = Buffer.Read(6) + 1; if (map_type == null || map_type.Length != maps) { map_type = new int[maps]; } if (MapParam == null || MapParam.Length != maps) { MapParam = new Object[maps]; } for (int i = 0; i < maps; i++) { map_type[i] = Buffer.Read(16); if (map_type[i] < 0 || map_type[i] >= VI_MAPB) { Clear(); return(-1); } MapParam[i] = FuncMapping.mapping_P[map_type[i]].unpack(this, Buffer); if (MapParam[i] == null) { Clear(); return(-1); } } // mode settings Modes = Buffer.Read(6) + 1; if (ModeParam == null || ModeParam.Length != Modes) { ModeParam = new InfoMode[Modes]; } for (int i = 0; i < Modes; i++) { ModeParam[i] = new InfoMode(); ModeParam[i].blockflag = Buffer.Read(1); ModeParam[i].windowtype = Buffer.Read(16); ModeParam[i].transformtype = Buffer.Read(16); ModeParam[i].mapping = Buffer.Read(8); if ((ModeParam[i].windowtype >= VI_WINDOWB) || (ModeParam[i].transformtype >= VI_WINDOWB) || (ModeParam[i].mapping >= maps)) { Clear(); return(-1); } } if (Buffer.Read(1) != 1) { Clear(); return(-1); } return(0); }
public int synthesis(Packet op) { Info vi = vd.vi; // first things first. Make sure decode is ready opb.ReadInit(op.packet_base, op.packet, op.bytes); // Check the packet type if (opb.Read(1) != 0) { // Oops. This is not an audio data packet return(-1); } // read our mode and pre/post windowsize int _mode = opb.Read(vd.modebits); if (_mode == -1) { return(-1); } mode = _mode; W = vi.ModeParam[mode].blockflag; if (W != 0) { lW = opb.Read(1); nW = opb.Read(1); if (nW == -1) { return(-1); } } else { lW = 0; nW = 0; } // more setup granulepos = op.granulepos; sequence = op.packetno - 3; // first block is third packet eofflag = op.e_o_s; // alloc pcm passback storage pcmend = vi.blocksizes[W]; if (pcm.Length < vi.Channels) { pcm = new float[vi.Channels][]; } for (int i = 0; i < vi.Channels; i++) { if (pcm[i] == null || pcm[i].Length < pcmend) { pcm[i] = new float[pcmend]; } else { for (int j = 0; j < pcmend; j++) { pcm[i][j] = 0; } } } // unpack_header enforces range checking int type = vi.map_type[vi.ModeParam[mode].mapping]; return(FuncMapping.mapping_P[type].inverse(this, vd.mode[mode])); }
// 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); }
public int BlockSize(Packet Packet) { //codec_setup_info var Buffer = new NVorbis.Ogg.BBuffer(); int mode; Buffer.ReadInit(Packet.packet_base, Packet.packet, Packet.bytes); /* Check the packet type */ if (Buffer.Read(1) != 0) { /* Oops. This is not an audio data packet */ return (OV_ENOTAUDIO); } { int modebits = 0; uint v = (uint)Modes; while (v > 1) { modebits++; v >>= 1; } /* read our mode and pre/post windowsize */ mode = Buffer.Read(modebits); } if (mode == -1) return (OV_EBADPACKET); return (blocksizes[ModeParam[mode].blockflag]); }