-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnoise_generator.py
1757 lines (1635 loc) · 66 KB
/
noise_generator.py
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import streamlit as st
import numpy as np
from scipy.io.wavfile import write
from scipy.signal import butter, lfilter
import scipy.signal as signal
import matplotlib.pyplot as plt
import io
import librosa
import librosa.display
import random
import soundfile as sf
import warnings
warnings.filterwarnings('ignore')
# For file management
import os
import pickle
import tempfile
import zipfile
# For interactive plots
import plotly.express as px
import plotly.graph_objects as go
# Set page configuration
st.set_page_config(
page_title="Industrial Noise Generator Pro Max with Variations",
page_icon="🎹",
layout="wide",
initial_sidebar_state="expanded",
)
# Custom CSS to enhance appearance
st.markdown("""
<style>
/* Main layout */
.main {
background-color: #1a1a1a;
color: white;
}
/* Sidebar styling */
.sidebar .sidebar-content {
background-color: #2d2d2d;
color: white;
}
/* Buttons */
.stButton>button {
width: 100%;
padding: 10px;
background-color: #FF4B4B;
color: white;
border-radius: 10px;
border: none;
}
.stButton>button:hover {
background-color: #ff3333;
}
.stDownloadButton>button {
width: 100%;
padding: 10px;
background-color: #00cc66;
color: white;
border-radius: 10px;
border: none;
}
.stDownloadButton>button:hover {
background-color: #00994d;
}
/* Headers */
h1, h2, h3, h4, h5, h6 {
color: #FF4B4B;
}
/* Text input and select boxes */
.stTextInput>div>div>input,
.stNumberInput>div>div>input,
.stSelectbox>div>div>div>div>input {
background-color: #3d3d3d;
color: white;
}
/* Sliders */
.stSlider>div>div>div {
color: white;
}
/* File uploader */
.stFileUploader>div>div {
background-color: #3d3d3d;
color: white;
}
/* Checkbox */
.stCheckbox>div>div>div {
color: white;
}
</style>
""", unsafe_allow_html=True)
# Title and description
st.title("🎹 Industrial Noise Generator Pro Max with Variations")
st.markdown("""
Welcome to the **Industrial Noise Generator Pro Max with Variations**! This app allows you to generate multiple industrial noise samples with advanced features:
- **Signal Flow Customization:** Reroute effects and components in any order.
- **BPM Customization:** Set beats per minute for rhythm-based noise.
- **Note and Scale Selection:** Choose notes and scales for the synthesizer.
- **Built-in Synthesizer:** Create unique sounds with various waveforms.
- **Advanced Effects:** Apply reverb, delay, distortion, and more in any order.
- **Variations:** Automatically generate variations for each sample.
- **Interactive Waveform Editor:** Zoom, pan, and interact with your waveform.
- **Session Management:** Store and download all your generated sounds.
**Get started by adjusting the parameters in the sidebar and click "Generate Noise" to create your samples!**
""")
# Sidebar for parameters
st.sidebar.header("🎛️ Controls")
# Number of samples to generate
st.sidebar.subheader("🔢 Sample Generation")
num_samples = st.sidebar.number_input(
"Number of Samples to Generate",
min_value=1,
max_value=100,
value=1,
help="Select how many unique samples you want to generate."
)
# Presets
st.sidebar.subheader("🎚️ Presets")
preset_options = ["Default", "Heavy Machinery", "Factory Floor", "Electric Hum", "Custom"]
preset = st.sidebar.selectbox(
"Choose a Preset",
preset_options,
help="Select a preset to quickly load predefined settings."
)
# Function to set preset parameters
def set_preset(preset):
params = {}
if preset == "Default":
params = {
'duration_type': 'Seconds',
'duration': 5,
'beats': 8,
'bpm': 120,
'noise_types': ["White Noise"],
'waveform_types': [],
'lowcut': 100,
'highcut': 5000,
'order': 6,
'amplitude': 1.0,
'sample_rate': 48000,
'channels': "Mono",
'fade_in': 0.0,
'fade_out': 0.0,
'panning': 0.5,
'bit_depth': 16,
'modulation': None,
'uploaded_file': None,
'reverse_audio': False,
'bitcrusher': False,
'bitcrusher_depth': 8,
'sample_reduction': False,
'sample_reduction_factor': 1,
'rhythmic_effects': [],
'arpeggiation': False,
'sequencer': False,
'sequence_pattern': 'Random',
'effects_chain': [],
'effect_params': {},
'voice_changer': False,
'pitch_shift_semitones': 0,
'algorithmic_composition': False,
'composition_type': None,
'synth_enabled': False,
'synth_notes': ['C4'],
'synth_scale': 'Major',
'synth_waveform': 'Sine',
'synth_attack': 0.01,
'synth_decay': 0.1,
'synth_sustain': 0.7,
'synth_release': 0.2
}
elif preset == "Heavy Machinery":
params = {
'duration_type': 'Seconds',
'duration': 10,
'beats': 16,
'bpm': 90,
'noise_types': ["Brown Noise"],
'waveform_types': ["Square Wave"],
'lowcut': 50,
'highcut': 3000,
'order': 8,
'amplitude': 0.9,
'sample_rate': 44100,
'channels': "Stereo",
'fade_in': 0.5,
'fade_out': 0.5,
'panning': 0.6,
'bit_depth': 24,
'modulation': "Amplitude Modulation",
'uploaded_file': None,
'reverse_audio': False,
'bitcrusher': True,
'bitcrusher_depth': 6,
'sample_reduction': True,
'sample_reduction_factor': 2,
'rhythmic_effects': ["Stutter"],
'arpeggiation': True,
'sequencer': True,
'sequence_pattern': 'Descending',
'effects_chain': ["Distortion"],
'effect_params': {'Distortion': {'gain': 30.0, 'threshold': 0.6}},
'voice_changer': False,
'pitch_shift_semitones': 0,
'algorithmic_composition': True,
'composition_type': "Rhythmic Pattern",
'synth_enabled': True,
'synth_notes': ['E2', 'G2', 'B2'],
'synth_scale': 'Minor',
'synth_waveform': 'Square',
'synth_attack': 0.05,
'synth_decay': 0.2,
'synth_sustain': 0.5,
'synth_release': 0.3
}
elif preset == "Factory Floor":
params = {
'duration_type': 'Seconds',
'duration': 7,
'beats': 12,
'bpm': 110,
'noise_types': ["Pink Noise", "White Noise"],
'waveform_types': ["Sawtooth Wave"],
'lowcut': 80,
'highcut': 4000,
'order': 6,
'amplitude': 0.8,
'sample_rate': 44100,
'channels': "Stereo",
'fade_in': 0.3,
'fade_out': 0.3,
'panning': 0.4,
'bit_depth': 24,
'modulation': "Frequency Modulation",
'uploaded_file': None,
'reverse_audio': False,
'bitcrusher': False,
'bitcrusher_depth': 8,
'sample_reduction': True,
'sample_reduction_factor': 2,
'rhythmic_effects': ["Glitch"],
'arpeggiation': False,
'sequencer': True,
'sequence_pattern': 'Random',
'effects_chain': ["Reverb"],
'effect_params': {'Reverb': {'decay': 0.7}},
'voice_changer': False,
'pitch_shift_semitones': 0,
'algorithmic_composition': True,
'composition_type': "Ambient Soundscape",
'synth_enabled': True,
'synth_notes': ['A3', 'C4', 'E4'],
'synth_scale': 'Pentatonic',
'synth_waveform': 'Sawtooth',
'synth_attack': 0.02,
'synth_decay': 0.1,
'synth_sustain': 0.6,
'synth_release': 0.2
}
elif preset == "Electric Hum":
params = {
'duration_type': 'Seconds',
'duration': 5,
'beats': 8,
'bpm': 100,
'noise_types': ["White Noise"],
'waveform_types': ["Sine Wave"],
'lowcut': 60,
'highcut': 120,
'order': 4,
'amplitude': 0.7,
'sample_rate': 48000,
'channels': "Mono",
'fade_in': 0.1,
'fade_out': 0.1,
'panning': 0.5,
'bit_depth': 16,
'modulation': "Amplitude Modulation",
'uploaded_file': None,
'reverse_audio': False,
'bitcrusher': False,
'bitcrusher_depth': 8,
'sample_reduction': False,
'sample_reduction_factor': 1,
'rhythmic_effects': [],
'arpeggiation': False,
'sequencer': False,
'sequence_pattern': 'Random',
'effects_chain': ["Tremolo"],
'effect_params': {'Tremolo': {'rate': 5.0, 'depth': 0.8}},
'voice_changer': False,
'pitch_shift_semitones': 0,
'algorithmic_composition': False,
'composition_type': None,
'synth_enabled': False,
'synth_notes': ['C4'],
'synth_scale': 'Major',
'synth_waveform': 'Sine',
'synth_attack': 0.01,
'synth_decay': 0.1,
'synth_sustain': 0.7,
'synth_release': 0.2
}
else: # Custom
params = None
return params
preset_params = set_preset(preset)
if preset != "Custom" and preset_params is not None:
# Set parameters from preset
duration_type = preset_params.get('duration_type', 'Seconds')
duration = preset_params['duration']
beats = preset_params.get('beats', 8)
bpm = preset_params.get('bpm', 120)
noise_types = preset_params.get('noise_types', [])
waveform_types = preset_params.get('waveform_types', [])
lowcut = preset_params['lowcut']
highcut = preset_params['highcut']
order = preset_params['order']
amplitude = preset_params['amplitude']
sample_rate = preset_params['sample_rate']
channels = preset_params['channels']
fade_in = preset_params['fade_in']
fade_out = preset_params['fade_out']
panning = preset_params['panning']
bit_depth = preset_params['bit_depth']
modulation = preset_params.get('modulation', None)
uploaded_file = preset_params.get('uploaded_file', None)
reverse_audio = preset_params.get('reverse_audio', False)
bitcrusher = preset_params.get('bitcrusher', False)
bitcrusher_depth = preset_params.get('bitcrusher_depth', 8)
sample_reduction = preset_params.get('sample_reduction', False)
sample_reduction_factor = preset_params.get('sample_reduction_factor', 1)
rhythmic_effects = preset_params.get('rhythmic_effects', [])
arpeggiation = preset_params.get('arpeggiation', False)
sequencer = preset_params.get('sequencer', False)
sequence_pattern = preset_params.get('sequence_pattern', 'Random')
effects_chain = preset_params.get('effects_chain', [])
effect_params = preset_params.get('effect_params', {})
voice_changer = preset_params.get('voice_changer', False)
pitch_shift_semitones = preset_params.get('pitch_shift_semitones', 0)
algorithmic_composition = preset_params.get('algorithmic_composition', False)
composition_type = preset_params.get('composition_type', None)
synth_enabled = preset_params.get('synth_enabled', False)
synth_notes = preset_params.get('synth_notes', ['C4'])
synth_scale = preset_params.get('synth_scale', 'Major')
synth_waveform = preset_params.get('synth_waveform', 'Sine')
synth_attack = preset_params.get('synth_attack', 0.01)
synth_decay = preset_params.get('synth_decay', 0.1)
synth_sustain = preset_params.get('synth_sustain', 0.7)
synth_release = preset_params.get('synth_release', 0.2)
else:
# Custom parameters
duration_type = st.sidebar.selectbox(
"Duration Type",
["Seconds", "Milliseconds", "Beats"],
help="Choose how you want to specify the duration."
)
if duration_type == "Seconds":
duration = st.sidebar.slider(
"Duration (seconds)",
min_value=1,
max_value=60,
value=5,
help="Select the duration of the noise in seconds."
)
elif duration_type == "Milliseconds":
duration_ms = st.sidebar.slider(
"Duration (milliseconds)",
min_value=100,
max_value=60000,
value=5000,
help="Select the duration of the noise in milliseconds."
)
duration = duration_ms / 1000.0 # Convert to seconds
elif duration_type == "Beats":
bpm = st.sidebar.slider(
"BPM",
min_value=30,
max_value=300,
value=120,
help="Set the beats per minute."
)
beats = st.sidebar.slider(
"Number of Beats",
min_value=1,
max_value=128,
value=8,
help="Set the number of beats."
)
duration = (60 / bpm) * beats # Convert beats to seconds
noise_options = ["White Noise", "Pink Noise", "Brown Noise", "Blue Noise", "Violet Noise", "Grey Noise"]
noise_types = st.sidebar.multiselect(
"Noise Types",
noise_options,
help="Select one or more types of noise to include."
)
waveform_options = ["Sine Wave", "Square Wave", "Sawtooth Wave", "Triangle Wave"]
waveform_types = st.sidebar.multiselect(
"Waveform Types",
waveform_options,
help="Select one or more waveforms to include."
)
lowcut = st.sidebar.slider(
"Low Cut Frequency (Hz)",
min_value=20,
max_value=10000,
value=100,
help="Set the low cut-off frequency for the bandpass filter."
)
highcut = st.sidebar.slider(
"High Cut Frequency (Hz)",
min_value=1000,
max_value=24000,
value=5000,
help="Set the high cut-off frequency for the bandpass filter."
)
order = st.sidebar.slider(
"Filter Order",
min_value=1,
max_value=10,
value=6,
help="Set the order of the bandpass filter."
)
amplitude = st.sidebar.slider(
"Amplitude",
min_value=0.0,
max_value=1.0,
value=1.0,
help="Set the amplitude (volume) of the generated noise."
)
sample_rate = st.sidebar.selectbox(
"Sample Rate (Hz)",
[48000, 44100, 32000, 22050, 16000, 8000],
index=0,
help="Choose the sample rate for the audio."
)
channels = st.sidebar.selectbox(
"Channels",
["Mono", "Stereo"],
help="Select mono or stereo output."
)
fade_in = st.sidebar.slider(
"Fade In Duration (seconds)",
min_value=0.0,
max_value=5.0,
value=0.0,
help="Set the duration for fade-in effect."
)
fade_out = st.sidebar.slider(
"Fade Out Duration (seconds)",
min_value=0.0,
max_value=5.0,
value=0.0,
help="Set the duration for fade-out effect."
)
panning = st.sidebar.slider(
"Panning (Stereo Only)",
min_value=0.0,
max_value=1.0,
value=0.5,
help="Adjust the panning for stereo output."
)
bit_depth = st.sidebar.selectbox(
"Bit Depth",
[16, 24, 32],
index=0,
help="Select the bit depth for the audio."
)
st.sidebar.subheader("🎵 Modulation")
modulation = st.sidebar.selectbox(
"Modulation",
[None, "Amplitude Modulation", "Frequency Modulation"],
help="Choose a modulation effect to apply."
)
st.sidebar.subheader("📁 Upload Audio")
uploaded_file = st.sidebar.file_uploader(
"Upload an audio file to include",
type=["wav", "mp3"],
help="Include an external audio file in the mix."
)
st.sidebar.subheader("🔄 Reverse Audio")
reverse_audio = st.sidebar.checkbox(
"Enable Audio Reversal",
help="Reverse the audio for a unique effect."
)
st.sidebar.subheader("🛠️ Bitcrusher")
bitcrusher = st.sidebar.checkbox(
"Enable Bitcrusher",
help="Apply a bitcrusher effect to reduce audio fidelity."
)
if bitcrusher:
bitcrusher_depth = st.sidebar.slider(
"Bit Depth for Bitcrusher",
min_value=1,
max_value=16,
value=8,
help="Set the bit depth for the bitcrusher effect."
)
else:
bitcrusher_depth = 16
st.sidebar.subheader("🔧 Sample Reduction")
sample_reduction = st.sidebar.checkbox(
"Enable Sample Rate Reduction",
help="Reduce the sample rate for a lo-fi effect."
)
if sample_reduction:
sample_reduction_factor = st.sidebar.slider(
"Reduction Factor",
min_value=1,
max_value=16,
value=1,
help="Set the factor by which to reduce the sample rate."
)
else:
sample_reduction_factor = 1
st.sidebar.subheader("🎚️ Rhythmic Effects")
rhythmic_effect_options = ["Stutter", "Glitch"]
rhythmic_effects = st.sidebar.multiselect(
"Select Rhythmic Effects",
rhythmic_effect_options,
help="Choose rhythmic effects to apply."
)
st.sidebar.subheader("🎹 Synthesizer")
synth_enabled = st.sidebar.checkbox(
"Enable Synthesizer",
help="Include synthesizer-generated tones."
)
if synth_enabled:
note_options = ['C', 'C#', 'D', 'D#', 'E', 'F',
'F#', 'G', 'G#', 'A', 'A#', 'B']
octave_options = [str(i) for i in range(1, 8)]
selected_notes = st.sidebar.multiselect(
"Notes",
[note + octave for octave in octave_options for note in note_options],
default=['C4'],
help="Select notes for the synthesizer."
)
synth_notes = selected_notes
scale_options = ['Major', 'Minor', 'Pentatonic', 'Blues', 'Chromatic']
synth_scale = st.sidebar.selectbox(
"Scale",
scale_options,
help="Choose a scale for the synthesizer."
)
synth_waveform = st.sidebar.selectbox(
"Waveform",
["Sine", "Square", "Sawtooth", "Triangle"],
help="Select the waveform for the synthesizer."
)
st.sidebar.markdown("**Envelope**")
synth_attack = st.sidebar.slider(
"Attack",
0.0,
1.0,
0.01,
help="Set the attack time for the envelope."
)
synth_decay = st.sidebar.slider(
"Decay",
0.0,
1.0,
0.1,
help="Set the decay time for the envelope."
)
synth_sustain = st.sidebar.slider(
"Sustain",
0.0,
1.0,
0.7,
help="Set the sustain level for the envelope."
)
synth_release = st.sidebar.slider(
"Release",
0.0,
1.0,
0.2,
help="Set the release time for the envelope."
)
else:
synth_notes = ['C4']
synth_scale = 'Major'
synth_waveform = 'Sine'
synth_attack = 0.01
synth_decay = 0.1
synth_sustain = 0.7
synth_release = 0.2
st.sidebar.subheader("🎹 Arpeggiation")
arpeggiation = st.sidebar.checkbox(
"Enable Arpeggiation",
help="Apply an arpeggiation effect to the notes."
)
st.sidebar.subheader("🎛️ Sequencer")
sequencer = st.sidebar.checkbox(
"Enable Sequencer",
help="Sequence the generated tones."
)
if sequencer:
sequence_patterns = ['Ascending', 'Descending', 'Random']
sequence_pattern = st.sidebar.selectbox(
"Sequence Pattern",
sequence_patterns,
help="Choose a pattern for the sequencer."
)
else:
sequence_pattern = 'Random'
st.sidebar.subheader("🎚️ Effects Chain")
effect_options = ["None", "Reverb", "Delay", "Distortion", "Tremolo", "Chorus", "Flanger", "Phaser", "Compression", "EQ", "Pitch Shifter", "High-pass Filter", "Low-pass Filter", "Vibrato", "Auto-pan"]
effects_chain = []
for i in range(1, 6):
effect = st.sidebar.selectbox(
f"Effect Slot {i}",
effect_options,
index=0,
key=f"effect_slot_{i}",
help="Select an effect to apply at this position in the chain."
)
if effect != "None":
effects_chain.append(effect)
# Collect parameters for each effect
effect_params = {}
for effect in effects_chain:
st.sidebar.markdown(f"**{effect} Parameters**")
params = {}
if effect == "Reverb":
decay = st.sidebar.slider(
"Reverb Decay",
0.1,
2.0,
0.5,
key=f"reverb_decay_{effect}",
help="Set the decay time for the reverb effect."
)
params['decay'] = decay
elif effect == "Delay":
delay_time = st.sidebar.slider(
"Delay Time (seconds)",
0.1,
1.0,
0.5,
key=f"delay_time_{effect}",
help="Set the delay time for the delay effect."
)
feedback = st.sidebar.slider(
"Delay Feedback",
0.0,
1.0,
0.5,
key=f"delay_feedback_{effect}",
help="Set the feedback level for the delay effect."
)
params['delay_time'] = delay_time
params['feedback'] = feedback
elif effect == "Distortion":
gain = st.sidebar.slider(
"Distortion Gain",
1.0,
50.0,
20.0,
key=f"distortion_gain_{effect}",
help="Set the gain level for the distortion effect."
)
threshold = st.sidebar.slider(
"Distortion Threshold",
0.0,
1.0,
0.5,
key=f"distortion_threshold_{effect}",
help="Set the threshold for the distortion effect."
)
params['gain'] = gain
params['threshold'] = threshold
elif effect == "Tremolo":
rate = st.sidebar.slider(
"Tremolo Rate (Hz)",
0.1,
20.0,
5.0,
key=f"tremolo_rate_{effect}",
help="Set the rate for the tremolo effect."
)
depth = st.sidebar.slider(
"Tremolo Depth",
0.0,
1.0,
0.8,
key=f"tremolo_depth_{effect}",
help="Set the depth for the tremolo effect."
)
params['rate'] = rate
params['depth'] = depth
elif effect == "Chorus":
rate = st.sidebar.slider(
"Chorus Rate (Hz)",
0.1,
5.0,
1.5,
key=f"chorus_rate_{effect}",
help="Set the rate for the chorus effect."
)
depth = st.sidebar.slider(
"Chorus Depth",
0.0,
1.0,
0.5,
key=f"chorus_depth_{effect}",
help="Set the depth for the chorus effect."
)
params['rate'] = rate
params['depth'] = depth
elif effect == "Flanger":
rate = st.sidebar.slider(
"Flanger Rate (Hz)",
0.1,
5.0,
0.5,
key=f"flanger_rate_{effect}",
help="Set the rate for the flanger effect."
)
depth = st.sidebar.slider(
"Flanger Depth",
0.0,
1.0,
0.7,
key=f"flanger_depth_{effect}",
help="Set the depth for the flanger effect."
)
params['rate'] = rate
params['depth'] = depth
elif effect == "Phaser":
rate = st.sidebar.slider(
"Phaser Rate (Hz)",
0.1,
5.0,
0.5,
key=f"phaser_rate_{effect}",
help="Set the rate for the phaser effect."
)
depth = st.sidebar.slider(
"Phaser Depth",
0.0,
1.0,
0.7,
key=f"phaser_depth_{effect}",
help="Set the depth for the phaser effect."
)
params['rate'] = rate
params['depth'] = depth
elif effect == "Compression":
threshold = st.sidebar.slider(
"Compressor Threshold",
0.0,
1.0,
0.5,
key=f"compressor_threshold_{effect}",
help="Set the threshold for the compressor."
)
ratio = st.sidebar.slider(
"Compressor Ratio",
1.0,
20.0,
2.0,
key=f"compressor_ratio_{effect}",
help="Set the ratio for the compressor."
)
params['threshold'] = threshold
params['ratio'] = ratio
elif effect == "EQ":
st.sidebar.markdown("**Equalizer Bands**")
eq_bands = {}
for freq in ['Low', 'Mid', 'High']:
gain = st.sidebar.slider(
f"{freq} Gain (dB)",
-12.0,
12.0,
0.0,
key=f"eq_{freq}_{effect}",
help=f"Set the gain for the {freq} frequencies."
)
eq_bands[freq.lower()] = gain
params['bands'] = eq_bands
elif effect == "Pitch Shifter":
semitones = st.sidebar.slider(
"Pitch Shift (semitones)",
-24,
24,
0,
key=f"pitch_shift_semitones_{effect}",
help="Set the number of semitones to shift the pitch."
)
params['semitones'] = semitones
elif effect == "High-pass Filter":
cutoff = st.sidebar.slider(
"High-pass Cutoff Frequency (Hz)",
20,
10000,
200,
key=f"highpass_cutoff_{effect}",
help="Set the cutoff frequency for the high-pass filter."
)
params['cutoff'] = cutoff
elif effect == "Low-pass Filter":
cutoff = st.sidebar.slider(
"Low-pass Cutoff Frequency (Hz)",
1000,
20000,
5000,
key=f"lowpass_cutoff_{effect}",
help="Set the cutoff frequency for the low-pass filter."
)
params['cutoff'] = cutoff
elif effect == "Vibrato":
rate = st.sidebar.slider(
"Vibrato Rate (Hz)",
0.1,
10.0,
5.0,
key=f"vibrato_rate_{effect}",
help="Set the rate for the vibrato effect."
)
depth = st.sidebar.slider(
"Vibrato Depth",
0.0,
1.0,
0.5,
key=f"vibrato_depth_{effect}",
help="Set the depth for the vibrato effect."
)
params['rate'] = rate
params['depth'] = depth
elif effect == "Auto-pan":
rate = st.sidebar.slider(
"Auto-pan Rate (Hz)",
0.1,
10.0,
1.0,
key=f"autopan_rate_{effect}",
help="Set the rate for the auto-pan effect."
)
params['rate'] = rate
effect_params[effect] = params
st.sidebar.subheader("🎤 Voice Changer")
voice_changer = st.sidebar.checkbox(
"Enable Voice Changer (Pitch Shift)",
help="Apply a pitch shift to a voice recording."
)
if voice_changer:
voice_file = st.sidebar.file_uploader(
"Upload your voice recording",
type=["wav", "mp3"],
help="Upload a voice recording to apply pitch shift."
)
pitch_shift_semitones = st.sidebar.slider(
"Pitch Shift (semitones)",
min_value=-24,
max_value=24,
value=-5,
help="Set the number of semitones to shift the pitch."
)
else:
voice_file = None
pitch_shift_semitones = 0
st.sidebar.subheader("🎼 Algorithmic Composition")
algorithmic_composition = st.sidebar.checkbox(
"Enable Algorithmic Composition",
help="Include algorithmically composed elements."
)
if algorithmic_composition:
composition_options = ["Random Melody", "Ambient Soundscape", "Rhythmic Pattern"]
composition_type = st.sidebar.selectbox(
"Composition Type",
composition_options,
help="Choose a type of algorithmic composition."
)
else:
composition_type = None
# Collect waveform frequencies
waveform_frequencies = {}
for waveform_type in waveform_types:
frequency = st.sidebar.slider(
f"{waveform_type} Frequency (Hz)",
min_value=20,
max_value=20000,
value=440,
key=f"{waveform_type}_frequency_slider",
help=f"Set the frequency for the {waveform_type.lower()}."
)
waveform_frequencies[waveform_type] = frequency
# Functions to generate noise
def generate_white_noise(duration, sample_rate):
samples = np.random.normal(0, 1, int(duration * sample_rate))
return samples
def generate_pink_noise(duration, sample_rate):
# Voss-McCartney algorithm
samples = int(duration * sample_rate)
n_rows = 16
n_columns = int(np.ceil(samples / n_rows))
array = np.random.randn(n_rows, n_columns)
cumulative = np.cumsum(array, axis=0)
pink_noise = cumulative[-1, :]
pink_noise = pink_noise[:samples]
return pink_noise
def generate_brown_noise(duration, sample_rate):
samples = int(duration * sample_rate)
brown_noise = np.cumsum(np.random.randn(samples))
brown_noise = brown_noise / np.max(np.abs(brown_noise) + 1e-7)
return brown_noise
def generate_blue_noise(duration, sample_rate):
# Differentiated white noise
samples = int(duration * sample_rate)
white = np.random.normal(0, 1, samples)
blue_noise = np.diff(white)
blue_noise = np.concatenate(([0], blue_noise))
return blue_noise
def generate_violet_noise(duration, sample_rate):
# Differentiated blue noise
samples = int(duration * sample_rate)
white = np.random.normal(0, 1, samples)
violet_noise = np.diff(np.diff(white))
violet_noise = np.concatenate(([0, 0], violet_noise))
return violet_noise
def generate_grey_noise(duration, sample_rate):
# Shaped white noise to match human hearing
samples = int(duration * sample_rate)
white = np.random.normal(0, 1, samples)
freqs = np.fft.rfftfreq(samples, 1/sample_rate)
a_weighting = (12200**2 * freqs**4) / ((freqs**2 + 20.6**2) * np.sqrt((freqs**2 + 107.7**2) * (freqs**2 + 737.9**2)) * (freqs**2 + 12200**2))
a_weighting = a_weighting / np.max(a_weighting + 1e-7)
white_fft = np.fft.rfft(white)
grey_fft = white_fft * a_weighting
grey_noise = np.fft.irfft(grey_fft)
return grey_noise
# Functions to generate waveforms
def generate_waveform(waveform_type, frequency, duration, sample_rate):
t = np.linspace(0, duration, int(sample_rate * duration), endpoint=False)
if waveform_type == "Sine Wave":
waveform = np.sin(2 * np.pi * frequency * t)
elif waveform_type == "Square Wave":
waveform = signal.square(2 * np.pi * frequency * t)
elif waveform_type == "Sawtooth Wave":
waveform = signal.sawtooth(2 * np.pi * frequency * t)
elif waveform_type == "Triangle Wave":
waveform = signal.sawtooth(2 * np.pi * frequency * t, width=0.5)
else:
waveform = np.zeros_like(t)
return waveform
def generate_synth_tone(note, duration, sample_rate, waveform='Sine', envelope=None):
frequency = note_to_freq(note)
t = np.linspace(0, duration, int(sample_rate * duration), endpoint=False)
if waveform == 'Sine':
tone = np.sin(2 * np.pi * frequency * t)
elif waveform == 'Square':
tone = signal.square(2 * np.pi * frequency * t)
elif waveform == 'Sawtooth':
tone = signal.sawtooth(2 * np.pi * frequency * t)
elif waveform == 'Triangle':
tone = signal.sawtooth(2 * np.pi * frequency * t, width=0.5)
else:
tone = np.zeros_like(t)
if envelope:
tone *= envelope
return tone
def note_to_freq(note):
# Convert note (e.g., 'A4') to frequency
A4_freq = 440.0
note_names = ['C', 'C#', 'D', 'D#', 'E', 'F',
'F#', 'G', 'G#', 'A', 'A#', 'B']
octave = int(note[-1])
key_number = note_names.index(note[:-1])
n = key_number + (octave - 4) * 12
freq = A4_freq * (2 ** (n / 12))
return freq
def generate_envelope(total_samples, sample_rate, attack, decay, sustain, release):
envelope = np.zeros(total_samples)
attack_samples = int(attack * sample_rate)