Пример #1
0
func (x *residue) ReadFrom(r *ogg.BitReader) error {
	x.residueType = r.Read16(16)
	if x.residueType > 2 {
		return ogg.ErrCorruptStream
	}
	x.begin = r.Read32(24)
	x.end = r.Read32(24)
	x.partitionSize = r.Read32(24) + 1
	x.classifications = r.Read8(6) + 1
	x.classbook = r.Read8(8)
	x.cascade = make([]uint8, x.classifications)
	for i := range x.cascade {
		highBits := uint8(0)
		lowBits := r.Read8(3)
		if r.ReadBool() {
			highBits = r.Read8(5)
		}
		x.cascade[i] = highBits*8 + lowBits
	}

	x.books = make([][8]uint8, x.classifications)
	for i := range x.books {
		for j := 0; j < 8; j++ {
			if x.cascade[i]&(1<<uint(j)) != 0 {
				x.books[i][j] = r.Read8(8)
			} else {
				x.books[i][j] = 0xFF //unused
			}
		}
	}

	return nil
}
Пример #2
0
func (f *floor0) ReadFrom(r *ogg.BitReader) error {
	f.order = r.Read8(8)
	f.rate = r.Read16(16)
	f.barkMapSize = r.Read16(16)
	f.amplitudeBits = r.Read8(6)
	f.amplitudeOffset = r.Read8(8)
	f.bookList = make([]uint8, r.Read8(4)+1)
	for i := range f.bookList {
		f.bookList[i] = r.Read8(8)
	}
	return nil
}
Пример #3
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
}