gijs commited on
Commit
ab6695d
·
verified ·
1 Parent(s): cd16a87

Add files using upload-large-folder tool

Browse files
README.md ADDED
@@ -0,0 +1,142 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: cc0-1.0
3
+ pretty_name: ProgrammaticAudio
4
+ language:
5
+ - en
6
+ task_categories:
7
+ - audio-classification
8
+ - text-to-audio
9
+ tags:
10
+ - audio
11
+ - synthetic
12
+ - sound-synthesis
13
+ - audio-captioning
14
+ - webdataset
15
+ size_categories:
16
+ - 100K<n<1M
17
+ configs:
18
+ - config_name: default
19
+ data_files:
20
+ - split: train
21
+ path: train/*.tar
22
+ ---
23
+
24
+ # ProgrammaticAudio
25
+
26
+ ProgrammaticAudio is a synthetic audio-text dataset: 103,038 clips (304.4 hours), each with an English caption.
27
+ All audio is computed with numpy and scipy. No recordings, samples or learned models produce the audio. The dataset
28
+ covers 123 signal types in 14 categories, from basic waveforms (sine, square, sawtooth), coloured noise and synthesis
29
+ techniques to filters, effects, drum sounds, test signals and digital silence. It was built as a training source for
30
+ contrastive language-audio models, so that they see clean, precisely described synthetic sounds with known
31
+ parameters (frequency, note, filter, effect).
32
+
33
+ | | |
34
+ |---|---|
35
+ | Clips | 103,038 |
36
+ | Duration | 304.4 h, 2–20 s per clip (mean 10.6 s) |
37
+ | Audio | FLAC, 48 kHz, 16-bit, mono |
38
+ | Captions | one per clip, English: 94,997 generator templates, 8,041 model rewrites (see below) |
39
+ | Shards | 26 WebDataset tars, `train/0001.tar` … `train/0026.tar`, 4,096 clips per tar (the last one 638) |
40
+ | License | CC0 1.0 |
41
+
42
+ ## Format
43
+
44
+ Each tar holds pairs `prog_NNNNNN.flac` + `prog_NNNNNN.json`. The JSON fields are:
45
+
46
+ | Field | Meaning |
47
+ |---|---|
48
+ | `__key__` | sample key, `prog_` + the index in the generation plan |
49
+ | `__url__` | the tar the sample is in |
50
+ | `text` | the caption |
51
+ | `original_text` | only on the 8,041 rewritten captions: the template caption from the generator |
52
+ | `generation_method` | the generator function, e.g. `gen_karplus_strong / numpy+scipy` |
53
+ | `category` | one of the 14 categories below |
54
+
55
+ Example:
56
+
57
+ ```json
58
+ {"__key__": "prog_000011", "__url__": "ProgrammaticAudio/train/0001.tar", "text": "A very loud, pure 2.9 kHz sine wave",
59
+ "generation_method": "gen_sine / numpy+scipy", "category": "basic_waveforms"}
60
+ ```
61
+
62
+ Loading:
63
+
64
+ ```python
65
+ from datasets import load_dataset
66
+
67
+ ds = load_dataset("gijs/ProgrammaticAudio", split="train", streaming=True)
68
+ sample = next(iter(ds))
69
+ print(sample["json"]["text"], sample["flac"]["sampling_rate"])
70
+ ```
71
+
72
+ ## Categories
73
+
74
+ | Category | Clips | Generators (`gen_<name>`) |
75
+ |---|---:|---|
76
+ | basic_waveforms | 13,000 | sine, square, sawtooth, triangle, pulse_pwm, supersaw, wavetable, sample_hold, bit_noise, unison_detune, drone |
77
+ | noise | 6,000 | white_noise, pink_noise, brown_noise, blue_noise, violet_noise, grey_noise, vinyl_crackle, tape_hiss, filtered_noise |
78
+ | synthesis_techniques | 11,500 | fm, am, ring_mod, additive, subtractive, granular, karplus_strong, physical_model |
79
+ | musical_constructs | 9,438 | chord, arpeggio, scale, interval, melody, harmonic_series, dtmf |
80
+ | pitch_tuning | 5,000 | vibrato, pitch_bend, glide, octaver, harmonizer, detune, formant_shift |
81
+ | filters | 8,000 | lowpass, highpass, bandpass, notch, peaking_eq, shelf_eq, comb_filter, allpass, formant_vowel, filter_sweep, wah, resonance |
82
+ | dynamics | 5,000 | compressor, limiter, gate, sidechain_pump, transient_shaper, ducker, amplitude_sweep |
83
+ | distortion | 6,100 | hard_clip, soft_clip, overdrive, fuzz, tape_saturation, waveshaper, bitcrush, sample_rate_reduce, rectify, wow_flutter, vinyl_lofi |
84
+ | time_effects | 6,000 | delay, slapback, pingpong, multitap, tape_delay, reverb_room, reverb_hall, reverb_plate, reverb_spring, gated_reverb, shimmer_reverb, reverse_reverb |
85
+ | modulation | 5,000 | chorus, flanger, phaser, tremolo, autopan, rotary, freq_shifter, lfo_filter |
86
+ | percussive | 8,000 | kick, snare, hihat, click_pop, clap, drum_pattern |
87
+ | special | 4,000 | silence, near_silence, dc_offset, clipping_max, nyquist, sub_bass, impulse, test_tone, sweep, beating, chirp |
88
+ | editing | 5,000 | reverse, stutter_glitch, beat_repeat, freeze, spectral_blur, vocoder, time_stretch, varispeed, chop_gate |
89
+ | combinations | 11,000 | layered, sequence, with_effects, crossfade, sound_design |
90
+
91
+ The `combinations` generators layer, sequence, crossfade or process the outputs of the other generators.
92
+
93
+ ## How it was generated
94
+
95
+ The full generator is in [`generator/`](generator/) (`generate.py`, one module per category in `generators/`,
96
+ shared helpers in `utils.py`, caption vocabularies in `constants.py`). It ran once on a 48-core CPU node:
97
+ `python generate.py --workers 92 --seed 42`.
98
+
99
+ 1. **Plan.** Each generator is registered with a clip count. The plan lists 103,100 samples; sample `i` gets the key
100
+ `prog_{i:06d}` and its own random generator `numpy.random.default_rng(42 + i)`. All parameters (duration
101
+ uniform in 2–20 s, frequencies, notes, chord types, filter cutoffs, effect settings, ...) are drawn from it.
102
+ 2. **Signal.** The generator function returns the signal at 48 kHz, a list of descriptor words and a core phrase
103
+ (e.g. `["resonant"]`, `"Karplus-Strong plucked string at G#4"`). Pitched sounds name the frequency or note,
104
+ filters their cutoff, rhythmic sounds their BPM.
105
+ 3. **Level.** The clip is peak-normalised to a random amplitude, uniform in 0.05–1.0. The amplitude sets a volume
106
+ word: below 0.15 "very quiet", below 0.35 "quiet" or "soft", below 0.65 none, below 0.85 "loud", otherwise
107
+ "very loud". A 10 ms linear fade is applied at both ends, the signal is clipped to [-1, 1] and written as
108
+ 16-bit FLAC.
109
+ 4. **Caption.** The template is `A {volume}, {descriptors} {core}`, for example "A soft, resonant Karplus-Strong
110
+ plucked string at G#4" or "A 112 BPM shuffle drum pattern with kick, snare, and hi-hat".
111
+ 5. **Failures.** 62 `gen_melody` samples raised an error and were dropped, so `musical_constructs` has 9,438 clips
112
+ instead of 9,500.
113
+
114
+ Tars are filled in completion order across worker processes, so keys inside a tar are not contiguous.
115
+
116
+ **Reproducibility.** Running the generator again with seed 42 gives bit-identical audio. We regenerated 40 randomly
117
+ chosen clips and compared the decoded 16-bit PCM: all 40 are identical. The generator reads `TAR_DIR` (output root)
118
+ from the environment and needs numpy, scipy, soundfile and python-dotenv.
119
+
120
+ ## Caption rewrites
121
+
122
+ After generation, a caption clean-up pass over our whole audio collection replaced captions that had at most 4 words,
123
+ more than 40 words, or were not detected as English by `langdetect`. In this dataset that affected 8,041 clips
124
+ (7.8 %): 2,339 templates with at most 4 words (e.g. "A pink noise", "A DC offset signal") and 5,702 English
125
+ templates that `langdetect` misclassified (e.g. "A quiet, buzzy 815 Hz square wave"). The new caption was written by
126
+ [Qwen3-Omni-30B-A3B-Instruct](https://huggingface.co/Qwen/Qwen3-Omni-30B-A3B-Instruct), which received the audio and
127
+ the prompt "Write an audio caption for this audio in 1 sentence. For potential context, see original caption:
128
+ {template caption}". The template caption is kept in `original_text`. Use `original_text` when present if you want
129
+ the exact generator description for every clip.
130
+
131
+ ## Known quirks
132
+
133
+ - The volume word comes from the random peak amplitude, independent of the generator. Every clip is peak-normalised,
134
+ so `near_silence` clips (Gaussian noise floor) play at a normal level, and some captions combine contradicting
135
+ words, e.g. "A very loud, barely audible, faint ambient noise floor".
136
+ - `silence` clips are all-zero samples. `dc_offset` clips are a constant value with 10 ms ramps at both ends.
137
+ - Captions are templates. Many clips of the same generator share the same caption except for the numbers.
138
+
139
+ ## License
140
+
141
+ CC0 1.0. The audio and the template captions are fully synthetic and generated by our own code. The rewritten
142
+ captions were generated by Qwen3-Omni (Apache 2.0).
generator/constants.py ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Musical constants, descriptor pools, and lookup tables."""
2
+
3
+ NOTE_NAMES = ["C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"]
4
+
5
+ CHORD_TYPES = {
6
+ "major": [0, 4, 7],
7
+ "minor": [0, 3, 7],
8
+ "diminished": [0, 3, 6],
9
+ "augmented": [0, 4, 8],
10
+ "major seventh": [0, 4, 7, 11],
11
+ "minor seventh": [0, 3, 7, 10],
12
+ "dominant seventh": [0, 4, 7, 10],
13
+ "sus2": [0, 2, 7],
14
+ "sus4": [0, 5, 7],
15
+ "power": [0, 7],
16
+ }
17
+
18
+ SCALE_TYPES = {
19
+ "major": [0, 2, 4, 5, 7, 9, 11],
20
+ "natural minor": [0, 2, 3, 5, 7, 8, 10],
21
+ "harmonic minor": [0, 2, 3, 5, 7, 8, 11],
22
+ "dorian": [0, 2, 3, 5, 7, 9, 10],
23
+ "mixolydian": [0, 2, 4, 5, 7, 9, 10],
24
+ "pentatonic major": [0, 2, 4, 7, 9],
25
+ "pentatonic minor": [0, 3, 5, 7, 10],
26
+ "blues": [0, 3, 5, 6, 7, 10],
27
+ "chromatic": list(range(12)),
28
+ "whole tone": [0, 2, 4, 6, 8, 10],
29
+ }
30
+
31
+ INTERVAL_NAMES = {
32
+ 0: "unison", 1: "minor second", 2: "major second", 3: "minor third",
33
+ 4: "major third", 5: "perfect fourth", 6: "tritone", 7: "perfect fifth",
34
+ 8: "minor sixth", 9: "major sixth", 10: "minor seventh", 11: "major seventh",
35
+ 12: "octave",
36
+ }
37
+
38
+ DTMF_FREQS = {
39
+ '1': (697, 1209), '2': (697, 1336), '3': (697, 1477),
40
+ '4': (770, 1209), '5': (770, 1336), '6': (770, 1477),
41
+ '7': (852, 1209), '8': (852, 1336), '9': (852, 1477),
42
+ '0': (941, 1336), '*': (941, 1209), '#': (941, 1477),
43
+ }
44
+
45
+ DRUM_PATTERNS = {
46
+ "rock": {
47
+ "kick": [1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0],
48
+ "snare": [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0],
49
+ "hihat": [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0],
50
+ },
51
+ "four on the floor": {
52
+ "kick": [1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0],
53
+ "snare": [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0],
54
+ "hihat": [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
55
+ },
56
+ "breakbeat": {
57
+ "kick": [1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0],
58
+ "snare": [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1],
59
+ "hihat": [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0],
60
+ },
61
+ "shuffle": {
62
+ "kick": [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0],
63
+ "snare": [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0],
64
+ "hihat": [1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1],
65
+ },
66
+ "funk": {
67
+ "kick": [1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0],
68
+ "snare": [0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0],
69
+ "hihat": [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
70
+ },
71
+ }
72
+
73
+ VOWEL_FORMANTS = {
74
+ 'a': [(730, 80), (1090, 90), (2440, 120)],
75
+ 'e': [(530, 60), (1840, 100), (2480, 120)],
76
+ 'i': [(270, 40), (2290, 110), (3010, 130)],
77
+ 'o': [(570, 70), (840, 80), (2410, 120)],
78
+ 'u': [(300, 50), (870, 80), (2240, 110)],
79
+ }
80
+
81
+ # Descriptor pools for perceptual qualities
82
+ LOW_DESCS = ["dark", "warm", "thick", "boomy", "deep"]
83
+ HIGH_DESCS = ["bright", "thin", "airy", "crisp", "sharp"]
84
+ DIST_DESCS = ["harsh", "gritty", "crunchy", "aggressive"]
85
+ REVERB_DESCS = ["spacious", "wet", "distant", "ethereal"]
86
+ CLEAN_DESCS = ["clean", "pure", "smooth", "clear"]
87
+ METAL_DESCS = ["metallic", "resonant", "bell-like", "ringy"]
88
+ BUZZ_DESCS = ["buzzy", "nasal", "reedy"]
89
+ SOFT_DESCS = ["smooth", "gentle", "mellow", "warm"]
generator/generate.py ADDED
@@ -0,0 +1,278 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Generate ProgrammaticAudio dataset — 100k+ synthetic audio samples.
3
+
4
+ Usage:
5
+ python programmatic_audio/generate.py --workers 92 --seed 42
6
+ """
7
+
8
+ import os
9
+ import sys
10
+
11
+ # Ensure project root is on path for dotenv
12
+ _project_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
13
+ sys.path.insert(0, _project_root)
14
+
15
+ from dotenv import load_dotenv
16
+ load_dotenv(os.path.join(_project_root, '.env'))
17
+
18
+ import argparse
19
+ import concurrent.futures
20
+ import io
21
+ import json
22
+ import tarfile
23
+ import time
24
+ from concurrent.futures import ProcessPoolExecutor
25
+ from pathlib import Path
26
+
27
+ import numpy as np
28
+ import soundfile as sf
29
+
30
+ sys.stdout.reconfigure(line_buffering=True)
31
+
32
+ # ── Config ────────────────────────────────────────────────────────────────────
33
+
34
+ from utils import SR, SAMPLES_PER_TAR, _vol_word, _build_caption, _normalize
35
+
36
+ OUTPUT_DIR = Path(os.environ["TAR_DIR"]) / "ProgrammaticAudio" / "train"
37
+ INFO_DIR = Path(os.environ["TAR_DIR"]) / "ProgrammaticAudio"
38
+
39
+ # Import registry & all generator modules to trigger registration
40
+ from generators import REGISTRY, GEN_BY_NAME, CAT_BY_NAME
41
+ import generators.waveforms # noqa: F401
42
+ import generators.noise # noqa: F401
43
+ import generators.synthesis # noqa: F401
44
+ import generators.musical # noqa: F401
45
+ import generators.pitch # noqa: F401
46
+ import generators.filters # noqa: F401
47
+ import generators.dynamics # noqa: F401
48
+ import generators.distortion # noqa: F401
49
+ import generators.time_effects # noqa: F401
50
+ import generators.modulation # noqa: F401
51
+ import generators.percussive # noqa: F401
52
+ import generators.special # noqa: F401
53
+ import generators.editing # noqa: F401
54
+ import generators.combinations # noqa: F401
55
+
56
+
57
+ # ── Sample plan ───────────────────────────────────────────────────────────────
58
+
59
+ def build_sample_plan():
60
+ """Build list of (gen_name, global_idx, category) for all samples."""
61
+ plan = []
62
+ global_idx = 0
63
+ for func, count, category in REGISTRY:
64
+ for _ in range(count):
65
+ plan.append((func.__name__, global_idx, category))
66
+ global_idx += 1
67
+ return plan
68
+
69
+
70
+ # ── Single-sample generation (runs in worker process) ─────────────────────────
71
+
72
+ def generate_one_sample(args):
73
+ """Generate one audio sample. Returns (key, flac_bytes, meta) or None."""
74
+ gen_name, global_idx, category, master_seed = args
75
+ try:
76
+ rng = np.random.default_rng(master_seed + global_idx)
77
+ gen_func = GEN_BY_NAME[gen_name]
78
+
79
+ # Generate audio + caption parts
80
+ audio, descriptors, core = gen_func(rng)
81
+ if audio is None or len(audio) == 0:
82
+ return None
83
+
84
+ # Sanitize audio
85
+ if not np.isfinite(audio).all():
86
+ audio = np.nan_to_num(audio, nan=0.0, posinf=0.0, neginf=0.0)
87
+ audio = audio.astype(np.float64)
88
+
89
+ # Random volume & normalize
90
+ amplitude = rng.uniform(0.05, 1.0)
91
+ peak = np.max(np.abs(audio))
92
+ if peak > 1e-10:
93
+ audio = audio * (amplitude / peak)
94
+
95
+ vol = _vol_word(rng, amplitude)
96
+ caption = _build_caption(vol, descriptors, core)
97
+
98
+ # Fade in/out (10 ms)
99
+ fade_n = min(int(0.01 * SR), len(audio) // 4)
100
+ if fade_n > 1:
101
+ audio[:fade_n] *= np.linspace(0, 1, fade_n)
102
+ audio[-fade_n:] *= np.linspace(1, 0, fade_n)
103
+
104
+ # Clip
105
+ audio = np.clip(audio, -1.0, 1.0)
106
+
107
+ # Encode FLAC
108
+ buf = io.BytesIO()
109
+ sf.write(buf, audio.astype(np.float32), SR, subtype='PCM_16', format='FLAC')
110
+ flac_bytes = buf.getvalue()
111
+
112
+ key = f"prog_{global_idx:06d}"
113
+ tar_idx = global_idx // SAMPLES_PER_TAR + 1
114
+ meta = {
115
+ "__key__": key,
116
+ "__url__": f"ProgrammaticAudio/train/{tar_idx:04d}.tar",
117
+ "text": caption,
118
+ "generation_method": f"{gen_name} / numpy+scipy",
119
+ "category": category,
120
+ }
121
+ return (key, flac_bytes, meta)
122
+
123
+ except Exception:
124
+ return None
125
+
126
+
127
+ # ── Tar writing ───────────────────────────────────────────────────────────────
128
+
129
+ def write_tar(samples, tar_path):
130
+ tar_path.parent.mkdir(parents=True, exist_ok=True)
131
+ with tarfile.open(tar_path, "w") as tar:
132
+ for key, flac_bytes, meta in samples:
133
+ fi = tarfile.TarInfo(name=f"{key}.flac")
134
+ fi.size = len(flac_bytes)
135
+ tar.addfile(fi, io.BytesIO(flac_bytes))
136
+ jb = json.dumps(meta, ensure_ascii=False).encode("utf-8")
137
+ ji = tarfile.TarInfo(name=f"{key}.json")
138
+ ji.size = len(jb)
139
+ tar.addfile(ji, io.BytesIO(jb))
140
+ return len(samples)
141
+
142
+
143
+ def write_info_md(total_samples, total_tars):
144
+ INFO_DIR.mkdir(parents=True, exist_ok=True)
145
+ # Gather category counts
146
+ cat_counts = {}
147
+ for _, count, cat in REGISTRY:
148
+ cat_counts[cat] = cat_counts.get(cat, 0) + count
149
+ cat_table = "\n".join(f"| {c} | {n:,} |" for c, n in sorted(cat_counts.items()))
150
+
151
+ info = f"""# ProgrammaticAudio Dataset
152
+
153
+ ## Description
154
+ Synthetic audio dataset covering programmatically-generated waveforms, noise,
155
+ synthesis techniques, effects, dynamics, spatial characteristics, and perceptual
156
+ qualities. All generated purely with numpy and scipy — no real-world recordings.
157
+
158
+ ## License
159
+ Public domain / CC0 — fully synthetic, no copyright concerns.
160
+
161
+ ## Format
162
+ - Audio: FLAC, 48 kHz, 16-bit, mono
163
+ - Duration: 2–20 seconds per sample
164
+ - Metadata: JSON with `__key__`, `__url__`, `text`, `generation_method`, `category`
165
+ - Max {SAMPLES_PER_TAR} samples per tar
166
+
167
+ ## Statistics
168
+ - Total samples generated: {total_samples:,}
169
+ - Total tar files: {total_tars}
170
+
171
+ ## Categories
172
+ | Category | Target Count |
173
+ |----------|-------------|
174
+ {cat_table}
175
+
176
+ ## Generation
177
+ - Tool: `programmatic_audio/generate.py`
178
+ - Dependencies: numpy, scipy, soundfile
179
+ """
180
+ (INFO_DIR / "info.md").write_text(info)
181
+
182
+
183
+ # ── Main ──────────────────────────────────────────────────────────────────────
184
+
185
+ def main():
186
+ parser = argparse.ArgumentParser(description="Generate ProgrammaticAudio dataset")
187
+ parser.add_argument("--workers", type=int, default=92)
188
+ parser.add_argument("--seed", type=int, default=42)
189
+ args = parser.parse_args()
190
+
191
+ plan = build_sample_plan()
192
+ total_plan = len(plan)
193
+ print(f"Registered {len(REGISTRY)} generators, {total_plan:,} total samples planned")
194
+ print(f"Workers: {args.workers}, Seed: {args.seed}")
195
+ print(f"Output: {OUTPUT_DIR}")
196
+
197
+ OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
198
+
199
+ total_ok = 0
200
+ total_fail = 0
201
+ tar_idx = 0
202
+ buffer = []
203
+ t_start = time.time()
204
+
205
+ pool = ProcessPoolExecutor(max_workers=args.workers)
206
+ pending = set()
207
+ MAX_PENDING = args.workers * 3
208
+
209
+ def _flush():
210
+ nonlocal tar_idx
211
+ tar_idx += 1
212
+ path = OUTPUT_DIR / f"{tar_idx:04d}.tar"
213
+ n = write_tar(buffer, path)
214
+ print(f" Wrote {tar_idx:04d}.tar ({n} samples)")
215
+ buffer.clear()
216
+
217
+ def drain():
218
+ nonlocal total_ok, total_fail
219
+ done = {f for f in pending if f.done()}
220
+ for f in done:
221
+ pending.discard(f)
222
+ result = f.result()
223
+ if result is None:
224
+ total_fail += 1
225
+ else:
226
+ buffer.append(result)
227
+ total_ok += 1
228
+ if len(buffer) >= SAMPLES_PER_TAR:
229
+ _flush()
230
+
231
+ def wait_below(threshold):
232
+ nonlocal total_ok, total_fail
233
+ while len(pending) > threshold:
234
+ done_set, _ = concurrent.futures.wait(
235
+ pending, return_when=concurrent.futures.FIRST_COMPLETED)
236
+ pending.difference_update(done_set)
237
+ for f in done_set:
238
+ result = f.result()
239
+ if result is None:
240
+ total_fail += 1
241
+ else:
242
+ buffer.append(result)
243
+ total_ok += 1
244
+ if len(buffer) >= SAMPLES_PER_TAR:
245
+ _flush()
246
+
247
+ for i, (gen_name, global_idx, category) in enumerate(plan):
248
+ if len(pending) >= MAX_PENDING:
249
+ wait_below(MAX_PENDING // 2)
250
+
251
+ task_args = (gen_name, global_idx, category, args.seed)
252
+ pending.add(pool.submit(generate_one_sample, task_args))
253
+
254
+ if (i + 1) % 5000 == 0 or i == 0:
255
+ drain()
256
+ elapsed = time.time() - t_start
257
+ rate = (total_ok + total_fail) / elapsed if elapsed > 0 else 0
258
+ eta = (total_plan - i) / rate if rate > 0 else 0
259
+ print(f"[{i + 1:,}/{total_plan:,}] ok={total_ok:,} fail={total_fail:,} "
260
+ f"pending={len(pending)} rate={rate:.1f}/s ETA={eta:.0f}s")
261
+
262
+ print(f"Draining {len(pending)} remaining futures...")
263
+ wait_below(0)
264
+
265
+ if buffer:
266
+ _flush()
267
+
268
+ pool.shutdown()
269
+ elapsed = time.time() - t_start
270
+ print(f"\nDONE: {total_ok:,} samples, {total_fail:,} failures, "
271
+ f"{tar_idx} tars, {elapsed:.0f}s")
272
+
273
+ write_info_md(total_ok, tar_idx)
274
+ print(f"Wrote {INFO_DIR / 'info.md'}")
275
+
276
+
277
+ if __name__ == "__main__":
278
+ main()
generator/generators/__init__.py ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Generator registry for programmatic audio generation."""
2
+
3
+ REGISTRY = [] # [(func, count, category), ...]
4
+ GEN_BY_NAME = {} # {name: func}
5
+ CAT_BY_NAME = {} # {name: category}
6
+
7
+
8
+ def register(count, category):
9
+ """Decorator to register a generator function with sample count and category."""
10
+ def decorator(func):
11
+ REGISTRY.append((func, count, category))
12
+ GEN_BY_NAME[func.__name__] = func
13
+ CAT_BY_NAME[func.__name__] = category
14
+ return func
15
+ return decorator
generator/generators/combinations.py ADDED
@@ -0,0 +1,188 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Category N: Combinations & Layers — 11,000 samples."""
2
+
3
+ import numpy as np
4
+ from scipy import signal as sig
5
+
6
+ from generators import register
7
+ from utils import (SR, _dur, _ns, _t, _log_uniform, _freq_str,
8
+ _random_base, _random_source, _pick, _normalize,
9
+ _chorus, _flanger, _compress, _apply_reverb, _reverb_ir,
10
+ _apply_delay, _sidechain_pump, _safe_butter, _apply_sos)
11
+ from constants import CLEAN_DESCS, SOFT_DESCS, REVERB_DESCS
12
+
13
+
14
+ @register(3000, "combinations")
15
+ def gen_layered(rng):
16
+ dur = _dur(rng)
17
+ n = _ns(dur)
18
+ n_layers = int(rng.integers(2, 5))
19
+ audio = np.zeros(n)
20
+ layer_descs = []
21
+ for _ in range(n_layers):
22
+ layer, desc, _ = _random_source(rng, n)
23
+ layer *= rng.uniform(0.3, 1.0)
24
+ audio += layer
25
+ layer_descs.append(desc)
26
+ if len(layer_descs) == 2:
27
+ core = f"layered sound combining {layer_descs[0]} and {layer_descs[1]}"
28
+ else:
29
+ core = f"layered sound combining {', '.join(layer_descs[:-1])}, and {layer_descs[-1]}"
30
+ return audio, _pick(rng, ["rich", "complex", "dense", "full"]), core
31
+
32
+
33
+ @register(2000, "combinations")
34
+ def gen_sequence(rng):
35
+ dur = _dur(rng, 4, 20)
36
+ n = _ns(dur)
37
+ n_parts = int(rng.integers(2, 5))
38
+ part_len = n // n_parts
39
+ audio = np.zeros(n)
40
+ part_descs = []
41
+ for i in range(n_parts):
42
+ start = i * part_len
43
+ end = min(start + part_len, n)
44
+ part, desc, _ = _random_source(rng, end - start)
45
+ audio[start:end] = part[:end - start]
46
+ part_descs.append(desc)
47
+ # Crossfade between parts
48
+ fade = min(int(0.02 * SR), part_len // 4)
49
+ for i in range(1, n_parts):
50
+ pos = i * part_len
51
+ if pos + fade <= n and pos - fade >= 0:
52
+ audio[pos - fade:pos] *= np.linspace(1, 0, fade)
53
+ audio[pos:pos + fade] *= np.linspace(0, 1, fade)
54
+ if len(part_descs) == 2:
55
+ core = f"sequence of {part_descs[0]} and {part_descs[1]}"
56
+ else:
57
+ core = f"sequence of {', '.join(part_descs[:-1])}, and {part_descs[-1]}"
58
+ return audio, _pick(rng, ["varied", "evolving"]), core
59
+
60
+
61
+ @register(4000, "combinations")
62
+ def gen_with_effects(rng):
63
+ dur = _dur(rng)
64
+ n = _ns(dur)
65
+ audio, desc, _ = _random_source(rng, n)
66
+ # Apply 2-4 random effects
67
+ effect_pool = [
68
+ ("chorus", lambda a, r: _chorus(a, r)),
69
+ ("compression", lambda a, r: _compress(a, r.uniform(-20, -5), r.uniform(2, 8))),
70
+ ("reverb", lambda a, r: _apply_reverb(a, _reverb_ir(r, r.uniform(0.5, 3), "hall"),
71
+ r.uniform(0.2, 0.5))),
72
+ ("delay", lambda a, r: _apply_delay(a, r.uniform(0.1, 0.4), r.uniform(0.3, 0.6),
73
+ r.uniform(0.2, 0.4))),
74
+ ("flanger", lambda a, r: _flanger(a, r)),
75
+ ("distortion", lambda a, r: np.tanh(a * r.uniform(2, 6))),
76
+ ("low-pass filter", lambda a, r: _apply_sos(a, _safe_butter(
77
+ 3, _log_uniform(r, 500, 5000), 'low'))),
78
+ ("high-pass filter", lambda a, r: _apply_sos(a, _safe_butter(
79
+ 3, _log_uniform(r, 200, 3000), 'high'))),
80
+ ]
81
+ n_effects = int(rng.integers(2, 5))
82
+ chosen = rng.choice(len(effect_pool), size=min(n_effects, len(effect_pool)), replace=False)
83
+ effect_names = []
84
+ for idx in chosen:
85
+ name, func = effect_pool[int(idx)]
86
+ try:
87
+ audio = func(audio, rng)
88
+ except Exception:
89
+ continue
90
+ effect_names.append(name)
91
+ if not effect_names:
92
+ effect_names = ["processing"]
93
+ if len(effect_names) == 1:
94
+ fx_str = effect_names[0]
95
+ elif len(effect_names) == 2:
96
+ fx_str = f"{effect_names[0]} and {effect_names[1]}"
97
+ else:
98
+ fx_str = ", ".join(effect_names[:-1]) + f", and {effect_names[-1]}"
99
+ return audio, _pick(rng, ["processed", "layered", "thick"]), \
100
+ f"{desc} with {fx_str}"
101
+
102
+
103
+ @register(1000, "combinations")
104
+ def gen_crossfade(rng):
105
+ dur = _dur(rng)
106
+ n = _ns(dur)
107
+ audio_a, desc_a, _ = _random_source(rng, n)
108
+ audio_b, desc_b, _ = _random_source(rng, n)
109
+ fade = np.linspace(0, 1, n)
110
+ audio = (1 - fade) * audio_a + fade * audio_b
111
+ return audio, _pick(rng, ["evolving", "morphing", "transitioning"]), \
112
+ f"crossfade from {desc_a} into {desc_b}"
113
+
114
+
115
+ @register(1000, "combinations")
116
+ def gen_sound_design(rng):
117
+ dur = _dur(rng)
118
+ n = _ns(dur)
119
+ # Start with synthesis
120
+ synth_type = int(rng.integers(0, 4))
121
+ t = _t(n)
122
+ if synth_type == 0:
123
+ # FM
124
+ carrier = _log_uniform(rng, 100, 1000)
125
+ index = rng.uniform(1, 8)
126
+ ratio = float(rng.choice([1, 2, 3]))
127
+ audio = np.sin(2 * np.pi * carrier * t + index * np.sin(2 * np.pi * carrier * ratio * t))
128
+ base_desc = "FM synthesis"
129
+ elif synth_type == 1:
130
+ # Granular texture
131
+ grain_size = int(rng.uniform(0.01, 0.05) * SR)
132
+ window = np.hanning(grain_size)
133
+ audio = np.zeros(n)
134
+ src = rng.standard_normal(n)
135
+ for _ in range(int(rng.uniform(20, 80) * dur)):
136
+ sp = int(rng.integers(0, max(n - grain_size, 1)))
137
+ op = int(rng.integers(0, max(n - grain_size, 1)))
138
+ end = min(op + grain_size, n)
139
+ gl = end - op
140
+ audio[op:end] += src[sp:sp + gl] * window[:gl]
141
+ base_desc = "granular texture"
142
+ elif synth_type == 2:
143
+ # Additive with movement
144
+ freq = _log_uniform(rng, 100, 500)
145
+ audio = np.zeros(n)
146
+ for h in range(1, int(rng.integers(5, 15))):
147
+ f = freq * h
148
+ if f > SR / 2:
149
+ break
150
+ lfo = 0.5 + 0.5 * np.sin(2 * np.pi * rng.uniform(0.05, 0.5) * t)
151
+ audio += lfo * np.sin(2 * np.pi * f * t) / h
152
+ base_desc = "evolving additive synthesis"
153
+ else:
154
+ audio, base_desc, _ = _random_source(rng, n)
155
+ # Apply 2-3 effects
156
+ effects = []
157
+ if rng.random() < 0.7:
158
+ # Filter sweep
159
+ f_start = _log_uniform(rng, 200, 5000)
160
+ f_end = _log_uniform(rng, 200, 5000)
161
+ block = 512
162
+ freqs = np.geomspace(f_start, f_end, n // block + 1)
163
+ out = np.zeros(n)
164
+ for i in range(0, n, block):
165
+ end = min(i + block, n)
166
+ f = float(np.clip(freqs[i // block], 20, SR / 2 - 100))
167
+ sos = _safe_butter(2, f, 'low')
168
+ if sos is not None:
169
+ out[i:end] = _apply_sos(audio[i:end], sos)
170
+ else:
171
+ out[i:end] = audio[i:end]
172
+ audio = out
173
+ effects.append("filter sweep")
174
+ if rng.random() < 0.6:
175
+ ir = _reverb_ir(rng, rng.uniform(1, 4), "hall")
176
+ audio = _apply_reverb(audio, ir, rng.uniform(0.2, 0.5))
177
+ effects.append("reverb")
178
+ if rng.random() < 0.5:
179
+ audio = np.tanh(audio * rng.uniform(1.5, 4))
180
+ effects.append("saturation")
181
+ fx_str = ""
182
+ if effects:
183
+ if len(effects) == 1:
184
+ fx_str = f" with {effects[0]}"
185
+ else:
186
+ fx_str = f" with {', '.join(effects[:-1])}, and {effects[-1]}"
187
+ return audio, _pick(rng, ["evolving", "complex", "textural", "atmospheric"]), \
188
+ f"sound design texture: {base_desc}{fx_str}"
generator/generators/distortion.py ADDED
@@ -0,0 +1,177 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Category H: Distortion / Saturation / Lo-fi — 6,000 samples."""
2
+
3
+ import numpy as np
4
+ from scipy import signal as sig
5
+
6
+ from generators import register
7
+ from utils import (SR, _dur, _ns, _t, _log_uniform, _wave, _freq_str,
8
+ _random_base, _pick, _safe_butter, _apply_sos, _normalize)
9
+ from constants import DIST_DESCS, LOW_DESCS, HIGH_DESCS, SOFT_DESCS, BUZZ_DESCS
10
+
11
+
12
+ @register(600, "distortion")
13
+ def gen_hard_clip(rng):
14
+ dur = _dur(rng)
15
+ n = _ns(dur)
16
+ audio, desc, _ = _random_base(rng, n, allow_noise=False)
17
+ drive = rng.uniform(2, 10)
18
+ threshold = rng.uniform(0.2, 0.6)
19
+ audio = np.clip(audio * drive, -threshold, threshold) / threshold
20
+ return audio, _pick(rng, DIST_DESCS), f"hard-clipped {desc}"
21
+
22
+
23
+ @register(600, "distortion")
24
+ def gen_soft_clip(rng):
25
+ dur = _dur(rng)
26
+ n = _ns(dur)
27
+ audio, desc, _ = _random_base(rng, n, allow_noise=False)
28
+ drive = rng.uniform(2, 8)
29
+ audio = np.tanh(audio * drive)
30
+ return audio, _pick(rng, SOFT_DESCS + ["saturated"]), f"soft-clipped {desc}"
31
+
32
+
33
+ @register(600, "distortion")
34
+ def gen_overdrive(rng):
35
+ dur = _dur(rng)
36
+ n = _ns(dur)
37
+ audio, desc, _ = _random_base(rng, n, allow_noise=False)
38
+ drive = rng.uniform(3, 15)
39
+ # Asymmetric soft clip
40
+ audio = audio * drive
41
+ pos = audio > 0
42
+ neg = audio < 0
43
+ audio[pos] = 1 - np.exp(-audio[pos])
44
+ audio[neg] = -(1 - np.exp(audio[neg])) * 0.8
45
+ return audio, _pick(rng, ["gritty", "overdriven", "warm", "driven"]), \
46
+ f"overdriven {desc}"
47
+
48
+
49
+ @register(600, "distortion")
50
+ def gen_fuzz(rng):
51
+ dur = _dur(rng)
52
+ n = _ns(dur)
53
+ audio, desc, _ = _random_base(rng, n, allow_noise=False)
54
+ drive = rng.uniform(10, 50)
55
+ audio = np.sign(audio) * (1 - np.exp(-np.abs(audio * drive)))
56
+ return audio, _pick(rng, ["aggressive", "fuzzy", "destroyed", "extreme"]), \
57
+ f"fuzzy {desc}"
58
+
59
+
60
+ @register(500, "distortion")
61
+ def gen_tape_saturation(rng):
62
+ dur = _dur(rng)
63
+ n = _ns(dur)
64
+ audio, desc, _ = _random_base(rng, n, allow_noise=False)
65
+ drive = rng.uniform(1.5, 5)
66
+ audio = np.tanh(audio * drive) * 0.9
67
+ # Tape-like frequency response: slight high cut, bass bump
68
+ sos_lp = _safe_butter(2, rng.uniform(8000, 14000), 'low')
69
+ if sos_lp is not None:
70
+ audio = _apply_sos(audio, sos_lp)
71
+ return audio, _pick(rng, ["warm", "saturated", "analog", "tape-like"]), \
72
+ f"tape-saturated {desc}"
73
+
74
+
75
+ @register(600, "distortion")
76
+ def gen_waveshaper(rng):
77
+ dur = _dur(rng)
78
+ n = _ns(dur)
79
+ audio, desc, _ = _random_base(rng, n, allow_noise=False)
80
+ # Chebyshev polynomial waveshaping
81
+ order = int(rng.integers(2, 6))
82
+ audio_clipped = np.clip(audio, -1, 1)
83
+ shaped = np.polynomial.chebyshev.chebval(audio_clipped,
84
+ [0] * order + [1])
85
+ return _normalize(shaped), _pick(rng, DIST_DESCS + ["complex"]), \
86
+ f"waveshaped {desc} with Chebyshev polynomial distortion"
87
+
88
+
89
+ @register(600, "distortion")
90
+ def gen_bitcrush(rng):
91
+ dur = _dur(rng)
92
+ n = _ns(dur)
93
+ audio, desc, _ = _random_base(rng, n)
94
+ bits = int(rng.integers(2, 8))
95
+ levels = 2 ** bits
96
+ audio = np.round(audio * levels / 2) / (levels / 2)
97
+ return audio, _pick(rng, ["crunchy", "lo-fi", "digital", "retro"]), \
98
+ f"{bits}-bit bitcrushed {desc}"
99
+
100
+
101
+ @register(500, "distortion")
102
+ def gen_sample_rate_reduce(rng):
103
+ dur = _dur(rng)
104
+ n = _ns(dur)
105
+ audio, desc, _ = _random_base(rng, n)
106
+ target_sr = int(_log_uniform(rng, 2000, 16000))
107
+ factor = max(SR // target_sr, 2)
108
+ # Decimate by holding samples
109
+ indices = np.repeat(np.arange(0, n, factor), factor)[:n]
110
+ audio = audio[indices]
111
+ return audio, _pick(rng, ["lo-fi", "decimated", "aliased", "crunchy"]), \
112
+ f"lo-fi {desc} at {target_sr} Hz effective sample rate"
113
+
114
+
115
+ @register(500, "distortion")
116
+ def gen_rectify(rng):
117
+ dur = _dur(rng)
118
+ n = _ns(dur)
119
+ freq = _log_uniform(rng, 50, 2000)
120
+ t = _t(n)
121
+ audio = np.sin(2 * np.pi * freq * t)
122
+ rect_type = str(rng.choice(["half", "full"]))
123
+ if rect_type == "half":
124
+ audio = np.maximum(audio, 0)
125
+ else:
126
+ audio = np.abs(audio)
127
+ return audio, _pick(rng, BUZZ_DESCS + ["distorted"]), \
128
+ f"{rect_type}-wave rectified {_freq_str(freq)} sine"
129
+
130
+
131
+ @register(500, "distortion")
132
+ def gen_wow_flutter(rng):
133
+ dur = _dur(rng)
134
+ n = _ns(dur)
135
+ audio, desc, _ = _random_base(rng, n, allow_noise=False)
136
+ # Wow: slow pitch drift (0.5-3 Hz)
137
+ wow_rate = rng.uniform(0.5, 3)
138
+ wow_depth = rng.uniform(0.002, 0.01)
139
+ # Flutter: fast pitch drift (5-15 Hz)
140
+ flutter_rate = rng.uniform(5, 15)
141
+ flutter_depth = rng.uniform(0.0005, 0.002)
142
+ t = _t(n)
143
+ mod = wow_depth * np.sin(2 * np.pi * wow_rate * t) + \
144
+ flutter_depth * np.sin(2 * np.pi * flutter_rate * t)
145
+ # Time-varying delay for pitch modulation
146
+ delay_samples = (mod * SR).astype(int)
147
+ indices = np.arange(n) - delay_samples
148
+ indices = np.clip(indices, 0, n - 1)
149
+ audio = audio[indices]
150
+ return audio, _pick(rng, ["wobbly", "warped", "degraded", "tape-like"]), \
151
+ f"{desc} with tape-like wow and flutter pitch drift"
152
+
153
+
154
+ @register(500, "distortion")
155
+ def gen_vinyl_lofi(rng):
156
+ dur = _dur(rng)
157
+ n = _ns(dur)
158
+ audio, desc, _ = _random_base(rng, n, allow_noise=False)
159
+ # Warmth: light saturation + low-pass
160
+ audio = np.tanh(audio * rng.uniform(1.2, 2.5))
161
+ sos = _safe_butter(2, rng.uniform(6000, 12000), 'low')
162
+ if sos is not None:
163
+ audio = _apply_sos(audio, sos)
164
+ # Add crackle
165
+ n_crackles = int(rng.uniform(3, 30) * dur)
166
+ for _ in range(n_crackles):
167
+ pos = int(rng.integers(0, n))
168
+ cl = min(int(rng.uniform(0.0001, 0.001) * SR), n - pos)
169
+ audio[pos:pos + cl] += rng.uniform(0.1, 0.4) * float(rng.choice([-1, 1]))
170
+ # Subtle rumble
171
+ rumble = rng.standard_normal(n) * 0.02
172
+ sos_lp = _safe_butter(2, 80, 'low')
173
+ if sos_lp is not None:
174
+ rumble = _apply_sos(rumble, sos_lp)
175
+ audio += rumble
176
+ return audio, _pick(rng, ["lo-fi", "warm", "vintage", "worn"]), \
177
+ f"lo-fi {desc} with vinyl crackle and warmth"
generator/generators/dynamics.py ADDED
@@ -0,0 +1,139 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Category G: Dynamics Processing — 5,000 samples."""
2
+
3
+ import numpy as np
4
+ from scipy import signal as sig
5
+
6
+ from generators import register
7
+ from utils import (SR, _dur, _ns, _t, _log_uniform, _freq_str, _random_base,
8
+ _pick, _compress, _sidechain_pump, _safe_butter, _apply_sos)
9
+ from constants import CLEAN_DESCS, LOW_DESCS, SOFT_DESCS
10
+
11
+
12
+ @register(800, "dynamics")
13
+ def gen_compressor(rng):
14
+ dur = _dur(rng)
15
+ n = _ns(dur)
16
+ audio, desc, _ = _random_base(rng, n)
17
+ threshold = rng.uniform(-20, -5)
18
+ ratio = rng.uniform(2, 10)
19
+ audio = _compress(audio, threshold, ratio)
20
+ return audio, _pick(rng, ["punchy", "squashed", "controlled", "tight"]), \
21
+ f"compressed {desc}"
22
+
23
+
24
+ @register(500, "dynamics")
25
+ def gen_limiter(rng):
26
+ dur = _dur(rng)
27
+ n = _ns(dur)
28
+ audio, desc, _ = _random_base(rng, n)
29
+ ceiling = rng.uniform(0.3, 0.8)
30
+ audio = np.clip(audio, -ceiling, ceiling) / ceiling
31
+ return audio, _pick(rng, ["loud", "squashed", "brickwalled"]), \
32
+ f"hard-limited {desc}"
33
+
34
+
35
+ @register(600, "dynamics")
36
+ def gen_gate(rng):
37
+ dur = _dur(rng)
38
+ n = _ns(dur)
39
+ audio, desc, _ = _random_base(rng, n, allow_noise=False)
40
+ gate_rate = rng.uniform(2, 16)
41
+ t = _t(n)
42
+ # Rhythmic gate
43
+ gate_env = (np.sin(2 * np.pi * gate_rate * t) > rng.uniform(-0.5, 0.3)).astype(float)
44
+ # Smooth edges
45
+ smooth_samples = int(0.005 * SR)
46
+ if smooth_samples > 1:
47
+ kernel = np.ones(smooth_samples) / smooth_samples
48
+ gate_env = np.convolve(gate_env, kernel, mode='same')
49
+ audio *= gate_env
50
+ return audio, _pick(rng, ["choppy", "rhythmic", "stuttering"]), \
51
+ f"noise-gated {desc} creating rhythmic stutters"
52
+
53
+
54
+ @register(1000, "dynamics")
55
+ def gen_sidechain_pump(rng):
56
+ dur = _dur(rng, 4, 20)
57
+ n = _ns(dur)
58
+ audio, desc, _ = _random_base(rng, n)
59
+ bpm = rng.uniform(100, 160)
60
+ depth = rng.uniform(0.5, 0.95)
61
+ curve = rng.uniform(2, 5)
62
+ audio = _sidechain_pump(audio, bpm, depth, curve)
63
+ return audio, _pick(rng, ["pumping", "pulsing", "ducking", "rhythmic"]), \
64
+ f"{desc} with heavy sidechain pumping at {bpm:.0f} BPM"
65
+
66
+
67
+ @register(600, "dynamics")
68
+ def gen_transient_shaper(rng):
69
+ dur = _dur(rng)
70
+ n = _ns(dur)
71
+ # Generate a percussive base
72
+ freq = _log_uniform(rng, 100, 2000)
73
+ t = _t(n)
74
+ audio = np.sin(2 * np.pi * freq * t)
75
+ # Create repeating transients
76
+ hit_rate = rng.uniform(2, 8)
77
+ period = int(SR / hit_rate)
78
+ env = np.zeros(n)
79
+ for pos in range(0, n, period):
80
+ click_len = min(int(rng.uniform(0.001, 0.01) * SR), n - pos)
81
+ env[pos:pos + click_len] += np.exp(-np.arange(click_len) / (0.002 * SR))
82
+ # Enhance transients
83
+ attack_gain = rng.uniform(2, 6)
84
+ env_boost = 1.0 + (attack_gain - 1) * np.minimum(env, 1.0)
85
+ audio *= env_boost
86
+ return audio, _pick(rng, ["snappy", "punchy", "sharp", "transient"]), \
87
+ f"transient-enhanced click pattern at {_freq_str(freq)}"
88
+
89
+
90
+ @register(500, "dynamics")
91
+ def gen_ducker(rng):
92
+ dur = _dur(rng, 4, 20)
93
+ n = _ns(dur)
94
+ # Background: noise
95
+ bg = rng.standard_normal(n) * 0.5
96
+ sos = _safe_butter(2, 3000, 'low')
97
+ if sos is not None:
98
+ bg = _apply_sos(bg, sos)
99
+ # Foreground: tone that appears periodically
100
+ freq = _log_uniform(rng, 200, 1000)
101
+ t = _t(n)
102
+ tone = np.sin(2 * np.pi * freq * t)
103
+ period = rng.uniform(1, 3)
104
+ period_samples = int(period * SR)
105
+ tone_dur = int(rng.uniform(0.2, 0.8) * period_samples)
106
+ # Create ducking envelope
107
+ duck_env = np.ones(n)
108
+ tone_env = np.zeros(n)
109
+ for pos in range(0, n, period_samples):
110
+ end = min(pos + tone_dur, n)
111
+ tone_env[pos:end] = 1.0
112
+ duck_env[pos:end] = 0.2
113
+ # Smooth
114
+ sm = int(0.02 * SR)
115
+ if sm > 1:
116
+ kernel = np.ones(sm) / sm
117
+ duck_env = np.convolve(duck_env, kernel, mode='same')
118
+ tone_env = np.convolve(tone_env, kernel, mode='same')
119
+ audio = bg * duck_env + tone * tone_env * 0.5
120
+ return audio, _pick(rng, ["ducking", "dynamic"]), \
121
+ f"noise bed that ducks when a {_freq_str(freq)} tone plays"
122
+
123
+
124
+ @register(1000, "dynamics")
125
+ def gen_amplitude_sweep(rng):
126
+ dur = _dur(rng)
127
+ n = _ns(dur)
128
+ audio, desc, _ = _random_base(rng, n)
129
+ direction = str(rng.choice(["crescendo", "decrescendo"]))
130
+ curve = rng.uniform(0.5, 3)
131
+ if direction == "crescendo":
132
+ env = np.linspace(0, 1, n) ** curve
133
+ sweep_desc = "crescendo from silence to loud"
134
+ else:
135
+ env = np.linspace(1, 0, n) ** curve
136
+ sweep_desc = "decrescendo from loud to silence"
137
+ audio *= env
138
+ return audio, _pick(rng, ["sweeping", "dynamic", "evolving"]), \
139
+ f"{sweep_desc} {desc}"
generator/generators/editing.py ADDED
@@ -0,0 +1,225 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Category M: Editing / Special Processing — 5,000 samples."""
2
+
3
+ import numpy as np
4
+ from scipy import signal as sig
5
+
6
+ from generators import register
7
+ from utils import (SR, _dur, _ns, _t, _log_uniform, _wave, _freq_str,
8
+ _random_base, _random_source, _pick, _normalize,
9
+ _safe_butter, _apply_sos, _make_kick, _make_snare)
10
+ from constants import CLEAN_DESCS, METAL_DESCS
11
+
12
+
13
+ @register(600, "editing")
14
+ def gen_reverse(rng):
15
+ dur = _dur(rng)
16
+ n = _ns(dur)
17
+ audio, desc, _ = _random_source(rng, n)
18
+ audio = audio[::-1].copy()
19
+ return audio, _pick(rng, ["reversed", "backwards"]), f"reversed {desc}"
20
+
21
+
22
+ @register(800, "editing")
23
+ def gen_stutter_glitch(rng):
24
+ dur = _dur(rng)
25
+ n = _ns(dur)
26
+ audio, desc, _ = _random_source(rng, n)
27
+ # Pick a short fragment and repeat it
28
+ frag_len = int(rng.uniform(0.01, 0.1) * SR)
29
+ frag_start = int(rng.integers(0, max(n - frag_len, 1)))
30
+ frag = audio[frag_start:frag_start + frag_len]
31
+ # Replace random sections with repeated fragment
32
+ n_glitches = int(rng.integers(5, 30))
33
+ for _ in range(n_glitches):
34
+ pos = int(rng.integers(0, max(n - frag_len, 1)))
35
+ repeats = int(rng.integers(2, 10))
36
+ for r in range(repeats):
37
+ start = pos + r * frag_len
38
+ end = min(start + frag_len, n)
39
+ if start >= n:
40
+ break
41
+ audio[start:end] = frag[:end - start]
42
+ return audio, _pick(rng, ["glitchy", "stuttering", "broken", "digital"]), \
43
+ f"glitchy, stuttering repeating fragment of {desc}"
44
+
45
+
46
+ @register(600, "editing")
47
+ def gen_beat_repeat(rng):
48
+ dur = _dur(rng, 3, 15)
49
+ n = _ns(dur)
50
+ audio, desc, _ = _random_source(rng, n)
51
+ # Pick a beat-length slice and repeat
52
+ beat_len = int(rng.uniform(0.1, 0.5) * SR)
53
+ slice_start = int(rng.integers(0, max(n - beat_len, 1)))
54
+ beat_slice = audio[slice_start:slice_start + beat_len]
55
+ # Repeat in a rhythmic pattern
56
+ out = np.zeros(n)
57
+ pos = 0
58
+ while pos < n:
59
+ if rng.random() < 0.6: # 60% chance to play the repeated slice
60
+ end = min(pos + beat_len, n)
61
+ out[pos:end] = beat_slice[:end - pos]
62
+ else:
63
+ end = min(pos + beat_len, n)
64
+ out[pos:end] = audio[pos:end]
65
+ pos += beat_len
66
+ return out, _pick(rng, ["rhythmic", "repetitive", "chopped"]), \
67
+ f"rhythmic beat-repeat slice of {desc}"
68
+
69
+
70
+ @register(600, "editing")
71
+ def gen_freeze(rng):
72
+ dur = _dur(rng)
73
+ n = _ns(dur)
74
+ # Short source
75
+ src_dur = min(rng.uniform(0.5, 2), dur)
76
+ src_n = _ns(src_dur)
77
+ src, src_desc, _ = _random_source(rng, src_n)
78
+ frame_size = 2048
79
+ freeze_pos = int(rng.integers(0, max(src_n - frame_size, 1)))
80
+ frame = src[freeze_pos:freeze_pos + frame_size]
81
+ mag = np.abs(np.fft.rfft(frame))
82
+ # Resynthesize with slowly evolving random phase
83
+ hop = frame_size // 4
84
+ n_frames = n // hop + 1
85
+ audio = np.zeros(n + frame_size)
86
+ window = np.hanning(frame_size)
87
+ for i in range(n_frames):
88
+ phase = rng.uniform(-np.pi, np.pi, len(mag))
89
+ spectrum = mag * np.exp(1j * phase)
90
+ frame_out = np.fft.irfft(spectrum, frame_size) * window
91
+ pos = i * hop
92
+ if pos + frame_size <= len(audio):
93
+ audio[pos:pos + frame_size] += frame_out
94
+ audio = audio[:n]
95
+ return audio, _pick(rng, ["frozen", "sustained", "static", "shimmering"]), \
96
+ f"frozen spectral slice of {src_desc}"
97
+
98
+
99
+ @register(500, "editing")
100
+ def gen_spectral_blur(rng):
101
+ dur = _dur(rng)
102
+ n = _ns(dur)
103
+ audio, desc, _ = _random_base(rng, n)
104
+ # Spectral blur: smooth magnitudes, randomize phase
105
+ fft = np.fft.rfft(audio)
106
+ mag = np.abs(fft)
107
+ kernel_size = int(rng.integers(5, 50))
108
+ kernel = np.ones(kernel_size) / kernel_size
109
+ mag_smooth = np.convolve(mag, kernel, mode='same')
110
+ phase = rng.uniform(-np.pi, np.pi, len(fft))
111
+ blurred = mag_smooth * np.exp(1j * phase)
112
+ audio = np.fft.irfft(blurred, n)
113
+ return audio, _pick(rng, ["blurred", "smeared", "hazy", "diffuse"]), \
114
+ f"spectrally blurred {desc}"
115
+
116
+
117
+ @register(600, "editing")
118
+ def gen_vocoder(rng):
119
+ dur = _dur(rng)
120
+ n = _ns(dur)
121
+ # Carrier
122
+ carrier_type = str(rng.choice(["noise", "sawtooth"]))
123
+ if carrier_type == "noise":
124
+ carrier = rng.standard_normal(n)
125
+ c_desc = "noise carrier"
126
+ else:
127
+ freq = _log_uniform(rng, 80, 400)
128
+ carrier = sig.sawtooth(2 * np.pi * freq * _t(n))
129
+ c_desc = f"sawtooth carrier at {_freq_str(freq)}"
130
+ # Modulator
131
+ mod_freq = _log_uniform(rng, 100, 1000)
132
+ t = _t(n)
133
+ modulator = np.sin(2 * np.pi * mod_freq * t)
134
+ m_desc = f"tonal modulator at {_freq_str(mod_freq)}"
135
+ # Vocoder bands
136
+ n_bands = int(rng.integers(8, 24))
137
+ audio = np.zeros(n)
138
+ band_freqs = np.logspace(np.log10(100), np.log10(10000), n_bands + 1)
139
+ for i in range(n_bands):
140
+ f_lo, f_hi = band_freqs[i], band_freqs[i + 1]
141
+ if f_hi > SR / 2 - 100:
142
+ break
143
+ sos = _safe_butter(3, [max(f_lo, 20), min(f_hi, SR / 2 - 100)], 'band')
144
+ if sos is None:
145
+ continue
146
+ mod_band = _apply_sos(modulator, sos)
147
+ car_band = _apply_sos(carrier, sos)
148
+ env = np.abs(sig.hilbert(mod_band))
149
+ smooth = _safe_butter(2, 50, 'low')
150
+ if smooth is not None:
151
+ env = _apply_sos(env, smooth)
152
+ audio += car_band * env
153
+ return audio, _pick(rng, ["robotic", "vocoded", "processed", "synthetic"]), \
154
+ f"vocoder effect with {c_desc} and {m_desc}"
155
+
156
+
157
+ @register(400, "editing")
158
+ def gen_time_stretch(rng):
159
+ dur = _dur(rng)
160
+ n = _ns(dur)
161
+ # Generate short source, stretch to fill duration
162
+ src_dur = rng.uniform(0.5, 2)
163
+ src_n = _ns(src_dur)
164
+ src, src_desc, _ = _random_base(rng, src_n, allow_noise=False)
165
+ # Granular time stretch
166
+ grain_size = int(rng.uniform(0.02, 0.08) * SR)
167
+ window = np.hanning(grain_size)
168
+ hop_out = grain_size // 2
169
+ stretch_ratio = dur / src_dur
170
+ hop_in = max(int(hop_out / stretch_ratio), 1)
171
+ audio = np.zeros(n + grain_size)
172
+ src_pos = 0
173
+ out_pos = 0
174
+ while out_pos < n:
175
+ si = int(src_pos) % max(src_n - grain_size, 1)
176
+ end_s = min(si + grain_size, src_n)
177
+ gl = end_s - si
178
+ end_o = min(out_pos + gl, n + grain_size)
179
+ ol = end_o - out_pos
180
+ gl = min(gl, ol)
181
+ audio[out_pos:out_pos + gl] += src[si:si + gl] * window[:gl]
182
+ src_pos += hop_in
183
+ out_pos += hop_out
184
+ audio = audio[:n]
185
+ return audio, _pick(rng, ["stretched", "granular", "smeared"]), \
186
+ f"granular time-stretched {src_desc}"
187
+
188
+
189
+ @register(400, "editing")
190
+ def gen_varispeed(rng):
191
+ dur = _dur(rng)
192
+ n = _ns(dur)
193
+ # Generate at different speed, resample to fill duration
194
+ speed = rng.uniform(0.3, 0.8) # slow down
195
+ src_n = int(n * speed)
196
+ src, src_desc, _ = _random_base(rng, src_n, allow_noise=False)
197
+ # Resample to fill n samples (changes both speed and pitch)
198
+ audio = sig.resample(src, n)
199
+ desc = "slowed-down" if speed < 1 else "sped-up"
200
+ return audio, _pick(rng, ["pitched", "warped", desc]), \
201
+ f"{desc} {src_desc} shifting both speed and pitch"
202
+
203
+
204
+ @register(500, "editing")
205
+ def gen_chop_gate(rng):
206
+ dur = _dur(rng)
207
+ n = _ns(dur)
208
+ audio, desc, _ = _random_source(rng, n)
209
+ # Rhythmic chopping
210
+ chop_rate = rng.uniform(4, 16) # chops per second
211
+ chop_samples = max(int(SR / chop_rate), 10)
212
+ gate_ratio = rng.uniform(0.3, 0.7)
213
+ on_samples = int(chop_samples * gate_ratio)
214
+ env = np.zeros(n)
215
+ for pos in range(0, n, chop_samples):
216
+ end = min(pos + on_samples, n)
217
+ env[pos:end] = 1.0
218
+ # Smooth edges
219
+ sm = int(0.003 * SR)
220
+ if sm > 1:
221
+ kernel = np.ones(sm) / sm
222
+ env = np.convolve(env, kernel, mode='same')
223
+ audio *= env
224
+ return audio, _pick(rng, ["choppy", "rhythmic", "gated", "stuttering"]), \
225
+ f"rhythmically chopped and gated {desc}"
generator/generators/filters.py ADDED
@@ -0,0 +1,227 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Category F: Filters & Tone Shaping — 8,000 samples."""
2
+
3
+ import numpy as np
4
+ from scipy import signal as sig
5
+
6
+ from generators import register
7
+ from utils import (SR, _dur, _ns, _t, _log_uniform, _wave, _freq_str,
8
+ _random_base, _pick, _safe_butter, _apply_sos,
9
+ _peaking_eq, _shelf_eq)
10
+ from constants import (LOW_DESCS, HIGH_DESCS, BUZZ_DESCS, METAL_DESCS,
11
+ CLEAN_DESCS, VOWEL_FORMANTS)
12
+
13
+
14
+ @register(800, "filters")
15
+ def gen_lowpass(rng):
16
+ dur = _dur(rng)
17
+ n = _ns(dur)
18
+ audio, desc, _ = _random_base(rng, n)
19
+ cutoff = _log_uniform(rng, 200, 5000)
20
+ sos = _safe_butter(4, cutoff, 'low')
21
+ audio = _apply_sos(audio, sos)
22
+ return audio, _pick(rng, LOW_DESCS), \
23
+ f"{desc} filtered with low-pass at {_freq_str(cutoff)}"
24
+
25
+
26
+ @register(800, "filters")
27
+ def gen_highpass(rng):
28
+ dur = _dur(rng)
29
+ n = _ns(dur)
30
+ audio, desc, _ = _random_base(rng, n)
31
+ cutoff = _log_uniform(rng, 500, 10000)
32
+ sos = _safe_butter(4, cutoff, 'high')
33
+ audio = _apply_sos(audio, sos)
34
+ return audio, _pick(rng, HIGH_DESCS), \
35
+ f"{desc} filtered with high-pass at {_freq_str(cutoff)}"
36
+
37
+
38
+ @register(800, "filters")
39
+ def gen_bandpass(rng):
40
+ dur = _dur(rng)
41
+ n = _ns(dur)
42
+ audio, desc, _ = _random_base(rng, n)
43
+ center = _log_uniform(rng, 300, 8000)
44
+ Q = rng.uniform(1, 10)
45
+ bw = center / Q
46
+ sos = _safe_butter(4, [max(center - bw / 2, 20), min(center + bw / 2, SR / 2 - 100)], 'band')
47
+ audio = _apply_sos(audio, sos)
48
+ return audio, _pick(rng, BUZZ_DESCS + ["nasal", "focused"]), \
49
+ f"bandpass-filtered {desc} at {_freq_str(center)}"
50
+
51
+
52
+ @register(500, "filters")
53
+ def gen_notch(rng):
54
+ dur = _dur(rng)
55
+ n = _ns(dur)
56
+ audio, desc, _ = _random_base(rng, n)
57
+ freq = _log_uniform(rng, 200, 8000)
58
+ Q = rng.uniform(10, 50)
59
+ try:
60
+ b, a = sig.iirnotch(freq, Q, SR)
61
+ audio = sig.lfilter(b, a, audio)
62
+ except Exception:
63
+ pass
64
+ return audio, _pick(rng, CLEAN_DESCS), \
65
+ f"{desc} with a notch filter removing {_freq_str(freq)}"
66
+
67
+
68
+ @register(500, "filters")
69
+ def gen_peaking_eq(rng):
70
+ dur = _dur(rng)
71
+ n = _ns(dur)
72
+ audio, desc, _ = _random_base(rng, n, allow_noise=False)
73
+ freq = _log_uniform(rng, 200, 8000)
74
+ gain = rng.uniform(6, 18)
75
+ Q = rng.uniform(1, 5)
76
+ try:
77
+ b, a = _peaking_eq(freq, gain, Q)
78
+ audio = sig.lfilter(b, a, audio)
79
+ except Exception:
80
+ pass
81
+ return audio, _pick(rng, HIGH_DESCS + ["resonant", "boosted"]), \
82
+ f"{desc} with {gain:.0f} dB peaking EQ boost at {_freq_str(freq)}"
83
+
84
+
85
+ @register(500, "filters")
86
+ def gen_shelf_eq(rng):
87
+ dur = _dur(rng)
88
+ n = _ns(dur)
89
+ audio, desc, _ = _random_base(rng, n, allow_noise=False)
90
+ shelf_type = str(rng.choice(["high", "low"]))
91
+ freq = _log_uniform(rng, 500, 5000)
92
+ gain = rng.uniform(-12, -3) # cut
93
+ try:
94
+ b, a = _shelf_eq(freq, gain, shelf_type)
95
+ audio = sig.lfilter(b, a, audio)
96
+ except Exception:
97
+ pass
98
+ char = "dark" if shelf_type == "high" else "thin"
99
+ return audio, _pick(rng, [char, "shaped", "sculpted"]), \
100
+ f"{desc} with {shelf_type}-shelf cut giving a {char} character"
101
+
102
+
103
+ @register(600, "filters")
104
+ def gen_comb_filter(rng):
105
+ dur = _dur(rng)
106
+ n = _ns(dur)
107
+ audio, desc, _ = _random_base(rng, n)
108
+ delay_ms = rng.uniform(0.5, 10)
109
+ delay_samples = max(int(delay_ms * SR / 1000), 1)
110
+ feedback = rng.uniform(0.3, 0.8)
111
+ out = audio.copy()
112
+ out[delay_samples:] += feedback * audio[:-delay_samples]
113
+ return out, _pick(rng, METAL_DESCS + ["flanged", "hollow"]), \
114
+ f"comb-filtered {desc}"
115
+
116
+
117
+ @register(500, "filters")
118
+ def gen_allpass(rng):
119
+ dur = _dur(rng)
120
+ n = _ns(dur)
121
+ audio, desc, _ = _random_base(rng, n)
122
+ n_stages = int(rng.integers(4, 12))
123
+ for _ in range(n_stages):
124
+ freq = _log_uniform(rng, 200, 8000)
125
+ Q = rng.uniform(0.5, 5)
126
+ try:
127
+ b, a = sig.iirpeak(min(freq, SR / 2 - 100), Q, SR)
128
+ # allpass = 2*bandpass - input
129
+ bp = sig.lfilter(b, a, audio)
130
+ audio = 2 * bp - audio
131
+ except Exception:
132
+ pass
133
+ return audio, _pick(rng, ["phaser-like", "swirling", "colored"]), \
134
+ f"cascade of allpass filters creating phaser-like coloring on {desc}"
135
+
136
+
137
+ @register(800, "filters")
138
+ def gen_formant_vowel(rng):
139
+ dur = _dur(rng)
140
+ n = _ns(dur)
141
+ freq = _log_uniform(rng, 50, 400)
142
+ t = _t(n)
143
+ audio = sig.sawtooth(2 * np.pi * freq * t)
144
+ vowel = str(rng.choice(list(VOWEL_FORMANTS.keys())))
145
+ formants = VOWEL_FORMANTS[vowel]
146
+ filtered = np.zeros(n)
147
+ for fc, bw in formants:
148
+ f_lo = max(fc - bw, 20)
149
+ f_hi = min(fc + bw, SR / 2 - 100)
150
+ if f_lo >= f_hi:
151
+ continue
152
+ sos = _safe_butter(2, [f_lo, f_hi], 'band')
153
+ if sos is not None:
154
+ filtered += _apply_sos(audio, sos)
155
+ if np.max(np.abs(filtered)) > 1e-10:
156
+ audio = filtered
157
+ return audio, _pick(rng, BUZZ_DESCS + ["vocal", "resonant"]), \
158
+ f"sawtooth shaped into an '{vowel}' vowel formant"
159
+
160
+
161
+ @register(1000, "filters")
162
+ def gen_filter_sweep(rng):
163
+ dur = _dur(rng)
164
+ n = _ns(dur)
165
+ audio, desc, _ = _random_base(rng, n)
166
+ ftype = str(rng.choice(["lowpass", "highpass"]))
167
+ f_start = _log_uniform(rng, 200, 8000)
168
+ f_end = _log_uniform(rng, 200, 8000)
169
+ # Process in blocks with changing filter
170
+ block_size = 1024
171
+ freqs = np.geomspace(f_start, f_end, n // block_size + 1)
172
+ out = np.zeros(n)
173
+ btype = 'low' if ftype == "lowpass" else 'high'
174
+ for i in range(0, n, block_size):
175
+ end = min(i + block_size, n)
176
+ f = float(np.clip(freqs[i // block_size], 20, SR / 2 - 100))
177
+ sos = _safe_butter(2, f, btype)
178
+ if sos is not None:
179
+ out[i:end] = _apply_sos(audio[i:end], sos)
180
+ else:
181
+ out[i:end] = audio[i:end]
182
+ direction = "opening" if (ftype == "lowpass" and f_end > f_start) or \
183
+ (ftype == "highpass" and f_end < f_start) else "closing"
184
+ pool = HIGH_DESCS if ftype == "highpass" else LOW_DESCS
185
+ return out, _pick(rng, pool + ["sweeping", "resonant"]), \
186
+ f"{direction} {ftype.replace('pass', '-pass')} filter sweep on {desc}"
187
+
188
+
189
+ @register(700, "filters")
190
+ def gen_wah(rng):
191
+ dur = _dur(rng)
192
+ n = _ns(dur)
193
+ audio, desc, _ = _random_base(rng, n, allow_noise=False)
194
+ rate = rng.uniform(1, 8)
195
+ center = _log_uniform(rng, 500, 3000)
196
+ t = _t(n)
197
+ # Auto-wah via STFT
198
+ nperseg = 1024
199
+ f, t_stft, Zxx = sig.stft(audio, fs=SR, nperseg=nperseg)
200
+ lfo = np.sin(2 * np.pi * rate * t)
201
+ for i in range(Zxx.shape[1]):
202
+ t_pos = t_stft[i] if i < len(t_stft) else t_stft[-1]
203
+ idx = min(int(t_pos * SR), n - 1)
204
+ cf = center * 2 ** (lfo[idx] * 1.5)
205
+ Q = 5
206
+ filt = np.exp(-0.5 * ((f - cf) / (cf / Q + 1)) ** 2)
207
+ Zxx[:, i] *= filt
208
+ _, out = sig.istft(Zxx, fs=SR, nperseg=nperseg)
209
+ out = out[:n] if len(out) >= n else np.pad(out, (0, n - len(out)))
210
+ return out, _pick(rng, ["funky", "expressive", "quacky"]), \
211
+ f"auto-wah envelope filter on {desc}"
212
+
213
+
214
+ @register(500, "filters")
215
+ def gen_resonance(rng):
216
+ dur = _dur(rng)
217
+ n = _ns(dur)
218
+ audio, desc, _ = _random_base(rng, n)
219
+ freq = _log_uniform(rng, 200, 5000)
220
+ Q = rng.uniform(10, 50)
221
+ try:
222
+ b, a = sig.iirpeak(min(freq, SR / 2 - 100), Q, SR)
223
+ audio = sig.lfilter(b, a, audio)
224
+ except Exception:
225
+ pass
226
+ return audio, _pick(rng, ["resonant", "ringing", "peaky"]), \
227
+ f"highly resonant bandpass filter at {_freq_str(freq)} on {desc}"
generator/generators/modulation.py ADDED
@@ -0,0 +1,152 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Category J: Modulation Effects — 5,000 samples."""
2
+
3
+ import numpy as np
4
+ from scipy import signal as sig
5
+
6
+ from generators import register
7
+ from utils import (SR, _dur, _ns, _t, _log_uniform, _wave, _freq_str,
8
+ _random_base, _pick, _chorus, _flanger, _safe_butter,
9
+ _apply_sos, _normalize)
10
+ from constants import CLEAN_DESCS, SOFT_DESCS, METAL_DESCS
11
+
12
+
13
+ @register(700, "modulation")
14
+ def gen_chorus(rng):
15
+ dur = _dur(rng)
16
+ n = _ns(dur)
17
+ audio, desc, _ = _random_base(rng, n, allow_noise=False)
18
+ audio = _chorus(audio, rng)
19
+ return audio, _pick(rng, ["warm", "lush", "wide", "shimmering"]), \
20
+ f"chorus effect on {desc}"
21
+
22
+
23
+ @register(700, "modulation")
24
+ def gen_flanger(rng):
25
+ dur = _dur(rng)
26
+ n = _ns(dur)
27
+ audio, desc, _ = _random_base(rng, n)
28
+ audio = _flanger(audio, rng)
29
+ return audio, _pick(rng, ["jet-like", "whooshing", "sweeping", "metallic"]), \
30
+ f"flanger sweep on {desc}"
31
+
32
+
33
+ @register(700, "modulation")
34
+ def gen_phaser(rng):
35
+ dur = _dur(rng)
36
+ n = _ns(dur)
37
+ audio, desc, _ = _random_base(rng, n, allow_noise=False)
38
+ rate = rng.uniform(0.1, 2)
39
+ n_stages = int(rng.integers(4, 8))
40
+ t = _t(n)
41
+ lfo = np.sin(2 * np.pi * rate * t)
42
+ # Cascade of modulated allpass filters
43
+ for stage in range(n_stages):
44
+ center = _log_uniform(rng, 200, 4000)
45
+ depth = rng.uniform(0.3, 0.8)
46
+ delay_mod = (center * (1 + depth * lfo)).astype(int)
47
+ delay_mod = np.clip(delay_mod, 1, n - 1)
48
+ indices = np.clip(np.arange(n) - delay_mod // 100, 0, n - 1)
49
+ delayed = audio[indices]
50
+ fb = rng.uniform(0.3, 0.7)
51
+ audio = audio + fb * delayed
52
+ audio = _normalize(audio)
53
+ return audio, _pick(rng, ["swirling", "phasing", "spacey", "psychedelic"]), \
54
+ f"phaser on {desc}"
55
+
56
+
57
+ @register(700, "modulation")
58
+ def gen_tremolo(rng):
59
+ dur = _dur(rng)
60
+ n = _ns(dur)
61
+ freq = _log_uniform(rng, 100, 2000)
62
+ trem_rate = rng.uniform(3, 15)
63
+ depth = rng.uniform(0.5, 1.0)
64
+ t = _t(n)
65
+ audio = np.sin(2 * np.pi * freq * t)
66
+ trem = 1.0 - depth * 0.5 * (1 + np.sin(2 * np.pi * trem_rate * t))
67
+ audio *= trem
68
+ depth_str = "deep" if depth > 0.7 else "subtle"
69
+ return audio, _pick(rng, ["pulsing", "throbbing", depth_str]), \
70
+ f"{_freq_str(freq)} sine with {depth_str} tremolo at {trem_rate:.0f} Hz"
71
+
72
+
73
+ @register(500, "modulation")
74
+ def gen_autopan(rng):
75
+ dur = _dur(rng)
76
+ n = _ns(dur)
77
+ audio, desc, _ = _random_base(rng, n, allow_noise=False)
78
+ rate = rng.uniform(0.5, 5)
79
+ t = _t(n)
80
+ # Simulated as amplitude oscillation (mono representation of panning)
81
+ pan = 0.5 + 0.4 * np.sin(2 * np.pi * rate * t)
82
+ audio *= pan
83
+ return audio, _pick(rng, ["sweeping", "moving", "spatial"]), \
84
+ f"auto-panning {desc} sweeping left and right"
85
+
86
+
87
+ @register(500, "modulation")
88
+ def gen_rotary(rng):
89
+ dur = _dur(rng)
90
+ n = _ns(dur)
91
+ # Organ-like source (additive harmonics)
92
+ freq = _log_uniform(rng, 100, 500)
93
+ t = _t(n)
94
+ audio = np.zeros(n)
95
+ for h in [1, 2, 3, 4, 6, 8]:
96
+ f = freq * h
97
+ if f > SR / 2:
98
+ break
99
+ audio += (1.0 / h) * np.sin(2 * np.pi * f * t)
100
+ # Leslie effect: amplitude + frequency modulation
101
+ slow_rate = rng.uniform(0.5, 2) # slow speed
102
+ fast_rate = rng.uniform(5, 8) # fast speed
103
+ rate = rng.choice([slow_rate, fast_rate])
104
+ am = 0.5 + 0.3 * np.sin(2 * np.pi * rate * t)
105
+ fm_depth = rng.uniform(0.001, 0.005)
106
+ fm_mod = fm_depth * np.sin(2 * np.pi * rate * t)
107
+ delay = (fm_mod * SR).astype(int)
108
+ indices = np.clip(np.arange(n) - delay, 0, n - 1)
109
+ audio = audio[indices] * am
110
+ return audio, _pick(rng, ["swirling", "warm", "rotating", "vintage"]), \
111
+ "Leslie rotary speaker effect on an organ-like tone"
112
+
113
+
114
+ @register(600, "modulation")
115
+ def gen_freq_shifter(rng):
116
+ dur = _dur(rng)
117
+ n = _ns(dur)
118
+ freq = _log_uniform(rng, 100, 2000)
119
+ shift = rng.uniform(1, 50)
120
+ t = _t(n)
121
+ audio = np.sin(2 * np.pi * freq * t)
122
+ # Frequency shifting via multiplication with complex exponential
123
+ shifted = audio * np.cos(2 * np.pi * shift * t)
124
+ audio = 0.5 * audio + 0.5 * shifted
125
+ return audio, _pick(rng, ["inharmonic", "metallic", "alien", "dissonant"]), \
126
+ f"frequency-shifted {_freq_str(freq)} sine creating inharmonic overtones"
127
+
128
+
129
+ @register(600, "modulation")
130
+ def gen_lfo_filter(rng):
131
+ dur = _dur(rng)
132
+ n = _ns(dur)
133
+ audio, desc, _ = _random_base(rng, n)
134
+ lfo_rate = rng.uniform(0.1, 2)
135
+ center = _log_uniform(rng, 500, 5000)
136
+ # Block processing with LFO-modulated filter
137
+ block_size = 512
138
+ t = _t(n)
139
+ lfo = np.sin(2 * np.pi * lfo_rate * t)
140
+ out = np.zeros(n)
141
+ for i in range(0, n, block_size):
142
+ end = min(i + block_size, n)
143
+ idx = min(i, n - 1)
144
+ f = center * 2 ** (lfo[idx] * 1.5)
145
+ f = float(np.clip(f, 20, SR / 2 - 100))
146
+ sos = _safe_butter(2, f, 'low')
147
+ if sos is not None:
148
+ out[i:end] = _apply_sos(audio[i:end], sos)
149
+ else:
150
+ out[i:end] = audio[i:end]
151
+ return out, _pick(rng, ["sweeping", "evolving", "modulated"]), \
152
+ f"slowly LFO-modulated filter cutoff on {desc}"
generator/generators/musical.py ADDED
@@ -0,0 +1,204 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Category D: Musical Constructs — 10,000 samples."""
2
+
3
+ import numpy as np
4
+ from scipy import signal as sig
5
+
6
+ from generators import register
7
+ from utils import (SR, _dur, _ns, _t, _log_uniform, _wave, _freq_str,
8
+ _midi_to_freq, _midi_to_name, _random_midi, _pick, _adsr)
9
+ from constants import (CHORD_TYPES, SCALE_TYPES, INTERVAL_NAMES, DTMF_FREQS,
10
+ NOTE_NAMES, LOW_DESCS, HIGH_DESCS, CLEAN_DESCS, SOFT_DESCS)
11
+
12
+
13
+ @register(2500, "musical_constructs")
14
+ def gen_chord(rng):
15
+ dur = _dur(rng)
16
+ n = _ns(dur)
17
+ root = _random_midi(rng, 36, 72)
18
+ chord_name = str(rng.choice(list(CHORD_TYPES.keys())))
19
+ intervals = CHORD_TYPES[chord_name]
20
+ wtype = str(rng.choice(["sine", "sawtooth", "square", "triangle"]))
21
+ t = _t(n)
22
+ audio = np.zeros(n)
23
+ for iv in intervals:
24
+ audio += _wave(wtype, _midi_to_freq(root + iv), t)
25
+ audio /= len(intervals)
26
+ env = _adsr(dur, attack=rng.uniform(0.005, 0.1), decay=rng.uniform(0.05, 0.3),
27
+ sustain=rng.uniform(0.5, 0.9), release=rng.uniform(0.1, 0.5))
28
+ audio *= env
29
+ root_name = _midi_to_name(root)
30
+ note_letter = NOTE_NAMES[root % 12]
31
+ return audio, _pick(rng, SOFT_DESCS + CLEAN_DESCS), \
32
+ f"{note_letter} {chord_name} chord played with {wtype} waves"
33
+
34
+
35
+ @register(1500, "musical_constructs")
36
+ def gen_arpeggio(rng):
37
+ dur = _dur(rng, 3, 20)
38
+ n = _ns(dur)
39
+ root = _random_midi(rng, 48, 72)
40
+ chord_name = str(rng.choice(list(CHORD_TYPES.keys())))
41
+ intervals = CHORD_TYPES[chord_name]
42
+ notes_per_sec = rng.uniform(3, 12)
43
+ direction = str(rng.choice(["ascending", "descending", "alternating"]))
44
+ wtype = str(rng.choice(["sine", "sawtooth", "triangle"]))
45
+ note_dur = 1.0 / notes_per_sec
46
+ note_samples = int(note_dur * SR)
47
+ t_note = _t(note_samples)
48
+ env = np.exp(-t_note * rng.uniform(3, 15))
49
+ audio = np.zeros(n)
50
+ note_list = list(intervals)
51
+ if direction == "descending":
52
+ note_list = list(reversed(note_list))
53
+ elif direction == "alternating":
54
+ note_list = list(intervals) + list(reversed(intervals[1:-1]))
55
+ if not note_list:
56
+ note_list = list(intervals)
57
+ idx = 0
58
+ pos = 0
59
+ while pos < n:
60
+ iv = note_list[idx % len(note_list)]
61
+ freq = _midi_to_freq(root + iv)
62
+ end = min(pos + note_samples, n)
63
+ sl = end - pos
64
+ audio[pos:end] += _wave(wtype, freq, t_note[:sl]) * env[:sl]
65
+ pos += note_samples
66
+ idx += 1
67
+ note_letter = NOTE_NAMES[root % 12]
68
+ return audio, _pick(rng, HIGH_DESCS + CLEAN_DESCS), \
69
+ f"{direction} {note_letter} {chord_name} arpeggio at {notes_per_sec:.0f} notes per second"
70
+
71
+
72
+ @register(1500, "musical_constructs")
73
+ def gen_scale(rng):
74
+ dur = _dur(rng, 3, 15)
75
+ n = _ns(dur)
76
+ root = _random_midi(rng, 48, 72)
77
+ scale_name = str(rng.choice(list(SCALE_TYPES.keys())))
78
+ degrees = SCALE_TYPES[scale_name]
79
+ direction = str(rng.choice(["ascending", "descending"]))
80
+ wtype = str(rng.choice(["sine", "sawtooth", "triangle"]))
81
+ note_list = [root + d for d in degrees]
82
+ if direction == "ascending":
83
+ note_list.append(root + 12)
84
+ else:
85
+ note_list = list(reversed(note_list))
86
+ note_list.insert(0, root + 12)
87
+ note_dur = dur / len(note_list)
88
+ note_samples = int(note_dur * SR)
89
+ t_note = _t(note_samples)
90
+ env = _adsr(note_dur, 0.005, 0.02, 0.8, 0.05)[:note_samples]
91
+ audio = np.zeros(n)
92
+ for i, midi in enumerate(note_list):
93
+ pos = i * note_samples
94
+ end = min(pos + note_samples, n)
95
+ sl = end - pos
96
+ audio[pos:end] += _wave(wtype, _midi_to_freq(midi), t_note[:sl]) * env[:sl]
97
+ note_letter = NOTE_NAMES[root % 12]
98
+ return audio, _pick(rng, CLEAN_DESCS), \
99
+ f"{direction} {note_letter} {scale_name} scale"
100
+
101
+
102
+ @register(1000, "musical_constructs")
103
+ def gen_interval(rng):
104
+ dur = _dur(rng)
105
+ n = _ns(dur)
106
+ root = _random_midi(rng, 48, 76)
107
+ semitones = int(rng.choice(list(INTERVAL_NAMES.keys())))
108
+ if semitones == 0:
109
+ semitones = 7 # default to fifth
110
+ interval_name = INTERVAL_NAMES.get(semitones, f"{semitones} semitones")
111
+ simultaneous = rng.random() > 0.3
112
+ wtype = str(rng.choice(["sine", "sawtooth", "triangle"]))
113
+ t = _t(n)
114
+ f1 = _midi_to_freq(root)
115
+ f2 = _midi_to_freq(root + semitones)
116
+ if simultaneous:
117
+ audio = 0.5 * (_wave(wtype, f1, t) + _wave(wtype, f2, t))
118
+ play_str = "played simultaneously"
119
+ else:
120
+ half = n // 2
121
+ audio = np.zeros(n)
122
+ audio[:half] = _wave(wtype, f1, t[:half])
123
+ audio[half:] = _wave(wtype, f2, t[:n - half])
124
+ play_str = "played sequentially"
125
+ return audio, _pick(rng, CLEAN_DESCS), \
126
+ f"{interval_name} interval from {_midi_to_name(root)}, {play_str}"
127
+
128
+
129
+ @register(1500, "musical_constructs")
130
+ def gen_melody(rng):
131
+ dur = _dur(rng, 4, 20)
132
+ n = _ns(dur)
133
+ root = _random_midi(rng, 48, 72)
134
+ scale_name = str(rng.choice(list(SCALE_TYPES.keys())))
135
+ degrees = SCALE_TYPES[scale_name]
136
+ bpm = rng.uniform(60, 180)
137
+ wtype = str(rng.choice(["sine", "sawtooth", "square", "triangle"]))
138
+ beat_samples = int(SR * 60 / bpm)
139
+ # Generate random note sequence from scale
140
+ n_notes = max(int(dur * bpm / 60), 4)
141
+ available = []
142
+ for octave_shift in [-12, 0, 12]:
143
+ for d in degrees:
144
+ available.append(root + d + octave_shift)
145
+ notes = [int(rng.choice(available)) for _ in range(n_notes)]
146
+ t_note = _t(beat_samples)
147
+ env = _adsr(beat_samples / SR, 0.005, 0.05, 0.6, 0.05)[:beat_samples]
148
+ audio = np.zeros(n)
149
+ for i, midi in enumerate(notes):
150
+ pos = i * beat_samples
151
+ end = min(pos + beat_samples, n)
152
+ sl = end - pos
153
+ freq = _midi_to_freq(midi)
154
+ audio[pos:end] += _wave(wtype, freq, t_note[:sl]) * env[:sl]
155
+ note_letter = NOTE_NAMES[root % 12]
156
+ return audio, _pick(rng, CLEAN_DESCS + ["playful", "melodic"]), \
157
+ f"random melody in {note_letter} {scale_name} at {bpm:.0f} BPM"
158
+
159
+
160
+ @register(1000, "musical_constructs")
161
+ def gen_harmonic_series(rng):
162
+ dur = _dur(rng)
163
+ n = _ns(dur)
164
+ fundamental = _log_uniform(rng, 50, 500)
165
+ n_harmonics = int(rng.integers(4, 16))
166
+ t = _t(n)
167
+ audio = np.zeros(n)
168
+ rolloff = rng.uniform(0.5, 2.0)
169
+ for h in range(1, n_harmonics + 1):
170
+ f = fundamental * h
171
+ if f > SR / 2:
172
+ break
173
+ amp = 1.0 / h ** rolloff
174
+ audio += amp * np.sin(2 * np.pi * f * t)
175
+ return audio, _pick(rng, CLEAN_DESCS + ["rich", "harmonic"]), \
176
+ f"overtone series on {_freq_str(fundamental)} with {n_harmonics} harmonics"
177
+
178
+
179
+ @register(500, "musical_constructs")
180
+ def gen_dtmf(rng):
181
+ dur = _dur(rng, 2, 8)
182
+ n = _ns(dur)
183
+ digits = list("0123456789")
184
+ length = int(rng.integers(3, 10))
185
+ sequence = "".join(str(rng.choice(digits)) for _ in range(length))
186
+ tone_dur = min(0.2, dur / (length * 2))
187
+ pause_dur = tone_dur * 0.5
188
+ tone_samples = int(tone_dur * SR)
189
+ pause_samples = int(pause_dur * SR)
190
+ audio = np.zeros(n)
191
+ pos = 0
192
+ for digit in sequence:
193
+ if digit in DTMF_FREQS and pos + tone_samples < n:
194
+ f1, f2 = DTMF_FREQS[digit]
195
+ t = _t(tone_samples)
196
+ tone = 0.5 * (np.sin(2 * np.pi * f1 * t) + np.sin(2 * np.pi * f2 * t))
197
+ # Apply short envelope
198
+ env_len = min(int(0.005 * SR), tone_samples // 4)
199
+ tone[:env_len] *= np.linspace(0, 1, env_len)
200
+ tone[-env_len:] *= np.linspace(1, 0, env_len)
201
+ audio[pos:pos + tone_samples] = tone
202
+ pos += tone_samples + pause_samples
203
+ return audio, _pick(rng, ["electronic", "digital"]), \
204
+ f"DTMF tones dialing the sequence {sequence}"
generator/generators/noise.py ADDED
@@ -0,0 +1,121 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Category B: Noise Types — 6,000 samples."""
2
+
3
+ import numpy as np
4
+ from scipy import signal as sig
5
+
6
+ from generators import register
7
+ from utils import (SR, _dur, _ns, _t, _log_uniform, _freq_str, _pick,
8
+ _pink_noise, _brown_noise, _blue_noise, _violet_noise,
9
+ _grey_noise, _safe_butter, _apply_sos)
10
+ from constants import LOW_DESCS, HIGH_DESCS, CLEAN_DESCS, SOFT_DESCS
11
+
12
+
13
+ @register(800, "noise")
14
+ def gen_white_noise(rng):
15
+ dur = _dur(rng)
16
+ audio = rng.standard_normal(_ns(dur))
17
+ return audio, _pick(rng, CLEAN_DESCS + ["broadband", "hissy"]), "white noise"
18
+
19
+
20
+ @register(800, "noise")
21
+ def gen_pink_noise(rng):
22
+ dur = _dur(rng)
23
+ audio = _pink_noise(rng, _ns(dur))
24
+ return audio, _pick(rng, SOFT_DESCS + ["natural"]), "pink noise"
25
+
26
+
27
+ @register(800, "noise")
28
+ def gen_brown_noise(rng):
29
+ dur = _dur(rng)
30
+ audio = _brown_noise(rng, _ns(dur))
31
+ return audio, _pick(rng, LOW_DESCS + ["rumbling"]), "brown noise"
32
+
33
+
34
+ @register(500, "noise")
35
+ def gen_blue_noise(rng):
36
+ dur = _dur(rng)
37
+ audio = _blue_noise(rng, _ns(dur))
38
+ return audio, _pick(rng, HIGH_DESCS), "blue noise"
39
+
40
+
41
+ @register(500, "noise")
42
+ def gen_violet_noise(rng):
43
+ dur = _dur(rng)
44
+ audio = _violet_noise(rng, _ns(dur))
45
+ return audio, _pick(rng, HIGH_DESCS + ["harsh"]), "violet noise"
46
+
47
+
48
+ @register(400, "noise")
49
+ def gen_grey_noise(rng):
50
+ dur = _dur(rng)
51
+ audio = _grey_noise(rng, _ns(dur))
52
+ return audio, _pick(rng, ["balanced", "even", "flat"]), \
53
+ "grey noise with perceptually flat loudness"
54
+
55
+
56
+ @register(600, "noise")
57
+ def gen_vinyl_crackle(rng):
58
+ dur = _dur(rng)
59
+ n = _ns(dur)
60
+ # Background hiss
61
+ hiss = rng.standard_normal(n) * 0.05
62
+ sos = _safe_butter(2, 2000, 'low')
63
+ if sos is not None:
64
+ hiss = _apply_sos(hiss, sos)
65
+ # Random crackles
66
+ n_crackles = int(rng.uniform(5, 50) * dur)
67
+ for _ in range(n_crackles):
68
+ pos = rng.integers(0, n)
69
+ length = int(rng.uniform(0.0001, 0.002) * SR)
70
+ end = min(pos + length, n)
71
+ hiss[pos:end] += rng.uniform(0.3, 1.0) * rng.choice([-1, 1]) * \
72
+ np.exp(-np.arange(end - pos) / (0.0005 * SR))
73
+ return hiss, _pick(rng, ["warm", "vintage", "nostalgic"]), \
74
+ "vinyl crackle and surface noise"
75
+
76
+
77
+ @register(600, "noise")
78
+ def gen_tape_hiss(rng):
79
+ dur = _dur(rng)
80
+ n = _ns(dur)
81
+ noise = rng.standard_normal(n)
82
+ # Tape hiss is mostly high-frequency
83
+ sos = _safe_butter(3, rng.uniform(3000, 8000), 'high')
84
+ if sos is not None:
85
+ noise = _apply_sos(noise, sos)
86
+ # Slight low-pass to remove harshest highs
87
+ sos2 = _safe_butter(2, rng.uniform(12000, 18000), 'low')
88
+ if sos2 is not None:
89
+ noise = _apply_sos(noise, sos2)
90
+ return noise, _pick(rng, ["warm", "analog", "soft", "gentle"]), \
91
+ "analog tape hiss"
92
+
93
+
94
+ @register(1000, "noise")
95
+ def gen_filtered_noise(rng):
96
+ dur = _dur(rng)
97
+ n = _ns(dur)
98
+ # Pick noise type
99
+ noise_type = str(rng.choice(["white", "pink"]))
100
+ if noise_type == "white":
101
+ audio = rng.standard_normal(n)
102
+ else:
103
+ audio = _pink_noise(rng, n)
104
+ # Pick filter type
105
+ ftype = str(rng.choice(["lowpass", "highpass", "bandpass"]))
106
+ freq = _log_uniform(rng, 200, 8000)
107
+ Q = rng.uniform(0.5, 10)
108
+ if ftype == "bandpass":
109
+ bw = freq / Q
110
+ sos = _safe_butter(4, [max(freq - bw / 2, 20), min(freq + bw / 2, SR / 2 - 100)], 'band')
111
+ filter_desc = f"resonant bandpass at {_freq_str(freq)}"
112
+ elif ftype == "lowpass":
113
+ sos = _safe_butter(4, freq, 'low')
114
+ filter_desc = f"low-pass filter at {_freq_str(freq)}"
115
+ else:
116
+ sos = _safe_butter(4, freq, 'high')
117
+ filter_desc = f"high-pass filter at {_freq_str(freq)}"
118
+ if sos is not None:
119
+ audio = _apply_sos(audio, sos)
120
+ descs = LOW_DESCS if ftype == "lowpass" else HIGH_DESCS if ftype == "highpass" else []
121
+ return audio, _pick(rng, descs), f"{noise_type} noise through a {filter_desc}"
generator/generators/percussive.py ADDED
@@ -0,0 +1,162 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Category K: Percussive & Transient — 8,000 samples."""
2
+
3
+ import numpy as np
4
+ from scipy import signal as sig
5
+
6
+ from generators import register
7
+ from utils import (SR, _dur, _ns, _t, _log_uniform, _pick,
8
+ _make_kick, _make_snare, _make_hihat,
9
+ _safe_butter, _apply_sos, _normalize)
10
+ from constants import DRUM_PATTERNS, LOW_DESCS, HIGH_DESCS, METAL_DESCS
11
+
12
+
13
+ @register(1500, "percussive")
14
+ def gen_kick(rng):
15
+ dur = _dur(rng, 2, 10)
16
+ n = _ns(dur)
17
+ hit_n = min(int(0.5 * SR), n)
18
+ hit = _make_kick(rng, hit_n)
19
+ audio = np.zeros(n)
20
+ # Place kicks periodically or as single hit
21
+ n_hits = int(rng.integers(1, max(int(dur * 3), 2)))
22
+ spacing = n // n_hits
23
+ for i in range(n_hits):
24
+ pos = i * spacing
25
+ end = min(pos + hit_n, n)
26
+ audio[pos:end] += hit[:end - pos]
27
+ return audio, _pick(rng, ["deep", "punchy", "boomy", "thumping"]), \
28
+ "synthesized kick drum"
29
+
30
+
31
+ @register(1500, "percussive")
32
+ def gen_snare(rng):
33
+ dur = _dur(rng, 2, 10)
34
+ n = _ns(dur)
35
+ hit_n = min(int(0.3 * SR), n)
36
+ hit = _make_snare(rng, hit_n)
37
+ audio = np.zeros(n)
38
+ n_hits = int(rng.integers(1, max(int(dur * 3), 2)))
39
+ spacing = n // n_hits
40
+ for i in range(n_hits):
41
+ pos = i * spacing
42
+ end = min(pos + hit_n, n)
43
+ audio[pos:end] += hit[:end - pos]
44
+ return audio, _pick(rng, ["crisp", "snappy", "bright", "cracking"]), \
45
+ "synthesized snare drum"
46
+
47
+
48
+ @register(1000, "percussive")
49
+ def gen_hihat(rng):
50
+ dur = _dur(rng, 2, 10)
51
+ n = _ns(dur)
52
+ open_close = str(rng.choice(["closed", "open"]))
53
+ hit_n = int(0.05 * SR) if open_close == "closed" else int(0.3 * SR)
54
+ hit_n = min(hit_n, n)
55
+ hit = _make_hihat(rng, hit_n)
56
+ audio = np.zeros(n)
57
+ rate = rng.uniform(4, 16)
58
+ spacing = max(int(SR / rate), hit_n)
59
+ for pos in range(0, n, spacing):
60
+ end = min(pos + hit_n, n)
61
+ audio[pos:end] += hit[:end - pos]
62
+ return audio, _pick(rng, METAL_DESCS[:2] + ["short", "sizzly"]), \
63
+ f"short, {open_close} hi-hat"
64
+
65
+
66
+ @register(500, "percussive")
67
+ def gen_click_pop(rng):
68
+ dur = _dur(rng)
69
+ n = _ns(dur)
70
+ rate = rng.uniform(2, 20)
71
+ spacing = max(int(SR / rate), 10)
72
+ audio = np.zeros(n)
73
+ for pos in range(0, n, spacing):
74
+ click_type = str(rng.choice(["impulse", "short_burst"]))
75
+ if click_type == "impulse":
76
+ if pos < n:
77
+ audio[pos] = rng.uniform(0.5, 1.0) * float(rng.choice([-1, 1]))
78
+ else:
79
+ cl = min(int(rng.uniform(0.0001, 0.003) * SR), n - pos)
80
+ audio[pos:pos + cl] = rng.uniform(0.3, 0.8) * \
81
+ np.exp(-np.arange(cl) / (0.0005 * SR)) * float(rng.choice([-1, 1]))
82
+ return audio, _pick(rng, ["sharp", "digital", "staccato", "percussive"]), \
83
+ "series of sharp digital clicks"
84
+
85
+
86
+ @register(500, "percussive")
87
+ def gen_clap(rng):
88
+ dur = _dur(rng, 2, 10)
89
+ n = _ns(dur)
90
+ # Clap: multiple short noise bursts close together + reverb tail
91
+ clap_n = min(int(0.15 * SR), n)
92
+ clap = np.zeros(clap_n)
93
+ n_micro = int(rng.integers(3, 7))
94
+ for j in range(n_micro):
95
+ pos = int(j * rng.uniform(0.003, 0.01) * SR)
96
+ burst_len = min(int(rng.uniform(0.002, 0.008) * SR), clap_n - pos)
97
+ if pos + burst_len <= clap_n:
98
+ clap[pos:pos + burst_len] += rng.standard_normal(burst_len) * \
99
+ np.exp(-np.arange(burst_len) / (0.003 * SR))
100
+ # Filter: bandpass
101
+ sos = _safe_butter(3, [500, 5000], 'band')
102
+ if sos is not None:
103
+ clap = _apply_sos(clap, sos)
104
+ # Reverb tail
105
+ tail_n = min(int(0.1 * SR), clap_n)
106
+ tail = rng.standard_normal(tail_n) * np.exp(-np.arange(tail_n) / (0.03 * SR)) * 0.3
107
+ clap[-tail_n:] += tail
108
+ audio = np.zeros(n)
109
+ n_claps = int(rng.integers(1, max(int(dur * 2), 2)))
110
+ spacing = n // n_claps
111
+ for i in range(n_claps):
112
+ pos = i * spacing
113
+ end = min(pos + clap_n, n)
114
+ audio[pos:end] += clap[:end - pos]
115
+ return audio, _pick(rng, ["snappy", "layered", "tight"]), \
116
+ "layered synthesized handclap"
117
+
118
+
119
+ @register(3000, "percussive")
120
+ def gen_drum_pattern(rng):
121
+ dur = _dur(rng, 4, 20)
122
+ n = _ns(dur)
123
+ bpm = rng.uniform(80, 160)
124
+ pattern_name = str(rng.choice(list(DRUM_PATTERNS.keys())))
125
+ pattern = DRUM_PATTERNS[pattern_name]
126
+ # 16th note duration
127
+ step_dur = 60.0 / bpm / 4
128
+ step_samples = max(int(step_dur * SR), 1)
129
+ # Generate hits
130
+ kick_hit = _make_kick(rng, min(int(0.3 * SR), step_samples))
131
+ snare_hit = _make_snare(rng, min(int(0.2 * SR), step_samples))
132
+ hihat_hit = _make_hihat(rng, min(int(0.05 * SR), step_samples))
133
+ audio = np.zeros(n)
134
+ steps = pattern["kick"]
135
+ n_steps = len(steps)
136
+ pos = 0
137
+ step_idx = 0
138
+ while pos < n:
139
+ idx = step_idx % n_steps
140
+ if pattern["kick"][idx]:
141
+ end = min(pos + len(kick_hit), n)
142
+ audio[pos:end] += kick_hit[:end - pos] * 0.8
143
+ if pattern["snare"][idx]:
144
+ end = min(pos + len(snare_hit), n)
145
+ audio[pos:end] += snare_hit[:end - pos] * 0.6
146
+ if pattern["hihat"][idx]:
147
+ end = min(pos + len(hihat_hit), n)
148
+ audio[pos:end] += hihat_hit[:end - pos] * 0.3
149
+ pos += step_samples
150
+ step_idx += 1
151
+ audio = _normalize(audio)
152
+ instruments = []
153
+ if any(pattern["kick"]):
154
+ instruments.append("kick")
155
+ if any(pattern["snare"]):
156
+ instruments.append("snare")
157
+ if any(pattern["hihat"]):
158
+ instruments.append("hi-hat")
159
+ inst_str = ", ".join(instruments[:-1]) + f", and {instruments[-1]}" \
160
+ if len(instruments) > 2 else " and ".join(instruments)
161
+ return audio, _pick(rng, ["punchy", "groovy", "rhythmic", "driving"]), \
162
+ f"{bpm:.0f} BPM {pattern_name} drum pattern with {inst_str}"
generator/generators/pitch.py ADDED
@@ -0,0 +1,152 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Category E: Pitch / Tuning Effects — 5,000 samples."""
2
+
3
+ import numpy as np
4
+ from scipy import signal as sig
5
+
6
+ from generators import register
7
+ from utils import (SR, _dur, _ns, _t, _log_uniform, _wave, _freq_str,
8
+ _midi_to_freq, _midi_to_name, _random_midi, _pick,
9
+ _safe_butter, _apply_sos)
10
+ from constants import CLEAN_DESCS, LOW_DESCS, HIGH_DESCS, SOFT_DESCS
11
+
12
+
13
+ @register(1000, "pitch_tuning")
14
+ def gen_vibrato(rng):
15
+ dur = _dur(rng)
16
+ n = _ns(dur)
17
+ freq = _log_uniform(rng, 100, 2000)
18
+ vib_rate = rng.uniform(3, 8)
19
+ vib_depth = rng.uniform(0.5, 3) # semitones
20
+ t = _t(n)
21
+ mod = vib_depth * np.sin(2 * np.pi * vib_rate * t)
22
+ inst_freq = freq * 2 ** (mod / 12)
23
+ phase = np.cumsum(2 * np.pi * inst_freq / SR)
24
+ audio = np.sin(phase)
25
+ return audio, _pick(rng, SOFT_DESCS + ["expressive", "singing"]), \
26
+ f"{_freq_str(freq)} sine with vibrato at {vib_rate:.0f} Hz rate"
27
+
28
+
29
+ @register(800, "pitch_tuning")
30
+ def gen_pitch_bend(rng):
31
+ dur = _dur(rng)
32
+ n = _ns(dur)
33
+ freq = _log_uniform(rng, 100, 2000)
34
+ bend_semitones = rng.uniform(2, 24)
35
+ direction = str(rng.choice(["up", "down"]))
36
+ t = _t(n)
37
+ if direction == "up":
38
+ bend = np.linspace(0, bend_semitones, n)
39
+ else:
40
+ bend = np.linspace(0, -bend_semitones, n)
41
+ inst_freq = freq * 2 ** (bend / 12)
42
+ phase = np.cumsum(2 * np.pi * inst_freq / SR)
43
+ audio = np.sin(phase)
44
+ desc = f"smooth pitch bend {direction}"
45
+ if bend_semitones >= 11:
46
+ desc += " one octave"
47
+ else:
48
+ desc += f" {bend_semitones:.0f} semitones"
49
+ return audio, _pick(rng, ["sweeping", "sliding"]), \
50
+ f"{_freq_str(freq)} tone with {desc}"
51
+
52
+
53
+ @register(800, "pitch_tuning")
54
+ def gen_glide(rng):
55
+ dur = _dur(rng, 2, 10)
56
+ n = _ns(dur)
57
+ midi1 = _random_midi(rng, 36, 72)
58
+ midi2 = _random_midi(rng, 36, 84)
59
+ while midi2 == midi1:
60
+ midi2 = _random_midi(rng, 36, 84)
61
+ wtype = str(rng.choice(["sine", "sawtooth", "square"]))
62
+ t = _t(n)
63
+ # Exponential glide
64
+ freq1 = _midi_to_freq(midi1)
65
+ freq2 = _midi_to_freq(midi2)
66
+ freq_env = freq1 * (freq2 / freq1) ** (t / (dur))
67
+ phase = np.cumsum(2 * np.pi * freq_env / SR)
68
+ if wtype == "sine":
69
+ audio = np.sin(phase)
70
+ elif wtype == "sawtooth":
71
+ audio = sig.sawtooth(phase)
72
+ else:
73
+ audio = sig.square(phase)
74
+ return audio, _pick(rng, ["smooth", "gliding", "sweeping"]), \
75
+ f"portamento glide from {_midi_to_name(midi1)} to {_midi_to_name(midi2)}"
76
+
77
+
78
+ @register(600, "pitch_tuning")
79
+ def gen_octaver(rng):
80
+ dur = _dur(rng)
81
+ n = _ns(dur)
82
+ freq = _log_uniform(rng, 100, 2000)
83
+ wtype = str(rng.choice(["sine", "sawtooth", "square"]))
84
+ direction = str(rng.choice(["down", "up"]))
85
+ t = _t(n)
86
+ main = _wave(wtype, freq, t)
87
+ oct_freq = freq / 2 if direction == "down" else freq * 2
88
+ octave = _wave(wtype, oct_freq, t)
89
+ mix = rng.uniform(0.3, 0.7)
90
+ audio = (1 - mix) * main + mix * octave
91
+ return audio, _pick(rng, ["thick", "wide", "full"]), \
92
+ f"{_freq_str(freq)} {wtype} with octave-{direction} doubling"
93
+
94
+
95
+ @register(600, "pitch_tuning")
96
+ def gen_harmonizer(rng):
97
+ dur = _dur(rng)
98
+ n = _ns(dur)
99
+ freq = _log_uniform(rng, 100, 2000)
100
+ interval_semitones = int(rng.choice([3, 4, 5, 7, 12]))
101
+ interval_names = {3: "minor third", 4: "major third", 5: "perfect fourth",
102
+ 7: "perfect fifth", 12: "octave"}
103
+ interval_name = interval_names.get(interval_semitones, f"{interval_semitones} semitones")
104
+ t = _t(n)
105
+ main = np.sin(2 * np.pi * freq * t)
106
+ harm_freq = freq * 2 ** (interval_semitones / 12)
107
+ harmony = np.sin(2 * np.pi * harm_freq * t)
108
+ audio = 0.6 * main + 0.4 * harmony
109
+ return audio, _pick(rng, CLEAN_DESCS + ["harmonic", "rich"]), \
110
+ f"{_freq_str(freq)} sine harmonized a {interval_name} above"
111
+
112
+
113
+ @register(600, "pitch_tuning")
114
+ def gen_detune(rng):
115
+ dur = _dur(rng)
116
+ n = _ns(dur)
117
+ freq = _log_uniform(rng, 100, 2000)
118
+ detune_hz = rng.uniform(0.5, 5)
119
+ t = _t(n)
120
+ audio = 0.5 * (np.sin(2 * np.pi * freq * t) +
121
+ np.sin(2 * np.pi * (freq + detune_hz) * t))
122
+ beat_rate = detune_hz
123
+ return audio, _pick(rng, ["shimmering", "wavering", "phasing"]), \
124
+ f"two slightly detuned {_freq_str(freq)} sines creating {beat_rate:.1f} Hz beating"
125
+
126
+
127
+ @register(600, "pitch_tuning")
128
+ def gen_formant_shift(rng):
129
+ dur = _dur(rng)
130
+ n = _ns(dur)
131
+ freq = _log_uniform(rng, 50, 500)
132
+ t = _t(n)
133
+ audio = sig.sawtooth(2 * np.pi * freq * t)
134
+ # Apply formant-like filter bank at shifted frequencies
135
+ shift = rng.uniform(0.5, 2.0)
136
+ formants = [(730 * shift, 80), (1090 * shift, 90), (2440 * shift, 120)]
137
+ filtered = np.zeros(n)
138
+ for fc, bw in formants:
139
+ fc = min(fc, SR / 2 - 200)
140
+ bw = max(bw, 50)
141
+ f_lo = max(fc - bw, 20)
142
+ f_hi = min(fc + bw, SR / 2 - 100)
143
+ if f_lo >= f_hi:
144
+ continue
145
+ sos = _safe_butter(2, [f_lo, f_hi], 'band')
146
+ if sos is not None:
147
+ filtered += _apply_sos(audio, sos) * rng.uniform(0.5, 1.0)
148
+ if np.max(np.abs(filtered)) > 1e-10:
149
+ audio = filtered
150
+ depth_desc = "deep" if shift < 0.8 else "high" if shift > 1.3 else "shifted"
151
+ return audio, _pick(rng, [depth_desc, "vocal", "resonant"]), \
152
+ f"formant-shifted sawtooth voice-like tone"
generator/generators/special.py ADDED
@@ -0,0 +1,133 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Category L: Special / Edge Cases — 4,000 samples."""
2
+
3
+ import numpy as np
4
+ from scipy import signal as sig
5
+
6
+ from generators import register
7
+ from utils import (SR, _dur, _ns, _t, _log_uniform, _freq_str, _pick, _normalize)
8
+ from constants import CLEAN_DESCS, LOW_DESCS, HIGH_DESCS
9
+
10
+
11
+ @register(300, "special")
12
+ def gen_silence(rng):
13
+ dur = _dur(rng)
14
+ audio = np.zeros(_ns(dur))
15
+ return audio, [], "complete digital silence"
16
+
17
+
18
+ @register(300, "special")
19
+ def gen_near_silence(rng):
20
+ dur = _dur(rng)
21
+ n = _ns(dur)
22
+ audio = rng.standard_normal(n) * rng.uniform(0.0001, 0.005)
23
+ return audio, _pick(rng, ["faint", "barely audible"]), "ambient noise floor"
24
+
25
+
26
+ @register(300, "special")
27
+ def gen_dc_offset(rng):
28
+ dur = _dur(rng)
29
+ n = _ns(dur)
30
+ offset = rng.uniform(0.1, 0.9) * float(rng.choice([-1, 1]))
31
+ audio = np.full(n, offset)
32
+ return audio, [], "DC offset signal"
33
+
34
+
35
+ @register(300, "special")
36
+ def gen_clipping_max(rng):
37
+ dur = _dur(rng)
38
+ n = _ns(dur)
39
+ # Fully saturated signal
40
+ freq = _log_uniform(rng, 50, 2000)
41
+ t = _t(n)
42
+ audio = np.clip(np.sin(2 * np.pi * freq * t) * 10, -1, 1)
43
+ return audio, _pick(rng, ["saturated", "clipped", "extreme"]), \
44
+ "fully saturated, clipped audio"
45
+
46
+
47
+ @register(300, "special")
48
+ def gen_nyquist(rng):
49
+ dur = _dur(rng)
50
+ n = _ns(dur)
51
+ freq = rng.uniform(20000, 23000)
52
+ t = _t(n)
53
+ audio = np.sin(2 * np.pi * freq * t)
54
+ return audio, _pick(rng, HIGH_DESCS[:2] + ["ultrasonic"]), \
55
+ f"near-Nyquist tone at {_freq_str(freq)}"
56
+
57
+
58
+ @register(400, "special")
59
+ def gen_sub_bass(rng):
60
+ dur = _dur(rng)
61
+ n = _ns(dur)
62
+ freq = rng.uniform(20, 60)
63
+ t = _t(n)
64
+ audio = np.sin(2 * np.pi * freq * t)
65
+ # Add slight harmonics for audibility
66
+ audio += 0.3 * np.sin(2 * np.pi * freq * 2 * t)
67
+ audio += 0.1 * np.sin(2 * np.pi * freq * 3 * t)
68
+ return audio, _pick(rng, ["deep", "rumbling", "subby", "seismic"]), \
69
+ f"sub-bass rumble at {freq:.0f} Hz"
70
+
71
+
72
+ @register(300, "special")
73
+ def gen_impulse(rng):
74
+ dur = _dur(rng)
75
+ n = _ns(dur)
76
+ audio = np.zeros(n)
77
+ # Place impulse after fade-in period
78
+ pos = min(int(0.015 * SR), n - 1)
79
+ audio[pos] = 1.0
80
+ return audio, _pick(rng, ["sharp", "transient"]), "single-sample impulse"
81
+
82
+
83
+ @register(400, "special")
84
+ def gen_test_tone(rng):
85
+ dur = _dur(rng)
86
+ n = _ns(dur)
87
+ freq = float(rng.choice([440, 1000, 100, 250, 500, 2000, 4000]))
88
+ t = _t(n)
89
+ audio = np.sin(2 * np.pi * freq * t)
90
+ return audio, _pick(rng, CLEAN_DESCS), f"{_freq_str(freq)} reference test tone"
91
+
92
+
93
+ @register(500, "special")
94
+ def gen_sweep(rng):
95
+ dur = _dur(rng)
96
+ n = _ns(dur)
97
+ f0 = rng.uniform(20, 200)
98
+ f1 = rng.uniform(5000, 20000)
99
+ direction = str(rng.choice(["up", "down"]))
100
+ method = str(rng.choice(["linear", "logarithmic"]))
101
+ t = _t(n)
102
+ if direction == "down":
103
+ f0, f1 = f1, f0
104
+ audio = sig.chirp(t, f0, t[-1], f1, method=method)
105
+ return audio, _pick(rng, ["sweeping", "rising" if direction == "up" else "falling"]), \
106
+ f"{method} frequency sweep from {_freq_str(min(f0, f1))} to {_freq_str(max(f0, f1))}"
107
+
108
+
109
+ @register(500, "special")
110
+ def gen_beating(rng):
111
+ dur = _dur(rng)
112
+ n = _ns(dur)
113
+ freq = _log_uniform(rng, 200, 2000)
114
+ beat_rate = rng.uniform(0.5, 10)
115
+ t = _t(n)
116
+ audio = 0.5 * (np.sin(2 * np.pi * freq * t) +
117
+ np.sin(2 * np.pi * (freq + beat_rate) * t))
118
+ return audio, _pick(rng, ["pulsing", "wavering", "beating"]), \
119
+ f"two close tones at {_freq_str(freq)} and {_freq_str(freq + beat_rate)} " \
120
+ f"creating a {beat_rate:.1f} Hz beat"
121
+
122
+
123
+ @register(400, "special")
124
+ def gen_chirp(rng):
125
+ dur = _dur(rng, 2, 10)
126
+ n = _ns(dur)
127
+ f0 = rng.uniform(50, 500)
128
+ f1 = rng.uniform(1000, 10000)
129
+ method = str(rng.choice(["linear", "logarithmic"]))
130
+ t = _t(n)
131
+ audio = sig.chirp(t, f0, t[-1], f1, method=method)
132
+ return audio, _pick(rng, ["rising", "sweeping", "accelerating"]), \
133
+ f"{method} chirp sweeping from {_freq_str(f0)} to {_freq_str(f1)}"
generator/generators/synthesis.py ADDED
@@ -0,0 +1,156 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Category C: Synthesis Techniques — 12,000 samples."""
2
+
3
+ import numpy as np
4
+ from scipy import signal as sig
5
+
6
+ from generators import register
7
+ from utils import (SR, _dur, _ns, _t, _log_uniform, _wave, _freq_str,
8
+ _midi_to_freq, _midi_to_name, _random_midi, _pick,
9
+ _normalize, _pink_noise, _safe_butter, _apply_sos, _adsr)
10
+ from constants import (LOW_DESCS, HIGH_DESCS, CLEAN_DESCS, METAL_DESCS,
11
+ BUZZ_DESCS, SOFT_DESCS)
12
+
13
+
14
+ @register(2000, "synthesis_techniques")
15
+ def gen_fm(rng):
16
+ dur = _dur(rng)
17
+ n = _ns(dur)
18
+ carrier = _log_uniform(rng, 50, 2000)
19
+ ratio = float(rng.choice([0.5, 1, 1.5, 2, 3, 4, 5, 7]))
20
+ mod_freq = carrier * ratio
21
+ index = rng.uniform(0.5, 10)
22
+ t = _t(n)
23
+ audio = np.sin(2 * np.pi * carrier * t + index * np.sin(2 * np.pi * mod_freq * t))
24
+ pool = METAL_DESCS if index > 5 else CLEAN_DESCS
25
+ return audio, _pick(rng, pool), \
26
+ f"FM synthesis with {_freq_str(carrier)} carrier modulated by {_freq_str(mod_freq)} at index {index:.1f}"
27
+
28
+
29
+ @register(1500, "synthesis_techniques")
30
+ def gen_am(rng):
31
+ dur = _dur(rng)
32
+ n = _ns(dur)
33
+ carrier = _log_uniform(rng, 100, 4000)
34
+ mod_rate = _log_uniform(rng, 0.5, 50)
35
+ depth = rng.uniform(0.3, 1.0)
36
+ t = _t(n)
37
+ mod = 1.0 - depth + depth * 0.5 * (1 + np.sin(2 * np.pi * mod_rate * t))
38
+ audio = np.sin(2 * np.pi * carrier * t) * mod
39
+ return audio, _pick(rng, CLEAN_DESCS + ["trembling", "pulsing"]), \
40
+ f"amplitude modulation of a {_freq_str(carrier)} sine by a {mod_rate:.1f} Hz modulator"
41
+
42
+
43
+ @register(1000, "synthesis_techniques")
44
+ def gen_ring_mod(rng):
45
+ dur = _dur(rng)
46
+ n = _ns(dur)
47
+ freq1 = _log_uniform(rng, 100, 2000)
48
+ freq2 = _log_uniform(rng, 100, 2000)
49
+ w1 = str(rng.choice(["sine", "square"]))
50
+ w2 = str(rng.choice(["sine", "square"]))
51
+ t = _t(n)
52
+ audio = _wave(w1, freq1, t) * _wave(w2, freq2, t)
53
+ return audio, _pick(rng, METAL_DESCS + ["dissonant", "inharmonic"]), \
54
+ f"ring modulation between {_freq_str(freq1)} {w1} and {_freq_str(freq2)} {w2}"
55
+
56
+
57
+ @register(1500, "synthesis_techniques")
58
+ def gen_additive(rng):
59
+ dur = _dur(rng)
60
+ n = _ns(dur)
61
+ fundamental = _log_uniform(rng, 50, 1000)
62
+ n_partials = int(rng.integers(4, 20))
63
+ t = _t(n)
64
+ audio = np.zeros(n)
65
+ for h in range(1, n_partials + 1):
66
+ f = fundamental * h
67
+ if f > SR / 2:
68
+ break
69
+ amp = rng.uniform(0.1, 1.0) / h ** rng.uniform(0.3, 1.5)
70
+ audio += amp * np.sin(2 * np.pi * f * t + rng.uniform(0, 2 * np.pi))
71
+ return audio, _pick(rng, CLEAN_DESCS + ["rich", "complex"]), \
72
+ f"additive synthesis with {n_partials} harmonic partials on {_freq_str(fundamental)}"
73
+
74
+
75
+ @register(1500, "synthesis_techniques")
76
+ def gen_subtractive(rng):
77
+ dur = _dur(rng)
78
+ n = _ns(dur)
79
+ freq = _log_uniform(rng, 50, 2000)
80
+ wtype = str(rng.choice(["sawtooth", "square"]))
81
+ t = _t(n)
82
+ audio = _wave(wtype, freq, t)
83
+ cutoff = _log_uniform(rng, 200, 8000)
84
+ resonance = rng.uniform(0.5, 5)
85
+ sos = _safe_butter(4, cutoff, 'low')
86
+ if sos is not None:
87
+ audio = _apply_sos(audio, sos)
88
+ pool = LOW_DESCS if cutoff < 1000 else CLEAN_DESCS
89
+ return audio, _pick(rng, pool), \
90
+ f"subtractive synthesis: {wtype} through low-pass filter at {_freq_str(cutoff)}"
91
+
92
+
93
+ @register(1500, "synthesis_techniques")
94
+ def gen_granular(rng):
95
+ dur = _dur(rng)
96
+ n = _ns(dur)
97
+ # Source sound
98
+ src_type = str(rng.choice(["sine", "noise"]))
99
+ if src_type == "sine":
100
+ freq = _log_uniform(rng, 100, 2000)
101
+ src = np.sin(2 * np.pi * freq * _t(n))
102
+ src_desc = "sine"
103
+ else:
104
+ src = rng.standard_normal(n)
105
+ src_desc = "noise"
106
+ grain_ms = rng.uniform(5, 50)
107
+ grain_size = max(int(grain_ms * SR / 1000), 64)
108
+ density = rng.uniform(10, 100)
109
+ n_grains = int(density * dur)
110
+ audio = np.zeros(n)
111
+ window = np.hanning(grain_size)
112
+ for _ in range(n_grains):
113
+ src_pos = int(rng.integers(0, max(n - grain_size, 1)))
114
+ out_pos = int(rng.integers(0, max(n - grain_size, 1)))
115
+ end = min(out_pos + grain_size, n)
116
+ gl = end - out_pos
117
+ audio[out_pos:end] += src[src_pos:src_pos + gl] * window[:gl]
118
+ return audio, _pick(rng, ["shimmering", "textural", "scattered", "ethereal"]), \
119
+ f"granular texture of tiny {src_desc} grains"
120
+
121
+
122
+ @register(1500, "synthesis_techniques")
123
+ def gen_karplus_strong(rng):
124
+ dur = _dur(rng, 2, 10)
125
+ n = _ns(dur)
126
+ midi = _random_midi(rng, 36, 84)
127
+ freq = _midi_to_freq(midi)
128
+ brightness = rng.uniform(0.3, 0.7)
129
+ D = max(int(SR / freq), 2)
130
+ out = np.zeros(n)
131
+ out[:D] = rng.uniform(-1, 1, D)
132
+ for i in range(D, n):
133
+ out[i] = brightness * out[i - D] + (1 - brightness) * out[i - D + 1]
134
+ pool = METAL_DESCS if brightness > 0.5 else SOFT_DESCS
135
+ return out, _pick(rng, pool), \
136
+ f"Karplus-Strong plucked string at {_midi_to_name(midi)}"
137
+
138
+
139
+ @register(1000, "synthesis_techniques")
140
+ def gen_physical_model(rng):
141
+ dur = _dur(rng, 2, 10)
142
+ n = _ns(dur)
143
+ freq = _log_uniform(rng, 200, 2000)
144
+ t = _t(n)
145
+ # Bar mode ratios (inharmonic)
146
+ ratios = [1, 2.756, 5.404, 8.933, 13.344]
147
+ audio = np.zeros(n)
148
+ for i, r in enumerate(ratios):
149
+ f = freq * r
150
+ if f > SR / 2:
151
+ break
152
+ decay = rng.uniform(0.5, 3.0) / (i + 1)
153
+ amp = 1.0 / (i + 1) ** 0.5
154
+ audio += amp * np.sin(2 * np.pi * f * t) * np.exp(-t / decay)
155
+ return audio, _pick(rng, METAL_DESCS), \
156
+ f"physical model of a struck metallic bar at {_freq_str(freq)}"
generator/generators/time_effects.py ADDED
@@ -0,0 +1,222 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Category I: Time-Based Effects — 6,000 samples."""
2
+
3
+ import numpy as np
4
+ from scipy import signal as sig
5
+
6
+ from generators import register
7
+ from utils import (SR, _dur, _ns, _t, _log_uniform, _freq_str,
8
+ _random_base, _random_source, _pick, _apply_delay,
9
+ _reverb_ir, _apply_reverb, _safe_butter, _apply_sos,
10
+ _make_kick, _make_snare, _make_hihat, _normalize)
11
+ from constants import REVERB_DESCS, CLEAN_DESCS, METAL_DESCS, SOFT_DESCS
12
+
13
+
14
+ @register(600, "time_effects")
15
+ def gen_delay(rng):
16
+ dur = _dur(rng)
17
+ n = _ns(dur)
18
+ audio, desc, _ = _random_base(rng, n, allow_noise=False)
19
+ delay_time = rng.uniform(0.1, 0.5)
20
+ feedback = rng.uniform(0.3, 0.7)
21
+ audio = _apply_delay(audio, delay_time, feedback, wet=rng.uniform(0.2, 0.5))
22
+ return audio, _pick(rng, CLEAN_DESCS + ["echoing"]), \
23
+ f"{desc} with clean delay echoes"
24
+
25
+
26
+ @register(500, "time_effects")
27
+ def gen_slapback(rng):
28
+ dur = _dur(rng)
29
+ n = _ns(dur)
30
+ # Short percussive source
31
+ audio, desc, _ = _random_base(rng, n, allow_noise=False)
32
+ delay_time = rng.uniform(0.03, 0.12)
33
+ audio = _apply_delay(audio, delay_time, feedback=0.1, wet=rng.uniform(0.3, 0.6), n_echoes=2)
34
+ return audio, _pick(rng, ["snappy", "doubled"]), \
35
+ f"{desc} with short slapback delay"
36
+
37
+
38
+ @register(500, "time_effects")
39
+ def gen_pingpong(rng):
40
+ dur = _dur(rng)
41
+ n = _ns(dur)
42
+ audio, desc, _ = _random_base(rng, n, allow_noise=False)
43
+ delay_time = rng.uniform(0.15, 0.5)
44
+ feedback = rng.uniform(0.3, 0.6)
45
+ # Simulate ping-pong: alternating amplitude between echoes
46
+ d = max(int(delay_time * SR), 1)
47
+ out = audio.copy()
48
+ for i in range(1, 10):
49
+ pos = i * d
50
+ if pos >= n:
51
+ break
52
+ gain = feedback ** i
53
+ pan = 0.5 + 0.3 * ((-1) ** i) # alternating levels
54
+ end = min(n, pos + n - pos)
55
+ out[pos:end] += gain * pan * audio[:end - pos]
56
+ out = _normalize(out)
57
+ return out, _pick(rng, ["bouncing", "stereo-like", "rhythmic"]), \
58
+ f"{desc} bouncing in ping-pong delay"
59
+
60
+
61
+ @register(500, "time_effects")
62
+ def gen_multitap(rng):
63
+ dur = _dur(rng)
64
+ n = _ns(dur)
65
+ audio, desc, _ = _random_base(rng, n, allow_noise=False)
66
+ n_taps = int(rng.integers(3, 7))
67
+ out = audio.copy()
68
+ for tap in range(n_taps):
69
+ delay = rng.uniform(0.05, 0.6)
70
+ gain = rng.uniform(0.2, 0.6)
71
+ d = int(delay * SR)
72
+ if d < n:
73
+ out[d:] += gain * audio[:n - d]
74
+ out = _normalize(out)
75
+ return out, _pick(rng, ["rhythmic", "echoing", "complex"]), \
76
+ f"multi-tap delay creating rhythmic echoes from {desc}"
77
+
78
+
79
+ @register(500, "time_effects")
80
+ def gen_tape_delay(rng):
81
+ dur = _dur(rng)
82
+ n = _ns(dur)
83
+ audio, desc, _ = _random_base(rng, n, allow_noise=False)
84
+ delay_time = rng.uniform(0.2, 0.5)
85
+ feedback = rng.uniform(0.4, 0.7)
86
+ d = max(int(delay_time * SR), 1)
87
+ out = audio.copy()
88
+ echo = audio.copy()
89
+ for i in range(1, 8):
90
+ pos = i * d
91
+ if pos >= n:
92
+ break
93
+ # Degrade each echo (low-pass + slight noise)
94
+ sos = _safe_butter(2, max(8000 - i * 1000, 1000), 'low')
95
+ if sos is not None:
96
+ echo = _apply_sos(echo, sos)
97
+ gain = feedback ** i
98
+ end = min(n, pos + len(echo))
99
+ out[pos:end] += gain * echo[:end - pos]
100
+ out = _normalize(out)
101
+ return out, _pick(rng, ["warm", "degrading", "analog", "tape-like"]), \
102
+ f"warm, degrading tape delay on {desc}"
103
+
104
+
105
+ @register(500, "time_effects")
106
+ def gen_reverb_room(rng):
107
+ dur = _dur(rng)
108
+ n = _ns(dur)
109
+ audio, desc, _ = _random_source(rng, n)
110
+ rt60 = rng.uniform(0.3, 1.0)
111
+ ir = _reverb_ir(rng, rt60, "room")
112
+ wet = rng.uniform(0.2, 0.5)
113
+ audio = _apply_reverb(audio, ir, wet)
114
+ return audio, _pick(rng, ["roomy", "natural"] + REVERB_DESCS[:2]), \
115
+ f"{desc} in a small room reverb"
116
+
117
+
118
+ @register(500, "time_effects")
119
+ def gen_reverb_hall(rng):
120
+ dur = _dur(rng)
121
+ n = _ns(dur)
122
+ audio, desc, _ = _random_source(rng, n)
123
+ rt60 = rng.uniform(2, 6)
124
+ ir = _reverb_ir(rng, rt60, "hall")
125
+ wet = rng.uniform(0.3, 0.6)
126
+ audio = _apply_reverb(audio, ir, wet)
127
+ return audio, _pick(rng, REVERB_DESCS), \
128
+ f"{desc} in a spacious hall reverb"
129
+
130
+
131
+ @register(500, "time_effects")
132
+ def gen_reverb_plate(rng):
133
+ dur = _dur(rng)
134
+ n = _ns(dur)
135
+ audio, desc, _ = _random_source(rng, n)
136
+ rt60 = rng.uniform(1, 3)
137
+ ir = _reverb_ir(rng, rt60, "plate")
138
+ wet = rng.uniform(0.2, 0.5)
139
+ audio = _apply_reverb(audio, ir, wet)
140
+ return audio, _pick(rng, ["bright", "dense", "shimmery"]), \
141
+ f"plate reverb on {desc}"
142
+
143
+
144
+ @register(400, "time_effects")
145
+ def gen_reverb_spring(rng):
146
+ dur = _dur(rng)
147
+ n = _ns(dur)
148
+ audio, desc, _ = _random_source(rng, n)
149
+ rt60 = rng.uniform(0.5, 2)
150
+ ir = _reverb_ir(rng, rt60, "spring")
151
+ wet = rng.uniform(0.2, 0.5)
152
+ audio = _apply_reverb(audio, ir, wet)
153
+ return audio, _pick(rng, METAL_DESCS[:2] + ["springy", "boingy"]), \
154
+ f"metallic spring reverb on {desc}"
155
+
156
+
157
+ @register(500, "time_effects")
158
+ def gen_gated_reverb(rng):
159
+ dur = _dur(rng)
160
+ n = _ns(dur)
161
+ # Percussive source
162
+ hit_n = min(int(0.3 * SR), n)
163
+ hit = _make_snare(rng, hit_n)
164
+ audio = np.zeros(n)
165
+ # Place hits
166
+ period = int(rng.uniform(0.5, 1.5) * SR)
167
+ for pos in range(0, n, period):
168
+ end = min(pos + hit_n, n)
169
+ audio[pos:end] += hit[:end - pos]
170
+ # Apply reverb
171
+ rt60 = rng.uniform(1, 3)
172
+ ir = _reverb_ir(rng, rt60, "room")
173
+ reverbed = _apply_reverb(audio, ir, wet=0.6)
174
+ # Gate: cut reverb tail sharply
175
+ gate_time = rng.uniform(0.1, 0.3)
176
+ gate_n = int(gate_time * SR)
177
+ gate_env = np.ones(n)
178
+ for pos in range(0, n, period):
179
+ cut = min(pos + gate_n, n)
180
+ if cut < n:
181
+ gate_env[cut:min(cut + int(0.01 * SR), n)] *= np.linspace(1, 0,
182
+ min(int(0.01 * SR), n - cut))
183
+ gate_env[min(cut + int(0.01 * SR), n):min(pos + period, n)] = 0
184
+ audio = reverbed * gate_env
185
+ return audio, _pick(rng, ["punchy", "80s", "powerful", "explosive"]), \
186
+ "snare with gated reverb"
187
+
188
+
189
+ @register(500, "time_effects")
190
+ def gen_shimmer_reverb(rng):
191
+ dur = _dur(rng)
192
+ n = _ns(dur)
193
+ audio, desc, _ = _random_source(rng, n)
194
+ rt60 = rng.uniform(2, 5)
195
+ ir = _reverb_ir(rng, rt60, "hall")
196
+ reverbed = sig.fftconvolve(audio, ir, mode='full')[:n]
197
+ # Pitch-shift reverb tail up an octave (simple: resample)
198
+ half = sig.resample(reverbed, n // 2)
199
+ shifted = np.zeros(n)
200
+ shifted[:len(half)] = half
201
+ wet = rng.uniform(0.2, 0.4)
202
+ audio = (1 - wet) * audio + wet * 0.5 * (reverbed[:n] + shifted[:n])
203
+ audio = _normalize(audio)
204
+ return audio, _pick(rng, ["shimmering", "ethereal", "celestial", "sparkling"]), \
205
+ f"shimmering, pitch-shifted reverb on {desc}"
206
+
207
+
208
+ @register(500, "time_effects")
209
+ def gen_reverse_reverb(rng):
210
+ dur = _dur(rng)
211
+ n = _ns(dur)
212
+ audio, desc, _ = _random_source(rng, n)
213
+ rt60 = rng.uniform(1, 3)
214
+ ir = _reverb_ir(rng, rt60, "hall")
215
+ # Reverse audio, apply reverb, reverse back
216
+ reversed_audio = audio[::-1]
217
+ reverbed = sig.fftconvolve(reversed_audio, ir, mode='full')[:n]
218
+ reverse_reverbed = reverbed[::-1]
219
+ wet = rng.uniform(0.3, 0.6)
220
+ audio = (1 - wet) * audio + wet * _normalize(reverse_reverbed)
221
+ return audio, _pick(rng, ["swelling", "ghostly", "reversed"]), \
222
+ f"reversed reverb swell into {desc}"
generator/generators/waveforms.py ADDED
@@ -0,0 +1,162 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Category A: Waveforms & Basic Synth Sources — 14,000 samples."""
2
+
3
+ import numpy as np
4
+ from scipy import signal as sig
5
+
6
+ from generators import register
7
+ from utils import (SR, _dur, _ns, _t, _log_uniform, _wave, _freq_str,
8
+ _midi_to_freq, _midi_to_name, _random_midi, _pick, _normalize,
9
+ _pink_noise, _brown_noise, _adsr)
10
+ from constants import LOW_DESCS, HIGH_DESCS, CLEAN_DESCS, BUZZ_DESCS, SOFT_DESCS
11
+
12
+
13
+ @register(1500, "basic_waveforms")
14
+ def gen_sine(rng):
15
+ dur = _dur(rng)
16
+ freq = _log_uniform(rng, 20, 20000)
17
+ t = _t(_ns(dur))
18
+ audio = np.sin(2 * np.pi * freq * t)
19
+ pool = CLEAN_DESCS if freq < 5000 else HIGH_DESCS
20
+ return audio, _pick(rng, pool), f"{_freq_str(freq)} sine wave"
21
+
22
+
23
+ @register(1500, "basic_waveforms")
24
+ def gen_square(rng):
25
+ dur = _dur(rng)
26
+ freq = _log_uniform(rng, 20, 10000)
27
+ duty = rng.uniform(0.1, 0.9)
28
+ t = _t(_ns(dur))
29
+ audio = sig.square(2 * np.pi * freq * t, duty=duty)
30
+ duty_s = f" with {duty * 100:.0f}% duty cycle" if abs(duty - 0.5) > 0.1 else ""
31
+ return audio, _pick(rng, HIGH_DESCS + BUZZ_DESCS), f"{_freq_str(freq)} square wave{duty_s}"
32
+
33
+
34
+ @register(1500, "basic_waveforms")
35
+ def gen_sawtooth(rng):
36
+ dur = _dur(rng)
37
+ freq = _log_uniform(rng, 20, 10000)
38
+ t = _t(_ns(dur))
39
+ audio = sig.sawtooth(2 * np.pi * freq * t)
40
+ return audio, _pick(rng, HIGH_DESCS + BUZZ_DESCS), f"{_freq_str(freq)} sawtooth wave"
41
+
42
+
43
+ @register(1500, "basic_waveforms")
44
+ def gen_triangle(rng):
45
+ dur = _dur(rng)
46
+ freq = _log_uniform(rng, 20, 10000)
47
+ t = _t(_ns(dur))
48
+ audio = sig.sawtooth(2 * np.pi * freq * t, width=0.5)
49
+ return audio, _pick(rng, SOFT_DESCS + CLEAN_DESCS), f"{_freq_str(freq)} triangle wave"
50
+
51
+
52
+ @register(1000, "basic_waveforms")
53
+ def gen_pulse_pwm(rng):
54
+ dur = _dur(rng)
55
+ n = _ns(dur)
56
+ freq = _log_uniform(rng, 50, 5000)
57
+ t = _t(n)
58
+ duty_start = rng.uniform(0.1, 0.9)
59
+ duty_end = rng.uniform(0.1, 0.9)
60
+ duty_sweep = np.linspace(duty_start, duty_end, n)
61
+ phase = 2 * np.pi * freq * t
62
+ audio = np.where(np.mod(phase, 2 * np.pi) / (2 * np.pi) < duty_sweep, 1.0, -1.0)
63
+ return audio, _pick(rng, BUZZ_DESCS), f"{_freq_str(freq)} pulse wave with sweeping duty cycle"
64
+
65
+
66
+ @register(1500, "basic_waveforms")
67
+ def gen_supersaw(rng):
68
+ dur = _dur(rng)
69
+ n = _ns(dur)
70
+ midi = _random_midi(rng, 36, 72)
71
+ freq = _midi_to_freq(midi)
72
+ n_voices = int(rng.integers(3, 9))
73
+ detune_cents = rng.uniform(0.1, 30)
74
+ t = _t(n)
75
+ audio = np.zeros(n)
76
+ for v in range(n_voices):
77
+ cents = rng.uniform(-detune_cents, detune_cents)
78
+ f = freq * 2 ** (cents / 1200)
79
+ audio += sig.sawtooth(2 * np.pi * f * t + rng.uniform(0, 2 * np.pi))
80
+ audio /= n_voices
81
+ note = _midi_to_name(midi)
82
+ return audio, _pick(rng, ["thick", "wide", "lush", "massive"]), \
83
+ f"supersaw with {n_voices} detuned voices at {note}"
84
+
85
+
86
+ @register(1000, "basic_waveforms")
87
+ def gen_wavetable(rng):
88
+ dur = _dur(rng)
89
+ n = _ns(dur)
90
+ freq = _log_uniform(rng, 80, 2000)
91
+ t = _t(n)
92
+ shapes = ["sine", "square", "sawtooth", "triangle"]
93
+ s1, s2 = rng.choice(shapes, size=2, replace=False)
94
+ morph = np.linspace(0, 1, n)
95
+ w1 = _wave(s1, freq, t)
96
+ w2 = _wave(s2, freq, t)
97
+ audio = (1 - morph) * w1 + morph * w2
98
+ return audio, _pick(rng, ["evolving", "morphing", "shifting"]), \
99
+ f"wavetable oscillator morphing from {s1} to {s2} at {_freq_str(freq)}"
100
+
101
+
102
+ @register(500, "basic_waveforms")
103
+ def gen_sample_hold(rng):
104
+ dur = _dur(rng)
105
+ n = _ns(dur)
106
+ hold_samples = int(rng.uniform(10, 500))
107
+ n_steps = n // hold_samples + 1
108
+ levels = rng.uniform(-1, 1, n_steps)
109
+ audio = np.repeat(levels, hold_samples)[:n]
110
+ rate_hz = SR / hold_samples
111
+ return audio, _pick(rng, BUZZ_DESCS + ["stepped", "random"]), \
112
+ f"sample-and-hold noise oscillator at {rate_hz:.0f} Hz rate"
113
+
114
+
115
+ @register(500, "basic_waveforms")
116
+ def gen_bit_noise(rng):
117
+ dur = _dur(rng)
118
+ n = _ns(dur)
119
+ bit_rate = int(_log_uniform(rng, 100, 20000))
120
+ hold = max(SR // bit_rate, 1)
121
+ n_steps = n // hold + 1
122
+ bits = rng.choice([-1.0, 1.0], size=n_steps)
123
+ audio = np.repeat(bits, hold)[:n]
124
+ return audio, _pick(rng, ["harsh", "metallic", "digital", "noisy"]), \
125
+ f"bit noise generator at {bit_rate} Hz"
126
+
127
+
128
+ @register(1000, "basic_waveforms")
129
+ def gen_unison_detune(rng):
130
+ dur = _dur(rng)
131
+ n = _ns(dur)
132
+ midi = _random_midi(rng, 36, 84)
133
+ freq = _midi_to_freq(midi)
134
+ wtype = str(rng.choice(["sine", "sawtooth", "square", "triangle"]))
135
+ n_voices = int(rng.integers(2, 9))
136
+ detune = rng.uniform(0.5, 15)
137
+ t = _t(n)
138
+ audio = np.zeros(n)
139
+ for v in range(n_voices):
140
+ cents = rng.uniform(-detune, detune)
141
+ f = freq * 2 ** (cents / 1200)
142
+ audio += _wave(wtype, f, t + rng.uniform(0, 1.0 / f))
143
+ audio /= n_voices
144
+ return audio, _pick(rng, ["wide", "thick", "lush", "detuned"]), \
145
+ f"detuned unison {wtype} at {_midi_to_name(midi)}"
146
+
147
+
148
+ @register(1500, "basic_waveforms")
149
+ def gen_drone(rng):
150
+ dur = _dur(rng, 5, 20)
151
+ n = _ns(dur)
152
+ freq = _log_uniform(rng, 30, 200)
153
+ t = _t(n)
154
+ # Base tone + harmonics with slow movement
155
+ audio = np.sin(2 * np.pi * freq * t)
156
+ for h in range(2, int(rng.integers(4, 10))):
157
+ lfo_rate = rng.uniform(0.01, 0.2)
158
+ lfo = 0.5 + 0.5 * np.sin(2 * np.pi * lfo_rate * t + rng.uniform(0, 2 * np.pi))
159
+ amp = rng.uniform(0.1, 0.5) / h
160
+ audio += amp * lfo * np.sin(2 * np.pi * freq * h * t)
161
+ return audio, _pick(rng, LOW_DESCS + ["droning", "sustained"]), \
162
+ f"drone at {_freq_str(freq)} with slow harmonic movement"
generator/slurm_generate.sh ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ #SBATCH --job-name=gen-prog-audio
3
+ #SBATCH --account=laionize
4
+ #SBATCH --partition=batch
5
+ #SBATCH --nodes=1
6
+ #SBATCH --ntasks=1
7
+ #SBATCH --cpus-per-task=48
8
+ #SBATCH --threads-per-core=2
9
+ #SBATCH --time=06:00:00
10
+ #SBATCH --output=programmatic_audio/logs/generate_%j.out
11
+ #SBATCH --error=programmatic_audio/logs/generate_%j.err
12
+
13
+ source /p/project1/ccstdl/wijngaard1/miniforge3/etc/profile.d/conda.sh
14
+ conda activate clapv2
15
+ cd /p/project1/ccstdl/wijngaard1/clapv2
16
+
17
+ python -u programmatic_audio/generate.py --workers 92 --seed 42
generator/utils.py ADDED
@@ -0,0 +1,408 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Audio utility functions for programmatic audio generation."""
2
+
3
+ import numpy as np
4
+ from scipy import signal
5
+
6
+ SR = 48000
7
+ SAMPLES_PER_TAR = 4096
8
+
9
+
10
+ # ── Duration / sample helpers ─────────────────────────────────────────────────
11
+
12
+ def _dur(rng, lo=2.0, hi=20.0):
13
+ return rng.uniform(lo, hi)
14
+
15
+
16
+ def _ns(dur):
17
+ return int(dur * SR)
18
+
19
+
20
+ def _t(n):
21
+ return np.arange(n) / SR
22
+
23
+
24
+ def _log_uniform(rng, lo, hi):
25
+ return np.exp(rng.uniform(np.log(lo), np.log(hi)))
26
+
27
+
28
+ # ── MIDI / note helpers ───────────────────────────────────────────────────────
29
+
30
+ def _midi_to_freq(midi):
31
+ return 440.0 * 2.0 ** ((midi - 69) / 12.0)
32
+
33
+
34
+ def _midi_to_name(midi):
35
+ from constants import NOTE_NAMES
36
+ return f"{NOTE_NAMES[int(midi) % 12]}{int(midi) // 12 - 1}"
37
+
38
+
39
+ def _random_midi(rng, lo=36, hi=84):
40
+ return int(rng.integers(lo, hi + 1))
41
+
42
+
43
+ def _freq_str(freq):
44
+ if freq >= 1000:
45
+ return f"{freq / 1000:.1f} kHz"
46
+ elif freq >= 100:
47
+ return f"{freq:.0f} Hz"
48
+ return f"{freq:.1f} Hz"
49
+
50
+
51
+ # ── Waveform generation ──────────────────────────────────────────────────────
52
+
53
+ def _wave(wtype, freq, t):
54
+ phase = 2 * np.pi * freq * t
55
+ if wtype == "sine":
56
+ return np.sin(phase)
57
+ elif wtype == "square":
58
+ return signal.square(phase)
59
+ elif wtype == "sawtooth":
60
+ return signal.sawtooth(phase)
61
+ elif wtype == "triangle":
62
+ return signal.sawtooth(phase, width=0.5)
63
+ raise ValueError(f"Unknown wave type: {wtype}")
64
+
65
+
66
+ # ── Descriptor / caption helpers ──────────────────────────────────────────────
67
+
68
+ def _pick(rng, pool, max_n=2):
69
+ """Pick 0-2 descriptors from pool."""
70
+ if not pool:
71
+ return []
72
+ n = int(rng.choice([0, 0, 1, 1, 1, 2]))
73
+ n = min(n, max_n, len(pool))
74
+ if n == 0:
75
+ return []
76
+ return list(rng.choice(pool, size=n, replace=False))
77
+
78
+
79
+ def _vol_word(rng, amp):
80
+ if amp < 0.15:
81
+ return "very quiet"
82
+ elif amp < 0.35:
83
+ return str(rng.choice(["quiet", "soft"]))
84
+ elif amp < 0.65:
85
+ return ""
86
+ elif amp < 0.85:
87
+ return "loud"
88
+ return "very loud"
89
+
90
+
91
+ def _build_caption(vol, descs, core):
92
+ parts = []
93
+ if vol:
94
+ parts.append(vol)
95
+ parts.extend(descs)
96
+ if parts:
97
+ return f"A {', '.join(parts)} {core}"
98
+ return f"A {core}"
99
+
100
+
101
+ # ── Noise generators ─────────────────────────────────────────────────────────
102
+
103
+ def _normalize(audio):
104
+ peak = np.max(np.abs(audio))
105
+ return audio / peak if peak > 1e-10 else audio
106
+
107
+
108
+ def _pink_noise(rng, n):
109
+ white = rng.standard_normal(n)
110
+ fft = np.fft.rfft(white)
111
+ freqs = np.fft.rfftfreq(n, 1.0 / SR)
112
+ freqs[0] = 1
113
+ fft /= np.sqrt(freqs)
114
+ return _normalize(np.fft.irfft(fft, n))
115
+
116
+
117
+ def _brown_noise(rng, n):
118
+ out = np.cumsum(rng.standard_normal(n))
119
+ out -= np.mean(out)
120
+ return _normalize(out)
121
+
122
+
123
+ def _blue_noise(rng, n):
124
+ return _normalize(np.diff(rng.standard_normal(n + 1)))
125
+
126
+
127
+ def _violet_noise(rng, n):
128
+ w = rng.standard_normal(n + 2)
129
+ return _normalize(np.diff(np.diff(w)))
130
+
131
+
132
+ def _grey_noise(rng, n):
133
+ white = rng.standard_normal(n)
134
+ fft = np.fft.rfft(white)
135
+ freqs = np.fft.rfftfreq(n, 1.0 / SR)
136
+ f = np.maximum(freqs, 1.0)
137
+ a = (12194**2 * f**4) / (
138
+ (f**2 + 20.6**2)
139
+ * np.sqrt((f**2 + 107.7**2) * (f**2 + 737.9**2))
140
+ * (f**2 + 12194**2)
141
+ )
142
+ a /= np.max(a)
143
+ fft /= (a + 1e-10)
144
+ return _normalize(np.fft.irfft(fft, n))
145
+
146
+
147
+ # ── Envelope ──────────────────────────────────────────────────────────────────
148
+
149
+ def _adsr(dur, attack=0.01, decay=0.05, sustain=0.7, release=0.1):
150
+ n = _ns(dur)
151
+ a_n = min(int(attack * SR), n)
152
+ d_n = min(int(decay * SR), max(n - a_n, 0))
153
+ r_n = min(int(release * SR), max(n - a_n - d_n, 0))
154
+ s_n = max(n - a_n - d_n - r_n, 0)
155
+ env = np.concatenate([
156
+ np.linspace(0, 1, max(a_n, 1)),
157
+ np.linspace(1, sustain, max(d_n, 1)),
158
+ np.full(s_n, sustain),
159
+ np.linspace(sustain, 0, max(r_n, 1)),
160
+ ])[:n]
161
+ if len(env) < n:
162
+ env = np.pad(env, (0, n - len(env)))
163
+ return env
164
+
165
+
166
+ # ── Filter helpers ────────────────────────────────────────────────────────────
167
+
168
+ def _safe_butter(order, freq, btype, fs=SR):
169
+ nyq = fs / 2
170
+ if isinstance(freq, (list, tuple, np.ndarray)):
171
+ freq = [max(20, min(f, nyq - 100)) for f in freq]
172
+ if freq[0] >= freq[1]:
173
+ return None
174
+ else:
175
+ freq = max(20, min(freq, nyq - 100))
176
+ try:
177
+ return signal.butter(order, freq, btype=btype, fs=fs, output='sos')
178
+ except Exception:
179
+ return None
180
+
181
+
182
+ def _apply_sos(audio, sos):
183
+ if sos is None:
184
+ return audio
185
+ try:
186
+ return signal.sosfilt(sos, audio)
187
+ except Exception:
188
+ return audio
189
+
190
+
191
+ def _peaking_eq(freq, gain_db, Q):
192
+ """Design a peaking EQ biquad. Returns (b, a)."""
193
+ A = 10 ** (gain_db / 40)
194
+ w0 = 2 * np.pi * freq / SR
195
+ alpha = np.sin(w0) / (2 * Q)
196
+ b0 = 1 + alpha * A
197
+ b1 = -2 * np.cos(w0)
198
+ b2 = 1 - alpha * A
199
+ a0 = 1 + alpha / A
200
+ a1 = -2 * np.cos(w0)
201
+ a2 = 1 - alpha / A
202
+ return np.array([b0, b1, b2]) / a0, np.array([1, a1, a2]) / a0
203
+
204
+
205
+ def _shelf_eq(freq, gain_db, shelf_type='high'):
206
+ """Design a shelving EQ. Returns (b, a)."""
207
+ A = 10 ** (gain_db / 40)
208
+ w0 = 2 * np.pi * freq / SR
209
+ alpha = np.sin(w0) / 2 * np.sqrt((A + 1 / A) * (1 / 0.707 - 1) + 2)
210
+ cos_w0 = np.cos(w0)
211
+ sqA = np.sqrt(A)
212
+ if shelf_type == 'low':
213
+ b0 = A * ((A + 1) - (A - 1) * cos_w0 + 2 * sqA * alpha)
214
+ b1 = 2 * A * ((A - 1) - (A + 1) * cos_w0)
215
+ b2 = A * ((A + 1) - (A - 1) * cos_w0 - 2 * sqA * alpha)
216
+ a0 = (A + 1) + (A - 1) * cos_w0 + 2 * sqA * alpha
217
+ a1 = -2 * ((A - 1) + (A + 1) * cos_w0)
218
+ a2 = (A + 1) + (A - 1) * cos_w0 - 2 * sqA * alpha
219
+ else:
220
+ b0 = A * ((A + 1) + (A - 1) * cos_w0 + 2 * sqA * alpha)
221
+ b1 = -2 * A * ((A - 1) + (A + 1) * cos_w0)
222
+ b2 = A * ((A + 1) + (A - 1) * cos_w0 - 2 * sqA * alpha)
223
+ a0 = (A + 1) - (A - 1) * cos_w0 + 2 * sqA * alpha
224
+ a1 = 2 * ((A - 1) - (A + 1) * cos_w0)
225
+ a2 = (A + 1) - (A - 1) * cos_w0 - 2 * sqA * alpha
226
+ return np.array([b0, b1, b2]) / a0, np.array([1, a1, a2]) / a0
227
+
228
+
229
+ # ── Random base sound helpers ─────────────────────────────────────────────────
230
+
231
+ def _random_base(rng, n, allow_noise=True):
232
+ """Simple random base waveform. Returns (audio, description, params)."""
233
+ choices = ["sine", "square", "sawtooth", "triangle"]
234
+ if allow_noise:
235
+ choices += ["white_noise", "pink_noise"]
236
+ choice = str(rng.choice(choices))
237
+ if choice == "white_noise":
238
+ return rng.standard_normal(n), "white noise", {"is_noise": True}
239
+ elif choice == "pink_noise":
240
+ return _pink_noise(rng, n), "pink noise", {"is_noise": True}
241
+ freq = _log_uniform(rng, 80, 4000)
242
+ t = _t(n)
243
+ audio = _wave(choice, freq, t)
244
+ return audio, f"{_freq_str(freq)} {choice} wave", {"freq": freq, "wave_type": choice}
245
+
246
+
247
+ def _random_source(rng, n):
248
+ """Richer random sound source (includes chords, FM, pads)."""
249
+ choice = int(rng.integers(0, 8))
250
+ if choice <= 3:
251
+ return _random_base(rng, n)
252
+ elif choice == 4:
253
+ root = _random_midi(rng, 48, 72)
254
+ intervals = [[0, 4, 7], [0, 3, 7], [0, 4, 7, 11]][int(rng.integers(0, 3))]
255
+ t = _t(n)
256
+ audio = sum(_wave("sine", _midi_to_freq(root + iv), t) for iv in intervals)
257
+ audio /= len(intervals)
258
+ return audio, f"{_midi_to_name(root)} chord", {"freq": _midi_to_freq(root)}
259
+ elif choice == 5:
260
+ carrier = _log_uniform(rng, 100, 1000)
261
+ ratio = float(rng.choice([1, 2, 3, 4]))
262
+ index = rng.uniform(1, 5)
263
+ t = _t(n)
264
+ audio = np.sin(2 * np.pi * carrier * t + index * np.sin(2 * np.pi * carrier * ratio * t))
265
+ return audio, f"FM tone at {_freq_str(carrier)}", {"freq": carrier}
266
+ elif choice == 6:
267
+ freq = _log_uniform(rng, 30, 200)
268
+ t = _t(n)
269
+ audio = np.sin(2 * np.pi * freq * t) + 0.5 * np.sin(4 * np.pi * freq * t)
270
+ audio += 0.3 * np.sin(6 * np.pi * freq * t)
271
+ return audio, f"drone at {_freq_str(freq)}", {"freq": freq}
272
+ else:
273
+ freq = _midi_to_freq(_random_midi(rng, 48, 72))
274
+ t = _t(n)
275
+ n_v = int(rng.integers(3, 7))
276
+ audio = np.zeros(n)
277
+ for _ in range(n_v):
278
+ audio += signal.sawtooth(2 * np.pi * freq * (1 + rng.uniform(-0.02, 0.02)) * t)
279
+ audio /= n_v
280
+ return audio, f"pad at {_freq_str(freq)}", {"freq": freq}
281
+
282
+
283
+ # ── Effect helpers ────────────────────────────────────────────────────────────
284
+
285
+ def _reverb_ir(rng, rt60, ir_type="room"):
286
+ n = max(int(rt60 * SR), SR // 10)
287
+ ir = rng.standard_normal(n)
288
+ decay = np.exp(-6.908 * np.arange(n) / n)
289
+ ir *= decay
290
+ if ir_type == "room":
291
+ for _ in range(int(rng.integers(3, 8))):
292
+ pos = int(rng.uniform(0.005, 0.05) * SR)
293
+ if pos < n:
294
+ ir[pos] += rng.uniform(0.3, 0.7) * float(rng.choice([-1, 1]))
295
+ elif ir_type == "plate":
296
+ sos = _safe_butter(2, 500, 'high')
297
+ if sos is not None:
298
+ ir = signal.sosfilt(sos, ir)
299
+ elif ir_type == "spring":
300
+ chirp_f = rng.uniform(50, 200)
301
+ t_ir = np.arange(n) / SR
302
+ ir *= np.sin(2 * np.pi * chirp_f * t_ir * (1 + 0.5 * t_ir))
303
+ elif ir_type == "hall":
304
+ ir += 0.3 * rng.standard_normal(n) * decay ** 0.8
305
+ return _normalize(ir)
306
+
307
+
308
+ def _apply_reverb(audio, ir, wet=0.3):
309
+ reverbed = signal.fftconvolve(audio, ir, mode='full')[:len(audio)]
310
+ peak = np.max(np.abs(reverbed))
311
+ if peak > 1e-10:
312
+ reverbed = reverbed / peak * np.max(np.abs(audio))
313
+ return (1 - wet) * audio + wet * reverbed
314
+
315
+
316
+ def _apply_delay(audio, delay_time, feedback=0.5, wet=0.3, n_echoes=8):
317
+ d = max(int(delay_time * SR), 1)
318
+ out = audio.copy()
319
+ for i in range(1, n_echoes + 1):
320
+ pos = i * d
321
+ if pos >= len(audio):
322
+ break
323
+ gain = feedback ** i
324
+ end = len(audio)
325
+ out[pos:end] += gain * audio[:end - pos]
326
+ peak = np.max(np.abs(out))
327
+ if peak > 1e-10:
328
+ out = out / peak * np.max(np.abs(audio))
329
+ return (1 - wet) * audio + wet * out
330
+
331
+
332
+ def _compress(audio, threshold_db=-10, ratio=4):
333
+ threshold = 10 ** (threshold_db / 20)
334
+ env = np.abs(audio)
335
+ sos = _safe_butter(1, 100, 'low')
336
+ if sos is not None:
337
+ env = np.maximum(signal.sosfilt(sos, env), 1e-10)
338
+ else:
339
+ env = np.maximum(env, 1e-10)
340
+ gain = np.ones_like(env)
341
+ above = env > threshold
342
+ gain[above] = (threshold / env[above]) ** (1 - 1 / ratio)
343
+ return audio * gain
344
+
345
+
346
+ def _chorus(audio, rng):
347
+ n = len(audio)
348
+ rate = rng.uniform(0.5, 3)
349
+ depth = int(rng.uniform(0.002, 0.01) * SR)
350
+ base_delay = int(0.02 * SR)
351
+ t = np.arange(n) / SR
352
+ delay = base_delay + (depth * np.sin(2 * np.pi * rate * t)).astype(int)
353
+ indices = np.clip(np.arange(n) - delay, 0, n - 1)
354
+ return 0.7 * audio + 0.3 * audio[indices]
355
+
356
+
357
+ def _flanger(audio, rng):
358
+ n = len(audio)
359
+ rate = rng.uniform(0.1, 1)
360
+ depth = max(int(rng.uniform(0.001, 0.005) * SR), 1)
361
+ t = np.arange(n) / SR
362
+ delay = (depth * (1 + np.sin(2 * np.pi * rate * t)) / 2).astype(int) + 1
363
+ indices = np.clip(np.arange(n) - delay, 0, n - 1)
364
+ fb = rng.uniform(0.3, 0.7)
365
+ return audio + fb * audio[indices]
366
+
367
+
368
+ def _sidechain_pump(audio, bpm, depth=0.8, curve=3.0):
369
+ beat_samples = max(int(SR * 60 / bpm), 1)
370
+ env = np.power(np.linspace(0, 1, beat_samples), curve)
371
+ env = 1.0 - depth * (1.0 - env)
372
+ full_env = np.tile(env, len(audio) // beat_samples + 1)[:len(audio)]
373
+ return audio * full_env
374
+
375
+
376
+ # ── Drum synthesis helpers ────────────────────────────────────────────────────
377
+
378
+ def _make_kick(rng, n):
379
+ t = _t(n)
380
+ f_start = rng.uniform(150, 300)
381
+ f_end = rng.uniform(30, 60)
382
+ freq_env = f_end + (f_start - f_end) * np.exp(-t * rng.uniform(20, 60))
383
+ phase = np.cumsum(2 * np.pi * freq_env / SR)
384
+ body = np.sin(phase)
385
+ amp_env = np.exp(-t * rng.uniform(3, 10))
386
+ click = np.zeros(n)
387
+ cl = min(int(0.005 * SR), n)
388
+ click[:cl] = rng.uniform(0.3, 0.8) * np.exp(-np.arange(cl) / (0.001 * SR))
389
+ return (body * amp_env + click) * 0.8
390
+
391
+
392
+ def _make_snare(rng, n):
393
+ t = _t(n)
394
+ body = np.sin(2 * np.pi * rng.uniform(150, 250) * t) * np.exp(-t * rng.uniform(15, 30))
395
+ noise = rng.standard_normal(n) * np.exp(-t * rng.uniform(8, 20))
396
+ sos = _safe_butter(4, rng.uniform(2000, 8000), 'high')
397
+ if sos is not None:
398
+ noise = signal.sosfilt(sos, noise)
399
+ return 0.5 * body + 0.5 * noise
400
+
401
+
402
+ def _make_hihat(rng, n):
403
+ t = _t(n)
404
+ noise = rng.standard_normal(n)
405
+ sos = _safe_butter(4, rng.uniform(5000, 12000), 'high')
406
+ if sos is not None:
407
+ noise = signal.sosfilt(sos, noise)
408
+ return noise * np.exp(-t * rng.uniform(20, 80))
train/0001.tar ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:08443b394750312fb9aec72903dd8ad03c7a5a846364d92f0859f26ebd9fe039
3
+ size 2031523840
train/0002.tar ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:367d4e6d6d317974ee90edd00c059f37f14251e201f61f374e0a0bd5f7c48fb9
3
+ size 2406379520
train/0003.tar ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e492f6cdf749939eb7413d44fe8ee9671338207fd0affe6ea86c9d496364000d
3
+ size 1978798080
train/0004.tar ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c0ca1bcf153a98dd8379e90962311789ce78ff6905d662e0000028b108a86eba
3
+ size 2699714560
train/0005.tar ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8d11d42a1c09c08856a80a46686b0be6cf78730f42eef8ec7325896cfca82728
3
+ size 2115788800
train/0006.tar ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d876c2bd66ea1cc2010abdcbcbc03658960b9df4a1b1416b1d0a499917851651
3
+ size 1612390400
train/0007.tar ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:eb7863afc9a062afead73b25b30757fb95182f9226c8dcff40a1418f58d79bac
3
+ size 1182382080
train/0008.tar ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cb68c100a6370ca3dcbe454644af1db66503cb80ba32cf4dae7def53a7ba0792
3
+ size 1241937920
train/0009.tar ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a33e184a9aa2ca8a69e46a4b84584eb7453aba0b57cb4f1aee07b9c5d52080f0
3
+ size 1681203200
train/0010.tar ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e7238d105c145361ef252c35b9d1a9b84138cf2e7919ed919e4fa3b2814ecfe2
3
+ size 1293608960
train/0011.tar ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:49293df979e3b56204f1982ce5a42044c16e62d61fed831aac2399f54da87555
3
+ size 1213030400
train/0012.tar ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f1d480d584a755db6478973af51b6acf8db20fb040046840f1e10ca6729666b7
3
+ size 1625978880
train/0013.tar ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:861307dab7d2dc88c73bf785ee14b5a7d641b6f9fbfc3f0ae3be70629f8586ea
3
+ size 1930004480
train/0014.tar ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:abc16518cb51cdff5bcf76cb7c84e5019b4e7dffc28c661469e766150ef24bea
3
+ size 2228244480
train/0015.tar ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3d08a209f977c38db9c9ad107fad51fdb4ced1f5f77c7592173571334ad9d662
3
+ size 2562600960
train/0016.tar ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e586bed8f3879c5a3b4a09667f3f97b4b43279d5757c3b16e1ee0e272d513caf
3
+ size 2500055040
train/0017.tar ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0f7ec2b94641a443687040971eee10eb625549df563cca98478fb79e6ac7345a
3
+ size 2139074560
train/0018.tar ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1b303bf168b83dde83bf14e032d3460c74eb30e0433764172022e434b5d45196
3
+ size 2052659200
train/0019.tar ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:bb7e168b05ed51cc6189aad8c4dfc49421154d5d4db5c30536b47c39d493a7f3
3
+ size 808386560
train/0020.tar ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3917c59fa822eb6abfe320e953918ea20bad36edb9a9582aa73f42dc36e23a26
3
+ size 1050255360
train/0021.tar ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ef8f7f053973c1b2a714d892035c224d0b2cb934a5fb657456906f5ae48d8eaa
3
+ size 1269288960
train/0022.tar ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9b27d7f8bdd53f909be89729246095275ffc7653d6e3896efa44f0e6eaf1461c
3
+ size 1944053760
train/0023.tar ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7265463ef4084d75c039f8766d82fdb4ce66c3d3f741fa703c28fc5cecdeae78
3
+ size 2260346880
train/0024.tar ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:36ee9f7cdc03fb0a1a949548270b974bc49e0df5ef2ebce0bd937b003b08b578
3
+ size 2318325760
train/0025.tar ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e77853970356afadfe2a8d468ac68d89753c8258a00107848a24089a094cc751
3
+ size 2223923200
train/0026.tar ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:022f4c13c3bf9a3010f37b279e68b799bab28554215b102d14273701153cbcd2
3
+ size 379965440