#!/usr/bin/env python import sys from dsptools import synth from dsptools import ladspa from dsptools.soundpaint import * def play(filename): if 1: #freq = midi2freq(note2midi('A-3')) freq = 1090. p_wave = synth.WavePlugin(filename, 1) #p_notch = ladspa.libs.notch_iir_1894.make('notch_iir') p_notch = ladspa.libs.bandpass_iir_1892.make('bandpass_iir') p_wave['Output0'].connect(p_notch['Input']) print p_notch['Center Frequency (Hz)'] print p_notch['Bandwidth (Hz)'] print p_notch['Stages(2 poles per stage)'] p_notch['Center Frequency (Hz)'].set(freq) p_notch['Bandwidth (Hz)'].set(20.) p_notch['Stages(2 poles per stage)'].set(4) print p_notch['Center Frequency (Hz)'].buffer[0] print p_notch['Bandwidth (Hz)'].buffer[0] print p_notch['Stages(2 poles per stage)'].buffer[0] output = p_notch['Output'] s = synth.Synth([], [output]) elif 1: p_wave = synth.WavePlugin(filename, 2) p_canyon = ladspa.libs.cmt.make('canyon_delay') p_canyon['In (Left)'].connect(p_wave['Output0']) # is_input, is_audio p_canyon['In (Right)'].connect(p_wave['Output1']) # is_input, is_audio left = p_canyon['Out (Left)'] right = p_canyon['Out (Right)'] # lower_bound = 0.00999999977648, upper_bound = 0.990000009537, is_input, is_control, is_hint_bounded_below, is_hint_bounded_above p_canyon['Left to Right Time (Seconds)'].set(0.01) # lower_bound = -1.0, upper_bound = 1.0, is_input, is_control, is_hint_bounded_below, is_hint_bounded_above p_canyon['Left to Right Feedback (Percent)'].set(0.754) # lower_bound = 0.00999999977648, upper_bound = 0.990000009537, is_input, is_control, is_hint_bounded_below, is_hint_bounded_above p_canyon['Right to Left Time (Seconds)'].set(0.414) # lower_bound = -1.0, upper_bound = 1.0, is_input, is_control, is_hint_bounded_below, is_hint_bounded_above p_canyon['Right to Left Feedback (Percent)'].set(0.834) # lower_bound = 1.0, upper_bound = 5000.0, is_input, is_control, is_hint_bounded_below, is_hint_bounded_above p_canyon['Low-Pass Cutoff (Hz)'].set(100.) #p_canyon['Low-Pass Cutoff (Hz)'].set(1.) s = synth.Synth([], [left, right]) else: p_wave = synth.WavePlugin(filename, 2) left, right = p_wave['Output0'], p_wave['Output1'] print "Synth:", hex(ladspa.bufaddr(left.buffer)) print "Synth:", hex(ladspa.bufaddr(right.buffer)) s = synth.Synth([], [left, right]) s.output_portaudio() def main(infile, outfile): import numwave import numpy a = numwave.read_wave(infile) a = a[:,0]+a[:,1] #print "max:", a.max() output = numpy.zeros(len(a), dtype=numpy.float32) ibuf = numpy.empty(1024, dtype=numpy.float32) obuf = numpy.empty(1024, dtype=numpy.float32) # p_band = ladspa.libs.bandpass_a_iir_1893.make('bandpass_a_iir') p_band = ladspa.libs.bandpass_iir_1892.make('bandpass_iir') #p_band = ladspa.libs.notch_iir_1894.make('notch_iir') assert p_band.blocksize == 1024 p_band.connect_port(p_band['Input'], ibuf) p_band.connect_port(p_band['Output'], obuf) print p_band['Center Frequency (Hz)'] print p_band['Bandwidth (Hz)'] p_band['Center Frequency (Hz)'].set(880.) p_band['Bandwidth (Hz)'].set(20.) p_band['Stages(2 poles per stage)'].set(2) p_band.activate() idx = 0 while idx < len(a): n = min(len(ibuf), len(a)-idx) ibuf[:n] = a[idx : idx+n] ibuf[n:] = 0. obuf[:] = 0. p_band.run() output[idx : idx+n] = obuf[:n] #output[idx : idx+n] = a[idx:idx+n] idx += n print a.shape, output.shape numwave.write_wave(outfile, output) if __name__ == "__main__": play(sys.argv[1]) #main(sys.argv[1], sys.argv[2])