diff options
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/tracker_compiler.cc | 97 |
1 files changed, 77 insertions, 20 deletions
diff --git a/tools/tracker_compiler.cc b/tools/tracker_compiler.cc index 5669cf9..81d7913 100644 --- a/tools/tracker_compiler.cc +++ b/tools/tracker_compiler.cc @@ -13,13 +13,14 @@ enum SampleType { ASSET }; -// Convert note name (e.g., "C4", "A#3", "Eb2") to frequency in Hz +// 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.empty()) + if (note_name.size() < 7) // "NOTE_" + note + octave minimum return 0.0f; - // Parse note (C, C#, D, etc.) and octave - const char* str = note_name.c_str(); + // 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; @@ -73,10 +74,16 @@ static float note_name_to_freq(const std::string& note_name) { } static bool is_note_name(const std::string& name) { - if (name.empty()) + // 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; - const char first = name[0]; - return (first >= 'A' && first <= 'G'); + 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 { @@ -295,7 +302,22 @@ int main(int argc, char** argv) { fprintf(out_file, " SCORE_TRIGGERS, %zu, %.1ff\n", score.size(), bpm); fprintf(out_file, "};\n\n"); - // Calculate maximum simultaneous patterns for optimal resource allocation + // ============================================================================ + // RESOURCE USAGE ANALYSIS + // ============================================================================ + + // Count unique samples + int asset_sample_count = 0; + int generated_sample_count = 0; + for (const auto& s : samples) { + if (s.type == ASSET) { + asset_sample_count++; + } else { + 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]++; @@ -308,27 +330,62 @@ int main(int argc, char** argv) { } } - // Add safety margin (2x) for overlapping pattern playback - const int recommended_voices = max_simultaneous_patterns * 2; - const int recommended_spectrograms = max_simultaneous_patterns * 2; + // Calculate maximum polyphony (events per pattern on average) + int total_events = 0; + for (const auto& p : patterns) { + total_events += p.events.size(); + } + const int avg_events_per_pattern = patterns.empty() ? 0 : total_events / patterns.size(); + const int estimated_max_polyphony = max_simultaneous_patterns * avg_events_per_pattern; + + // Conservative recommendations with safety margins + // - Each asset sample needs 1 spectrogram slot (shared across all events) + // - Each generated note needs 1 spectrogram slot PER EVENT (no caching yet) + // - Add 50% safety margin for peak moments + const int min_spectrograms = asset_sample_count + (generated_sample_count * estimated_max_polyphony); + const int recommended_spectrograms = (int)(min_spectrograms * 1.5f); + const int recommended_voices = estimated_max_polyphony * 2; - fprintf(out_file, "// Resource usage analysis:\n"); - fprintf(out_file, "// Maximum simultaneous pattern triggers: %d\n", + fprintf(out_file, "// ============================================================\n"); + fprintf(out_file, "// RESOURCE USAGE ANALYSIS (for synth.h configuration)\n"); + fprintf(out_file, "// ============================================================\n"); + fprintf(out_file, "// Total samples: %d (%d assets + %d generated notes)\n", + (int)samples.size(), asset_sample_count, generated_sample_count); + fprintf(out_file, "// Max simultaneous pattern triggers: %d\n", max_simultaneous_patterns); - fprintf(out_file, "// Recommended MAX_VOICES: %d (current: see synth.h)\n", - recommended_voices); - fprintf(out_file, - "// Recommended MAX_SPECTROGRAMS: %d (current: see synth.h)\n", - recommended_spectrograms); + fprintf(out_file, "// Estimated max polyphony: %d voices\n", + estimated_max_polyphony); + fprintf(out_file, "// \n"); + fprintf(out_file, "// REQUIRED (minimum to avoid pool exhaustion):\n"); + fprintf(out_file, "// MAX_VOICES: %d\n", estimated_max_polyphony); + fprintf(out_file, "// MAX_SPECTROGRAMS: %d (no caching)\n", min_spectrograms); + fprintf(out_file, "// \n"); + fprintf(out_file, "// RECOMMENDED (with 50%% safety margin):\n"); + fprintf(out_file, "// MAX_VOICES: %d\n", recommended_voices); + fprintf(out_file, "// MAX_SPECTROGRAMS: %d (no caching)\n", recommended_spectrograms); + fprintf(out_file, "// \n"); + fprintf(out_file, "// NOTE: With spectrogram caching by note parameters,\n"); + fprintf(out_file, "// MAX_SPECTROGRAMS could be reduced to ~%d\n", + asset_sample_count + generated_sample_count); + fprintf(out_file, "// ============================================================\n\n"); fclose(out_file); 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(), asset_sample_count, generated_sample_count); printf(" Max simultaneous patterns: %d\n", max_simultaneous_patterns); - printf(" Recommended MAX_VOICES: %d\n", recommended_voices); - printf(" Recommended MAX_SPECTROGRAMS: %d\n", recommended_spectrograms); + printf(" Estimated max polyphony: %d voices\n", estimated_max_polyphony); + printf("\n"); + printf("RESOURCE REQUIREMENTS:\n"); + printf(" Required MAX_VOICES: %d\n", estimated_max_polyphony); + printf(" Required MAX_SPECTROGRAMS: %d (without caching)\n", min_spectrograms); + printf(" Recommended MAX_VOICES: %d (with safety margin)\n", recommended_voices); + printf(" Recommended MAX_SPECTROGRAMS: %d (with safety margin)\n", recommended_spectrograms); + printf(" With caching: MAX_SPECTROGRAMS could be ~%d\n", + asset_sample_count + generated_sample_count); return 0; } |
