summaryrefslogtreecommitdiff
path: root/tools/tracker_compiler.cc
blob: d12005d57d7b97c64e8f3a956e5084089e4c46de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <iostream>
#include <map>
#include <sstream>
#include <string>
#include <vector>

// Enum to differentiate between sample types
enum SampleType {
  GENERATED,
  ASSET
};

// Convert note name (e.g., "NOTE_C4", "NOTE_A#3", "NOTE_Eb2") to frequency in
// Hz CRITICAL: Now requires "NOTE_" prefix (changed to prevent ASSET_*
// confusion)
static float note_name_to_freq(const std::string& note_name) {
  if (note_name.size() < 7) // "NOTE_" + note + octave minimum
    return 0.0f;

  // Skip "NOTE_" prefix (5 characters) to get to the actual note
  const char* str = note_name.c_str() + 5;
  char note_char = str[0];
  int semitone = 0;

  // Map note name to semitone (C=0, D=2, E=4, F=5, G=7, A=9, B=11)
  switch (note_char) {
  case 'C':
    semitone = 0;
    break;
  case 'D':
    semitone = 2;
    break;
  case 'E':
    semitone = 4;
    break;
  case 'F':
    semitone = 5;
    break;
  case 'G':
    semitone = 7;
    break;
  case 'A':
    semitone = 9;
    break;
  case 'B':
    semitone = 11;
    break;
  default:
    return 0.0f; // Invalid note
  }

  int idx = 1;
  // Check for sharp (#) or flat (b)
  if (str[idx] == '#') {
    semitone++;
    idx++;
  } else if (str[idx] == 'b') {
    semitone--;
    idx++;
  }

  // Parse octave
  int octave = atoi(&str[idx]);

  // A4 = 440 Hz is our reference (A4 = octave 4, semitone 9)
  // Formula: freq = 440 * 2^((semitone - 9 + 12*(octave - 4)) / 12)
  const int midi_note = semitone + 12 * (octave + 1);
  const int a4_midi = 69; // A4 = MIDI note 69
  const float freq = 440.0f * powf(2.0f, (midi_note - a4_midi) / 12.0f);

  return freq;
}

static bool is_note_name(const std::string& name) {
  // CRITICAL FIX: Require "NOTE_" prefix to avoid false positives with ASSET_*
  // Valid: NOTE_E2, NOTE_A4, NOTE_C#3, NOTE_Bb5
  // Invalid: ASSET_KICK_1, E2 (no prefix), etc.
  if (name.size() <
      7) // "NOTE_" + note + octave = minimum 7 chars (e.g. "NOTE_C4")
    return false;
  if (name.substr(0, 5) != "NOTE_")
    return false;
  // Check that the 6th character (after "NOTE_") is a valid note letter A-G
  const char note_letter = name[5];
  return (note_letter >= 'A' && note_letter <= 'G');
}

struct Sample {
  std::string name;
  SampleType type = GENERATED; // Default to GENERATED
  std::string asset_id_name;   // Store AssetId name for asset samples

  // Parameters for generated samples
  float freq, dur, amp, attack, harmonic_decay;
  int harmonics;
};

struct Event {
  float unit_time; // Unit-less time within pattern
  std::string sample_name;
  float volume, pan;
};

struct Pattern {
  std::string name;
  std::vector<Event> events;
  float unit_length; // Pattern duration in units (default 1.0 for 4-beat
                     // patterns)
};

struct Trigger {
  float time;
  std::string pattern_name;
};

// Resource usage analysis for synth configuration
struct ResourceAnalysis {
  int asset_sample_count;
  int generated_sample_count;
  int max_simultaneous_patterns;
  int avg_events_per_pattern;
  int estimated_max_polyphony;
  int min_spectrograms;
  int recommended_spectrograms;
  int recommended_voices;
};

// Analyze resource requirements from tracker data
ResourceAnalysis analyze_resources(const std::vector<Sample>& samples,
                                    const std::vector<Pattern>& patterns,
                                    const std::vector<Trigger>& score) {
  ResourceAnalysis result = {};

  // Count sample types
  for (const auto& s : samples) {
    if (s.type == ASSET) {
      result.asset_sample_count++;
    } else {
      result.generated_sample_count++;
    }
  }

  // Calculate maximum simultaneous pattern triggers
  std::map<float, int> time_pattern_count;
  for (const auto& t : score) {
    time_pattern_count[t.time]++;
  }

  for (const auto& entry : time_pattern_count) {
    if (entry.second > result.max_simultaneous_patterns) {
      result.max_simultaneous_patterns = entry.second;
    }
  }

  // Calculate average events per pattern
  int total_events = 0;
  for (const auto& p : patterns) {
    total_events += p.events.size();
  }
  result.avg_events_per_pattern =
      patterns.empty() ? 0 : total_events / patterns.size();
  result.estimated_max_polyphony =
      result.max_simultaneous_patterns * result.avg_events_per_pattern;

  // Conservative recommendations with 50% safety margin
  result.min_spectrograms = result.asset_sample_count +
                            (result.generated_sample_count *
                             result.estimated_max_polyphony);
  result.recommended_spectrograms = (int)(result.min_spectrograms * 1.5f);
  result.recommended_voices = result.estimated_max_polyphony * 2;

  return result;
}

// Validate and report issues with tracker data
int validate_tracker_data(const std::vector<Sample>& samples,
                          const std::vector<Pattern>& patterns,
                          const std::vector<Trigger>& score, float bpm) {
  int warnings = 0;
  int errors = 0;

  // Validate BPM
  if (bpm <= 0.0f || bpm > 300.0f) {
    fprintf(stderr, "WARNING: Unusual BPM value: %.1f\n", bpm);
    warnings++;
  }

  // Validate samples
  for (const auto& s : samples) {
    if (s.type == GENERATED) {
      if (s.freq <= 0.0f || s.freq > 20000.0f) {
        fprintf(stderr, "ERROR: Sample '%s' invalid frequency: %.1f Hz\n",
                s.name.c_str(), s.freq);
        errors++;
      }
      if (s.dur <= 0.0f || s.dur > 10.0f) {
        fprintf(stderr, "WARNING: Sample '%s' unusual duration: %.2f s\n",
                s.name.c_str(), s.dur);
        warnings++;
      }
    }
  }

  // Validate patterns
  for (const auto& p : patterns) {
    if (p.unit_length <= 0.0f) {
      fprintf(stderr, "ERROR: Pattern '%s' invalid length: %.2f\n",
              p.name.c_str(), p.unit_length);
      errors++;
    }

    // Check event ordering
    for (size_t i = 1; i < p.events.size(); ++i) {
      if (p.events[i].unit_time < p.events[i - 1].unit_time) {
        fprintf(stderr,
                "WARNING: Pattern '%s' has unsorted events: [%zu]=%.3f < "
                "[%zu]=%.3f\n",
                p.name.c_str(), i, p.events[i].unit_time, i - 1,
                p.events[i - 1].unit_time);
        warnings++;
      }
    }

    // Validate event ranges
    for (const auto& e : p.events) {
      if (e.unit_time < 0.0f || e.unit_time > p.unit_length) {
        fprintf(stderr,
                "ERROR: Pattern '%s' event time %.3f outside pattern length "
                "%.2f\n",
                p.name.c_str(), e.unit_time, p.unit_length);
        errors++;
      }
      if (e.volume < 0.0f || e.volume > 2.0f) {
        fprintf(stderr,
                "WARNING: Pattern '%s' unusual volume: %.2f (expected 0.0-2.0)\n",
                p.name.c_str(), e.volume);
        warnings++;
      }
      if (e.pan < -1.0f || e.pan > 1.0f) {
        fprintf(stderr,
                "ERROR: Pattern '%s' invalid pan: %.2f (must be -1.0 to 1.0)\n",
                p.name.c_str(), e.pan);
        errors++;
      }
    }
  }

  return errors;
}

// Write sanitized .track file
void write_sanitized_track(const char* output_path, float bpm,
                           const std::vector<Sample>& samples,
                           std::vector<Pattern>& patterns,
                           const std::vector<Trigger>& score) {
  FILE* out = fopen(output_path, "w");
  if (!out) {
    fprintf(stderr, "Could not open output file: %s\n", output_path);
    return;
  }

  fprintf(out, "# Sanitized tracker file\n");
  fprintf(out, "# Generated by tracker_compiler --sanitize\n\n");

  fprintf(out, "BPM %.1f\n\n", bpm);

  // Write samples
  if (!samples.empty()) {
    fprintf(out, "# Samples (%zu total)\n", samples.size());
    for (const auto& s : samples) {
      fprintf(out, "SAMPLE %s", s.name.c_str());
      if (s.type == GENERATED) {
        fprintf(out, ", %.1f, %.2f, %.1f, %.2f, %d, %.1f", s.freq, s.dur,
                s.amp, s.attack, s.harmonics, s.harmonic_decay);
      }
      fprintf(out, "\n");
    }
    fprintf(out, "\n");
  }

  // Write patterns (sorted events)
  for (auto& p : patterns) {
    // Sort events by time
    std::sort(p.events.begin(), p.events.end(),
              [](const Event& a, const Event& b) {
                return a.unit_time < b.unit_time;
              });

    fprintf(out, "PATTERN %s", p.name.c_str());
    if (p.unit_length != 1.0f) {
      fprintf(out, " LENGTH %.2f", p.unit_length);
    }
    fprintf(out, "\n");

    for (const auto& e : p.events) {
      fprintf(out, "  %.4f, %s, %.1f, %.1f\n", e.unit_time,
              e.sample_name.c_str(), e.volume, e.pan);
    }
    fprintf(out, "\n");
  }

  // Write score
  if (!score.empty()) {
    fprintf(out, "SCORE\n");
    for (const auto& t : score) {
      fprintf(out, "  %.1f, %s\n", t.time, t.pattern_name.c_str());
    }
  }

  fclose(out);
  printf("Sanitized track written to: %s\n", output_path);
}

// Write resource analysis to output file
void write_resource_analysis(FILE* out, const ResourceAnalysis& analysis,
                              int total_samples) {
  fprintf(out, "// ============================================================\n");
  fprintf(out, "// RESOURCE USAGE ANALYSIS (for synth.h configuration)\n");
  fprintf(out, "// ============================================================\n");
  fprintf(out, "// Total samples: %d (%d assets + %d generated notes)\n",
          total_samples, analysis.asset_sample_count,
          analysis.generated_sample_count);
  fprintf(out, "// Max simultaneous pattern triggers: %d\n",
          analysis.max_simultaneous_patterns);
  fprintf(out, "// Estimated max polyphony: %d voices\n",
          analysis.estimated_max_polyphony);
  fprintf(out, "// \n");
  fprintf(out, "// REQUIRED (minimum to avoid pool exhaustion):\n");
  fprintf(out, "//   MAX_VOICES: %d\n", analysis.estimated_max_polyphony);
  fprintf(out, "//   MAX_SPECTROGRAMS: %d (no caching)\n",
          analysis.min_spectrograms);
  fprintf(out, "// \n");
  fprintf(out, "// RECOMMENDED (with 50%% safety margin):\n");
  fprintf(out, "//   MAX_VOICES: %d\n", analysis.recommended_voices);
  fprintf(out, "//   MAX_SPECTROGRAMS: %d (no caching)\n",
          analysis.recommended_spectrograms);
  fprintf(out, "// \n");
  fprintf(out, "// NOTE: With spectrogram caching by note parameters,\n");
  fprintf(out, "//       MAX_SPECTROGRAMS could be reduced to ~%d\n",
          analysis.asset_sample_count + analysis.generated_sample_count);
  fprintf(out, "// ============================================================\n\n");
}

int main(int argc, char** argv) {
  // Parse mode flags
  bool check_mode = false;
  bool sanitize_mode = false;
  const char* input_file = nullptr;
  const char* output_file = nullptr;

  int arg_idx = 1;
  while (arg_idx < argc) {
    if (strcmp(argv[arg_idx], "--check") == 0) {
      check_mode = true;
      arg_idx++;
    } else if (strcmp(argv[arg_idx], "--sanitize") == 0) {
      sanitize_mode = true;
      arg_idx++;
    } else if (!input_file) {
      input_file = argv[arg_idx];
      arg_idx++;
    } else if (!output_file) {
      output_file = argv[arg_idx];
      arg_idx++;
    } else {
      fprintf(stderr, "Unexpected argument: %s\n", argv[arg_idx]);
      return 1;
    }
  }

  // Validate arguments
  if (!input_file) {
    fprintf(stderr, "Usage:\n");
    fprintf(stderr, "  %s <input.track> <output.cc>         # Compile\n",
            argv[0]);
    fprintf(stderr, "  %s --check <input.track>             # Validate only\n",
            argv[0]);
    fprintf(stderr,
            "  %s --sanitize <input.track> <output.track>  # Sanitize\n",
            argv[0]);
    return 1;
  }

  if (!check_mode && !output_file) {
    fprintf(stderr, "Error: Output file required for compile/sanitize mode\n");
    fprintf(stderr, "Use --check for validation only\n");
    return 1;
  }

  if (check_mode && sanitize_mode) {
    fprintf(stderr, "Error: Cannot use --check and --sanitize together\n");
    return 1;
  }

  std::ifstream in(input_file);
  if (!in.is_open()) {
    fprintf(stderr, "Could not open input file: %s\n", input_file);
    return 1;
  }

  float bpm = 120.0f;
  std::vector<Sample> samples;
  std::map<std::string, int> sample_map;
  std::vector<Pattern> patterns;
  std::map<std::string, int> pattern_map;
  std::vector<Trigger> score;

  std::string line;
  std::string current_section = "";

  while (std::getline(in, line)) {
    if (line.empty() || line[0] == '#')
      continue;

    std::stringstream ss(line);
    std::string cmd;
    ss >> cmd;

    // Skip comment lines (including indented comments)
    if (cmd.empty() || cmd[0] == '#')
      continue;

    if (cmd == "BPM") {
      ss >> bpm;
    } else if (cmd == "SAMPLE") {
      Sample s;
      std::string name;
      ss >> name;
      if (name.back() == ',')
        name.pop_back();
      s.name = name;

      if (name.rfind("ASSET_", 0) == 0) {
        s.type = ASSET;
        s.asset_id_name = name;
        // Parameters for asset samples are ignored, so we don't parse them
        // here. However, we must consume the rest of the line to avoid issues
        // if a comma is present.
        std::string dummy;
        while (ss >> dummy) {
        } // Consume rest of line
      } else {
        s.type = GENERATED;
        // Very simple parsing: freq, dur, amp, attack, harmonics,
        // harmonic_decay
        char comma;
        ss >> s.freq >> comma >> s.dur >> comma >> s.amp >> comma >> s.attack >>
            comma >> s.harmonics >> comma >> s.harmonic_decay;
      }

      sample_map[s.name] = samples.size();
      samples.push_back(s);
    } else if (cmd == "PATTERN") {
      Pattern p;
      ss >> p.name;
      p.unit_length = 1.0f; // Default: 1 unit = 4 beats
      // Check for optional LENGTH parameter
      std::string next_token;
      if (ss >> next_token) {
        if (next_token == "LENGTH") {
          ss >> p.unit_length;
        }
      }
      current_section = "PATTERN:" + p.name;
      patterns.push_back(p);
      pattern_map[p.name] = patterns.size() - 1;
    } else if (cmd == "SCORE") {
      current_section = "SCORE";
    } else {
      if (current_section.rfind("PATTERN:", 0) == 0) {
        // Parse event: unit_time, sample, vol, pan
        Event e;
        float unit_time;
        std::stringstream ss2(line);
        ss2 >> unit_time;
        char comma;
        ss2 >> comma;
        std::string sname;
        ss2 >> sname;
        if (sname.back() == ',')
          sname.pop_back();
        e.unit_time = unit_time;
        e.sample_name = sname;
        ss2 >> e.volume >> comma >> e.pan;

        // Auto-create SAMPLE entry for note names (e.g., "E2", "A4")
        if (is_note_name(sname) && sample_map.find(sname) == sample_map.end()) {
          Sample s;
          s.name = sname;
          s.type = GENERATED;
          s.freq = note_name_to_freq(sname);
          s.dur = 0.5f;            // Default note duration
          s.amp = 1.0f;            // Default amplitude
          s.attack = 0.01f;        // Default attack
          s.harmonics = 3;         // Default harmonics
          s.harmonic_decay = 0.6f; // Default decay
          sample_map[s.name] = samples.size();
          samples.push_back(s);
        }

        patterns.back().events.push_back(e);
      } else if (current_section == "SCORE") {
        Trigger t;
        float time;
        std::stringstream ss2(line);
        ss2 >> time;
        char comma;
        ss2 >> comma;
        std::string pname;
        ss2 >> pname;
        t.time = time;
        t.pattern_name = pname;
        score.push_back(t);
      }
    }
  }

  // Validate tracker data
  int errors = validate_tracker_data(samples, patterns, score, bpm);
  if (errors > 0) {
    fprintf(stderr, "\nValidation failed with %d errors\n", errors);
    if (check_mode) {
      return 1;
    }
    // Continue compilation with warnings
  }

  // Handle different modes
  if (check_mode) {
    printf("Validation passed for: %s\n", input_file);
    printf("  Patterns: %zu\n", patterns.size());
    printf("  Score triggers: %zu\n", score.size());
    printf("  Samples: %zu\n", samples.size());
    return 0;
  }

  if (sanitize_mode) {
    write_sanitized_track(output_file, bpm, samples, patterns, score);
    return 0;
  }

  // Normal compilation mode
  FILE* out_file = fopen(output_file, "w");
  if (!out_file) {
    fprintf(stderr, "Could not open output file: %s\n", output_file);
    return 1;
  }
  fprintf(out_file, "// Generated by tracker_compiler. Do not edit.\n\n");
  fprintf(out_file, "#include \"audio/tracker.h\"\n\n");
  // Need to include assets.h for AssetId enum
  fprintf(out_file, "#include \"generated/assets.h\"\n\n");

  fprintf(out_file, "const NoteParams g_tracker_samples[] = {\n");
  for (const auto& s : samples) {
    if (s.type == GENERATED) {
      fprintf(out_file,
              "    { %.1ff, %.2ff, %.1ff, %.2ff, 0.0f, 0.0f, 0.0f, %d, %.1ff, "
              "0.0f, 0.0f }, // %s\n",
              s.freq, s.dur, s.amp, s.attack, s.harmonics, s.harmonic_decay,
              s.name.c_str());
    } else {
      fprintf(out_file, "    { 0 }, // %s (ASSET)\n", s.name.c_str());
    }
  }
  fprintf(out_file, "};\n");
  fprintf(out_file, "const uint32_t g_tracker_samples_count = %zu;\n\n",
          samples.size());

  fprintf(out_file, "const AssetId g_tracker_sample_assets[] = {\n");
  for (const auto& s : samples) {
    if (s.type == ASSET) {
      fprintf(out_file, "  AssetId::%s,\n", s.asset_id_name.c_str());
    } else {
      fprintf(out_file, "  AssetId::ASSET_LAST_ID,\n");
    }
  }
  fprintf(out_file, "};\n\n");

  // Sort pattern events by time (required by runtime early-exit optimization)
  for (auto& p : patterns) {
    std::sort(p.events.begin(), p.events.end(),
              [](const Event& a, const Event& b) {
                return a.unit_time < b.unit_time;
              });
  }

  for (const auto& p : patterns) {
    fprintf(out_file, "static const TrackerEvent PATTERN_EVENTS_%s[] = {\n",
            p.name.c_str());
    for (const auto& e : p.events) {
      // When referencing a sample, we need to get its index or synth_id.
      // If it's an asset, the name starts with ASSET_.
      // For now, assume sample_map is used for both generated and asset
      // samples. This will need refinement if asset samples are not in
      // sample_map directly.
      fprintf(out_file, "    { %.2ff, %d, %.1ff, %.1ff },\n", e.unit_time,
              sample_map[e.sample_name], e.volume, e.pan);
    }
    fprintf(out_file, "};\n");
  }
  fprintf(out_file, "\n");

  fprintf(out_file, "const TrackerPattern g_tracker_patterns[] = {\n");
  for (const auto& p : patterns) {
    fprintf(out_file, "    { PATTERN_EVENTS_%s, %zu, %.2ff }, // %s\n",
            p.name.c_str(), p.events.size(), p.unit_length, p.name.c_str());
  }
  fprintf(out_file, "};\n");
  fprintf(out_file, "const uint32_t g_tracker_patterns_count = %zu;\n\n",
          patterns.size());

  fprintf(out_file,
          "static const TrackerPatternTrigger SCORE_TRIGGERS[] = {\n");
  for (const auto& t : score) {
    fprintf(out_file, "    { %.1ff, %d },\n", t.time,
            pattern_map[t.pattern_name]);
  }
  fprintf(out_file, "};\n\n");

  fprintf(out_file, "const TrackerScore g_tracker_score = {\n");
  fprintf(out_file, "    SCORE_TRIGGERS, %zu, %.1ff\n", score.size(), bpm);
  fprintf(out_file, "};\n\n");

  // Analyze resource requirements
  ResourceAnalysis analysis = analyze_resources(samples, patterns, score);

  // Write analysis to output file
  write_resource_analysis(out_file, analysis, samples.size());

  fclose(out_file);

  // Print compilation summary
  printf("Tracker compilation successful.\n");
  printf("  Patterns: %zu\n", patterns.size());
  printf("  Score triggers: %zu\n", score.size());
  printf("  Samples: %d (%d assets + %d generated)\n", (int)samples.size(),
         analysis.asset_sample_count, analysis.generated_sample_count);
  printf("  Max simultaneous patterns: %d\n",
         analysis.max_simultaneous_patterns);
  printf("  Estimated max polyphony: %d voices\n",
         analysis.estimated_max_polyphony);
  printf("\n");
  printf("RESOURCE REQUIREMENTS:\n");
  printf("  Required MAX_VOICES: %d\n", analysis.estimated_max_polyphony);
  printf("  Required MAX_SPECTROGRAMS: %d (without caching)\n",
         analysis.min_spectrograms);
  printf("  Recommended MAX_VOICES: %d (with safety margin)\n",
         analysis.recommended_voices);
  printf("  Recommended MAX_SPECTROGRAMS: %d (with safety margin)\n",
         analysis.recommended_spectrograms);
  printf("  With caching: MAX_SPECTROGRAMS could be ~%d\n",
         analysis.asset_sample_count + analysis.generated_sample_count);

  return 0;
}