-
Notifications
You must be signed in to change notification settings - Fork 7
Acoustic event detector #46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 5 commits
2ff0dfe
bbac57a
f16db9f
a9a1e76
ed2315e
df0b123
972b5c2
8bfec1e
a6bba78
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# makefile for user application | ||
|
||
# the current directory | ||
APP_DIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST)))) | ||
|
||
# files needed for this code | ||
C_SRCS := $(wildcard *.c) | ||
INCLUDE_PATHS += . ./kiss_fft ./kiss_fft/tools ./log2fix/ | ||
|
||
CFLAGS += -DFIXED_POINT=16 -std=c99 | ||
CFLAGS += -Wno-type-limits -Wno-sign-compare | ||
|
||
TOCK_BOARD = audio_module | ||
|
||
# include makefile settings that are shared between applications | ||
include ../../AppMakefile.mk | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Fixed-point ridge tracker for acoustic event detection in C | ||
|
||
|
||
## Quick start | ||
``` | ||
make clean | ||
make | ||
./main input.wav | ||
``` | ||
Use test.ipynb to visualize the resulting \*.mat files | ||
|
||
## Prerequisites | ||
* Fixed-point FFT: git clone https://github.com/longle2718/kiss_fft | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If these dependecies are vendored (which I believe you've done) I don't think they need to be listed as prerequisites. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree. However, once we have a hierarchical directory structure, we won't be copying the sources and just leave them as prerequisites. Thanks! |
||
* Fixed-point log: git clone https://github.com/dmoulding/log2fix | ||
* libsndfile: sudo apt-get install libsndfile1-dev |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#ifndef __COMMON_H__ | ||
#define __COMMON_H__ | ||
|
||
#include "_kiss_fft_guts.h" | ||
|
||
#define BUF_LEN (512) | ||
#define INC_LEN (BUF_LEN/2) | ||
#define FRE_LEN (BUF_LEN/2) | ||
|
||
#define S_SQ(a) S_MUL((a),(a)) // scalar square | ||
#define S_DIV(a,b) S_MUL((a),SAMP_MAX/(b)) // a < b | ||
#define MAX(a,b) (((a) > (b)) ? (a) : (b)) | ||
#define MIN(a,b) (((a) < (b)) ? (a) : (b)) | ||
#define ABS(a) (((a) < 0) ? -(a): (a)) | ||
// Magnitude Estimator | ||
// http://dspguru.com/book/export/html/62 | ||
#define ALPHA ((kiss_fft_scalar)(0.947543636291*SAMP_MAX)) | ||
#define BETA ((kiss_fft_scalar)(0.392485425092*SAMP_MAX)) | ||
#define MAG(r,i) ( S_MUL(ALPHA,MAX(ABS((r)),ABS((i)))) + S_MUL(BETA,MIN(ABS((r)),ABS((i)))) ) | ||
|
||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include "dynArray.h" | ||
#include "_kiss_fft_guts.h" | ||
|
||
void initArray(Array *a, size_t initialSize) { | ||
a->maxSize = initialSize; | ||
a->used = 0; | ||
|
||
a->size = a->maxSize; | ||
printf("Init array size = %zu\n",a->size); | ||
|
||
a->SNR = malloc(a->size * sizeof(kiss_fft_scalar)); | ||
a->FI = malloc(a->size * sizeof(size_t)); | ||
a->TI = malloc(a->size * sizeof(size_t)); | ||
} | ||
|
||
void insertArray(Array *a, kiss_fft_scalar snr, size_t fi, size_t ti) { | ||
// a->used is the number of used entries, because a->array[a->used++] updates a->used only *after* the array has been accessed. | ||
// Therefore a->used can go up to a->size | ||
if (a->size > 0 && a->used == a->size) { | ||
a->maxSize *= 2; | ||
printf("Doubled array max size to %zu\n",a->maxSize); | ||
} | ||
if (a->size < a->maxSize) { | ||
a->size = a->maxSize; | ||
// with NULL ptr, realloc == malloc | ||
a->SNR = realloc(a->SNR, a->size * sizeof(kiss_fft_scalar)); | ||
a->FI = realloc(a->FI, a->size * sizeof(size_t)); | ||
a->TI = realloc(a->TI, a->size * sizeof(size_t)); | ||
} | ||
a->SNR[a->used] = snr; | ||
a->FI[a->used] = fi; | ||
a->TI[a->used] = ti; | ||
a->used++; | ||
} | ||
|
||
void freeArray(Array *a) { | ||
free(a->SNR); | ||
free(a->FI); | ||
free(a->TI); | ||
a->SNR = NULL; | ||
a->FI = NULL; | ||
a->TI = NULL; | ||
a->used = a->size = 0; | ||
} | ||
size_t getMaxDurArray(Array a){ | ||
if (a.used == 0) | ||
return 0; | ||
|
||
size_t minTI = a.TI[0]; | ||
size_t maxTI = a.TI[a.used-1]; | ||
return maxTI-minTI; | ||
} | ||
|
||
kiss_fft_scalar getAvgSNRArray(Array a){ | ||
if (a.used == 0) | ||
return 0; | ||
|
||
SAMPPROD sum = 0; | ||
for (size_t k=0; k < a.used; k++){ | ||
sum += a.SNR[k]; | ||
} | ||
return (kiss_fft_scalar)(sum/a.used); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#ifndef __DYNARRAY_H__ | ||
#define __DYNARRAY_H__ | ||
|
||
#include "kiss_fft.h" | ||
|
||
typedef struct { | ||
kiss_fft_scalar *SNR; // log SNR | ||
size_t *FI; // frequency index | ||
size_t *TI; // time index | ||
size_t size; | ||
size_t used; | ||
size_t maxSize; | ||
} Array; | ||
|
||
void initArray(Array *a, size_t initialSize); | ||
void insertArray(Array *a, kiss_fft_scalar snr, size_t fi, size_t ti); | ||
void freeArray(Array *a); | ||
|
||
size_t getMaxDurArray(Array a); | ||
kiss_fft_scalar getAvgSNRArray(Array a); | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the Makefile variable you want to adjust if you want to have a non-flat hierarchy. I believe something like this would include all C files in all subdirectories work:
You could also be more explicit if you only want to include certain subdirectories or files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Amit,
Thank you so much for your help! I tried
but still get
Namely, the Makefile still looks under the
build/
but didn't copy the source files into it?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ugh... yes you are right... the problem is that there is no
lib2fix
subdirectory in thebuild/cortex-m4
directory and our Makefile rule assumes there is (and GCC won't just create one). If you create one after the build fails the first time, it will be able to move past it, but that's not solution.@ppannuto please halp! You are the resident dependency file expert!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a quick follow-up on this motivated by today's phone call. This should be largely fixed by the updates to the Tock build system. I updated signpost a few days ago in the
tock-master
branch, but we're holding off on merging that until after the paper deadline. I'll follow up again on April 11 :)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Pat,
Thanks for the follow-up. And no worries at all, I understand the burden of a paper deadline. We'll get this working soon.
In the meantime, godspeed to your paper!