Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions Baku
Original file line number Diff line number Diff line change
@@ -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()