summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gbeat.c40
-rw-r--r--gbeat.glade27
2 files changed, 53 insertions, 14 deletions
diff --git a/gbeat.c b/gbeat.c
index ff5fb8e..8fedf2c 100644
--- a/gbeat.c
+++ b/gbeat.c
@@ -103,12 +103,13 @@ static gboolean errbox(gpointer data)
#define NBANDS 32
#define EVALBANDS 32
#define FPS 60
-#define HISTSIZE FPS * 7
+#define HISTSIZE (FPS * 3) / 4
struct bdctx {
double bandenergy[EVALBANDS][HISTSIZE];
// double boffs[EVALBANDS];
double goffs;
+ bool beats[EVALBANDS];
};
struct renderargs {
@@ -117,7 +118,7 @@ struct renderargs {
};
size_t bd_nbands, bd_bandlim;
-double bd_charge, bd_decay;
+double bd_charge, bd_decay, bd_cthres;
static void logscale(fftw_complex *in, size_t isz, fftw_complex *out, size_t osz)
{
@@ -144,8 +145,8 @@ static void logscale(fftw_complex *in, size_t isz, fftw_complex *out, size_t osz
}
for (size_t o = 0; o < osz; o++) {
double d = divs[o];
- out[o][0] /= d;
- out[o][1] /= d;
+ out[o][0] /= d * 6.0;
+ out[o][1] /= d * 6.0;
}
}
@@ -167,8 +168,11 @@ static bool bd_perform(struct bdctx *ctx, fftw_complex *data, size_t size)
average += ctx->bandenergy[i][j];
average /= HISTSIZE;
- if (energy > average * 1.5 * (1.0 + ctx->goffs))
+ if (energy > average * bd_cthres * (1.0 + ctx->goffs)) {
beatbands++;
+ ctx->beats[i] = true;
+ } else
+ ctx->beats[i] = false;
memmove(&ctx->bandenergy[i][0], &ctx->bandenergy[i][1],
(HISTSIZE - 1) * sizeof(double));
@@ -239,9 +243,22 @@ static gpointer renderf(gpointer param)
pow(pos[0][0], 2.0) +
pow(pos[0][1], 2.0));
pos++;
- col = complex2color(c, 4.0);
- if (beat)
- col = colorinv(col);
+
+ if (c[0] > 1.0) {
+ col.red = 65535;
+ col.green = 65535 * (2.0 - (c[0] > 2.0 ? 0.0 : c[0]));
+ } else {
+ if (beat) {
+ col.red = 49152;
+ col.green = 49152 + 16383 * c[0];
+ } else {
+ col.red = 0;
+ col.green = 65535 * c[0];
+ }
+ }
+ col.blue =
+ arg->bdctx.beats[(pos - logsc) / (logsz / EVALBANDS)] ?
+ (beat ? 65535 : 32768) : 0;
gdk_gc_set_rgb_fg_color(gc, &col);
gdk_draw_point(drawto, gc, w - 1, y);
@@ -264,11 +281,13 @@ void on_bdapply(GtkWidget *widget, gpointer user_data)
{
gladewidget(bdnbands);
gladewidget(bdbandlim);
+ gladewidget(bdcthres);
gladewidget(bdcharge);
gladewidget(bddecay);
const gchar *nbands = gtk_entry_get_text(GTK_ENTRY(bdnbands));
const gchar *bandlim = gtk_entry_get_text(GTK_ENTRY(bdbandlim));
+ const gchar *cthres = gtk_entry_get_text(GTK_ENTRY(bdcthres));
const gchar *charge = gtk_entry_get_text(GTK_ENTRY(bdcharge));
const gchar *decay = gtk_entry_get_text(GTK_ENTRY(bddecay));
@@ -276,6 +295,7 @@ void on_bdapply(GtkWidget *widget, gpointer user_data)
bd_bandlim = strtoul(bandlim, NULL, 10);
if (bd_bandlim > EVALBANDS)
bd_bandlim = EVALBANDS;
+ bd_cthres = strtod(cthres, NULL);
bd_charge = strtod(charge, NULL);
bd_decay = strtod(decay, NULL);
}
@@ -332,7 +352,7 @@ void on_run_toggled(GtkWidget *widget, gpointer user_data)
if (!dev)
return;
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(brun))) {
- struct fft_runner *fftr = fftrun_attach(dev, window_hard, 6);
+ struct fft_runner *fftr = fftrun_attach(dev, window_hann, 5);
struct renderargs *arg = calloc(sizeof(*arg), 1);
arg->fftr = fftr;
g_thread_create(renderf, arg, 0, &error);
@@ -360,7 +380,7 @@ int main(int argc, char **argv)
//gtk_image_set_from_pixbuf(GTK_IMAGE(img), pxb);
//img_buffer = gdk_image_new(GDK_IMAGE_FASTEST, gdk_visual_get_system(), 300, 740);
//gtk_image_set_from_image(GTK_IMAGE(img), img_buffer, NULL);
- pxm = gdk_pixmap_new(NULL, 300, 720, 24);
+ pxm = gdk_pixmap_new(NULL, 300, 400, 24);
gtk_image_set_from_pixmap(GTK_IMAGE(img), pxm, NULL);
}
on_bdapply(NULL, NULL);
diff --git a/gbeat.glade b/gbeat.glade
index ac0cc39..c43794b 100644
--- a/gbeat.glade
+++ b/gbeat.glade
@@ -207,7 +207,7 @@
<property name="editable">True</property>
<property name="visibility">True</property>
<property name="max_length">0</property>
- <property name="text" translatable="yes">3</property>
+ <property name="text" translatable="yes">6</property>
<property name="has_frame">True</property>
<property name="activates_default">False</property>
<property name="width_chars">7</property>
@@ -226,7 +226,26 @@
<property name="editable">True</property>
<property name="visibility">True</property>
<property name="max_length">0</property>
- <property name="text" translatable="yes">12</property>
+ <property name="text" translatable="yes">32</property>
+ <property name="has_frame">True</property>
+ <property name="activates_default">False</property>
+ <property name="width_chars">7</property>
+ </widget>
+ <packing>
+ <property name="padding">0</property>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ </packing>
+ </child>
+
+ <child>
+ <widget class="GtkEntry" id="bdcthres">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="editable">True</property>
+ <property name="visibility">True</property>
+ <property name="max_length">0</property>
+ <property name="text" translatable="yes">2.0</property>
<property name="has_frame">True</property>
<property name="activates_default">False</property>
<property name="width_chars">7</property>
@@ -245,7 +264,7 @@
<property name="editable">True</property>
<property name="visibility">True</property>
<property name="max_length">0</property>
- <property name="text" translatable="yes">1.4</property>
+ <property name="text" translatable="yes">3.0</property>
<property name="has_frame">True</property>
<property name="activates_default">False</property>
<property name="width_chars">7</property>
@@ -264,7 +283,7 @@
<property name="editable">True</property>
<property name="visibility">True</property>
<property name="max_length">0</property>
- <property name="text" translatable="yes">0.6</property>
+ <property name="text" translatable="yes">0.82</property>
<property name="has_frame">True</property>
<property name="activates_default">False</property>
<property name="width_chars">7</property>