コード例 #1
0
 def generate_pure(self):
     a = self.preprocess()
     self.sound_objects = []
     for generator in self.generators.values():
         lso = generator.generate(a)
         self.sound_objects += lso
     self.output = sounds.render(self.sound_objects, a.rate)
     self.output.samples = (Fx().normalize().reverb())(self.output.samples)
コード例 #2
0
ファイル: gensound.py プロジェクト: Kyntaz/sound-music
def mutate_chorus(so: SoundObject):
    samps = (Fx().chorus(random.uniform(0, 1), random.uniform(0, 1), [[
        random.uniform(40, 60),
        random.uniform(0, 1),
        random.uniform(0.2, 0.3),
        random.uniform(1, 5),
        random.choice(["s", "t"])
    ] for _ in range(random.randrange(1, 5))]))(so.samples)
    return SoundObject(samps)
コード例 #3
0
 def play(self, note: Note, smpRt: int):
     b_wave = np.array([])
     freq = lr.midi_to_hz(note.pitch)
     oscs = floor(note.duration * freq)
     for _ in range(oscs):
         l = round(0.005 * smpRt)
         p = random.randint(0, len(self.sample) - l)
         p_wave = self.sample[p:p + l]
         b_wave = np.concatenate((b_wave, p_wave))
     l = round(0.005 * smpRt)
     p = random.randint(0, len(self.sample) - l)
     wave = self.sample[p:p + l]
     wave = np.tile(wave, oscs)
     b_wave = (Fx().gain(-10))(b_wave)
     wave = wave + b_wave
     factor = (len(wave) / smpRt) / note.duration
     wave = (Fx().speed(factor).highpass(100).lowpass(2000))(wave)
     wave = envl.adsr(len(wave))(wave)
     return wave
コード例 #4
0
 def play(self, note: Note, smpRt: int) -> np.ndarray:
     event, c_pitch = self.get_event(note.pitch)
     ratio = (len(event.data) / smpRt) / note.duration
     ratio = np.clip(ratio, 0.5, 100)
     shift = note.pitch - c_pitch
     wave = lr.effects.harmonic(event.data)
     wave = (Fx().pitch(shift * 100).tempo(ratio).highpass(
         lr.midi_to_hz(note.pitch)))(wave)
     wave = envl.adsr(len(wave))(wave)
     return wave
コード例 #5
0
 def play(self, note: Note, smpRt):
     wave = None
     shift = math.inf
     for _ in range(self.limit):
         twave = self.gen_wave(note.duration, smpRt)
         tc_pitch = get_strong_freq(twave)
         if tc_pitch == -math.inf: continue
         tshift = note.pitch - tc_pitch
         if abs(tshift) < abs(shift):
             wave = twave
             shift = tshift
         if abs(shift) < 30: break
     wave = (Fx().pitch(shift * 100).highpass(lr.midi_to_hz(
         note.pitch)))(wave)
     wave = envl.adsr(len(wave))(wave)
     return wave
コード例 #6
0
 def render(self, piece: Piece, smpRt: int, out: str):
     wave = np.array([])
     for j,line in enumerate(piece.lines):
         line_wave = np.array([])
         for i,note in enumerate(line.notes):
             print(f"Rendering line {j+1} of {len(piece.lines)}. Rendering at {round((i+1) / len(line.notes) * 100, 2)}% ({exceptions.n_exceptions()} exceptions)     ", end='\r')
             try:
                 pad = pad = [0] * round(note.start*smpRt)
                 note_wave = line.instrument.play(note, smpRt)
                 note_wave = np.concatenate((pad, note_wave))
                 line_wave = join_waves(line_wave, note_wave)
             except Exception as e:
                 #traceback.print_exc()
                 exceptions.save_exception(e)
         wave = join_waves(wave, line_wave)
     assert len(wave) > 0
     wave = (
         Fx()
         .normalize()
         .reverb()
     )(wave)
     sf.write(out, wave, smpRt, subtype='PCM_24')
     print("\nDone Rendering.")
     return Audio(wave, smpRt)
コード例 #7
0
ファイル: Wave.py プロジェクト: Kyntaz/sound-music
def get_strong_freq(wave):
    pwave = (Fx().highpass(100))(wave)
    spect = lr.amplitude_to_db(np.abs(lr.stft(pwave)))
    profile = np.mean(spect, axis=1)
    bins = lr.fft_frequencies()
    return round(lr.hz_to_midi(stats.mode(bins, profile)), 2)
コード例 #8
0
ファイル: gensound.py プロジェクト: Kyntaz/sound-music
def mutate_compand(so: SoundObject):
    samps = (Fx().compand(random.uniform(0.1, 1.0), random.uniform(0.1, 1.0),
                          random.uniform(0.5, 2.0), random.uniform(-20, -3),
                          random.uniform(-20, -3),
                          random.uniform(-20, -3)))(so.samples)
    return SoundObject(samps)
コード例 #9
0
ファイル: gensound.py プロジェクト: Kyntaz/sound-music
def mutate_bandreject(so: SoundObject):
    samps = (Fx().bandreject(random.uniform(20, 20e3),
                             random.uniform(0.1, 2.0)))(so.samples)
    return SoundObject(samps)
コード例 #10
0
ファイル: gensound.py プロジェクト: Kyntaz/sound-music
def mutate_reverb(so: SoundObject):
    samps = (Fx().reverb(random.uniform(0, 100), random.uniform(0, 100),
                         random.uniform(0, 100), random.uniform(0, 100),
                         random.uniform(0, 100)))(so.samples)
    return SoundObject(samps)