sbc: fiz loading stereo wav file

This commit is contained in:
Milanka Ringwald 2016-05-18 19:38:57 +02:00
parent c9498b1266
commit 9462b3da58
3 changed files with 17 additions and 18 deletions

View File

@ -165,7 +165,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.uint16)
for blk in range(frame.nr_blocks):
for sb in range(frame.nr_subbands):
@ -303,6 +303,7 @@ def sbc_bit_allocation_stereo_joint(frame):
if bitneed[ch][sb] > max_bitneed:
max_bitneed = bitneed[ch][sb]
# calculate how many bitslices fit into the bitpool
bitcount = 0
slicecount = 0
@ -397,7 +398,8 @@ def sbc_bit_allocation_mono_dual(frame):
for sb in range(frame.nr_subbands):
if bitneed[ch][sb] > max_bitneed:
max_bitneed = bitneed[ch][sb]
print "mono: bitneed", bitneed, max_bitneed
# calculate how many bitslices fit into the bitpool
bitcount = 0
slicecount = 0
@ -419,6 +421,7 @@ def sbc_bit_allocation_mono_dual(frame):
bitcount = bitcount + slicecount
bitslice = bitslice - 1
print "mono: bitslice", bitslice
for sb in range(frame.nr_subbands):
if bitneed[ch][sb] < bitslice+2 :
bits[ch][sb]=0;

View File

@ -9,13 +9,13 @@ X = np.zeros(shape=(2,80), dtype = np.int16)
def fetch_samples_for_next_sbc_frame(fin, frame):
nr_samples = frame.nr_blocks * frame.nr_subbands
nr_samples = frame.nr_blocks * frame.nr_subbands
raw_data = fin.readframes(nr_samples) # Returns byte data
fmt = "%ih" % (len(raw_data) / 2)
data = struct.unpack(fmt, raw_data)
if frame.nr_channels == 2:
for i in range(len(data)/2 - 1):
for i in range(len(data)/2):
frame.pcm[0][i] = data[2*i]
frame.pcm[1][i] = data[2*i+1]
else:
@ -40,7 +40,6 @@ def sbc_frame_analysis(frame, ch, blk, C):
X[ch][i] = X[ch][i-M]
for i in range(M-1, -1, -1):
X[ch][i] = frame.EX[M-1-i]
for i in range(L):
Z[i] = X[ch][i] * C[i]
@ -55,7 +54,7 @@ def sbc_frame_analysis(frame, ch, blk, C):
for sb in range(M):
frame.sb_sample[blk][ch][sb] = S[sb]
def sbc_analysis(frame):
if frame.nr_subbands == 4:
C = Proto_4_40
@ -154,8 +153,8 @@ if __name__ == "__main__":
sbc_encode(sbc_encoder_frame)
sbc_write_frame(fout, sbc_encoder_frame)
# if subband_frame_count == 0:
# exit(0)
if subband_frame_count == 1:
exit(0)
audio_frame_count += nr_samples
subband_frame_count += 1

View File

@ -61,15 +61,15 @@ def sbc_compare_headers(frame_count, actual_frame, expected_frame):
if mse(actual_frame.scale_factor, expected_frame.scale_factor) > 0:
print "scale_factor error \nE:\n %s \nD:\n %s" % (actual_frame.scale_factor, expected_frame.scale_factor)
print "scale_factor error %d \nE:\n %s \nD:\n %s" % (frame_count, actual_frame.scale_factor, expected_frame.scale_factor)
return -1
if mse(actual_frame.scalefactor, expected_frame.scalefactor) > 0:
print "scalefactor error \nE:\n %s \nD:\n %s" % (actual_frame.scalefactor, expected_frame.scalefactor)
print "scalefactor error %d \nE:\n %s \nD:\n %s" % (frame_count, actual_frame.scalefactor, expected_frame.scalefactor)
return -1
if mse(actual_frame.bits, expected_frame.bits) > 0:
print "bits error \nE:\n %s \nD:\n %s" % (actual_frame.bits, expected_frame.bits)
print "bits error %d \nE:\n %s \nD:\n %s" % (frame_count, actual_frame.bits, expected_frame.bits)
return -1
if actual_frame.crc_check != expected_frame.crc_check:
@ -141,23 +141,20 @@ try:
err = sbc_compare_headers(subband_frame_count, actual_frame, expected_frame)
if err < 0:
exit(1)
err = sbc_compare_audio_frames(subband_frame_count, actual_frame, expected_frame)
if err < 0:
exit(1)
if subband_frame_count == 0:
print actual_frame
audio_frame_count += nr_samples
subband_frame_count += 1
print "DONE, max MSE audio sample error %d", max_error
print ("DONE, max MSE audio sample error %f" % max_error)
fin.close()
fin_expected.close()
except TypeError:
print "DONE, max MSE audio sample error %d", max_error
print ("DONE, max MSE audio sample error %f" % max_error)
fin.close()
fin_expected.close()