aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniil Cherednik <dan.cherednik@gmail.com>2018-11-04 01:19:48 +0300
committerDaniil Cherednik <dan.cherednik@gmail.com>2018-11-04 01:19:48 +0300
commit5b176978c464b4d60ccd8b4d576eb31e3039f9a8 (patch)
tree17ed62357e735ff46e477b816537daef962e5b7c
parentd8502a297b556cb06bf59bd00b2524931a8f034a (diff)
downloadlibgha-5b176978c464b4d60ccd8b4d576eb31e3039f9a8.tar.gz
Simple method to extract K sinusoids for one call
-rw-r--r--include/libgha.h25
-rw-r--r--src/gha.c8
-rw-r--r--test/dtmf.c3
3 files changed, 32 insertions, 4 deletions
diff --git a/include/libgha.h b/include/libgha.h
index 31639ac..10c5625 100644
--- a/include/libgha.h
+++ b/include/libgha.h
@@ -28,13 +28,34 @@ void gha_free_ctx(gha_ctx_t ctx);
/*
* Performs one GHA step for given PCM signal,
- * the result will be writen in to given gha_ingo structure
+ * the result will be writen in to given gha_info structure
+ *
+ * Complexity: O(n * log(n)),
+ * where n is number of samples to anayze
*/
void gha_analyze_one(const FLOAT* pcm, struct gha_info* info, gha_ctx_t ctx);
/*
- * Performs one GHA step and extract analysed harmonic from given PCM signal
+ * Performs one GHA step and extracts analysed harmonic from given PCM signal
+ * the result will be writen in to given gha_info structure
+ *
+ * Complexity: O(n * log(n)),
+ * where n is number of samples to anayze
*/
void gha_extract_one(FLOAT* pcm, struct gha_info* info, gha_ctx_t ctx);
+/*
+ * Performs k GHA steps and extracts analysed harmonics from given PCM signal.
+ *
+ * The result will be writen in to given gha_info structures
+ * corresponding ammount of memory should be allocated (k * sizeof(struct gha_info))
+ *
+ * Effectively this function is equivalent of calling gha_extract_one k times
+ *
+ * Complexity: O(n * log(n) * K),
+ * where n is number of samples to anayze, k is number of harmonics to extract
+ *
+ */
+void gha_extract_many_simple(FLOAT* pcm, struct gha_info* info, size_t k, gha_ctx_t ctx);
+
#endif
diff --git a/src/gha.c b/src/gha.c
index 39812ea..7e4fd16 100644
--- a/src/gha.c
+++ b/src/gha.c
@@ -213,3 +213,11 @@ void gha_extract_one(FLOAT* pcm, struct gha_info* info, gha_ctx_t ctx)
for (i = 0; i < ctx->size; i++)
pcm[i] -= ctx->tmp_buf[i] * magnitude;
}
+
+void gha_extract_many_simple(FLOAT* pcm, struct gha_info* info, size_t k, gha_ctx_t ctx)
+{
+ int i;
+ for (i = 0; i < k; i++) {
+ gha_extract_one(pcm, info + i, ctx);
+ }
+}
diff --git a/test/dtmf.c b/test/dtmf.c
index 54fcb6d..a2146be 100644
--- a/test/dtmf.c
+++ b/test/dtmf.c
@@ -41,8 +41,7 @@ int main(int argc, char** argv) {
}
struct gha_info res[2];
- gha_extract_one(buf, &res[0], ctx);
- gha_extract_one(buf, &res[1], ctx);
+ gha_extract_many_simple(buf, &res[0], 2, ctx);
if (res[0].frequency > res[1].frequency) {
struct gha_info tmp;