Пример #1
0
    parser.add_option(
        "--plot-fft", dest="plot_fft_file", help="[output] spectrogram", default=None, type=str, metavar="FILE"
    )

    (options, args) = parser.parse_args()

    # argv check
    if len(args) < 2:
        print >> sys.stderr, "Usage: music.py <in: tf.zip(HARK2 transfer function file)> <in: src.wav>"
        quit()
        #
        # read tf
    npr.seed(1234)
    tf_filename = args[0]
    tf_config = read_hark_tf(tf_filename)
    mic_pos = read_hark_tf_param(tf_filename)
    permutation = permutation_hark_tf(tf_filename)

    print "# mic positions:", mic_pos
    # read wav
    music_filename = args[1]
    print "... reading", music_filename
    power = np.load(music_filename)
    nch = len(mic_pos)
    # print info
    print "# channel num : ", nch

    # reading data
    fftLen = int(tf_config["nfft"])
    fs = float(tf_config["samplingRate"])
Пример #2
0
                        type=int,
                        default=3,
                        help="minimum event size (MUSIC frame)")
    parser.add_argument('--out_localization',
                        metavar='LOC_FILE',
                        type=str,
                        default=None,
                        help='[output] localization file(.json)')

    args = parser.parse_args()
    if not args:
        quit()
    #
    # read tf
    print "... reading", args.tf_filename
    tf_config = read_hark_tf(args.tf_filename)

    # print positions of microphones
    #mic_pos=read_hark_tf_param(args.tf_filename)
    #print "# mic positions:",mic_pos

    spec, m_power, m_full_power, setting = music.compute_music_power(
        args.wav_filename, tf_config, args.normalize_factor,
        args.stft_win_size, args.stft_step, args.min_freq, args.max_freq,
        args.music_src_num, args.music_win_size, args.music_step)

    # save setting
    if args.out_setting:
        outfilename = args.out_setting
        fp = open(outfilename, "w")
        json.dump(setting, fp, sort_keys=True, indent=2)
Пример #3
0
		w=wiener_filter_eigen(spec1_temp,spec2_temp,win_size=nframe,r_step=1)
		print "# filter:",w.shape
		out_spec=apply_filter_eigen(spec1_temp,w)
		# ISTFT
		recons=simmch.istft_mch(out_spec, win, step)
		simmch.save_mch_wave(recons*32767.0,"recons_eigen.wav")
		quit()
	#print spec1_temp.shape
	#print spec2_temp.shape
	#win_size=50
	# spec[ch, frame, freq_bin]
	# w[ch2,ch1]
	w,_,_=wiener_filter_freq(spec1_temp,spec2_temp,win_size=nframe,r_step=1)
	print "# filter:",w.shape
	if options.tf is not None:
		tf_config=read_hark_tf(options.tf)
		if(len(w.shape)==3):
			for i in xrange(len(w.shape)):
				save_sidelobe("sidelobe_wiener%i.png"%(i+1),tf_config,w[:,:,i],sidelobe_freq_bin)
		else:
			save_sidelobe("sidelobe_wiener.png",tf_config,w,sidelobe_freq_bin)
	# filter
	out_spec=apply_filter_freq(spec1_temp,w)
	# ISTFT
	recons=simmch.istft_mch(out_spec, win, step)

	#recons.reshape((recons.shape[0],1))
	simmch.save_mch_wave(recons*32767.0,"recons_wiener.wav")
	
	
Пример #4
0
			help='[output] stting file (.json)')
	####
	parser.add_argument('--thresh',metavar='F',type=float,default=None,
			help="threshold of MUSIC power spectrogram")
	parser.add_argument('--event_min_size', metavar="W", type=int, default=3,
			help="minimum event size (MUSIC frame)")
	parser.add_argument('--out_localization', metavar='LOC_FILE', type=str, default=None,
			help='[output] localization file(.json)')

	args = parser.parse_args()
	if not args:
		quit()
	#
	# read tf
	print "... reading", args.tf_filename
	tf_config=read_hark_tf(args.tf_filename)
	
	# print positions of microphones
	#mic_pos=read_hark_tf_param(args.tf_filename)
	#print "# mic positions:",mic_pos
	
	spec,m_power,m_full_power,setting=music.compute_music_power(
			args.wav_filename,
			tf_config,
			args.normalize_factor,
			args.stft_win_size,
			args.stft_step,
			args.min_freq,
			args.max_freq,
			args.music_src_num,
			args.music_win_size,
Пример #5
0
		"-N", "--noise", dest="noise",
		help="noise amplitude",
		default=0,
		type=float,
		metavar="N")
	

	(options, args) = parser.parse_args()
	
	# argv check
	if len(args)<2:
		quit()
	#
	npr.seed(1234)
	tf_filename=options.tf
	tf_config=read_hark_tf(tf_filename)
	target_ch=options.channel
	src_theta=options.direction/180.0*math.pi
	src_index=nearest_direction_index(tf_config,src_theta)
	src_volume=options.volume
	output_filename=args[1]
	if not src_index in tf_config["tf"]:
		print >>sys.stderr, "Error: tf index",src_index,"does not exist in TF file"
		quit()
	mic_pos=read_hark_tf_param(tf_filename)
	print "# mic positions:",mic_pos
	wav_filename=args[0]
	wr = wave.open(wav_filename, "rb")

	# print info
	print "# channel num : ", wr.getnchannels()
Пример #6
0
        # ISTFT
        recons = simmch.istft_mch(out_spec, win, step)
        simmch.save_mch_wave(recons * 32767.0, "recons_eigen.wav")
        quit()
    #print spec1_temp.shape
    #print spec2_temp.shape
    #win_size=50
    # spec[ch, frame, freq_bin]
    # w[ch2,ch1]
    w, _, _ = wiener_filter_freq(spec1_temp,
                                 spec2_temp,
                                 win_size=nframe,
                                 r_step=1)
    print "# filter:", w.shape
    if options.tf is not None:
        tf_config = read_hark_tf(options.tf)
        if (len(w.shape) == 3):
            for i in xrange(len(w.shape)):
                save_sidelobe("sidelobe_wiener%i.png" % (i + 1), tf_config,
                              w[:, :, i], sidelobe_freq_bin)
        else:
            save_sidelobe("sidelobe_wiener.png", tf_config, w,
                          sidelobe_freq_bin)
    # filter
    out_spec = apply_filter_freq(spec1_temp, w)
    # ISTFT
    recons = simmch.istft_mch(out_spec, win, step)

    #recons.reshape((recons.shape[0],1))
    simmch.save_mch_wave(recons * 32767.0, "recons_wiener.wav")