import numpy as np
from scipy import signal
from IPython.display import Audio
def generate_keikyu_physical_model():
sample_rate = 44100
# 物理的な共鳴を模倣するフォルマント・フィルターの設定
# モーター筐体の響きを再現するために特定の周波数を強調する
def apply_motor_resonance(data, sr):
# 800Hz付近にモーターの共鳴ピークを設定
b, a = signal.butter(2, [600/(sr/2), 1200/(sr/2)], btype='bandpass')
resonance = signal.lfilter(b, a, data)
return data + 0.4 * resonance
sequence = [
(140, 180, 0.45, 0.7), # 起動時(非同期モード)
(349, 354, 0.6, 1.0), # F (Fa)
(392, 398, 0.3, 1.0), # G (Sol)
(440, 447, 0.3, 1.0), # A (La)
(466, 475, 0.2, 1.0), # Bb (Si-flat)
(523, 535, 0.2, 1.0), # C (Do)
(587, 602, 0.2, 1.0), # D (Re)
(622, 642, 0.2, 1.0), # Eb (Mi-flat)
(698, 725, 0.2, 1.0), # F (Fa)
(784, 880, 1.8, 1.0), # G (Sol)
(1100, 1400, 1.2, 0.6) # 高速域へのシフト
]
def create_gto_tone(freqs, sr, start_phase):
num_samples = len(freqs)
# スイッチングの微細な揺らぎ(ジッター)を追加
jitter = 1.0 + 0.0005 * np.random.randn(num_samples)
phases = start_phase + 2 * np.pi * np.cumsum(freqs * jitter) / sr
# 波形の合成:基本波に加えて、GTO特有の奇数倍音を強調
# 矩形波に近い成分を作るために3次、5次、7次を強く配合
wave = (1.0 * np.sin(phases) +
0.5 * np.sin(3 * phases) +
0.25 * np.sin(5 * phases) +
0.15 * np.sin(7 * phases))
# 非線形歪み(サチュレーション)を適用して図太さを出す
wave = np.clip(wave * 1.5, -1, 1)
return wave, phases[-1]
total_waveform = np.array([])
current_phase = 0.0
for f_start, f_end, dur, vol in sequence:
num_samples = int(sample_rate * dur)
f_path = np.linspace(f_start, f_end, num_samples)
chunk, last_p = create_gto_tone(f_path, sample_rate, current_phase)
current_phase = last_p
# 音の立ち上がりと立ち下がりに微細なエンベロープを適用
window = signal.windows.hann(int(sample_rate * 0.02) * 2)
fade_in = window[:len(window)//2]
fade_out = window[len(window)//2:]
env = np.ones(num_samples)
env[:len(fade_in)] = fade_in
env[-len(fade_out):] = fade_out
total_waveform = np.append(total_waveform, chunk * env * vol)
# モーターの筐体共鳴をフィルターで付加
final_audio = apply_motor_resonance(total_waveform, sample_rate)
# 最終的なマスタリング:100Hzの重低音(電磁振動)を薄くミックス
t_full = np.linspace(0, len(final_audio)/sample_rate, len(final_audio))
sub_bass = 0.08 * np.sin(2 * np.pi * 100 * t_full)
final_audio += sub_bass
final_audio = final_audio / np.max(np.abs(final_audio)) * 0.85
return Audio(final_audio, rate=sample_rate, autoplay=True)
# シミュレーションの実行
generate_keikyu_physical_model()