wider range

master
Ondřej Hruška 9 years ago
parent bd7f65abdb
commit fdf067159d
  1. 2
      Makefile
  2. 2
      project/hw_init.c
  3. 83
      project/main.c

@ -113,7 +113,7 @@ LIB_CFLAGS = -Wno-shadow -Wno-float-equal -Wno-inline -Wno-unused-parameter -W
############################################################################### ###############################################################################
# Linker flags # Linker flags
LDFLAGS += --static -lm -lc -nostartfiles -specs=nano.specs LDFLAGS += --static -lm -lc -nostartfiles
LDFLAGS += -Llib LDFLAGS += -Llib
LDFLAGS += -T$(LDSCRIPT) LDFLAGS += -T$(LDSCRIPT)
LDFLAGS += -Wl,-Map=$(*).map LDFLAGS += -Wl,-Map=$(*).map

@ -62,7 +62,7 @@ static void conf_subsystems(void)
timebase_init(15, 15); timebase_init(15, 15);
// event and task queues // event and task queues
queues_init(15, 15); queues_init(30, 30);
// initialize SBMP for ESP8266 // initialize SBMP for ESP8266
dlnk_init(); dlnk_init();

@ -20,11 +20,17 @@
#include "arm_math.h" #include "arm_math.h"
static volatile bool capture_pending = false;
static volatile bool print_next_fft = false;
static volatile bool capturing_silence = false;
static float virt_zero_value = 2045.0f;
static void poll_subsystems(void); static void poll_subsystems(void);
static DotMatrix_Cfg *dmtx; static DotMatrix_Cfg *dmtx;
#define SAMP_BUF_LEN 128 #define SAMP_BUF_LEN 256
union samp_buf_union { union samp_buf_union {
uint32_t uints[SAMP_BUF_LEN]; uint32_t uints[SAMP_BUF_LEN];
@ -44,8 +50,30 @@ void audio_capture_done(void* unused)
float *bins = samp_buf.floats; float *bins = samp_buf.floats;
// Convert to floats
for (int i = 0; i < samp_count; i++) {
samp_buf.floats[i] = (float)samp_buf.uints[i];
}
if (capturing_silence) {
float mean;
arm_mean_f32(samp_buf.floats, samp_count, &mean);
virt_zero_value = mean;
info("New zero level = %f", virt_zero_value);
capturing_silence = false;
}
for (int i = 0; i < samp_count; i++) {
samp_buf.floats[i] -= virt_zero_value;
}
if (print_next_fft) {
printf("--- Raw (adjusted) ---\n");
for(int i = 0; i < samp_count; i++) { for(int i = 0; i < samp_count; i++) {
samp_buf.floats[i] = samp_buf.uints[i] - 2045.0f; printf("%.2f, ", samp_buf.floats[i]);
}
printf("\n");
} }
for (int i = samp_count - 1; i >= 0; i--) { for (int i = samp_count - 1; i >= 0; i--) {
@ -54,11 +82,19 @@ void audio_capture_done(void* unused)
} }
const arm_cfft_instance_f32 *S; const arm_cfft_instance_f32 *S;
S = &arm_cfft_sR_f32_len64; S = &arm_cfft_sR_f32_len128;
arm_cfft_f32(S, bins, 0, true); // bit reversed FFT arm_cfft_f32(S, bins, 0, true); // bit reversed FFT
arm_cmplx_mag_f32(bins, bins, bin_count); // get magnitude (extract real values) arm_cmplx_mag_f32(bins, bins, bin_count); // get magnitude (extract real values)
if (print_next_fft) {
printf("--- Bins ---\n");
for(int i = 0; i < bin_count; i++) {
printf("%.2f, ", bins[i]);
}
printf("\n");
}
// normalize // normalize
dmtx_clear(dmtx); dmtx_clear(dmtx);
float factor = (1.0f/bin_count)*0.1f; float factor = (1.0f/bin_count)*0.1f;
@ -66,7 +102,8 @@ void audio_capture_done(void* unused)
bins[i] *= factor; bins[i] *= factor;
bins[i+1] *= factor; bins[i+1] *= factor;
float avg = i==0 ? bins[1] : (bins[i] + bins[i+1])/2; //float avg = i==0 ? bins[1] : (bins[i] + bins[i+1])/2;
float avg = (bins[i] + bins[i+1])/2;
for(int j = 0; j < ceilf(avg); j++) { for(int j = 0; j < ceilf(avg); j++) {
dmtx_set(dmtx, i/2, j, true); dmtx_set(dmtx, i/2, j, true);
@ -74,25 +111,55 @@ void audio_capture_done(void* unused)
} }
dmtx_show(dmtx); dmtx_show(dmtx);
print_next_fft = false;
capture_pending = false;
} }
static void capture_audio(void *unused) static void capture_audio(void *unused)
{ {
(void)unused; (void)unused;
if (capture_pending) return;
capture_pending = true;
start_adc_dma(samp_buf.uints, SAMP_BUF_LEN/2); start_adc_dma(samp_buf.uints, SAMP_BUF_LEN/2);
} }
static void rx_char(ComIface *iface)
{
uint8_t ch;
while(com_rx(iface, &ch)) {
if (ch == 'p') {
info("PRINT_NEXT");
print_next_fft = true;
}
if (ch == 's') {
info("SILENCE");
capturing_silence = true;
}
}
}
static task_pid_t capture_task_id;
int main(void) int main(void)
{ {
hw_init(); hw_init();
capturing_silence = true; // capture silence at start
banner("*** LED MATRIX DEMO ***"); banner("*** LED MATRIX DEMO ***");
banner_info("(c) Ondrej Hruska, 2016"); banner_info("(c) Ondrej Hruska, 2016");
banner_info("Katedra mereni K338, CVUT FEL"); banner_info("Katedra mereni K338, CVUT FEL");
debug_iface->rx_callback = rx_char;
DotMatrix_Init dmtx_cfg; DotMatrix_Init dmtx_cfg;
dmtx_cfg.CS_GPIOx = GPIOA; dmtx_cfg.CS_GPIOx = GPIOA;
dmtx_cfg.CS_PINx = GPIO_Pin_4; dmtx_cfg.CS_PINx = GPIO_Pin_4;
@ -104,7 +171,13 @@ int main(void)
dmtx_intensity(dmtx, 7); dmtx_intensity(dmtx, 7);
add_periodic_task(capture_audio, NULL, 10, false); for(int i = 0; i < 16; i++) {
dmtx_set(dmtx, i, 0, 1);
dmtx_show(dmtx);
delay_ms(25);
}
capture_task_id = add_periodic_task(capture_audio, NULL, 10, false);
ms_time_t last; ms_time_t last;
while (1) { while (1) {

Loading…
Cancel
Save