diff options
Diffstat (limited to 'src/audio')
| -rw-r--r-- | src/audio/dct.h | 4 | ||||
| -rw-r--r-- | src/audio/fft.cc | 6 | ||||
| -rw-r--r-- | src/audio/mp3_sample.cc | 5 | ||||
| -rw-r--r-- | src/audio/mp3_sample.h | 2 | ||||
| -rw-r--r-- | src/audio/ola.h | 3 | ||||
| -rw-r--r-- | src/audio/synth.cc | 3 | ||||
| -rw-r--r-- | src/audio/synth.h | 4 | ||||
| -rw-r--r-- | src/audio/tracker.cc | 16 |
8 files changed, 24 insertions, 19 deletions
diff --git a/src/audio/dct.h b/src/audio/dct.h index ca423c2..a44bb15 100644 --- a/src/audio/dct.h +++ b/src/audio/dct.h @@ -4,9 +4,9 @@ #pragma once -#define DCT_SIZE 512 +#define DCT_SIZE 512 #define OLA_HOP_SIZE 256 -#define OLA_OVERLAP 256 +#define OLA_OVERLAP 256 // Forward declarations void fdct_512(const float* input, float* output); diff --git a/src/audio/fft.cc b/src/audio/fft.cc index 6029454..ddd442e 100644 --- a/src/audio/fft.cc +++ b/src/audio/fft.cc @@ -143,7 +143,8 @@ void dct_fft(const float* input, float* output, size_t N) { // IMDCT via FFT // Produces 2N time-domain samples from N MDCT coefficients. // Formula: x[n] = (2/N) * sum_{k=0}^{N-1} X[k] * cos(pi*(2n+1+N)*(2k+1)/(2N)) -// When windowed (Hann, length 2N) and OLA'd with hop N, gives perfect reconstruction. +// When windowed (Hann, length 2N) and OLA'd with hop N, gives perfect +// reconstruction. void imdct_fft(const float* input, float* output, size_t N) { const float PI = 3.14159265358979323846f; const size_t M = 2 * N; // output length @@ -172,7 +173,8 @@ void imdct_fft(const float* input, float* output, size_t N) { imag[i] *= scale; } - // Post-multiply by 2N * exp(-j*pi*(2n+1)/(4N)) and take real part, scale by 2/N + // Post-multiply by 2N * exp(-j*pi*(2n+1)/(4N)) and take real part, scale by + // 2/N const float gain = 2.0f; for (size_t n = 0; n < M; n++) { const float angle = -PI * (2.0f * n + 1.0f) / (4.0f * N); diff --git a/src/audio/mp3_sample.cc b/src/audio/mp3_sample.cc index 028fbff..9a3805b 100644 --- a/src/audio/mp3_sample.cc +++ b/src/audio/mp3_sample.cc @@ -45,9 +45,10 @@ int mp3_decode(Mp3Decoder* dec, int num_frames, float* out) { } void mp3_close(Mp3Decoder* dec) { - if (!dec) return; + if (!dec) + return; ma_decoder_uninit(&dec->dec); delete dec; } -#endif // !STRIP_ALL +#endif // !STRIP_ALL diff --git a/src/audio/mp3_sample.h b/src/audio/mp3_sample.h index e7e759e..bf3147a 100644 --- a/src/audio/mp3_sample.h +++ b/src/audio/mp3_sample.h @@ -31,4 +31,4 @@ int mp3_decode(Mp3Decoder* dec, int num_frames, float* out); // Release the decoder. void mp3_close(Mp3Decoder* dec); -#endif // !STRIP_ALL +#endif // !STRIP_ALL diff --git a/src/audio/ola.h b/src/audio/ola.h index 3dbc368..2d6267e 100644 --- a/src/audio/ola.h +++ b/src/audio/ola.h @@ -7,8 +7,7 @@ // Returns number of OLA frames for n_samples PCM input. static inline int ola_num_frames(int n_samples) { - return (n_samples > DCT_SIZE) ? (n_samples - DCT_SIZE) / OLA_HOP_SIZE + 1 - : 1; + return (n_samples > DCT_SIZE) ? (n_samples - DCT_SIZE) / OLA_HOP_SIZE + 1 : 1; } // Hann-windowed FDCT with 50% overlap (analysis). diff --git a/src/audio/synth.cc b/src/audio/synth.cc index 3212e0b..0866bda 100644 --- a/src/audio/synth.cc +++ b/src/audio/synth.cc @@ -204,7 +204,8 @@ void synth_trigger_voice(int spectrogram_id, float volume, float pan, g_synth_data.spectrograms[spectrogram_id].num_frames; v.ola_mode = (g_synth_data.spectrograms[spectrogram_id].version == SPEC_VERSION_V2_OLA); - v.buffer_pos = v.ola_mode ? OLA_HOP_SIZE : DCT_SIZE; // Force reload on first render + v.buffer_pos = + v.ola_mode ? OLA_HOP_SIZE : DCT_SIZE; // Force reload on first render if (v.ola_mode) memset(v.overlap_buf, 0, sizeof(v.overlap_buf)); v.fractional_pos = diff --git a/src/audio/synth.h b/src/audio/synth.h index 61ecfd0..e5a8197 100644 --- a/src/audio/synth.h +++ b/src/audio/synth.h @@ -21,8 +21,8 @@ #define MAX_SPECTROGRAMS \ 32 // Current track: 14 unique, 32 provides comfortable headroom -#define SPEC_VERSION_V1 1 -#define SPEC_VERSION_V2_OLA 2 +#define SPEC_VERSION_V1 1 +#define SPEC_VERSION_V2_OLA 2 struct Spectrogram { const float* spectral_data_a; // Front buffer diff --git a/src/audio/tracker.cc b/src/audio/tracker.cc index 7ce96fc..93c279e 100644 --- a/src/audio/tracker.cc +++ b/src/audio/tracker.cc @@ -12,7 +12,7 @@ #include "audio/dct.h" #include "audio/mp3_sample.h" #include "audio/window.h" -#endif // !defined(STRIP_ALL) +#endif // !defined(STRIP_ALL) static uint32_t g_last_trigger_idx = 0; @@ -44,7 +44,6 @@ static bool g_cache_initialized = false; // Forward declarations static int get_free_pool_slot(); - #if !defined(STRIP_ALL) // Decode an in-memory MP3 blob to a heap-allocated spectrogram (caller owns). // Uses OLA analysis: 512-sample Hann window, OLA_HOP_SIZE advance per frame. @@ -53,7 +52,8 @@ static float* convert_mp3_to_spectrogram(const uint8_t* data, size_t size, int* out_num_frames) { *out_num_frames = 0; Mp3Decoder* dec = mp3_open(data, size); - if (!dec) return nullptr; + if (!dec) + return nullptr; float window[DCT_SIZE]; hann_window_512(window); @@ -82,11 +82,13 @@ static float* convert_mp3_to_spectrogram(const uint8_t* data, size_t size, fdct_512(pcm_chunk, dct_chunk); spec_data.insert(spec_data.end(), dct_chunk, dct_chunk + DCT_SIZE); - if (decoded == 0) break; + if (decoded == 0) + break; } mp3_close(dec); - if (spec_data.empty()) return nullptr; + if (spec_data.empty()) + return nullptr; const int num_frames = (int)(spec_data.size() / DCT_SIZE); float* result = new float[spec_data.size()]; @@ -94,7 +96,7 @@ static float* convert_mp3_to_spectrogram(const uint8_t* data, size_t size, *out_num_frames = num_frames; return result; } -#endif // !defined(STRIP_ALL) +#endif // !defined(STRIP_ALL) void tracker_init() { g_last_trigger_idx = 0; @@ -159,7 +161,7 @@ void tracker_init() { FATAL_CHECK(data == nullptr || GetAssetType(aid) != AssetType::MP3, "MP3 assets not supported in STRIP_ALL builds\n"); #endif - if (data && size >= sizeof(SpecHeader)) { + if (data && size >= sizeof(SpecHeader)) { const SpecHeader* header = (const SpecHeader*)data; const int note_frames = header->num_frames; const float* spectral_data = |
