Commit c1d0a8b5 authored by Max Kellermann's avatar Max Kellermann

dsd2pcm: move the bit reversing code to a generic library

Instead of doing run-time initialisation, use a constant lookup table.
parent 08ce24ec
......@@ -227,6 +227,7 @@ src_mpd_SOURCES = \
$(MIXER_API_SRC) \
src/util/list.h \
src/util/list_sort.c src/util/list_sort.h \
src/util/bit_reverse.c src/util/bit_reverse.h \
src/glib_socket.h \
src/notify.c \
src/audio_config.c src/audio_config.h \
......@@ -1174,6 +1175,7 @@ test_run_normalize_LDADD = \
$(GLIB_LIBS)
test_run_convert_SOURCES = test/run_convert.c \
src/util/bit_reverse.c \
src/dsd2pcm/dsd2pcm.c \
src/fifo_buffer.c \
src/audio_format.c \
......@@ -1272,6 +1274,7 @@ if HAVE_CXX
noinst_PROGRAMS += src/dsd2pcm/dsd2pcm
src_dsd2pcm_dsd2pcm_SOURCES = \
src/util/bit_reverse.c \
src/dsd2pcm/dsd2pcm.c src/dsd2pcm/dsd2pcm.h \
src/dsd2pcm/noiseshape.c src/dsd2pcm/noiseshape.h \
src/dsd2pcm/main.cpp
......
#include "util/bit_reverse.h"
#include <stdlib.h>
#include <string.h>
......@@ -84,7 +86,6 @@ static const double htaps[HTAPS] = {
};
static float ctables[CTABLES][256];
static unsigned char bitreverse[256];
static int precalculated = 0;
static void precalc(void)
......@@ -92,11 +93,6 @@ static void precalc(void)
int t, e, m, k;
double acc;
if (precalculated) return;
for (t=0, e=0; t<256; ++t) {
bitreverse[t] = e;
for (m=128; m && !((e^=m)&m); m>>=1)
;
}
for (t=0; t<CTABLES; ++t) {
k = HTAPS - t*8;
if (k>8) k=8;
......@@ -170,10 +166,10 @@ extern void dsd2pcm_translate(
lsbf = lsbf ? 1 : 0;
while (samples-- > 0) {
bite1 = *src & 0xFFu;
if (lsbf) bite1 = bitreverse[bite1];
if (lsbf) bite1 = bit_reverse(bite1);
ptr->fifo[ffp] = bite1; src += src_stride;
p = ptr->fifo + ((ffp-CTABLES) & FIFOMASK);
*p = bitreverse[*p & 0xFF];
*p = bit_reverse(*p);
acc = 0;
for (i=0; i<CTABLES; ++i) {
bite1 = ptr->fifo[(ffp -i) & FIFOMASK] & 0xFF;
......
/*
* Copyright (C) 2003-2012 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "bit_reverse.h"
/**
* @see http://graphics.stanford.edu/~seander/bithacks.html#BitReverseTable
*/
const uint8_t bit_reverse_table[256] =
{
#define R2(n) n, n + 2*64, n + 1*64, n + 3*64
#define R4(n) R2(n), R2(n + 2*16), R2(n + 1*16), R2(n + 3*16)
#define R6(n) R4(n), R4(n + 2*4 ), R4(n + 1*4 ), R4(n + 3*4 )
R6(0), R6(2), R6(1), R6(3)
};
/*
* Copyright (C) 2003-2012 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef MPD_BIT_REVERSE_H
#define MPD_BIT_REVERSE_H
#include <glib.h>
#include <stdint.h>
extern const uint8_t bit_reverse_table[256];
G_GNUC_CONST
static inline uint8_t
bit_reverse(uint8_t x)
{
return bit_reverse_table[x];
}
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment