def pdfilter(inp, outp, patch, folder='.'): inw = wave.open(inp, 'rb') outw = wave.open(outp, 'wb') try: w = inw.getsampwidth() if w != 2: raise Exception('wrong sample width') ch = inw.getnchannels() sr = inw.getframerate() n = inw.getnframes() outw.setsampwidth(w) outw.setnchannels(ch) outw.setframerate(sr) outw.setnframes(n) p = pylibpd.libpd_open_patch(patch, folder) m = pylibpd.PdManager(ch, ch, sr, 1) for i in range(int(n / 64)): x = inw.readframes(64) y = m.process(x) outw.writeframesraw(y) r = n % 64 x = inw.readframes(r) + b'\x00' * w * ch * (64 - r) y = m.process(x) outw.writeframesraw(y[:w * ch * r]) pylibpd.libpd_close_patch(p) finally: inw.close() outw.close()
def pdfilter(inp, outp, patch, folder = '.'): inw = wave.open(inp, 'rb') outw = wave.open(outp, 'wb') try: w = inw.getsampwidth() if w != 2: raise Exception('wrong sample width') ch = inw.getnchannels() sr = inw.getframerate() n = inw.getnframes() outw.setsampwidth(w) outw.setnchannels(ch) outw.setframerate(sr) outw.setnframes(n) p = pylibpd.libpd_open_patch(patch, folder) m = pylibpd.PdManager(ch, ch, sr, 1) for i in xrange(n / 64): x = inw.readframes(64) y = m.process(x) outw.writeframesraw(y) r = n % 64 x = inw.readframes(r) + b'\x00' * w * ch * (64 - r) y = m.process(x) outw.writeframesraw(y[: w * ch * r]) pylibpd.libpd_close_patch(p) finally: inw.close() outw.close()
def openPatch(self, patch, dir='.'): """Open a PD patch and return $0 Args: patch (str): The file path to the patch dir (str, optional): The directory the patch is in Returns: int: $0 value for this patch """ return pd.libpd_open_patch(patch, dir)
import scipy as sp from scipy.io.wavfile import read, write import pylibpd as pd num_chans = 1 sampling_rate = 44100 # open a Pure Data patch m = pd.PdManager(num_chans, num_chans, sampling_rate, 1) patch = pd.libpd_open_patch("ring_mod.pd") # get the default frame size frame_size = pd.libpd_blocksize() # read audio file audio = read("drums.wav")[1] # process each frame out = sp.array([], dtype=sp.int16) for i in range(0, len(audio), frame_size): f = audio[i:i + frame_size] p = m.process(f) p = sp.fromstring(p, sp.int16) out = sp.hstack((out, p)) # close the patch pd.libpd_close_patch(patch) # write the audio file to disk write("drums_ringmod.wav", 44100, out)
import scipy as sp from scipy.io.wavfile import read, write import pylibpd as pd num_chans = 1 sampling_rate = 44100 # open a Pure Data patch m = pd.PdManager(num_chans, num_chans, sampling_rate, 1) patch = pd.libpd_open_patch("ring_mod.pd") # get the default frame size frame_size = pd.libpd_blocksize() # read audio file audio = read("drums.wav")[1] # process each frame out = sp.array([], dtype=sp.int16) for i in range(0, len(audio), frame_size): f = audio[i:i+frame_size] p = m.process(f) p = sp.fromstring(p, sp.int16) out = sp.hstack((out, p)) # close the patch pd.libpd_close_patch(patch) # write the audio file to disk write("drums_ringmod.wav", 44100, out)