From 6fd48f28154d60d402743795028b5aa6d316a0db Mon Sep 17 00:00:00 2001 From: Ahmet Inan Date: Tue, 13 Jan 2015 20:26:27 +0100 Subject: [PATCH] do rms compression again .. removed analyzer normalization it makes the spectrum visualization less colorful, but a lot clearer. --- app/src/main/rs/decoder.rs | 5 +++-- app/src/main/rs/stft.rsh | 7 ++----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/app/src/main/rs/decoder.rs b/app/src/main/rs/decoder.rs index 77b8593..79222ac 100644 --- a/app/src/main/rs/decoder.rs +++ b/app/src/main/rs/decoder.rs @@ -212,12 +212,13 @@ void decode(int samples) { *saved_height = 0; for (int sample = 0; sample < samples; ++sample, ++buffer_pos) { int amp = audio_buffer[sample]; - float avg_amp = filter(&avg_amplitude, abs(amp)); + float avg_rms = filter(&avg_amplitude, amp * amp); + float avg_amp = sqrt(2.0f * avg_rms); if (avg_amp < 16.0f) continue; float norm_amp = amp / avg_amp; - spectrum_analyzer(amp); + spectrum_analyzer(127.0f * norm_amp); complex_t cnt_baseband = convert(&cnt_ddc, norm_amp); complex_t dat_baseband = convert(&dat_ddc, norm_amp); diff --git a/app/src/main/rs/stft.rsh b/app/src/main/rs/stft.rsh index ed32bd1..80388d4 100644 --- a/app/src/main/rs/stft.rsh +++ b/app/src/main/rs/stft.rsh @@ -76,7 +76,7 @@ static void spectrum_analyzer(int amplitude) #endif buffer[n] = amplitude; - if (!((++n)%(radix2_N))) { + if (!(++n&(radix2_N-1))) { n &= stft_N - 1; for (int i = 0; i < stft_N; ++i) input[i&(radix2_N-1)] += complex(stft_w[i] * buffer[(i+n)&(stft_N-1)], 0.0f); @@ -84,15 +84,12 @@ static void spectrum_analyzer(int amplitude) radix2(output, input, radix2_N, 1, 0); for (int i = 0; i < radix2_N; ++i) input[i] = 0.0f; - float maximum = 0.0f; - for (int i = 0; i < radix2_N; ++i) - maximum = max(maximum, cabs(output[i])); for (int j = spectrum_height - 1; 0 < j; --j) for (int i = 0; i < spectrum_width; ++i) spectrum_buffer[spectrum_width * j + i] = spectrum_buffer[spectrum_width * (j-1) + i]; for (int i = 0; i < spectrum_width; ++i) { int b = (i * (radix2_N / 2)) / spectrum_width; - float power = clamp(pown(cabs(output[b]) / maximum, 2), 0.0f, 1.0f); + float power = clamp(pown(cabs(output[b]) / 127.0f, 2), 0.0f, 1.0f); float dB = 10.0f * log10(max(0.000001f, power)); float v = clamp((60.0f + dB) / 60.0f, 0.0f, 1.0f); spectrum_buffer[i] = rainbow(v);