mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-04-16 08:42:28 +00:00
measure time im ms for synthesis and analysis
This commit is contained in:
parent
ef8a7a12f4
commit
1bd8157e8c
@ -3,6 +3,8 @@ import numpy as np
|
|||||||
import wave
|
import wave
|
||||||
import struct
|
import struct
|
||||||
import sys
|
import sys
|
||||||
|
import time
|
||||||
|
|
||||||
|
|
||||||
# channel mode
|
# channel mode
|
||||||
MONO = 0
|
MONO = 0
|
||||||
@ -20,6 +22,7 @@ sampling_frequencies = [16000, 32000, 44100, 48000]
|
|||||||
nr_blocks = [4, 8, 12, 16]
|
nr_blocks = [4, 8, 12, 16]
|
||||||
nr_subbands = [4, 8]
|
nr_subbands = [4, 8]
|
||||||
|
|
||||||
|
time_ms = lambda: int(round(time.time() * 1000))
|
||||||
|
|
||||||
def allocation_method_to_str(allocation_method):
|
def allocation_method_to_str(allocation_method):
|
||||||
global allocation_methods
|
global allocation_methods
|
||||||
|
@ -6,6 +6,8 @@ import sys
|
|||||||
from sbc import *
|
from sbc import *
|
||||||
|
|
||||||
V = np.zeros(shape = (2, 10*2*8))
|
V = np.zeros(shape = (2, 10*2*8))
|
||||||
|
total_time_ms = 0
|
||||||
|
implementation = "SIG"
|
||||||
|
|
||||||
def sbc_unpack_frame(fin, available_bytes, frame):
|
def sbc_unpack_frame(fin, available_bytes, frame):
|
||||||
if available_bytes == 0:
|
if available_bytes == 0:
|
||||||
@ -103,7 +105,7 @@ def sbc_reconstruct_subband_samples(frame):
|
|||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
def sbc_frame_synthesis(frame, ch, blk, proto_table):
|
def sbc_frame_synthesis_sig(frame, ch, blk, proto_table):
|
||||||
global V
|
global V
|
||||||
M = frame.nr_subbands
|
M = frame.nr_subbands
|
||||||
L = 10 * M
|
L = 10 * M
|
||||||
@ -126,7 +128,7 @@ def sbc_frame_synthesis(frame, ch, blk, proto_table):
|
|||||||
for i in range(M):
|
for i in range(M):
|
||||||
N = np.cos((i+0.5)*(k+M/2)*np.pi/M)
|
N = np.cos((i+0.5)*(k+M/2)*np.pi/M)
|
||||||
V[ch][k] += N * S[i]
|
V[ch][k] += N * S[i]
|
||||||
|
|
||||||
for i in range(5):
|
for i in range(5):
|
||||||
for j in range(M):
|
for j in range(M):
|
||||||
U[i*M2+j] = V[ch][i*2*M2+j]
|
U[i*M2+j] = V[ch][i*2*M2+j]
|
||||||
@ -144,6 +146,22 @@ def sbc_frame_synthesis(frame, ch, blk, proto_table):
|
|||||||
frame.pcm[ch][offset + j] = np.int16(frame.X[j])
|
frame.pcm[ch][offset + j] = np.int16(frame.X[j])
|
||||||
|
|
||||||
|
|
||||||
|
def sbc_frame_synthesis(frame, ch, blk, proto_table):
|
||||||
|
global total_time_ms, implementation
|
||||||
|
|
||||||
|
t1 = time_ms()
|
||||||
|
if implementation == "SIG":
|
||||||
|
sbc_frame_synthesis_sig(frame, ch, blk, proto_table)
|
||||||
|
elif implementation == "V1":
|
||||||
|
sbc_frame_synthesis_v1(frame, ch, blk, proto_table)
|
||||||
|
else:
|
||||||
|
print ("synthesis %s not implemented" % implementation)
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
t2 = time_ms()
|
||||||
|
total_time_ms += t2-t1
|
||||||
|
|
||||||
|
|
||||||
def sbc_synthesis(frame):
|
def sbc_synthesis(frame):
|
||||||
if frame.nr_subbands == 4:
|
if frame.nr_subbands == 4:
|
||||||
proto_table = Proto_4_40
|
proto_table = Proto_4_40
|
||||||
@ -231,15 +249,29 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
write_wav_file(fout, sbc_decoder_frame)
|
write_wav_file(fout, sbc_decoder_frame)
|
||||||
frame_count += 1
|
frame_count += 1
|
||||||
|
|
||||||
|
if frame_count == 1:
|
||||||
|
break
|
||||||
|
|
||||||
except TypeError as err:
|
except TypeError as err:
|
||||||
if not fout:
|
if not fout:
|
||||||
print err
|
print err
|
||||||
else:
|
else:
|
||||||
fout.close()
|
fout.close()
|
||||||
print ("DONE, SBC file %s decoded into WAV file %s " % (infile, wavfile))
|
if frame_count > 0:
|
||||||
|
print ("DONE, SBC file %s decoded into WAV file %s " % (infile, wavfile))
|
||||||
|
print ("Sythesis average %d ms/frame", total_time_ms/frame_count)
|
||||||
|
else:
|
||||||
|
print ("No frame found")
|
||||||
exit(0)
|
exit(0)
|
||||||
|
|
||||||
|
fout.close()
|
||||||
|
if frame_count > 0:
|
||||||
|
print ("DONE: SBC file %s decoded into WAV file %s " % (infile, wavfile))
|
||||||
|
print ("Average sythesis time per frame: %d ms/frame" % (total_time_ms/frame_count))
|
||||||
|
else:
|
||||||
|
print ("No frame found")
|
||||||
|
|
||||||
except IOError as e:
|
except IOError as e:
|
||||||
print(usage)
|
print(usage)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
@ -6,6 +6,7 @@ import sys
|
|||||||
from sbc import *
|
from sbc import *
|
||||||
|
|
||||||
X = np.zeros(shape=(2,80), dtype = np.int16)
|
X = np.zeros(shape=(2,80), dtype = np.int16)
|
||||||
|
implementation = "SIG"
|
||||||
|
|
||||||
def fetch_samples_for_next_sbc_frame(fin, frame):
|
def fetch_samples_for_next_sbc_frame(fin, frame):
|
||||||
raw_data = fin.readframes(frame.nr_blocks * frame.nr_subbands)
|
raw_data = fin.readframes(frame.nr_blocks * frame.nr_subbands)
|
||||||
@ -52,7 +53,22 @@ def sbc_frame_analysis(frame, ch, blk, C):
|
|||||||
|
|
||||||
for sb in range(M):
|
for sb in range(M):
|
||||||
frame.sb_sample[blk][ch][sb] = S[sb]
|
frame.sb_sample[blk][ch][sb] = S[sb]
|
||||||
|
|
||||||
|
|
||||||
|
def sbc_frame_analysis(frame, ch, blk, proto_table):
|
||||||
|
global total_time_ms, implementation
|
||||||
|
|
||||||
|
t1 = time_ms()
|
||||||
|
if implementation == "SIG":
|
||||||
|
sbc_frame_analysis_sig(frame, ch, blk, proto_table)
|
||||||
|
else:
|
||||||
|
print ("Analysis %s not implemented" % implementation)
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
t2 = time_ms()
|
||||||
|
total_time_ms += t2-t1
|
||||||
|
|
||||||
|
|
||||||
def sbc_analysis(frame):
|
def sbc_analysis(frame):
|
||||||
if frame.nr_subbands == 4:
|
if frame.nr_subbands == 4:
|
||||||
C = Proto_4_40
|
C = Proto_4_40
|
||||||
@ -164,7 +180,11 @@ if __name__ == "__main__":
|
|||||||
fin.close()
|
fin.close()
|
||||||
fout.close()
|
fout.close()
|
||||||
print("DONE, WAV file %s encoded into SBC file %s " % (infile, sbcfile))
|
print("DONE, WAV file %s encoded into SBC file %s " % (infile, sbcfile))
|
||||||
|
if frame_count > 0:
|
||||||
|
print ("Average analysis time per frame: %d ms/frame" % (total_time_ms/frame_count))
|
||||||
|
else:
|
||||||
|
print ("No frame found")
|
||||||
|
|
||||||
|
|
||||||
except IOError as e:
|
except IOError as e:
|
||||||
print(usage)
|
print(usage)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user