spek

Acoustic spectrum analyser
git clone http://git.hanabi.in/repos/spek.git
Log | Files | Refs | README

commit 2e8355ee84a298472c081759f5503832af432fa2
parent 4e186744ad2c4d8f595e662885c6705c0a8f672f
Author: Alexander Kojevnikov <alexander@kojevnikov.com>
Date:   Sat,  3 Jul 2010 22:43:40 +1000

Apply Hamming window function

Diffstat:
Msrc/spek-pipeline.vala | 9++++++---
Msrc/spek-spectrogram.vala | 4++--
2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/src/spek-pipeline.vala b/src/spek-pipeline.vala @@ -39,8 +39,8 @@ namespace Spek { private uint8[] buffer; private Fft.Plan fft; private int nfft; - float[] input; - float[] output; + private float[] input; + private float[] output; public Pipeline (string file_name, int bands, int samples, int threshold, Callback cb) { this.cx = new Audio.Context (file_name); @@ -113,7 +113,10 @@ namespace Spek { acc_error < cx.error_base && frames == cx.frames_per_interval || acc_error >= cx.error_base && frames == 1 + cx.frames_per_interval) { for (int i = 0; i < nfft; i++) { - fft.input[i] = input[(pos + i) % nfft]; + double val = input[(pos + i) % nfft]; + // Hamming window. + val *= 0.53836 - 0.46164 * Math.cos (2.0 * Math.PI * i / nfft); + fft.input[i] = (float) val; } fft.execute (); num_fft++; diff --git a/src/spek-spectrogram.vala b/src/spek-spectrogram.vala @@ -27,7 +27,7 @@ namespace Spek { public string file_name { get; private set; } private Pipeline pipeline; private string info; - private const int THRESHOLD = -86; + private const int THRESHOLD = -92; private const int NFFT = 2048; private const int BANDS = NFFT / 2 + 1; @@ -103,7 +103,7 @@ namespace Spek { } private void data_cb (int sample, float[] values) { - for (int y = 0; y < values.length; y++) { + for (int y = 0; y < BANDS; y++) { var level = double.min ( 1.0, Math.log10 (1.0 - THRESHOLD + values[y]) / Math.log10 (-THRESHOLD)); put_pixel (image, sample, y, get_color (level));