当前位置: 首页>>代码示例>>Python>>正文


Python Base.samples方法代码示例

本文整理汇总了Python中Base.samples方法的典型用法代码示例。如果您正苦于以下问题:Python Base.samples方法的具体用法?Python Base.samples怎么用?Python Base.samples使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Base的用法示例。


在下文中一共展示了Base.samples方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: core

# 需要导入模块: import Base [as 别名]
# 或者: from Base import samples [as 别名]
	def core(self, repeats=1, w=None, data=None):
					
		self.timestamps['core'] = prectime()
		sleep_msec = 1.0
		self.timestamps['before'] = []
		self.timestamps['after'] = []
		preplay_done = False

		subs = [slice(None),slice(None)]
		nsamp = Base.samples(data)
		start = 0
		while repeats != 0:
			start %= nsamp
			while start < nsamp:
				while True:
					if not self.keepgoing or self.timedout(): self.keepgoing=False; break
					towrite = self.stream.get_write_available()
					nleft = (float(nsamp) - float(start)) / float(self.speed)
					if towrite >= nleft: break
					if towrite >= self.buffersize: break
					sleep(sleep_msec/1000.0)
				if not self.keepgoing: break
				
				speed = float(self.speed)
				if speed == 1.0:
					start = int(round(start))
					stop = start + towrite
					if repeats == 1: stop = min(nsamp, stop)
					subs[across_samples] = slice(start,stop)
					dd = data[subs]
				else:
					start = float(start)
					stop = start + float(speed) * float(towrite)
					if repeats == 1: stop = min(float(nsamp), stop)
					xi = numpy.linspace(start=start, stop=stop, endpoint=False, num=towrite)
					xi %= float(nsamp)
					dd = Base.interpsamples(data, xi)

				vols = float(self.vol) * Base.panhelper(self.pan, nchan=dd, norm=self.norm)
				dd = dd * vols  #   *= won't work for broadcasting here

				raw = w.dat2str(data=dd)
				if not preplay_done and self.preplay != None and self.preplay['func'] != None:
					self.preplay['func'](*self.preplay['pargs'], **self.preplay['kwargs'])
					preplay_done = True
				if len(self.timestamps['before']) < 100: self.timestamps['before'].append(prectime())	
				self.stream.write(raw)
				if len(self.timestamps['after']) < 100:  self.timestamps['after'].append(prectime())
				start = stop
			if not self.keepgoing: break
			repeats -= 1

		if self.postplay != None and self.postplay['func'] != None:
			self.postplay['func'](*self.postplay['pargs'], **self.postplay['kwargs'])
		self.__playing = False
		towrite = self.stream.get_write_available()	
		bytes_per_frame = self.interface.get_sample_size(self.format) * self.stream._channels
		if towrite > 0: self.stream.write('\0' * towrite * bytes_per_frame)
		while self.stream.get_write_available() < self.stream._frames_per_buffer: sleep(0.001)
		sleep(float(self.stream._frames_per_buffer) / float(self.stream._rate) + self.stream.get_output_latency())
开发者ID:ACrazyer,项目名称:NeuralSystemsBCI2000,代码行数:62,代码来源:PyAudioInterface.py


注:本文中的Base.samples方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。