From 9a1b51ca63beb1d524035c5b5fa3477f86fb247f Mon Sep 17 00:00:00 2001 From: Tommaso Cucinotta Date: Fri, 19 Feb 2021 10:24:01 +0100 Subject: [PATCH] compilation patch (Ubuntu 20.10) --- Makefile | 8 +++++--- include/capture.h | 4 ++-- include/gui.h | 12 ++++++------ include/playback.h | 5 ++--- include/task.h | 14 +++++++------- src/capture.c | 5 ++++- src/gui.c | 11 ++++++++++- src/playback.c | 3 +++ src/task.c | 23 ++++++++++++++++++++++- 9 files changed, 61 insertions(+), 24 deletions(-) diff --git a/Makefile b/Makefile index 796fd70..11b7abb 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,9 @@ SRCS := $(wildcard $(SRC_DIR)/*.c) OBJS := $(patsubst $(SRC_DIR)/%.c, $(OBJ_DIR)/%.o, $(SRCS)) .PHONY: all -all: $(OBJS) +all: $(MAIN) + +$(MAIN): $(OBJS) $(CC) -o $(MAIN) $? $(CFLAGS_1) $(LIBS) @@ -23,5 +25,5 @@ $(OBJS): $(OBJ_DIR)/%.o: $(SRC_DIR)/%.c $(INCLUDES) $(CC) -c -o $@ $< $(LIBS) $(CFLAGS_1) clean: - rm bin/main - rm lib/*.o + rm -f bin/main + rm -f lib/*.o diff --git a/include/capture.h b/include/capture.h index e8b442b..b19d293 100644 --- a/include/capture.h +++ b/include/capture.h @@ -16,8 +16,8 @@ typedef struct { unsigned channels; } capHW; -capHW hw; -int err; +extern capHW hw; +extern int err; void loadCapSettings(const char name[], const unsigned sr, const unsigned c); diff --git a/include/gui.h b/include/gui.h index ee14e7c..80cbf7a 100644 --- a/include/gui.h +++ b/include/gui.h @@ -9,13 +9,13 @@ #include // Windows -WINDOW *selectorContainer; -WINDOW *selector; +extern WINDOW *selectorContainer; +extern WINDOW *selector; // Geometrical features -int LEN_CONTAINER, POSX_CONTAINER; -int LEN_SELECTOR, POSX0_SELECTOR, POSX1_SELECTOR, POSX2_SELECTOR; -int POSX_STEREO, POSX_FRONT, POSX_SURROUND; +extern int LEN_CONTAINER, POSX_CONTAINER; +extern int LEN_SELECTOR, POSX0_SELECTOR, POSX1_SELECTOR, POSX2_SELECTOR; +extern int POSX_STEREO, POSX_FRONT, POSX_SURROUND; void initGui(char const *dev_names[]); // init interface void refreshGui(); // updates screen @@ -23,4 +23,4 @@ void killGui(); // deallocate used memory void toogleSelectorGui(unsigned char t); -#endif \ No newline at end of file +#endif diff --git a/include/playback.h b/include/playback.h index 0bc3e09..a5dd1ed 100644 --- a/include/playback.h +++ b/include/playback.h @@ -17,8 +17,7 @@ typedef struct { long unsigned frames; } PlaybackHW; -PlaybackHW hwpb; -int err; +extern PlaybackHW hwpb; void loadPBSettings(const char name[], const unsigned sr, const unsigned c, const unsigned f); snd_pcm_t * playbackSetup(); @@ -36,4 +35,4 @@ do { \ } \ } while (0) -#endif \ No newline at end of file +#endif diff --git a/include/task.h b/include/task.h index 67ab263..90e1f0e 100644 --- a/include/task.h +++ b/include/task.h @@ -13,15 +13,15 @@ #include // Alsa handlers -snd_pcm_t *cHandle; // capture handler -snd_pcm_t *pbHandle; // playback handler +extern snd_pcm_t *cHandle; // capture handler +extern snd_pcm_t *pbHandle; // playback handler // Variables -short bufRead[CHANNELS * M]; // buffer for capturing -short bufWrite[CHANNELS * M]; // buffer for playback -int readData, writeData; // number of samples captured +extern short bufRead[CHANNELS * M]; // buffer for capturing +extern short bufWrite[CHANNELS * M]; // buffer for playback +extern int readData, writeData; // number of samples captured -struct BufferSem inBufferSem, outBufferSem; // to synch tasks +extern struct BufferSem inBufferSem, outBufferSem; // to synch tasks extern unsigned short exitLoop; extern unsigned char toggle; @@ -35,4 +35,4 @@ void *captureThread(void *arg); void *playbackThread(void *arg); -#endif \ No newline at end of file +#endif diff --git a/src/capture.c b/src/capture.c index ceb2fe0..d2033fe 100644 --- a/src/capture.c +++ b/src/capture.c @@ -8,6 +8,9 @@ #include "capture.h" +capHW hw; +int err; + void loadCapSettings(const char name[], const unsigned sr, const unsigned c){ strcpy(hw.name, name); hw.samplerate = sr; @@ -95,4 +98,4 @@ int capture(snd_pcm_t *h, short *b, const size_t f) { count -= res; return res; -} \ No newline at end of file +} diff --git a/src/gui.c b/src/gui.c index 27439ca..e38d6f0 100644 --- a/src/gui.c +++ b/src/gui.c @@ -8,6 +8,15 @@ #include +// Windows +WINDOW *selectorContainer; +WINDOW *selector; + +// Geometrical features +int LEN_CONTAINER, POSX_CONTAINER; +int LEN_SELECTOR, POSX0_SELECTOR, POSX1_SELECTOR, POSX2_SELECTOR; +int POSX_STEREO, POSX_FRONT, POSX_SURROUND; + void computeGeometricalParams(){ // Geometry for Container LEN_CONTAINER = COLS / 3; @@ -106,4 +115,4 @@ void toogleSelectorGui(unsigned char t) { void killGui() { endwin(); -} \ No newline at end of file +} diff --git a/src/playback.c b/src/playback.c index 7f816db..936b53b 100644 --- a/src/playback.c +++ b/src/playback.c @@ -8,6 +8,8 @@ #include #include "playback.h" +PlaybackHW hwpb; + void loadPBSettings(const char name[], const unsigned sr, const unsigned c, const unsigned f) { strcpy(hwpb.name, name); hwpb.samplerate = sr; @@ -18,6 +20,7 @@ void loadPBSettings(const char name[], const unsigned sr, const unsigned c, cons snd_pcm_t * playbackSetup() { snd_pcm_hw_params_t *hw_params; static snd_pcm_t *pb_handle; + int err; if ((err = snd_pcm_open(&pb_handle, hwpb.name, SND_PCM_STREAM_PLAYBACK, 0)) < 0) { fprintf(stderr, "[ERROR:] cannot open audio device %s (%s)\n", hwpb.name, snd_strerror(err)); diff --git a/src/task.c b/src/task.c index bae76a7..d112e32 100644 --- a/src/task.c +++ b/src/task.c @@ -16,11 +16,24 @@ #include // #include +// Alsa handlers +snd_pcm_t *cHandle; // capture handler +snd_pcm_t *pbHandle; // playback handler + +// Variables +short bufRead[CHANNELS * M]; // buffer for capturing +short bufWrite[CHANNELS * M]; // buffer for playback +int readData, writeData; // number of samples captured + +struct BufferSem inBufferSem, outBufferSem; // to synch tasks + unsigned short exitLoop = 0; +/* #ifdef MEASURE_LATENCY struct Latency m_latency; #endif +*/ //struct timeval start, end; void initAlsa(const char *dev_name[], const unsigned fq, const unsigned c, const unsigned f) { @@ -105,9 +118,11 @@ void *captureThread(void *arg) { while (1) { sem_wait(&inBufferSem.priv_w); + /* #ifdef MEASURE_LATENCY gettimeofday(&m_latency.start, NULL); #endif + */ readData = capture(cHandle, bufRead, M); inBuffer_post_write(&inBufferSem); @@ -121,9 +136,11 @@ void *captureThread(void *arg) { void *playbackThread(void *arg) { + /* #ifdef MEASURE_LATENCY initLatencyBuffer(&m_latency); #endif + */ outBuffer_post_read(&outBufferSem); @@ -132,17 +149,21 @@ void *playbackThread(void *arg) { sem_wait(outBufferSem.priv_r); playback(pbHandle, bufWrite, writeData); + /* #ifdef MEASURE_LATENCY gettimeofday(&m_latency.end, NULL); #endif + */ outBuffer_post_read(&outBufferSem); + /* #ifdef MEASURE_LATENCY computeLatency(&m_latency); logLatency(&m_latency, (float)m_latency.micros/writeData); #endif - + */ + if (exitLoop) break; } pthread_exit(NULL);