From 968fea3bed34378f017d78d4ccdb00c105af4bd5 Mon Sep 17 00:00:00 2001 From: Ahmet Inan Date: Sat, 10 Jan 2015 10:13:26 +0100 Subject: [PATCH] made analyzer initialization nicer --- app/src/main/rs/initialization.rsh | 6 ++---- app/src/main/rs/stft.rsh | 20 +++++++++++--------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/app/src/main/rs/initialization.rsh b/app/src/main/rs/initialization.rsh index 937c5f5..2aa90aa 100644 --- a/app/src/main/rs/initialization.rsh +++ b/app/src/main/rs/initialization.rsh @@ -20,6 +20,7 @@ limitations under the License. #include "constants.rsh" #include "state.rsh" #include "modes.rsh" +#include "stft.rsh" void initialize(float rate, int length, int iw, int ih, int sw, int sh) { @@ -28,14 +29,11 @@ void initialize(float rate, int length, int iw, int ih, int sw, int sh) buffer_mask = length - 1; maximum_width = iw; maximum_height = ih; - spectrum_width = sw; - spectrum_height = sh; for (int i = 0; i < iw * ih; ++i) pixel_buffer[i] = 0; - for (int i = 0; i < sw * sh; ++i) - spectrum_buffer[i] = 0; + init_analyzer(sw, sh); automatic_mode_detection = 1; debug_mode = 0; diff --git a/app/src/main/rs/stft.rsh b/app/src/main/rs/stft.rsh index 6cd500b..a71f1b0 100644 --- a/app/src/main/rs/stft.rsh +++ b/app/src/main/rs/stft.rsh @@ -35,10 +35,17 @@ static inline uchar4 rainbow(float v) static void freq_marker(int freq) { - for (int j = 0; j < spectrum_height; ++j) { - int i = (radix2_N * freq + sample_rate / 2) / sample_rate; - spectrum_buffer[spectrum_width * j + i] = rgb(255, 255, 255); - } + int i = (radix2_N * freq + sample_rate / 2) / sample_rate; + spectrum_buffer[i] = rgb(255, 255, 255); +} + +static void init_analyzer(int sw, int sh) +{ + spectrum_width = sw; + spectrum_height = sh; + for (int j = 0; j < spectrum_height; ++j) + for (int i = 0; i < spectrum_width; ++i) + spectrum_buffer[spectrum_width * j + i] = rainbow((float)i / spectrum_width); } static void spectrum_analyzer(int amplitude) @@ -92,11 +99,6 @@ static void spectrum_analyzer(int amplitude) freq_marker(1300 * M); freq_marker(1500 * M); freq_marker(2300 * M); -#if 0 - for (int j = spectrum_height / 2; j < spectrum_height; ++j) - for (int i = 0; i < spectrum_width; ++i) - spectrum_buffer[spectrum_width * j + i] = rainbow((float)i / spectrum_width); -#endif } }