measure time im ms for synthesis and analysis

This commit is contained in:
Milanka Ringwald 2016-05-20 10:32:31 +02:00
parent ef8a7a12f4
commit 1bd8157e8c
3 changed files with 60 additions and 5 deletions

View File

@ -3,6 +3,8 @@ import numpy as np
import wave
import struct
import sys
import time
# channel mode
MONO = 0
@ -20,6 +22,7 @@ sampling_frequencies = [16000, 32000, 44100, 48000]
nr_blocks = [4, 8, 12, 16]
nr_subbands = [4, 8]
time_ms = lambda: int(round(time.time() * 1000))
def allocation_method_to_str(allocation_method):
global allocation_methods

View File

@ -6,6 +6,8 @@ import sys
from sbc import *
V = np.zeros(shape = (2, 10*2*8))
total_time_ms = 0
implementation = "SIG"
def sbc_unpack_frame(fin, available_bytes, frame):
if available_bytes == 0:
@ -103,7 +105,7 @@ def sbc_reconstruct_subband_samples(frame):
return 0
def sbc_frame_synthesis(frame, ch, blk, proto_table):
def sbc_frame_synthesis_sig(frame, ch, blk, proto_table):
global V
M = frame.nr_subbands
L = 10 * M
@ -144,6 +146,22 @@ def sbc_frame_synthesis(frame, ch, blk, proto_table):
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):
if frame.nr_subbands == 4:
proto_table = Proto_4_40
@ -232,14 +250,28 @@ if __name__ == "__main__":
write_wav_file(fout, sbc_decoder_frame)
frame_count += 1
if frame_count == 1:
break
except TypeError as err:
if not fout:
print err
else:
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)
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:
print(usage)
sys.exit(1)

View File

@ -6,6 +6,7 @@ import sys
from sbc import *
X = np.zeros(shape=(2,80), dtype = np.int16)
implementation = "SIG"
def fetch_samples_for_next_sbc_frame(fin, frame):
raw_data = fin.readframes(frame.nr_blocks * frame.nr_subbands)
@ -53,6 +54,21 @@ def sbc_frame_analysis(frame, ch, blk, C):
for sb in range(M):
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):
if frame.nr_subbands == 4:
C = Proto_4_40
@ -164,6 +180,10 @@ if __name__ == "__main__":
fin.close()
fout.close()
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: