コード例 #1
0
ファイル: vorbis_test.go プロジェクト: runningwild/gorbis
func HuffmanDecodeSpec(c gospec.Context) {
	c.Specify("Basic huffman decode", func() {
		var codebook vorbis.Codebook
		codebook.Entries = make([]vorbis.CodebookEntry, 8)
		codebook.Entries[0].Length = 2
		codebook.Entries[1].Length = 4
		codebook.Entries[2].Length = 4
		codebook.Entries[3].Length = 4
		codebook.Entries[4].Length = 4
		codebook.Entries[5].Length = 2
		codebook.Entries[6].Length = 3
		codebook.Entries[7].Length = 3
		codebook.AssignCodewords()

		v := []uint8{0x5F, 0x6E, 0x2A, 0x00}
		br := vorbis.MakeBitReader(bytes.NewBuffer(v))

		c.Expect(codebook.DecodeScalar(br), Equals, 7)
		c.Expect(codebook.DecodeScalar(br), Equals, 6)
		c.Expect(codebook.DecodeScalar(br), Equals, 5)
		c.Expect(codebook.DecodeScalar(br), Equals, 4)
		c.Expect(codebook.DecodeScalar(br), Equals, 3)
		c.Expect(codebook.DecodeScalar(br), Equals, 2)
		c.Expect(codebook.DecodeScalar(br), Equals, 1)
		c.Expect(codebook.DecodeScalar(br), Equals, 0)
	})
}
コード例 #2
0
ファイル: vorbis_test.go プロジェクト: runningwild/gorbis
func BitReaderSpec(c gospec.Context) {
	v := []uint8{1, 1, 3, 0, 0, 9}
	//  00001001 00000000 00000000 00000011 00000001 00000001
	//                                                      1
	//                                           001 0000000
	//       001 00000000 00000000 00000011 00000
	//  00001

	c.Specify("Bitreader reads from an io.Reader properly", func() {
		br := vorbis.MakeBitReader(bytes.NewBuffer(v))
		c.Expect(uint32(0x1), Equals, br.ReadBits(1))
		c.Expect(uint32(0x80), Equals, br.ReadBits(10))
		c.Expect(uint32(0x20000060), Equals, br.ReadBits(32))
		c.Expect(uint32(0x1), Equals, br.ReadBits(5))
	})
}