コード例 #1
0
ファイル: normalize.py プロジェクト: Takusei/SimMch
                      help="volumes of input sound (0<=v<=1)",
                      default=1.0,
                      type=str,
                      metavar="VOL")

    (options, args) = parser.parse_args()

    # argv check
    if len(args) < 1:
        quit()
    #
    npr.seed(1234)
    src_volume = options.volume
    output_filename = options.output_file
    data = []
    #
    wav_filename = args[0]
    print "... reading", wav_filename
    wav_data = simmch.read_mch_wave(wav_filename)
    wav = wav_data["wav"]
    fs = wav_data["framerate"]
    nch = wav_data["nchannels"]
    amp = np.max(np.abs(wav))
    print "[INFO] max amplitude:", amp
    g = 32767.0 / amp * src_volume
    print "[INFO] gain:", g
    wav = wav * g
    # save data
    if output_filename != None:
        simmch.save_mch_wave(wav, output_filename)
コード例 #2
0
ファイル: wiener_filter.py プロジェクト: naegawa/SimMch
	spec2=simmch.stft_mch(wav2,win,step)
	##
	##
	nframe1=spec1.shape[1]
	nframe2=spec2.shape[1]
	nframe=min(nframe1,nframe2)
	spec1_temp=spec1[:,0:nframe,min_freq_bin:max_freq_bin]
	spec2_temp=spec2[:,0:nframe,min_freq_bin:max_freq_bin]

	if options.noise is not None:
		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)
コード例 #3
0
ファイル: normalize.py プロジェクト: naegawa/SimMch
		default=1.0,
		type=str,
		metavar="VOL")
	
	(options, args) = parser.parse_args()
	
	# argv check
	if len(args)<1:
		quit()
	#
	npr.seed(1234)
	src_volume=options.volume
	output_filename=options.output_file
	data=[]
	#
	wav_filename=args[0]
	print "... reading", wav_filename
	wav_data=simmch.read_mch_wave(wav_filename)
	wav=wav_data["wav"]
	fs=wav_data["framerate"]
	nch=wav_data["nchannels"]
	amp=np.max(np.abs(wav))
	print "[INFO] max amplitude:",amp
	g=32767.0/amp*src_volume
	print "[INFO] gain:",g
	wav=wav*g
	# save data
	if output_filename!=None:
		simmch.save_mch_wave(wav,output_filename)
	
コード例 #4
0
ファイル: sim_tf.py プロジェクト: naegawa/SimMch
	if not src_index in tf_config["tf"]:
		print >>sys.stderr, "Error: tf index",src_index,"does not exist in TF file"
		quit()
	

	## read wav file
	print "... reading", wav_filename
	wav_data=simmch.read_mch_wave(wav_filename)
	scale=32767.0
	wav=wav_data["wav"]/scale
	fs=wav_data["framerate"]
	nch=wav_data["nchannels"]
	## print info
	print "# channel num : ", nch
	print "# sample size : ", wav.shape
	print "# sampling rate : ", fs
	print "# sec : ", wav_data["duration"]
	mono_wavdata = wav[0,:]

	## apply TF
	fftLen = 512
	step = fftLen / 4
	mch_wavdata=apply_tf(mono_wavdata,fftLen, step,tf_config,src_index)
	a=np.max(mch_wavdata)
	mch_wavdata=mch_wavdata/a
	mch_wavdata=mch_wavdata*scale*src_volume
	## save data
	simmch.save_mch_wave(mch_wavdata,output_filename)


コード例 #5
0
ファイル: make_noise.py プロジェクト: Takusei/SimMch
		nsamples=options.samples
		length=((nsamples-(fftLen-step))-1)/step+1
	elif options.frames!=None:
		length=options.frames
		nsamples=length*step+(fftLen-step)
	elif options.duration!=None:
		nsamples=options.samplingrate*options.duration
		length=((nsamples-(fftLen-step))-1)/step+1
	elif options.template!=None:
		wav_filename=options.template
		print "... reading", wav_filename
		wav_data=simmch.read_mch_wave(wav_filename)
		nsamples=wav_data["nframes"]
		nch=wav_data["nchannels"]
		length=((nsamples-(fftLen-step))-1)/step+1
	else:
		print >>sys.stderr,"[ERROR] unknown duration (please indicate --duration, --samples, or --frames)"
		quit()

	print "#channels:",nch
	print "#frames:",length
	print "#samples:",nsamples
	print "window size:",fftLen
	mch_wavdata=make_white_noise(nch,length,fftLen,step)
	
	g=32767.0*options.amp
	print "[INFO] gain:",g
	mch_wavdata=mch_wavdata*g
	simmch.save_mch_wave(mch_wavdata,output_filename,sample_width=2,framerate=options.samplingrate)
	
コード例 #6
0
    src_index = simmch.nearest_direction_index(tf_config, src_theta)
    print "# mic positions  :", mic_pos
    print "# direction index:", src_index
    if not src_index in tf_config["tf"]:
        print >> sys.stderr, "Error: tf index", src_index, "does not exist in TF file"
        quit()

    ## read wav file
    print "... reading", wav_filename
    wav_data = simmch.read_mch_wave(wav_filename)
    scale = 32767.0
    wav = wav_data["wav"] / scale
    fs = wav_data["framerate"]
    nch = wav_data["nchannels"]
    ## print info
    print "# channel num : ", nch
    print "# sample size : ", wav.shape
    print "# sampling rate : ", fs
    print "# sec : ", wav_data["duration"]
    mono_wavdata = wav[0, :]

    ## apply TF
    fftLen = 512
    step = fftLen / 4
    mch_wavdata = apply_tf(mono_wavdata, fftLen, step, tf_config, src_index)
    a = np.max(mch_wavdata)
    mch_wavdata = mch_wavdata / a
    mch_wavdata = mch_wavdata * scale * src_volume
    ## save data
    simmch.save_mch_wave(mch_wavdata, output_filename)
コード例 #7
0
				segment_enabled_flag=True
			if segment_enabled_flag:
				start_fram=m
	print "... detected segments by frame-based thresholds"
	sample_segs=[(seg[0]*step,seg[1]*step+length)for seg in frame_segs]
	print sample_segs
	print "... detected segments"
	filtered_segs=[seg for seg in sample_segs if seg[1]-seg[0]>thresh_seg_size*fs]
	print filtered_segs
	for seg_id,s in enumerate(filtered_segs):
		w=wav[:,s[0]:s[1]]
		# save data
		if options.output_file!=None:
			o=options.output_file%seg_id
			print "[save]",o
			simmch.save_mch_wave(w,o)
	#
	plt.subplot(4, 1, 1)
	disable_xy_label=False
	if disable_xy_label:
		plt.tick_params(labelbottom='off')
		plt.tick_params(labelleft='off')
	plt.xlabel("time [second]")
	plt.ylabel("wav")
	plt.plot(wav[ch])
	#
	plt.subplot(4, 1, 2)
	disable_xy_label=False
	if disable_xy_label:
		plt.tick_params(labelbottom='off')
		plt.tick_params(labelleft='off')
コード例 #8
0
ファイル: wiener_filter.py プロジェクト: Takusei/SimMch
    nframe1 = spec1.shape[1]
    nframe2 = spec2.shape[1]
    nframe = min(nframe1, nframe2)
    spec1_temp = spec1[:, 0:nframe, min_freq_bin:max_freq_bin]
    spec2_temp = spec2[:, 0:nframe, min_freq_bin:max_freq_bin]

    if options.noise is not None:
        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)):
コード例 #9
0
ファイル: gsc.py プロジェクト: Takusei/SimMch
	#mv_freq=np.array([mv_freq])
	save_sidelobe("sidelobe_mv.png",tf_config,w_mv,sidelobe_freq_bin)
### GSC for MV beamformer
	w_a,_,_=wiener_filter.wiener_filter_freq(blocked_freq,mv_freq)
	y_mv=wiener_filter.apply_filter_freq(blocked_freq,w_a)
	w_gsc_mv=np.zeros((nfreq_bin,nch),dtype=complex)
	for freq_bin in xrange(nfreq_bin):
		w_gsc_mv[freq_bin,:]=w_mv[freq_bin,:]-w_a[freq_bin,:].dot(B.dot(A[freq_bin,:,:]))
	save_sidelobe("sidelobe_gsc_mv.png",tf_config,w_gsc_mv,sidelobe_freq_bin,clear_flag=False)
###
	out_gsc_ds=ds_freq-y_ds
	out_gsc_mv=mv_freq-y_mv
	recons_out_gsc_ds=simmch.istft_mch(out_gsc_ds, win, step)
	recons_out_gsc_mv=simmch.istft_mch(out_gsc_mv, win, step)
	recons_ds_y=simmch.istft_mch(y_ds, win, step)
	recons_mv_y=simmch.istft_mch(y_mv, win, step)
	recons_b=simmch.istft_mch(blocked_freq, win, step)
	recons_ds=simmch.istft_mch(ds_freq, win, step)
	recons_mv=simmch.istft_mch(mv_freq, win, step)
	simmch.save_mch_wave(recons_mv*32767.0,"mv.wav")
	simmch.save_mch_wave(recons_ds*32767.0,"ds.wav")
	simmch.save_mch_wave(recons_ds_y*32767.0,"y_ds.wav")
	simmch.save_mch_wave(recons_mv_y*32767.0,"y_mv.wav")
	simmch.save_mch_wave(recons_out_gsc_ds*32767.0,"gsc_ds.wav")
	simmch.save_mch_wave(recons_out_gsc_mv*32767.0,"gsc_mv.wav")
	simmch.save_mch_wave(recons_b*32767.0,"b.wav")

	quit()