@@ -46,7 +46,7 @@ def __init__(self, bufferSize=1000, attDb=0.):
4646
4747 def addSamples (self , sample_array ):
4848 '''
49- Extracts samples of the supported band and coverts them into bit stream.
49+ Extracts samples of the supported band and converts them into bit stream.
5050
5151 Parameters
5252 ----------
@@ -58,7 +58,7 @@ def addSamples(self, sample_array):
5858 numpy.ndarray(dtype=numpy.uint8)
5959 Array of type uint8 containing the encoded data.
6060 '''
61- return Encoder . EMPTY_RESULT
61+ raise NotImplementedError ()
6262
6363 def flush (self ):
6464 '''
@@ -70,10 +70,15 @@ def flush(self):
7070 Array of type uint8 containing the encoded data.
7171 '''
7272 if self .n_bits > 0 and self .n_bits % 8 != 0 :
73- self .bits += (8 - self .n_bits % 8 )
74- res = numpy .packbits (self .bits [0 :self .n_bits ])
75- self .n_bits = 0
76- return res
73+ self .n_bits += (8 - self .n_bits % 8 )
74+ if self .n_bits :
75+ res = numpy .packbits (self .bits [0 :self .n_bits ])
76+ self .bits [0 :self .n_bits ].fill (0 )
77+ self .n_bits = 0
78+ return res
79+ else :
80+ # Pack bits returns incorrect result in case of empty source bit set.
81+ return Encoder .EMPTY_RESULT
7782
7883 def encodeValues (self ):
7984 '''
@@ -91,6 +96,7 @@ def encodeValues(self):
9196 n_left = self .n_bits - n_offset
9297 res = numpy .packbits (self .bits [0 : n_offset ])
9398 self .bits [0 :n_left ] = self .bits [n_offset :n_offset + n_left ]
99+ self .bits [n_left :].fill (0 )
94100 self .n_bits = n_left
95101 return res
96102
0 commit comments