From: han.lu@intel.com
To: tiwai@suse.de, liam.r.girdwood@linux.intel.com,
bernard.gautier@intel.com, alsa-devel@alsa-project.org
Cc: "Lu, Han" <han.lu@intel.com>
Subject: [PATCH 1/1] alsabat: truncate sample frames for faster FFT analysis
Date: Mon, 29 Feb 2016 10:33:45 +0800 [thread overview]
Message-ID: <1456713225-11173-1-git-send-email-han.lu@intel.com> (raw)
From: "Lu, Han" <han.lu@intel.com>
Truncate the sample frames to powers of 2, since the FFTW algorithm
runs especially fast in this case, and other sizes may be computed
by means of a slow, general-purpose algorithm.
In my test environment applying the patch, a sound clip of 33072
frames is cut off to 32768 frames before analysis, and the time
cost is reduced from 6.128s to 0.224s.
Signed-off-by: Lu, Han <han.lu@intel.com>
diff --git a/bat/analyze.c b/bat/analyze.c
index 60e2d1c..5cfdac3 100644
--- a/bat/analyze.c
+++ b/bat/analyze.c
@@ -256,6 +256,20 @@ static int reorder_data(struct bat *bat)
return 0;
}
+/* truncate sample frames for faster FFT analysis process */
+static int truncate_frames(struct bat *bat)
+{
+ int shift = SHIFT_MAX;
+
+ for (; shift > SHIFT_MIN; shift--)
+ if (bat->frames & (1 << shift)) {
+ bat->frames = 1 << shift;
+ return 0;
+ }
+
+ return -EINVAL;
+}
+
int analyze_capture(struct bat *bat)
{
int err = 0;
@@ -263,6 +277,13 @@ int analyze_capture(struct bat *bat)
int c;
struct analyze a;
+ err = truncate_frames(bat);
+ if (err < 0) {
+ fprintf(bat->err, _("Invalid frame number for analysis: %d\n"),
+ bat->frames);
+ return err;
+ }
+
fprintf(bat->log, _("\nBAT analysis: signal has %d frames at %d Hz,"),
bat->frames, bat->rate);
fprintf(bat->log, _(" %d channels, %d bytes per sample.\n"),
diff --git a/bat/common.h b/bat/common.h
index b8f6670..ff03fc1 100644
--- a/bat/common.h
+++ b/bat/common.h
@@ -68,6 +68,12 @@
#define FOUND_DC (1<<1)
#define FOUND_WRONG_PEAK (1<<0)
+/* Truncate sample frames to (1 << N), for faster FFT analysis process. The
+ * valid range of N is (SHIFT_MIN, SHIFT_MAX). When N increases, the analysis
+ * will be more time-consuming, and the result will be more accurate. */
+#define SHIFT_MAX (sizeof(int) * 8 - 2)
+#define SHIFT_MIN 8
+
struct wav_header {
unsigned int magic; /* 'RIFF' */
unsigned int length; /* file len */
--
2.5.0
next reply other threads:[~2016-02-29 2:32 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-29 2:33 han.lu [this message]
2016-03-01 9:34 ` [PATCH 1/1] alsabat: truncate sample frames for faster FFT analysis Takashi Iwai
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1456713225-11173-1-git-send-email-han.lu@intel.com \
--to=han.lu@intel.com \
--cc=alsa-devel@alsa-project.org \
--cc=bernard.gautier@intel.com \
--cc=liam.r.girdwood@linux.intel.com \
--cc=tiwai@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.