[squeak-dev] The Inbox: Sound-nice.44.mcz

commits at source.squeak.org commits at source.squeak.org
Mon Dec 11 20:29:16 UTC 2017


Nicolas Cellier uploaded a new version of Sound to project The Inbox:
http://source.squeak.org/inbox/Sound-nice.44.mcz

==================== Summary ====================

Name: Sound-nice.44
Author: nice
Time: 11 December 2017, 9:28:57.599 pm
UUID: 815ceacc-8a61-46c9-946d-0d6ea2761f67
Ancestors: Sound-topa.43

Transform 2 repeat loops into whileTrue: loops in ADPCMCodec

=============== Diff against Sound-topa.43 ===============

Item was changed:
  ----- Method: ADPCMCodec>>nextBits: (in category 'bit streaming') -----
  nextBits: n
  	"Answer the next n bits of my bit stream as an unsigned integer."
  
  	| result remaining shift |
  	<inline: true>
  
  	result := 0.
  	remaining := n.
  	
  	[
  		shift := remaining - bitPosition.
+ 		shift > 0 ]
+ 			whileTrue: [  "consumed currentByte buffer; fetch next byte"
- 		shift > 0
- 			ifTrue: [  "consumed currentByte buffer; fetch next byte"
  				result := result + (currentByte << shift).
  				remaining := remaining - bitPosition.			
  				currentByte := (encodedBytes at: (byteIndex := byteIndex + 1)).
+ 				bitPosition := 8].
+ 	
+ 	"update bits left in currentByte buffer"
+ 	result := result + (currentByte >> (0 - shift)).
+ 	bitPosition := bitPosition - remaining.
+ 	"mask out the consumed bits:"
+ 	currentByte := currentByte bitAnd: (255 >> (8 - bitPosition)).
+ 	^ result
- 				bitPosition := 8]
- 			ifFalse: [  "still some bits left in currentByte buffer"
- 				result := result + (currentByte >> (0 - shift)).
- 				bitPosition := bitPosition - remaining.
- 				"mask out the consumed bits:"
- 				currentByte := currentByte bitAnd: (255 >> (8 - bitPosition)).
- 				^ result]] repeat
  !

Item was changed:
  ----- Method: ADPCMCodec>>nextBits:put: (in category 'bit streaming') -----
  nextBits: n put: anInteger
  	"Write the next n bits to my bit stream."
  
  	| buf bufBits bitsAvailable shift |
  	<inline: true>
  
  	buf := anInteger.
  	bufBits := n.
  	[
  		bitsAvailable := 8 - bitPosition.
  		shift := bitsAvailable - bufBits.  "either left or right shift"
  		"append high bits of buf to end of currentByte:"
+ 		shift < 0 ]
+ 			whileTrue: [  "currentByte buffer filled; output it"
- 		shift < 0
- 			ifTrue: [  "currentByte buffer filled; output it"
  				currentByte := currentByte + (buf >> (0 - shift)).
  				encodedBytes at: (byteIndex := byteIndex + 1) put: currentByte.
  				bitPosition := 0.
  				currentByte := 0.
  				"clear saved high bits of buf:"
  				buf := buf bitAnd: (1 << (0 - shift)) - 1.
+ 				bufBits := bufBits - bitsAvailable].
+ 			
+ 	"update bits available in currentByte buffer"
+ 	currentByte := currentByte + (buf << shift).
+ 	bitPosition := bitPosition + bufBits.
+ 	^ self
- 				bufBits := bufBits - bitsAvailable]
- 			ifFalse: [  "still some bits available in currentByte buffer"
- 				currentByte := currentByte + (buf << shift).
- 				bitPosition := bitPosition + bufBits.
- 				^ self]] repeat
  !



More information about the Squeak-dev mailing list