Created
May 14, 2018 19:17
-
-
Save JayKickliter/4f325f0bd46f2089c305d5759f28a02c to your computer and use it in GitHub Desktop.
fosphor command-line app to read complex i16 samples from stdin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/fosphor/Makefile b/lib/fosphor/Makefile | |
index a8fb3bb..07af0e6 100644 | |
--- a/lib/fosphor/Makefile | |
+++ b/lib/fosphor/Makefile | |
@@ -1,6 +1,6 @@ | |
UNAME=$(shell uname) | |
CC=gcc | |
-CFLAGS=-Wall -Werror -O2 `pkg-config freetype2 glfw3 --cflags` -g | |
+CFLAGS=-Wall -O2 `pkg-config freetype2 glfw3 --cflags` -g | |
LDLIBS=`pkg-config freetype2 glfw3 --libs` -lm | |
ifneq ($(AMDAPPSDKROOT), ) | |
CFLAGS+=-I$(AMDAPPSDKROOT)/include | |
diff --git a/lib/fosphor/main.c b/lib/fosphor/main.c | |
index efb5413..db43bbf 100644 | |
--- a/lib/fosphor/main.c | |
+++ b/lib/fosphor/main.c | |
@@ -26,6 +26,7 @@ struct app_state | |
struct fosphor_render render_zoom; | |
FILE *src_fh; | |
+ void *raw_buf; | |
void *src_buf; | |
int w, h; | |
@@ -162,13 +163,13 @@ glfw_render(GLFWwindow *wnd) | |
/* Process some samples */ | |
for (c=0; c<BATCH_COUNT; c++) { | |
- r = sizeof(float) * 2 * FOSPHOR_FFT_LEN * BATCH_LEN; | |
+ r = sizeof(uint16_t) * 2 * FOSPHOR_FFT_LEN * BATCH_LEN; | |
o = 0; | |
while (r) { | |
int rc; | |
- rc = fread((char*)g_as->src_buf + o, 1, r, g_as->src_fh); | |
+ rc = fread((char*)g_as->raw_buf + o, 1, r, g_as->src_fh); | |
if (rc <= 0) { | |
if (fseek(g_as->src_fh, 0, SEEK_SET)) | |
abort(); | |
@@ -178,6 +179,9 @@ glfw_render(GLFWwindow *wnd) | |
r -= rc; | |
o += rc; | |
} | |
+ for (int i = 0; i < 2 * FOSPHOR_FFT_LEN * BATCH_LEN; ++i) { | |
+ ((float *)g_as->src_buf)[i] = (float)((int16_t *)g_as->raw_buf)[i] * (1.0/INT16_MAX); | |
+ } | |
fosphor_process(g_as->fosphor, g_as->src_buf, FOSPHOR_FFT_LEN * BATCH_LEN); | |
} | |
@@ -396,7 +400,13 @@ int main(int argc, char *argv[]) | |
return -EINVAL;; | |
} | |
- g_as->src_buf = malloc(2 * sizeof(float) * FOSPHOR_FFT_LEN * FOSPHOR_FFT_MAX_BATCH); | |
+ g_as->raw_buf = malloc(2 * sizeof(uint16_t) * FOSPHOR_FFT_LEN * FOSPHOR_FFT_MAX_BATCH); | |
+ if (!g_as->raw_buf) { | |
+ rv = -ENOMEM; | |
+ goto error; | |
+ } | |
+ | |
+ g_as->src_buf = malloc(2 * sizeof(float) * FOSPHOR_FFT_LEN * FOSPHOR_FFT_MAX_BATCH); | |
if (!g_as->src_buf) { | |
rv = -ENOMEM; | |
goto error; | |
@@ -453,6 +463,7 @@ error: | |
glfw_cleanup(wnd); | |
free(g_as->src_buf); | |
+ free(g_as->raw_buf); | |
fclose(g_as->src_fh); | |
return rv; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment