Ejemplo n.º 1
0
def compute_spatial_feats(args, S):
    if args.type == "srp":
        num_ffts = nextpow2(
            args.frame_len) if args.round_power_of_two else args.frame_len
        srp_kwargs = {
            "sample_frequency": args.samp_frequency,
            "num_doa": args.num_doa,
            "num_bins": num_ffts // 2 + 1,
            "samp_doa": not args.samp_tdoa
        }
        return srp_phat_linear(S, args.linear_topo, **srp_kwargs)
    elif args.type == "ipd":
        if S.ndim < 3:
            raise ValueError("Only one-channel STFT available")
        ipd_list = []
        for p in args.ipd_pair.split(";"):
            indexes = list(map(int, p.split(",")))
            if len(indexes) != 2:
                raise ValueError("Invalid --ipd.pair configuration " +
                                 f"detected: {args.ipd_pair}")
            L, R = indexes
            if R > S.shape[0]:
                raise RuntimeError(f"Could not access channel {R}")
            ipd_mat = ipd(S[L], S[R], cos=args.ipd_cos, sin=args.ipd_sin)
            ipd_list.append(ipd_mat)
        # concat along frequency axis
        return np.hstack(ipd_list)
    else:
        return msc(S, context=args.msc_ctx)
Ejemplo n.º 2
0
def compute_spatial_feats(args, S):
    if args.type == "srp":
        srp_kwargs = {
            "sample_frequency": args.samp_frequency,
            "num_doa": args.num_doa,
            "num_bins": nfft(args.frame_length) // 2 + 1,
            "samp_doa": not args.samp_tdoa
        }
        linear_topo = list(map(float, args.linear_topo.split(",")))
        return srp_phat(S, linear_topo, **srp_kwargs)
    elif args.type == "ipd":
        indexes = list(map(int, args.ipd_index.split(",")))
        if len(indexes) != 2:
            raise ValueError(
                "Invalid --ipd.index configuration detected: {}".format(
                    args.ipd_index))
        if S.ndim < 3:
            raise ValueError("Only one-channel STFT available")
        L, R = indexes
        return ipd(S[L], S[R], sin=args.ipd_sin)
    else:
        return msc(S, context=args.context)