Example #1
0
func (i *identification) ReadFrom(r *ogg.BitReader) error {
	if r.Read8(8) != headerTypeIdentification {
		return ogg.ErrCorruptStream
	}
	if r.Read64(48) != pattern {
		return ogg.ErrCorruptStream
	}
	if r.Read32(32) != 0 {
		return ogg.ErrCorruptStream
	}
	i.audioChannels = r.Read8(8)
	i.audioSampleRate = r.Read32(32)
	i.bitrateMaximum = r.Read32(32)
	i.bitrateNominal = r.Read32(32)
	i.bitrateMinimum = r.Read32(32)
	i.blocksize0 = uint16(1) << r.Read8(4)
	i.blocksize1 = uint16(1) << r.Read8(4)
	if !r.ReadBool() {
		return ogg.ErrCorruptStream
	}
	return nil
}
Example #2
0
func (s *setup) ReadFrom(r *ogg.BitReader) error {
	if r.Read8(8) != headerTypeSetup {
		return ogg.ErrCorruptStream
	}
	if r.Read64(48) != pattern {
		return ogg.ErrCorruptStream
	}

	// CODEBOOKS
	s.codebooks = make([]codebook, r.Read16(8)+1)
	for i := range s.codebooks {
		err := s.codebooks[i].ReadFrom(r)
		if err != nil {
			return err
		}
	}

	// TIME DOMAIN TRANSFORMS
	transformCount := r.Read8(6) + 1
	for i := 0; i < int(transformCount); i++ {
		if r.Read16(16) != 0 {
			return ogg.ErrCorruptStream
		}
	}

	// FLOORS
	s.floors = make([]floor, r.Read8(6)+1)
	for i := range s.floors {
		var err error
		switch r.Read16(16) {
		case 0:
			// TODO
			// floor0 is not supported right now, also I haven't found any files that use it.
			/*var f floor0
			err = f.ReadFrom(r)
			s.floors[i] = &f*/
		case 1:
			f := new(floor1)
			err = f.ReadFrom(r)
			s.floors[i] = f
		default:
			err = ogg.ErrCorruptStream
		}
		if err != nil {
			return err
		}
	}

	// RESIDUES
	s.residues = make([]residue, r.Read8(6)+1)
	for i := range s.residues {
		err := s.residues[i].ReadFrom(r)
		if err != nil {
			return err
		}
	}

	// MAPPINGS
	s.mappings = make([]mapping, r.Read8(6)+1)
	for i := range s.mappings {
		m := &s.mappings[i]
		if r.Read16(16) != 0 {
			return ogg.ErrCorruptStream
		}
		if r.ReadBool() {
			m.submaps = make([]mappingSubmap, r.Read8(4)+1)
		} else {
			m.submaps = make([]mappingSubmap, 1)
		}
		if r.ReadBool() {
			m.couplingSteps = r.Read16(8) + 1
			m.magnitude = make([]uint8, m.couplingSteps)
			m.angle = make([]uint8, m.couplingSteps)
			for i := range m.magnitude {
				m.magnitude[i] = r.Read8(ilog(s.channels - 1))
				m.angle[i] = r.Read8(ilog(s.channels - 1))
			}
		}
		if r.Read8(2) != 0 {
			return ogg.ErrCorruptStream
		}
		m.mux = make([]uint8, s.channels)
		if len(m.submaps) > 1 {
			for i := range m.mux {
				m.mux[i] = r.Read8(4)
			}
		}
		for i := range m.submaps {
			r.Read8(8)
			m.submaps[i].floor = r.Read8(8)
			m.submaps[i].residue = r.Read8(8)
		}
	}

	// MODES
	s.modes = make([]mode, r.Read8(6)+1)
	for i := range s.modes {
		m := &s.modes[i]
		m.blockflag = r.Read8(1)
		if r.Read16(16) != 0 {
			return ogg.ErrCorruptStream
		}
		if r.Read16(16) != 0 {
			return ogg.ErrCorruptStream
		}
		m.mapping = r.Read8(8)
	}

	if !r.ReadBool() {
		return ogg.ErrCorruptStream
	}
	return nil
}