diff --git a/Baku b/Baku new file mode 100644 index 0000000..ef62c81 --- /dev/null +++ b/Baku @@ -0,0 +1,39 @@ +import numpy as np +import scipy.io.wavfile as wav +from scipy.signal import chirp +import matplotlib.pyplot as plt + +# Параметры бита +bpm = 90 +beat_duration = 60 / bpm # длительность одного удара +sample_rate = 44100 # частота дискретизации (CD-качество) +total_duration = 16 * beat_duration # длительность в 16 ударов +t = np.linspace(0, total_duration, int(sample_rate * total_duration), endpoint=False) + +# Создание ударных элементов +kick = np.zeros_like(t) +snare = np.zeros_like(t) +hihat = np.zeros_like(t) + +# Ритм 4/4: kick на 1 и 3, snare на 2 и 4 +for i in range(16): + index = int(i * beat_duration * sample_rate) + if i % 4 == 0: + kick[index:index+500] = chirp(t[:500], f0=60, f1=30, t1=0.01, method='linear') * np.hanning(500) + if i % 4 == 2: + snare[index:index+1000] = chirp(t[:1000], f0=300, f1=400, t1=0.01, method='linear') * np.hanning(1000) + hihat[index:index+300] += np.random.randn(300) * np.hanning(300) * 0.2 + +# Сведение и нормализация +beat = kick + snare + hihat +beat /= np.max(np.abs(beat)) + +# Сохранение в WAV-файл +wav.write("baku_rap_beat.wav", sample_rate, (beat * 32767).astype(np.int16)) + +# Отобразить волну звука +plt.plot(t[:sample_rate], beat[:sample_rate]) +plt.title("Превью бита (первая секунда)") +plt.xlabel("Время (сек)") +plt.ylabel("Амплитуда") +plt.show()