mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-01-25 09:35:42 +00:00
cleanup prints
This commit is contained in:
parent
c21a9c2f36
commit
41a4a18d9c
@ -4,7 +4,6 @@ import wave
|
||||
import struct
|
||||
import sys
|
||||
|
||||
|
||||
# channel mode
|
||||
MONO = 0
|
||||
DUAL_CHANNEL = 1
|
||||
@ -172,7 +171,6 @@ class SBCFrame:
|
||||
return res
|
||||
|
||||
|
||||
|
||||
def sbc_bit_allocation_stereo_joint(frame, ch):
|
||||
bitneed = np.zeros(shape=(frame.nr_channels, frame.nr_subbands))
|
||||
bits = np.zeros(shape=(frame.nr_channels, frame.nr_subbands))
|
||||
@ -206,8 +204,6 @@ def sbc_bit_allocation_stereo_joint(frame, ch):
|
||||
for sb in range(frame.nr_subbands):
|
||||
if bitneed[ch][sb] > max_bitneed:
|
||||
max_bitneed = bitneed[ch][sb]
|
||||
|
||||
# # print "max_bitneed: ", max_bitneed
|
||||
|
||||
# calculate how many bitslices fit into the bitpool
|
||||
bitcount = 0
|
||||
@ -227,8 +223,6 @@ def sbc_bit_allocation_stereo_joint(frame, ch):
|
||||
if bitcount + slicecount >= frame.bitpool:
|
||||
break
|
||||
|
||||
# print "bitcount %d, slicecount %d" % (bitcount, slicecount)
|
||||
|
||||
if bitcount + slicecount == frame.bitpool:
|
||||
bitcount = bitcount + slicecount
|
||||
bitslice = bitslice - 1
|
||||
@ -241,7 +235,6 @@ def sbc_bit_allocation_stereo_joint(frame, ch):
|
||||
else:
|
||||
bits[ch][sb] = min(bitneed[ch][sb]-bitslice,16)
|
||||
|
||||
|
||||
ch = 0
|
||||
sb = 0
|
||||
while bitcount < frame.bitpool and sb < frame.nr_subbands:
|
||||
@ -304,13 +297,11 @@ 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 "max_bitneed: ", max_bitneed
|
||||
|
||||
|
||||
# calculate how many bitslices fit into the bitpool
|
||||
bitcount = 0
|
||||
slicecount = 0
|
||||
bitslice = max_bitneed + 1 #/* init just above the largest sf */
|
||||
bitslice = max_bitneed + 1
|
||||
|
||||
while True:
|
||||
bitslice = bitslice - 1
|
||||
@ -324,20 +315,16 @@ def sbc_bit_allocation_mono_dual(frame):
|
||||
if bitcount + slicecount >= frame.bitpool:
|
||||
break
|
||||
|
||||
#print "bitcount %d, slicecount %d" % (bitcount, slicecount)
|
||||
|
||||
if bitcount + slicecount == frame.bitpool:
|
||||
bitcount = bitcount + slicecount
|
||||
bitslice = bitslice - 1
|
||||
|
||||
# bits are distributed until the last bitslice is reached
|
||||
for sb in range(frame.nr_subbands):
|
||||
if bitneed[ch][sb] < bitslice+2 :
|
||||
bits[ch][sb]=0;
|
||||
else:
|
||||
bits[ch][sb] = min(bitneed[ch][sb]-bitslice,16)
|
||||
|
||||
# The remaining bits are allocated starting at subband 0.
|
||||
sb = 0
|
||||
while bitcount < frame.bitpool and sb < frame.nr_subbands:
|
||||
if bits[ch][sb] >= 2 and bits[ch][sb] < 16:
|
||||
@ -377,30 +364,9 @@ def sbc_sampling_frequency_index(sample_rate):
|
||||
break
|
||||
return sbc_sampling_frequency_index
|
||||
|
||||
# static uint8_t sbc_crc8(const uint8_t * data, size_t len)
|
||||
# 158 {
|
||||
# 159 uint8_t crc = 0x0f;
|
||||
# 160 size_t i;
|
||||
# 161 uint8_t octet;
|
||||
# 162
|
||||
# 163 for (i = 0; i < len / 8; i++)
|
||||
# 164 crc = crc_table[crc ^ data[i]];
|
||||
# 165
|
||||
# 166 octet = data[i];
|
||||
# 167 for (i = 0; i < len % 8; i++) {
|
||||
# 168 char bit = ((octet ^ crc) & 0x80) >> 7;
|
||||
# 169
|
||||
# 170 crc = ((crc & 0x7f) << 1) ^ (bit ? 0x1d : 0);
|
||||
# 171
|
||||
# 172 octet = octet << 1;
|
||||
# 173 }
|
||||
# 174
|
||||
# 175 return crc;
|
||||
# 176 }
|
||||
|
||||
def sbc_crc8(data, data_len):
|
||||
crc = 0x0f
|
||||
|
||||
j = 0
|
||||
for i in range(data_len / 8):
|
||||
crc = crc_table[crc ^ data[i]]
|
||||
@ -463,7 +429,7 @@ def calculate_crc(frame):
|
||||
for ch in range(frame.nr_channels):
|
||||
for sb in range(frame.nr_subbands):
|
||||
add_bits(frame.scale_factor[ch][sb], 4)
|
||||
# bitstream_len = 16 + frame.nr_subbands + frame.nr_channels * frame.nr_subbands * 4
|
||||
|
||||
bitstream_len = (bitstream_index + 1) * 8
|
||||
if bitstream_bits_available:
|
||||
bitstream_len += (8-bitstream_bits_available)
|
||||
|
@ -116,15 +116,8 @@ def sbc_unpack_frame(fin, frame):
|
||||
AS = frame.audio_sample[blk][ch][sb]
|
||||
SF = frame.scalefactor[ch][sb]
|
||||
L = frame.levels[ch][sb]
|
||||
|
||||
SB = SF * ((AS*2.0+1.0) / L -1.0 )
|
||||
# if sb == 3:
|
||||
# print "decoder SF, L, AS ", SF, L, AS
|
||||
frame.sb_sample[blk][ch][sb] = SB
|
||||
# tmpa = (((frame.audio_sample[blk][ch][sb] << 16) | 0x8000) / levels[ch][sb] ) - 0x8000
|
||||
# tmpb = tmpa >> 3
|
||||
# frame.sb_sample[blk][ch][sb] = tmpb * frame.scalefactor[ch][sb]
|
||||
|
||||
|
||||
frame.sb_sample[blk][ch][sb] = SF * ((AS*2.0+1.0) / L -1.0 )
|
||||
else:
|
||||
frame.sb_sample[blk][ch][sb] = 0
|
||||
|
||||
@ -137,14 +130,7 @@ def sbc_unpack_frame(fin, frame):
|
||||
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
|
||||
|
||||
|
||||
# print "Scale factors ", frame.scale_factor[0]
|
||||
|
||||
# print "\nReconstructed subband samples: "
|
||||
# for blk in range(frame.nr_blocks):
|
||||
# print "block %2d - recon. sample: %s" % (blk, frame.sb_sample[blk][0])
|
||||
# print
|
||||
return 0
|
||||
|
||||
|
||||
|
@ -5,7 +5,7 @@ import struct
|
||||
import sys
|
||||
from sbc import *
|
||||
|
||||
X = np.zeros(40)
|
||||
X = np.zeros(80)
|
||||
|
||||
def fetch_samples_for_next_sbc_frame(fin, nr_audio_frames, frame):
|
||||
raw_data = fin.readframes(nr_audio_frames) # Returns byte data
|
||||
@ -16,11 +16,6 @@ def fetch_samples_for_next_sbc_frame(fin, nr_audio_frames, frame):
|
||||
frame.pcm = np.array(struct.unpack(fmt, raw_data))
|
||||
del raw_data
|
||||
|
||||
# channels = [ [] for ch in range(frame.nr_channels) ]
|
||||
# for index, value in enumerate(integer_data):
|
||||
# bucket = index % nr_channels
|
||||
# channels[bucket].append(value)
|
||||
|
||||
|
||||
def sbc_analyse(frame, ch, blk, C, debug):
|
||||
global X
|
||||
@ -72,25 +67,18 @@ def sbc_encode(frame,debug):
|
||||
return -1
|
||||
|
||||
frame.sb_sample = np.ndarray(shape=(frame.nr_blocks, frame.nr_channels, frame.nr_subbands))
|
||||
|
||||
# channels = [ [] for ch in range(frame.nr_channels) ]
|
||||
# for index, value in enumerate(frame.pcm):
|
||||
# bucket = index % frame.nr_channels
|
||||
# channels[bucket].append(value)
|
||||
|
||||
# print "encoder pcm ", frame.pcm
|
||||
|
||||
index = 0
|
||||
for ch in range(frame.nr_channels):
|
||||
for blk in range(frame.nr_blocks):
|
||||
for sb in range(frame.nr_subbands):
|
||||
frame.EX[sb] = frame.pcm[index] #channels[ch][blk * frame.nr_subbands + sb]
|
||||
frame.EX[sb] = frame.pcm[index]
|
||||
index+=1
|
||||
sbc_analyse(frame, ch, blk, proto_table,debug)
|
||||
sbc_quantization(frame)
|
||||
|
||||
|
||||
def should_use_joint_coding(frame):
|
||||
# TODO: implement this
|
||||
return False
|
||||
|
||||
def calculate_scalefactor(max_subbandsample):
|
||||
@ -128,11 +116,9 @@ def frame_to_bitstream(frame):
|
||||
for sb in range(frame.nr_subbands):
|
||||
add_bits(frame.audio_sample[blk][ch][sb], frame.bits[ch][sb])
|
||||
|
||||
# bitstream_len = 16 + frame.nr_subbands + frame.nr_channels * frame.nr_subbands * 4
|
||||
return bitstream
|
||||
|
||||
def sbc_quantization(frame):
|
||||
|
||||
frame.join = np.zeros(frame.nr_subbands, dtype = np.uint8)
|
||||
if should_use_joint_coding(frame):
|
||||
return
|
||||
@ -169,8 +155,8 @@ def sbc_quantization(frame):
|
||||
SB = frame.sb_sample[blk][ch][sb]
|
||||
SF = frame.scalefactor[ch][sb]
|
||||
L = frame.levels[ch][sb]
|
||||
AS = np.uint16(((SB * L / SF + L) - 1.0)/2.0)
|
||||
frame.audio_sample[blk][ch][sb] = AS
|
||||
|
||||
frame.audio_sample[blk][ch][sb] = np.uint16(((SB * L / SF + L) - 1.0)/2.0)
|
||||
else:
|
||||
frame.audio_sample[blk][ch][sb] = 0
|
||||
|
||||
|
@ -151,7 +151,7 @@ try:
|
||||
sbc_decoder_frame.bitpool)
|
||||
|
||||
sbc_encoder_frame.pcm = np.array(sbc_decoder_frame.pcm)
|
||||
# TODO: joi field
|
||||
# TODO: join field
|
||||
# TODO: clear memory
|
||||
|
||||
# sbc_encoder_frame.sb_sample = np.array(sbc_decoder_frame.sb_sample)
|
||||
|
Loading…
x
Reference in New Issue
Block a user