From 1bd8157e8c1d5bbfe83038c2ea9e6b99d35fcb36 Mon Sep 17 00:00:00 2001 From: Milanka Ringwald Date: Fri, 20 May 2016 10:32:31 +0200 Subject: [PATCH] measure time im ms for synthesis and analysis --- test/sbc/sbc.py | 3 +++ test/sbc/sbc_decoder.py | 38 +++++++++++++++++++++++++++++++++++--- test/sbc/sbc_encoder.py | 24 ++++++++++++++++++++++-- 3 files changed, 60 insertions(+), 5 deletions(-) diff --git a/test/sbc/sbc.py b/test/sbc/sbc.py index 9b1866ef4..6864eac8f 100644 --- a/test/sbc/sbc.py +++ b/test/sbc/sbc.py @@ -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 diff --git a/test/sbc/sbc_decoder.py b/test/sbc/sbc_decoder.py index a69b1814b..c01222ebc 100755 --- a/test/sbc/sbc_decoder.py +++ b/test/sbc/sbc_decoder.py @@ -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 @@ -126,7 +128,7 @@ def sbc_frame_synthesis(frame, ch, blk, proto_table): for i in range(M): N = np.cos((i+0.5)*(k+M/2)*np.pi/M) V[ch][k] += N * S[i] - + for i in range(5): for j in range(M): 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]) +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 @@ -231,15 +249,29 @@ 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) diff --git a/test/sbc/sbc_encoder.py b/test/sbc/sbc_encoder.py index 0783cc082..0ecb07b34 100755 --- a/test/sbc/sbc_encoder.py +++ b/test/sbc/sbc_encoder.py @@ -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) @@ -52,7 +53,22 @@ 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,7 +180,11 @@ 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: print(usage)