Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions software/apps/audio_module/event_detector/Makefile
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)
Copy link
Contributor

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:

C_SRCS := $(wildcard *.c)
C_SRCS += $(wildcard **/*.c)

You could also be more explicit if you only want to include certain subdirectories or files.

Copy link
Author

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

C_SRCS   := $(wildcard *.c)
C_SRCS   := $(wildcard **/log2fix.c)

but still get

DEP        log2fix/log2fix.c
<built-in>: fatal error: opening dependency file /mnt/c/Users/Long/Projects/signpost/software/apps/audio_module/event_detector/build/cortex-m4/log2fix/log2fix.d: No such file or directory
compilation terminated.

Namely, the Makefile still looks under the build/ but didn't copy the source files into it?

Copy link
Contributor

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 the build/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!

Copy link
Member

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 :)

Copy link
Author

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!

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

14 changes: 14 additions & 0 deletions software/apps/audio_module/event_detector/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Fixed-point ridge tracker for acoustic event detection in C
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this README is just copied from the original repo, and maybe with proper modifications to the Makefile, that's just a submodule or something. However, I think it would be good to have a signpost-port-specific README that

  1. explains a bit more about what the app actually does (e.g. "Detects acoustic events", what "acoustic events" are, etc),

  2. and gives instructions relevant to Signpost (e.g. you can't run main with arguments on Signposts).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your guess is correct! I've updated the README according to your suggestion. Thank you.


## 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
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Author

Choose a reason for hiding this comment

The 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
21 changes: 21 additions & 0 deletions software/apps/audio_module/event_detector/common.h
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
64 changes: 64 additions & 0 deletions software/apps/audio_module/event_detector/dynArray.c
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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a debug message? Perhaps better for library code to do this in a DEBUG_PRINTF macro that can be turned off at compiled time? (As opposed to printfs from the actual application code, like in main.c)

Copy link
Author

@longle2718 longle2718 Mar 12, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much for telling me about DEBUG_PRINTF! This will be fixed in the next pull request.

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);
}
21 changes: 21 additions & 0 deletions software/apps/audio_module/event_detector/dynArray.h
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
Loading