diff --git a/Makefile b/Makefile index dc37661..37ec369 100644 --- a/Makefile +++ b/Makefile @@ -30,6 +30,9 @@ all: options ${ALL} bench: all ${BENCH} @echo LD ${BENCH} ${MID} -o $@ @${CC} ${ALL_CFLAGS} ${BENCH} -o $@ ${ALL_LDFLAGS} -rdynamic -ldl + +.PHONY: benchmark +benchmark: bench ./benchtime ./bench ${AGAINST} .PHONY: options diff --git a/README.md b/README.md index 060ce8f..608e718 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ white noise generator. loud, full-range, 0dBFS. don't say i didn't warn you. ## build notes -`make` it. optional `bench` benchmarking target, doesn't build on Windows. +`make` it. optional `benchmark` target which doesn't build on Windows. if you're using gcc, try `CFLAGS='-O3 -ffast-math'`. `-march=native` actually seems to degrade performance slightly, but YMMV. diff --git a/bench.c b/bench.c index e1eff39..bcc94ff 100644 --- a/bench.c +++ b/bench.c @@ -1,4 +1,5 @@ #include +#include #include #include @@ -10,13 +11,14 @@ enum { BLOCK_SIZE=2048 }; -float inputs[BLOCK_SIZE]; -float outputs[BLOCK_SIZE]; void *plug = NULL; +static float *audio_buffer; +static int audio_count = 0; static void cleanup() { dlclose(plug); + if (audio_count) free(audio_buffer); } static const LADSPA_Descriptor* @@ -43,12 +45,21 @@ main(int argc, char **argv) { LADSPA_Handle h = d->instantiate(d, 44100); assert(h); - d->connect_port(h, 0, inputs); - d->connect_port(h, 1, outputs); + // we're lazy so we don't distinguish inputs and outputs + for (int i = 0; i < d->PortCount; i++) + if (LADSPA_IS_PORT_AUDIO(d->PortDescriptors[i])) + audio_count++; + + audio_buffer = calloc(audio_count*BLOCK_SIZE, sizeof(float)); + + int a = 0; + for (int i = 0; i < d->PortCount; i++) + if (LADSPA_IS_PORT_AUDIO(d->PortDescriptors[i])) + d->connect_port(h, i, audio_buffer + a++*BLOCK_SIZE); mirand = time(NULL); - for (int i = 0; i < BLOCK_SIZE; i++) - inputs[i] = whitenoise(); + for (int i = 0; i < audio_count*BLOCK_SIZE; i++) + audio_buffer[i] = whitenoise(); if (d->activate) d->activate(h); for (int i = 0; i < 64*64*8; i++) diff --git a/benchtime b/benchtime index d6a8d73..3cec957 100755 --- a/benchtime +++ b/benchtime @@ -2,6 +2,12 @@ bench="$1" against="$2" +cleanup() { + echo -e "\e[0;" + exit 0 +} +trap cleanup INT + TIMEFORMAT='%3R' for i in {1..8}; do time "$bench" "$against"