sbc: working JOINT_STEREO, bug left in STEREO, check div 2 in decoder u=in the JOINT STEREO reconstruction part

This commit is contained in:
Milanka Ringwald 2016-05-19 11:31:55 +02:00
parent 57f2bc22c3
commit ba345fb8f4
3 changed files with 15 additions and 14 deletions

View File

@ -164,7 +164,7 @@ def calculate_channel_mode_and_scale_factors(frame):
frame.channel_mode = STEREO
frame.join = np.zeros(frame.nr_subbands, dtype = np.uint8)
return
sb_sample = np.zeros(shape = (frame.nr_blocks,2,frame.nr_subbands), dtype = np.int32)
for blk in range(frame.nr_blocks):
for sb in range(frame.nr_subbands):
@ -177,10 +177,10 @@ def calculate_channel_mode_and_scale_factors(frame):
suma = frame.scale_factor[0][sb] + frame.scale_factor[1][sb]
sumb = scale_factor[0][sb] + scale_factor[1][sb]
if suma >= sumb:
if suma > sumb:
frame.channel_mode = JOINT_STEREO
frame.join[sb] = 1
frame.scale_factor[0][sb] = scale_factor[0][sb]
frame.scale_factor[1][sb] = scale_factor[1][sb]
frame.scalefactor[0][sb] = scalefactor[0][sb]
@ -206,7 +206,7 @@ class SBCFrame:
scale_factor = np.zeros(shape=(2, 8), dtype = np.int32)
scalefactor = np.zeros(shape=(2, 8), dtype = np.int32)
audio_sample = np.zeros(shape = (16,2,8), dtype = np.uint16)
sb_sample = np.zeros(shape = (16,2,8), dtype = np.uint16)
sb_sample = np.zeros(shape = (16,2,8), dtype = np.int32)
X = np.zeros(8, dtype = np.int16)
EX = np.zeros(8)
pcm = np.zeros(shape=(2, 8*16), dtype = np.int16)
@ -228,7 +228,7 @@ class SBCFrame:
self.scale_factor = np.zeros(shape=(nr_channels, nr_subbands), dtype = np.int32)
self.scalefactor = np.zeros(shape=(nr_channels, nr_subbands), dtype = np.int32)
self.audio_sample = np.zeros(shape=(nr_blocks, nr_channels, nr_subbands), dtype = np.uint16)
self.sb_sample = np.zeros(shape=(nr_blocks, nr_channels, nr_subbands), dtype = np.uint16)
self.sb_sample = np.zeros(shape=(nr_blocks, nr_channels, nr_subbands), dtype = np.int32)
self.levels = np.zeros(shape=(nr_channels, nr_subbands), dtype = np.int32)
self.pcm = np.zeros(shape=(nr_channels, nr_subbands*nr_blocks), dtype = np.int16)
self.join = np.zeros(nr_subbands, dtype = np.uint8)

View File

@ -18,8 +18,9 @@ def sbc_unpack_frame(fin, available_bytes, frame):
return -1
frame.sampling_frequency = get_bits(fin,2)
frame.nr_blocks = nr_blocks[get_bits(fin,2)]
frame.channel_mode = get_bits(fin,2)
if frame.channel_mode == MONO:
frame.nr_channels = 1
else:
@ -77,8 +78,6 @@ def sbc_reconstruct_subband_samples(frame):
for ch in range(frame.nr_channels):
for sb in range(frame.nr_subbands):
frame.levels[ch][sb] = pow(2.0, frame.bits[ch][sb]) - 1
joint_stereo_const = 1
for blk in range(frame.nr_blocks):
for ch in range(frame.nr_channels):
@ -87,7 +86,7 @@ def sbc_reconstruct_subband_samples(frame):
AS = frame.audio_sample[blk][ch][sb]
L = frame.levels[ch][sb]
SF = frame.scalefactor[ch][sb]
frame.sb_sample[blk][ch][sb] = SF * ((AS*2.0+1.0) / (L) -1.0 )
frame.sb_sample[blk][ch][sb] = SF * ((AS*2.0+1.0) / L -1.0 )
else:
frame.sb_sample[blk][ch][sb] = 0
@ -98,8 +97,8 @@ def sbc_reconstruct_subband_samples(frame):
if frame.join[sb]==1:
ch_a = frame.sb_sample[blk][0][sb] + frame.sb_sample[blk][1][sb]
ch_b = frame.sb_sample[blk][0][sb] - frame.sb_sample[blk][1][sb]
frame.sb_sample[blk][0][sb] = ch_a
frame.sb_sample[blk][1][sb] = ch_b
frame.sb_sample[blk][0][sb] = ch_a/2
frame.sb_sample[blk][1][sb] = ch_b/2
return 0

View File

@ -103,7 +103,7 @@ def sbc_quantization(frame):
# if frame.channel_mode == JOINT_STEREO and frame.join[sb]:
# SB = SB * 2
frame.audio_sample[blk][ch][sb] = np.uint16(((SB * L / SF + L) - 1.0)/2.0)
else:
frame.audio_sample[blk][ch][sb] = 0
@ -158,8 +158,10 @@ if __name__ == "__main__":
sbc_encode(sbc_encoder_frame)
sbc_write_frame(fout, sbc_encoder_frame)
# if subband_frame_count == 1:
# exit(0)
if subband_frame_count == 0:
print sbc_encoder_frame.channel_mode
print sbc_encoder_frame
audio_frame_count += nr_samples
subband_frame_count += 1