def collect(self): # handle slight lag at beginning pre_offset = int( self.node_dist(self.listener, self.source) / 343 * self.rate) wet_arr = self.listener.wet_out[pre_offset:] wet = Recording(array=wet_arr, name='reverb_wet_out') wet.amplify(self.wet * 1 / 100) self.rec.amplify(self.dry * 1 / 100) self.rec.arr = mix(self.rec, wet, name='temp_mix').arr
def effects_main(): """ """ a = Recording() scrambler(a, 1000) a.playback() sf.write("scamble_piano.wav", a.arr, a.rate)
def add_recording(self): """ desc: create a new Recording from an audio file or live recording """ self.add_child( Recording(parent=self, mode="create") )
def triangle(freq, dur, amp=0.1, rate=44100, name=None): """ freqency (Hz) duration (secs) amplitude (0-1) 0.05 default rate (sps) 44100 """ print("\nGenerating simple triangle wave ...") freq = RelPitch.valid_freq(freq) dur = RelSecs.valid_beatsec(dur) period = int(rate / freq) period_arr = [] delta = 4 * amp / period # amount change per sample val = 0 # value of sample for _ in range(period): period_arr.append([val, val]) val += delta if abs(val) > (amp + 0.001): delta *= -1 arr = period_arr * int(freq * dur * 1.1) arr = arr[:int(rate * dur)] source_block = { "generator": sys._getframe().f_code.co_name, "frequency": freq, "duration": dur, "amplitude": amp } return Recording(array=arr, source_block=source_block, rate=rate, name=name)
def square(note, dur, amp=0.05, rate=44100, name=None): """ freqency (Hz) duration (secs) amplitude (0-1) 0.05 default rate (sps) 44100 """ print("\nGenerating simple square wave ...") freq = RelPitch.valid_freq(note) dur = RelSecs.valid_beatsec(dur) period = freq.get_period(rate) period_arr = [amp] * (period // 2) + [-amp] * ((period + 1) // 2) arr = period_arr * int(freq * dur) arr = arr[:int(rate * dur)] arr = [[i, i] for i in arr] source_block = { "generator": sys._getframe().f_code.co_name, "frequency": note, "duration": dur, "amplitude": amp } return Recording(array=arr, source_block=source_block, rate=rate, name=name)
def sine(note, dur, amp=0.1, rate=44100, name=None): """ sine wave generator freqency (Hz) duration (secs) amplitude (0-1) 0.1 default returns Recording obj """ print("\nGenerating simple sine wave ...") freq = RelPitch.valid_freq(note) dur = RelTime.valid_beatsec(dur).samps() amp = inpt_validate(amp, 'flt', allowed=[0, 2]) arr = BaseGenerator.wave(dur, freq.get_period(rate), shift=0, amp=amp) source_block = { "type": "generator", "name": sys._getframe().f_code.co_name, "note": freq, "duration": dur, "amplitude": amp } return Recording(array=arr, source_block=source_block, rate=rate, name=name)
def clip_click(amp=0.5): array = [[amp, amp]] source_block = { "generator": sys._getframe().f_code.co_name, "amplitude": amp } return Recording(array=array, source_block=source_block)
def clip_click2(amp=0.5): array = [] for _ in range(300): a = rd.random() * amp array.append([a, a]) source_block = { "generator": sys._getframe().f_code.co_name, "amplitude": amp } return Recording(array=array, source_block=source_block)
def add_sample(self, new_sample): if isinstance(new_sample, Recording): if not self.validate_child_name(new_sample, new_sample.name): err_mess( "Sample with name '{0}' already exists in Sample Group '{1}'! You may rename it and add it again" .format(new_sample.name, self.name)) else: new_sample = Recording(mode="create", parent=self, reltype="Sample") self.samples[new_sample.name] = new_sample
def concatenate(*recs): """ add rec2 directly to back of rec1 """ string = "Concatenating '" + recs[0].name + "'" source_block = ["concatenation", recs[0].name] for i in recs[1:]: string += " and '" + i.name + "'" source_block[1] += " + " + i.name section_head(string) arr = np.concatenate([i.get_panned_rec() for i in recs]) return Recording(array=arr, source_block=source_block)
def add_sample(self, new_samp=None): """ desc: add a sample from file, project, or another sampler cat: edit """ if isinstance(new_samp, Recording): new_samp.reltype = "Sample" else: new_samp = Recording(reltype="Sample", parent=self) self.smps.append(new_samp) self.list_samples() nl() p("Process this sample? y/n") if inpt("yn"): process(new_samp)
def mix(rec1, rec2, mix_level=None, offset=0, name=None): """ mix two recordings into new recording object offset (beat/sec): rec2 will be this beats behind rec1 mix_level: 0-1: post-mix amplification """ section_head("Mixing '" + rec1.name + "' and '" + rec2.name + "' ...") if rec1.rate != rec2.rate: raise RateError( "Two recordings must have the same sample rate to be mixed") offset = samps(offset) arr1 = rec1.get_panned_rec__() arr2 = rec2.get_panned_rec__() total_length = arr1.shape[ 0] if arr1.shape[0] > offset + arr2.shape[0] else arr2.shape[0] # mixing mix_arr = np.zeros((total_length, 2)) mix_arr[0:arr1.shape[0]] = arr1 mix_arr[offset:offset + arr2.shape[0]] = arr2 mix_arr *= mix_level # format source_block = ["mix", rec1.name + " with " + rec2.name] mix_rec = Recording(mix_arr, source_block=source_block, name=name) return mix_rec