-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfix_audio_shapes.py
More file actions
99 lines (74 loc) · 3.88 KB
/
fix_audio_shapes.py
File metadata and controls
99 lines (74 loc) · 3.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
"""
Fix for audio shape broadcasting errors in beat_studio_professional.py
"""
def fix_audio_shapes():
"""Fix the audio shape mismatches in the beat generation."""
# Read the current file
with open('beat_studio_professional.py', 'r', encoding='utf-8') as f:
content = f.read()
# Find and replace the problematic sections
# Fix 1: Ensure consistent array lengths in kick drum generation
old_kick = ''' # Generate sub (longer sine)
sub = Oscillator.sine(sub_freq, duration) * 0.7
# Mix and apply envelope
kick = punch + sub'''
new_kick = ''' # Generate sub (longer sine)
sub = Oscillator.sine(sub_freq, duration) * 0.7
# Ensure same length for mixing
min_len = min(len(punch), len(sub))
punch = punch[:min_len]
sub = sub[:min_len]
# Mix and apply envelope
kick = punch + sub'''
content = content.replace(old_kick, new_kick)
# Fix 2: Ensure consistent array lengths in beat mixing
old_mixing = ''' # Mix tracks
final_mix = (
drum_track * 0.8 +
melody_track * 0.6 +
bass_track * 0.7
) * AudioConstants.MASTER_VOLUME'''
new_mixing = ''' # Ensure all tracks have same length
min_length = min(len(drum_track), len(melody_track), len(bass_track))
drum_track = drum_track[:min_length]
melody_track = melody_track[:min_length]
bass_track = bass_track[:min_length]
# Mix tracks
final_mix = (
drum_track * 0.8 +
melody_track * 0.6 +
bass_track * 0.7
) * AudioConstants.MASTER_VOLUME'''
content = content.replace(old_mixing, new_mixing)
# Fix 3: Add safety check for sound array lengths in drum rendering
old_drum_render = ''' sound *= note.velocity
end_sample = min(start_sample + len(sound), total_samples)
drum_track[start_sample:end_sample] += sound[:end_sample - start_sample]'''
new_drum_render = ''' sound *= note.velocity
end_sample = min(start_sample + len(sound), total_samples)
if start_sample < total_samples:
sound_length = min(len(sound), end_sample - start_sample)
drum_track[start_sample:start_sample + sound_length] += sound[:sound_length]'''
content = content.replace(old_drum_render, new_drum_render)
# Fix 4: Add safety check for melody rendering
old_melody_render = ''' end_sample = min(start_sample + len(sound), total_samples)
melody_track[start_sample:end_sample] += sound[:end_sample - start_sample]'''
new_melody_render = ''' end_sample = min(start_sample + len(sound), total_samples)
if start_sample < total_samples:
sound_length = min(len(sound), end_sample - start_sample)
melody_track[start_sample:start_sample + sound_length] += sound[:sound_length]'''
content = content.replace(old_melody_render, new_melody_render)
# Fix 5: Add safety check for bass rendering
old_bass_render = ''' end_sample = min(start_sample + len(sound), total_samples)
bass_track[start_sample:end_sample] += sound[:end_sample - start_sample]'''
new_bass_render = ''' end_sample = min(start_sample + len(sound), total_samples)
if start_sample < total_samples:
sound_length = min(len(sound), end_sample - start_sample)
bass_track[start_sample:start_sample + sound_length] += sound[:sound_length]'''
content = content.replace(old_bass_render, new_bass_render)
# Write back the fixed content
with open('beat_studio_professional.py', 'w', encoding='utf-8') as f:
f.write(content)
print("✅ Audio shape broadcasting errors fixed!")
if __name__ == "__main__":
fix_audio_shapes()