made analyzer initialization nicer

This commit is contained in:
Ahmet Inan 2015-01-10 10:13:26 +01:00
parent cb489f426d
commit 968fea3bed
2 changed files with 13 additions and 13 deletions

View file

@ -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;

View file

@ -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
}
}