Created
April 4, 2022 11:56
-
-
Save sreimers/67440f237cae34537c9c1667900a7c57 to your computer and use it in GitHub Desktop.
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
#include <re.h> | |
#include <rem.h> | |
#include <stdint.h> | |
enum { | |
SILENCE_Q = 1024 * 1024, /* Quadratic sample value for silence */ | |
}; | |
static bool auframe_silence(struct auframe *af) | |
{ | |
const int16_t *v; | |
int32_t sum = 0; | |
size_t i; | |
v = af->sampv; | |
for (i = 0; i < af->sampc; i++) { | |
sum += v[i] * v[i]; | |
if (sum > (int32_t)(i + 1) * SILENCE_Q) | |
return false; | |
} | |
return true; | |
} | |
static bool auframe_silence2(struct auframe *af) | |
{ | |
return auframe_level(af) < -30.; | |
} | |
int main(void) | |
{ | |
uint64_t start, end; | |
int16_t testv[1920] = {0, 0}; | |
struct auframe af; | |
bool ret; | |
int cnt = 0; | |
auframe_init(&af, AUFMT_S16LE, testv, ARRAY_SIZE(testv), 48000, 2); | |
for (int j = 0; j < 2; j++) { | |
cnt = 0; | |
start = tmr_jiffies_usec(); | |
for (int i = 0; i < 2000; i++) { | |
ret = auframe_silence(&af); | |
if (ret) | |
cnt++; | |
af.level = AULEVEL_UNDEF; | |
} | |
end = tmr_jiffies_usec(); | |
re_printf("auframe_silence %d usecs (%d)\n", end - start, cnt); | |
cnt = 0; | |
start = tmr_jiffies_usec(); | |
for (int i = 0; i < 2000; i++) { | |
ret = auframe_silence2(&af); | |
if (ret) | |
cnt++; | |
af.level = AULEVEL_UNDEF; | |
} | |
end = tmr_jiffies_usec(); | |
re_printf("auframe_silence2 %d usecs (%d)\n", end - start, | |
cnt); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
We found that the example code has to be compiled also with same optimization level like
rem
. But anyway your silence detection is slightly faster:Also I tried with this code:
Here
b += SILENCE_Q;
andif (sum > b)
leads to the performance loss.