Skip to content

Commit

Permalink
Optimize median filter
Browse files Browse the repository at this point in the history
We're only interested in sorting the first half of the sample buffer.
  • Loading branch information
ReservedField committed Oct 18, 2016
1 parent b8ad192 commit 2aec8ed
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/atomizer/Atomizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,9 @@ static uint16_t Atomizer_MedianFilter(uint16_t value, Atomizer_MedianFilterCtx_t
ctx->buf[ctx->idx] = value;
ctx->idx = (ctx->idx + 1) % ATOMIZER_MEDIANFILTER_WINDOW;

// Selection sort
// Selection sort. We only need to sort the first half.
memcpy(sortBuf, ctx->buf, sizeof(sortBuf));
for(i = 0; i < ATOMIZER_MEDIANFILTER_WINDOW; i++) {
for(i = 0; i < (ATOMIZER_MEDIANFILTER_WINDOW + 1) / 2; i++) {
minIdx = i;
for(j = i + 1; j < ATOMIZER_MEDIANFILTER_WINDOW; j++) {
if(sortBuf[j] < sortBuf[minIdx]) {
Expand Down

0 comments on commit 2aec8ed

Please sign in to comment.