mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-04-09 21:45:54 +00:00
sbc: fix bit allocation for stereo
This commit is contained in:
parent
1522543de8
commit
f08a674b88
@ -337,14 +337,29 @@ def sbc_bit_allocation_stereo_joint(frame):
|
||||
bitcount += 1
|
||||
elif (bitneed[ch][sb] == bitslice+1) and (frame.bitpool > bitcount+1):
|
||||
bits[ch][sb] = 2
|
||||
bitcount += 2
|
||||
|
||||
bitcount += 2
|
||||
if ch == 1:
|
||||
ch = 0
|
||||
sb += 1
|
||||
else:
|
||||
ch = 1
|
||||
|
||||
|
||||
ch = 0
|
||||
sb = 0
|
||||
while bitcount < frame.bitpool and sb < frame.nr_subbands:
|
||||
if bits[ch][sb] < 16:
|
||||
bits[ch][sb]+=1
|
||||
bitcount+=1
|
||||
if ch == 1:
|
||||
ch = 0
|
||||
sb += 1
|
||||
else:
|
||||
ch = 1
|
||||
|
||||
if bits.sum() != frame.bitpool:
|
||||
print "bit allocation failed, bitpool %d, allocated %d" % (bits.sum() , frame.bitpool)
|
||||
exit(1)
|
||||
return bits
|
||||
|
||||
|
||||
@ -507,12 +522,14 @@ def get_bit(fin):
|
||||
|
||||
def drop_remaining_bits():
|
||||
global ibuffer_count
|
||||
#print "dropping %d bits" % ibuffer_count
|
||||
ibuffer_count = 0
|
||||
|
||||
def get_bits(fin, bit_count):
|
||||
bits = 0
|
||||
for i in range(bit_count):
|
||||
bits = (bits << 1) | get_bit(fin)
|
||||
# print "get bits: %d -> %02x" %(bit_count, bits)
|
||||
return bits
|
||||
|
||||
|
||||
|
@ -9,11 +9,20 @@ V = np.zeros(shape = (2, 10*2*8))
|
||||
|
||||
def sbc_unpack_frame(fin, available_bytes, frame):
|
||||
if available_bytes == 0:
|
||||
print "no available_bytes"
|
||||
raise TypeError
|
||||
|
||||
frame.syncword = get_bits(fin,8)
|
||||
if frame.syncword != 156:
|
||||
print "incorrect syncword ", frame.syncword
|
||||
# i = 0
|
||||
# while available_bytes:
|
||||
# if i%10 == 0:
|
||||
# print
|
||||
# bt = get_bits(fin,8)
|
||||
# print "0x%0x "% bt,
|
||||
# available_bytes -= 1
|
||||
# i+=1
|
||||
print ("out of sync %02x" % frame.syncword)
|
||||
return -1
|
||||
frame.sampling_frequency = get_bits(fin,2)
|
||||
frame.nr_blocks = nr_blocks[get_bits(fin,2)]
|
||||
@ -64,7 +73,7 @@ def sbc_unpack_frame(fin, available_bytes, frame):
|
||||
for ch in range(frame.nr_channels):
|
||||
for sb in range(frame.nr_subbands):
|
||||
frame.audio_sample[blk][ch][sb] = get_bits(fin, frame.bits[ch][sb])
|
||||
# print "block %2d - audio sample: %s" % (blk, frame.audio_sample[blk][0])
|
||||
#print "block %2d - audio sample: %s" % (blk, frame.audio_sample[blk][0])
|
||||
|
||||
drop_remaining_bits()
|
||||
return 0
|
||||
@ -210,7 +219,8 @@ if __name__ == "__main__":
|
||||
while True:
|
||||
sbc_decoder_frame = SBCFrame()
|
||||
if frame_count % 200 == 0:
|
||||
print "== Frame %d ==" % (frame_count)
|
||||
print "== Frame %d == %d" % (frame_count, fin.tell())
|
||||
|
||||
|
||||
err = sbc_unpack_frame(fin, file_size - fin.tell(), sbc_decoder_frame)
|
||||
|
||||
|
@ -103,6 +103,7 @@ try:
|
||||
if subband_frame_count % 200 == 0:
|
||||
print ("== Frame %d ==" % subband_frame_count)
|
||||
|
||||
|
||||
actual_frame = get_actual_frame(fin)
|
||||
|
||||
|
||||
@ -112,6 +113,10 @@ try:
|
||||
actual_frame.allocation_method)
|
||||
|
||||
err = sbc_compare_headers(subband_frame_count, actual_frame, expected_frame)
|
||||
print ("%03d : %s %s"%( subband_frame_count,
|
||||
channel_mode_to_str(actual_frame.channel_mode),
|
||||
channel_mode_to_str(expected_frame.channel_mode)))
|
||||
|
||||
if err < 0:
|
||||
print ("Headers differ \n%s\n%s" % (actual_frame, expected_frame))
|
||||
exit(1)
|
||||
@ -129,7 +134,7 @@ try:
|
||||
except TypeError:
|
||||
fin_expected.close()
|
||||
fin.close()
|
||||
print ("DONE, max MSE PCM error %d" % max_error)
|
||||
print ("DONE, max MSE PCM error %f" % max_error)
|
||||
exit(0)
|
||||
|
||||
except IOError as e:
|
||||
|
@ -139,6 +139,9 @@ try:
|
||||
actual_frame = get_actual_frame(fin, nr_blocks, nr_subbands, nr_channels, bitpool, sampling_frequency, allocation_method)
|
||||
expected_frame = get_expected_frame(fin_expected)
|
||||
|
||||
print actual_frame.sb_sample
|
||||
print expected_frame.sb_sample
|
||||
|
||||
err = sbc_compare_headers(subband_frame_count, actual_frame, expected_frame)
|
||||
if err < 0:
|
||||
exit(1)
|
||||
|
Loading…
x
Reference in New Issue
Block a user