Exemple #1
0
def main(argv):
	plot = False
	if "plot" in argv:
		import subprocess
		argv.pop(argv.index("plot"))
		plot = True
	wave_path = argv[1]
	if not os.path.isfile(wave_path):
		return usage(argv)
	if not os.path.exists("/tmp/cfdg"):
		os.mkdir("/tmp/cfdg")
	base_path = "/tmp/cfdg/%s" % '.'.join(os.path.basename(wave_path).split('.')[:-1])

	if plot:
		ostats = [ ]
		for i in xrange(4):
			ostats.append(open("/tmp/pycf%d" % i, "w"))
		ofluid_stats = []
		for i in xrange(4):
			ofluid_stats.append(open("/tmp/pycf%d_fluid" % i, "w"))

	shape = triburn()
	filters = dsp()
	try:
		
		frames_per_buffer = 44100 / 25
		input_stream = wave_file(wave_path)
		while True:
			data = input_stream.read(frames_per_buffer)
			stats = filters.gen(data)
			fluid_stats.impulse(stats)
			open("%s_%05d.cfdg" % (base_path, idx), "w").write(
				shape.get(stats[:4], None)
			)
			if plot:
				for i in xrange(4):
					ostats[i].write("%f\n" % stats[i])
					ofluid_stats[i].write("%f\n" % fluid_stats[i])

	except KeyboardInterrupt:
		pass

	if plot:
		p = subprocess.Popen("gnuplot", stdin=subprocess.PIPE)
		cmd = ["plot"]
		for i in [1,2,3]:
		#	cmd.append("'/tmp/pycf%d' with lines," % i)
			cmd.append("'/tmp/pycf%d_fluid' with lines," % i)
		cmd[-1] = cmd[-1][:-1]
		p.stdin.write(" ".join(cmd)+"\n")
		raw_input("press enter when done")
		p.terminate()
Exemple #2
0
    def run(self):
        import os
        try:
            os.nice(-5)
        except OSError:
            print("Could not set high priority on audio processing, "
                  "beware of input overflow")
        self.dsp = dsp()
        self.p = pyaudio.PyAudio()

        if os.path.isfile(self.input_fd):
            self.input_stream = wave_file(self.input_fd)
            self.check_input_stream()
            print("Input stream: '%s' format %d bytes, rate %d Hz, "
                  "%d channels" % (
                          self.input_fd,
                          self.input_stream.format,
                          self.input_stream.rate,
                          self.input_stream.channels))

            print("Opening Output stream: '%s'" %
                  self.get_device_name(self.output_device_index))
            self.output_stream = self.open_stream(output=True)
        #     self.output_stream = None
        else:
            print("Opening Input stream: '%s' paInt16 %d Hz stream of "
                  "%d size" % (
                    self.get_device_name(self.input_fd),
                    self.rate, self.frames_per_buffer))
            self.input_stream = self.open_stream(input=True)
            self.output_stream = None

        while True:
            try:
                self.process()
            except IOError as e:
                print("IOError:", e)
#            except Full as e:
#                print("The queue is full!")
            except KeyboardInterrupt:
                break
        print("Closing streams")
        self.input_stream.close()
        if self.output_stream:
            self.output_stream.close()
        self.p.terminate()