def calc_stack(self, before): stack = list(before) if self.name in basic_instr_inv or self.name in ex_instr: if self.name in ex_instr: push, pop = getattr(self, 'cmd_getstackops_' + self.name)(*self.args) else: push, pop = basic_instr_inv[self.name] try: self.inreg = list(reversed(utils.pop_many(stack, pop))) except IndexError: raise IRError('Pop from empty stack at %s' % self, self) max_reg = max(stack + [self.varcount - 1]) self.outreg = list(xrange(max_reg + 1, max_reg + 1 + push)) stack.extend(self.outreg) else: getattr(self, 'cmd_run_' + self.name)(stack) self.name = 'nop' # not pretty return tuple(stack)
def generate_random_audio_track(out_path, max_len_smpl, midi_range, overlap_list, overlap_prob, packed, sr=16000, zero_padding=0): min_midi = min(midi_range) max_midi = max(midi_range) n_midi = max_midi - min_midi midi_list = [] sound = np.zeros(zero_padding) meta_dict = [] idx = 0 # Loop generating audio and meta while len(sound) <= max_len_smpl: if not midi_list: midi_list = random.sample(range(min_midi, max_midi), n_midi) fragment_overlap = random.choices(overlap_list, weights=overlap_prob, k=1)[0] fragment_midi = pop_many(midi_list, fragment_overlap) fragment = RandomChord(idx, fragment_midi, packed, sr=sr) fragment_sound = fragment.generate_audio() current_time = librosa.samples_to_time(len(sound), sr=sr) sound = np.concatenate((sound, fragment_sound)) meta_dict = append_fragment_to_meta(meta_dict, fragment, out_path, current_time) print(f" Appending audio at: {current_time}") idx += 1 return sound, meta_dict
def cmd_run_swapn(self, stack): n, = self.args list = utils.pop_many(stack, n) stack.extend(list)