diff --git a/gsrp_tdoa_hyperres.py b/gsrp_tdoa_hyperres.py index b3b29d68e8ee260b9d0104480ef53a53391b19ad..8ae9549dfe370095d3a41b3d14e012c7a8d94636 100755 --- a/gsrp_tdoa_hyperres.py +++ b/gsrp_tdoa_hyperres.py @@ -79,7 +79,7 @@ def corr(data, pos, w_size, max_tdoa, decimate=1, mode='prepare', hyper=True, ve mat[k, j - 1] = 1 v1[k] = i v2[k] = j - dw_size = w_size // decimate + dw_size = (w_size // decimate) & ~1 if mode == 'prepare': slices = slicer(-(cc_size // 2), cc_size // 2, (num_channels - 1), 16) tausf = [] @@ -136,7 +136,7 @@ def corr(data, pos, w_size, max_tdoa, decimate=1, mode='prepare', hyper=True, ve cc -= cc.min(-1, keepdims=True) maxs = cc.max(1, keepdims=True) cc /= maxs - maxs = np.log10(maxs.prod()) + maxs = np.log10(maxs).sum() if mode == 'prepare': tdoas[i, :2], index = c_corr.c_corr_at(cc, tausf) tdoas[i, 2:] = ((tausf[:, index] + dw_size // 2) % dw_size) - dw_size // 2 @@ -183,6 +183,10 @@ def main(args): if sound.shape[1] < 2: raise ValueError(f'{BColors.FAIL}{args.infile} with channels {args.channel} has not enough channels' f'{BColors.ENDC}') + elif sound.shape[1] == 2 and args.mode == 'smart': + print(f'{BColors.WARNING}{args.infile} as only 2 channels which is not supported by mode smart. Switching to ' + f'on-the-fly mode.{BColors.ENDC}') + args.mode = 'on-the-fly' if args.inverse is not None: for c in args.inverse: @@ -229,7 +233,7 @@ def main(args): result1[:, 0] /= sr result1[:, 3:] /= sr if args.temporal else sr/args.decimate columns = ','.join(['pos', 'db_norm', 'db'] + [f't{i}{j}'for i, j in combinations(range(sound.shape[1]), 2)]) - stem, ext = args.outfile.rsplit('.', 1) + stem, ext = os.path.splitext(args.outfile) if ext == 'npy': np.save(args.outfile, result1) if not args.no_hyperres: @@ -359,9 +363,10 @@ if __name__ == "__main__": sys.exit(main(args)) except Exception as e: - trace = getattr(sys, 'gettrace', None) + trace = getattr(sys, 'gettrace', None) # if debug is activated, raise the error if trace is not None: if trace(): raise e from None - print(f'{BColors.WARNING}{type(e).__name__}: {e}{BColors.ENDC}') + print(f'{BColors.WARNING}{type(e).__name__}: {e}\n' + f'Enable Debugger for more info{BColors.ENDC}') sys.exit(2)