// This file is part of the 64k demo project. // It defines the public interface and data structures for the synth. // Supports spectrogram registration, voice triggering, and real-time rendering. #pragma once #include "dct.h" #include #define MAX_VOICES 48 // Per tracker_compiler: required=24, recommended=48 #define MAX_SPECTROGRAMS \ 32 // Current track: 14 unique, 32 provides comfortable headroom #define SPEC_VERSION_V1 1 #define SPEC_VERSION_V2_OLA 2 struct Spectrogram { const float* spectral_data_a; // Front buffer const float* spectral_data_b; // Back buffer (for double-buffering) int num_frames; int version; // SPEC_VERSION_V1 or SPEC_VERSION_V2_OLA }; void synth_init(); void synth_shutdown(); // Register a spectrogram for playback. Returns an ID or -1. int synth_register_spectrogram(const Spectrogram* spec); void synth_unregister_spectrogram(int spectrogram_id); // Double-buffering API for thread-safe updates float* synth_begin_update(int spectrogram_id); void synth_commit_update(int spectrogram_id); void synth_trigger_voice(int spectrogram_id, float volume, float pan, int start_offset_samples = 0); void synth_render(float* output_buffer, int num_frames); void synth_set_tempo_scale( float tempo_scale); // Set playback speed (1.0 = normal) float synth_get_tempo_scale(); int synth_get_active_voice_count(); // Get peak amplitude of synthesized audio (measured at ring buffer write time) // NOTE: For audio-visual synchronization, use audio_get_realtime_peak() instead // This function measures peak ~400ms ahead of playback (at synth_render time) float synth_get_output_peak();