mirror of https://github.com/ericonr/sndio.git
move aparams.c contents in dsp.c
This commit is contained in:
parent
f1c34efede
commit
0a0b1c0b20
|
@ -43,7 +43,7 @@ clean:
|
|||
# ---------------------------------------------------------- dependencies ---
|
||||
|
||||
OBJS = \
|
||||
abuf.o aparams.o utils.o dev.o dsp.o file.o listen.o midi.o miofile.o opt.o \
|
||||
abuf.o utils.o dev.o dsp.o file.o listen.o midi.o miofile.o opt.o \
|
||||
siofile.o sndiod.o sock.o
|
||||
|
||||
sndiod: ${OBJS}
|
||||
|
@ -52,23 +52,24 @@ sndiod: ${OBJS}
|
|||
.c.o:
|
||||
${CC} ${CFLAGS} ${INCLUDE} ${DEFS} -c $<
|
||||
|
||||
### cdeps begin
|
||||
abuf.o: abuf.c abuf.h defs.h utils.h
|
||||
aparams.o: aparams.c aparams.h utils.h
|
||||
dev.o: dev.c abuf.h defs.h dev.h aparams.h dsp.h miofile.h \
|
||||
siofile.h midi.h opt.h sysex.h utils.h
|
||||
dsp.o: dsp.c aparams.h defs.h dsp.h utils.h
|
||||
dev.o: dev.c abuf.h defs.h dev.h dsp.h miofile.h siofile.h \
|
||||
midi.h opt.h sysex.h utils.h
|
||||
dsp.o: dsp.c defs.h dsp.h utils.h
|
||||
file.o: file.c defs.h file.h utils.h
|
||||
listen.o: listen.c listen.h file.h sock.h ../libsndio/amsg.h \
|
||||
utils.h ../bsd-compat/bsd-compat.h
|
||||
midi.o: midi.c abuf.h defs.h dev.h aparams.h dsp.h file.h midi.h \
|
||||
miofile.h sysex.h utils.h ../bsd-compat/bsd-compat.h
|
||||
midi.o: midi.c abuf.h defs.h dev.h dsp.h file.h midi.h miofile.h \
|
||||
sysex.h utils.h ../bsd-compat/bsd-compat.h
|
||||
miofile.o: miofile.c defs.h file.h midi.h abuf.h miofile.h utils.h
|
||||
opt.o: opt.c dev.h abuf.h aparams.h dsp.h defs.h opt.h utils.h
|
||||
siofile.o: siofile.c aparams.h abuf.h defs.h dev.h dsp.h file.h \
|
||||
siofile.h utils.h
|
||||
sndiod.o: sndiod.c ../libsndio/amsg.h aparams.h defs.h dev.h \
|
||||
abuf.h dsp.h file.h listen.h midi.h opt.h sock.h utils.h \
|
||||
opt.o: opt.c dev.h abuf.h dsp.h defs.h opt.h utils.h
|
||||
siofile.o: siofile.c abuf.h defs.h dev.h dsp.h file.h siofile.h \
|
||||
utils.h
|
||||
sndiod.o: sndiod.c ../libsndio/amsg.h defs.h dev.h abuf.h dsp.h \
|
||||
file.h listen.h midi.h opt.h sock.h utils.h \
|
||||
../bsd-compat/bsd-compat.h
|
||||
sock.o: sock.c abuf.h defs.h dev.h aparams.h dsp.h file.h midi.h \
|
||||
opt.h sock.h ../libsndio/amsg.h utils.h
|
||||
sock.o: sock.c abuf.h defs.h dev.h dsp.h file.h midi.h opt.h \
|
||||
sock.h ../libsndio/amsg.h utils.h
|
||||
utils.o: utils.c utils.h
|
||||
### cdeps end
|
||||
|
|
198
sndiod/aparams.c
198
sndiod/aparams.c
|
@ -1,198 +0,0 @@
|
|||
/* $OpenBSD$ */
|
||||
/*
|
||||
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "aparams.h"
|
||||
#include "utils.h"
|
||||
|
||||
int aparams_ctltovol[128] = {
|
||||
0,
|
||||
256, 266, 276, 287, 299, 310, 323, 335,
|
||||
348, 362, 376, 391, 406, 422, 439, 456,
|
||||
474, 493, 512, 532, 553, 575, 597, 621,
|
||||
645, 670, 697, 724, 753, 782, 813, 845,
|
||||
878, 912, 948, 985, 1024, 1064, 1106, 1149,
|
||||
1195, 1241, 1290, 1341, 1393, 1448, 1505, 1564,
|
||||
1625, 1689, 1756, 1825, 1896, 1971, 2048, 2128,
|
||||
2212, 2299, 2389, 2483, 2580, 2682, 2787, 2896,
|
||||
3010, 3128, 3251, 3379, 3511, 3649, 3792, 3941,
|
||||
4096, 4257, 4424, 4598, 4778, 4966, 5161, 5363,
|
||||
5574, 5793, 6020, 6256, 6502, 6757, 7023, 7298,
|
||||
7585, 7883, 8192, 8514, 8848, 9195, 9556, 9931,
|
||||
10321, 10726, 11148, 11585, 12040, 12513, 13004, 13515,
|
||||
14045, 14596, 15170, 15765, 16384, 17027, 17696, 18390,
|
||||
19112, 19863, 20643, 21453, 22295, 23170, 24080, 25025,
|
||||
26008, 27029, 28090, 29193, 30339, 31530, 32768
|
||||
};
|
||||
|
||||
/*
|
||||
* Generate a string corresponding to the encoding in par,
|
||||
* return the length of the resulting string.
|
||||
*/
|
||||
int
|
||||
aparams_enctostr(struct aparams *par, char *ostr)
|
||||
{
|
||||
char *p = ostr;
|
||||
|
||||
*p++ = par->sig ? 's' : 'u';
|
||||
if (par->bits > 9)
|
||||
*p++ = '0' + par->bits / 10;
|
||||
*p++ = '0' + par->bits % 10;
|
||||
if (par->bps > 1) {
|
||||
*p++ = par->le ? 'l' : 'b';
|
||||
*p++ = 'e';
|
||||
if (par->bps != APARAMS_BPS(par->bits) ||
|
||||
par->bits < par->bps * 8) {
|
||||
*p++ = par->bps + '0';
|
||||
if (par->bits < par->bps * 8) {
|
||||
*p++ = par->msb ? 'm' : 'l';
|
||||
*p++ = 's';
|
||||
*p++ = 'b';
|
||||
}
|
||||
}
|
||||
}
|
||||
*p++ = '\0';
|
||||
return p - ostr - 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Parse an encoding string, examples: s8, u8, s16, s16le, s24be ...
|
||||
* set *istr to the char following the encoding. Return the number
|
||||
* of bytes consumed.
|
||||
*/
|
||||
int
|
||||
aparams_strtoenc(struct aparams *par, char *istr)
|
||||
{
|
||||
char *p = istr;
|
||||
int i, sig, bits, le, bps, msb;
|
||||
|
||||
#define IS_SEP(c) \
|
||||
(((c) < 'a' || (c) > 'z') && \
|
||||
((c) < 'A' || (c) > 'Z') && \
|
||||
((c) < '0' || (c) > '9'))
|
||||
|
||||
/*
|
||||
* get signedness
|
||||
*/
|
||||
if (*p == 's') {
|
||||
sig = 1;
|
||||
} else if (*p == 'u') {
|
||||
sig = 0;
|
||||
} else
|
||||
return 0;
|
||||
p++;
|
||||
|
||||
/*
|
||||
* get number of bits per sample
|
||||
*/
|
||||
bits = 0;
|
||||
for (i = 0; i < 2; i++) {
|
||||
if (*p < '0' || *p > '9')
|
||||
break;
|
||||
bits = (bits * 10) + *p - '0';
|
||||
p++;
|
||||
}
|
||||
if (bits < BITS_MIN || bits > BITS_MAX)
|
||||
return 0;
|
||||
bps = APARAMS_BPS(bits);
|
||||
msb = 1;
|
||||
le = ADATA_LE;
|
||||
|
||||
/*
|
||||
* get (optional) endianness
|
||||
*/
|
||||
if (p[0] == 'l' && p[1] == 'e') {
|
||||
le = 1;
|
||||
p += 2;
|
||||
} else if (p[0] == 'b' && p[1] == 'e') {
|
||||
le = 0;
|
||||
p += 2;
|
||||
} else if (IS_SEP(*p)) {
|
||||
goto done;
|
||||
} else
|
||||
return 0;
|
||||
|
||||
/*
|
||||
* get (optional) number of bytes
|
||||
*/
|
||||
if (*p >= '0' && *p <= '9') {
|
||||
bps = *p - '0';
|
||||
if (bps < (bits + 7) / 8 ||
|
||||
bps > (BITS_MAX + 7) / 8)
|
||||
return 0;
|
||||
p++;
|
||||
|
||||
/*
|
||||
* get (optional) alignement
|
||||
*/
|
||||
if (p[0] == 'm' && p[1] == 's' && p[2] == 'b') {
|
||||
msb = 1;
|
||||
p += 3;
|
||||
} else if (p[0] == 'l' && p[1] == 's' && p[2] == 'b') {
|
||||
msb = 0;
|
||||
p += 3;
|
||||
} else if (IS_SEP(*p)) {
|
||||
goto done;
|
||||
} else
|
||||
return 0;
|
||||
} else if (!IS_SEP(*p))
|
||||
return 0;
|
||||
|
||||
done:
|
||||
par->msb = msb;
|
||||
par->sig = sig;
|
||||
par->bits = bits;
|
||||
par->bps = bps;
|
||||
par->le = le;
|
||||
return p - istr;
|
||||
}
|
||||
|
||||
/*
|
||||
* Initialise parameters structure with the defaults natively supported
|
||||
* by the machine.
|
||||
*/
|
||||
void
|
||||
aparams_init(struct aparams *par)
|
||||
{
|
||||
par->bps = sizeof(adata_t);
|
||||
par->bits = ADATA_BITS;
|
||||
par->le = ADATA_LE;
|
||||
par->sig = 1;
|
||||
par->msb = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Print the format/channels/encoding on stderr.
|
||||
*/
|
||||
void
|
||||
aparams_log(struct aparams *par)
|
||||
{
|
||||
char enc[ENCMAX];
|
||||
|
||||
aparams_enctostr(par, enc);
|
||||
log_puts(enc);
|
||||
}
|
||||
|
||||
/*
|
||||
* Return true if encoding can be represented as adata_t
|
||||
*/
|
||||
int
|
||||
aparams_native(struct aparams *par)
|
||||
{
|
||||
return par->bps == sizeof(adata_t) && par->bits == ADATA_BITS &&
|
||||
(par->bps > 1 || par->le == ADATA_LE) &&
|
||||
(par->bits < par->bps * 8 || !par->msb);
|
||||
}
|
133
sndiod/aparams.h
133
sndiod/aparams.h
|
@ -1,133 +0,0 @@
|
|||
/* $OpenBSD$ */
|
||||
/*
|
||||
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
#ifndef APARAMS_H
|
||||
#define APARAMS_H
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#define NCHAN_MAX 16 /* max channel in a stream */
|
||||
#define RATE_MIN 4000 /* min sample rate */
|
||||
#define RATE_MAX 192000 /* max sample rate */
|
||||
#define BITS_MIN 1 /* min bits per sample */
|
||||
#define BITS_MAX 32 /* max bits per sample */
|
||||
|
||||
/*
|
||||
* Maximum size of the encording string (the longest possible
|
||||
* encoding is ``s24le3msb'').
|
||||
*/
|
||||
#define ENCMAX 10
|
||||
|
||||
/*
|
||||
* Default bytes per sample for the given bits per sample.
|
||||
*/
|
||||
#define APARAMS_BPS(bits) (((bits) <= 8) ? 1 : (((bits) <= 16) ? 2 : 4))
|
||||
|
||||
/*
|
||||
* Encoding specification.
|
||||
*/
|
||||
struct aparams {
|
||||
unsigned int bps; /* bytes per sample */
|
||||
unsigned int bits; /* actually used bits */
|
||||
unsigned int le; /* 1 if little endian, 0 if big endian */
|
||||
unsigned int sig; /* 1 if signed, 0 if unsigned */
|
||||
unsigned int msb; /* 1 if msb justified, 0 if lsb justified */
|
||||
};
|
||||
|
||||
/*
|
||||
* Samples are numbers in the interval [-1, 1[, note that 1, the upper
|
||||
* boundary is excluded. We represent them as signed fixed point numbers
|
||||
* of ADATA_BITS. We also assume that 2^(ADATA_BITS - 1) fits in a int.
|
||||
*/
|
||||
#ifndef ADATA_BITS
|
||||
#define ADATA_BITS 16
|
||||
#endif
|
||||
#define ADATA_LE (BYTE_ORDER == LITTLE_ENDIAN)
|
||||
#define ADATA_UNIT (1 << (ADATA_BITS - 1))
|
||||
|
||||
#if ADATA_BITS == 16
|
||||
|
||||
typedef short adata_t;
|
||||
|
||||
#define ADATA_MUL(x,y) (((int)(x) * (int)(y)) >> (ADATA_BITS - 1))
|
||||
#define ADATA_MULDIV(x,y,z) ((int)(x) * (int)(y) / (int)(z))
|
||||
|
||||
#elif ADATA_BITS == 24
|
||||
|
||||
typedef int adata_t;
|
||||
|
||||
#if defined(__i386__) && defined(__GNUC__)
|
||||
|
||||
static inline int
|
||||
fp24_mul(int x, int a)
|
||||
{
|
||||
int res;
|
||||
|
||||
asm volatile (
|
||||
"imull %2\n\t"
|
||||
"shrdl $23, %%edx, %%eax\n\t"
|
||||
: "=a" (res)
|
||||
: "a" (x), "r" (a)
|
||||
: "%edx"
|
||||
);
|
||||
return res;
|
||||
}
|
||||
|
||||
static inline int
|
||||
fp24_muldiv(int x, int a, int b)
|
||||
{
|
||||
int res;
|
||||
|
||||
asm volatile (
|
||||
"imull %2\n\t"
|
||||
"idivl %3\n\t"
|
||||
: "=a" (res)
|
||||
: "a" (x), "d" (a), "r" (b)
|
||||
);
|
||||
return res;
|
||||
}
|
||||
|
||||
#define ADATA_MUL(x,y) fp24_mul(x, y)
|
||||
#define ADATA_MULDIV(x,y,z) fp24_muldiv(x, y, z);
|
||||
|
||||
#elif defined(__amd64__) || defined(__sparc64__)
|
||||
|
||||
#define ADATA_MUL(x,y) \
|
||||
((int)(((long long)(x) * (long long)(y)) >> (ADATA_BITS - 1)))
|
||||
#define ADATA_MULDIV(x,y,z) \
|
||||
((int)((long long)(x) * (long long)(y) / (long long)(z)))
|
||||
|
||||
#else
|
||||
#error "no 24-bit code for this architecture"
|
||||
#endif
|
||||
|
||||
#else
|
||||
#error "only 16-bit and 24-bit precisions are supported"
|
||||
#endif
|
||||
|
||||
#define MIDI_MAXCTL 127
|
||||
#define MIDI_TO_ADATA(m) (aparams_ctltovol[m] << (ADATA_BITS - 16))
|
||||
|
||||
extern int aparams_ctltovol[128];
|
||||
extern struct aparams aparams_none;
|
||||
|
||||
void aparams_init(struct aparams *);
|
||||
void aparams_log(struct aparams *);
|
||||
int aparams_strtoenc(struct aparams *, char *);
|
||||
int aparams_enctostr(struct aparams *, char *);
|
||||
int aparams_native(struct aparams *);
|
||||
|
||||
#endif /* !defined(APARAMS_H) */
|
|
@ -59,9 +59,12 @@ extern unsigned int log_level;
|
|||
#define XRUN_ERROR 2 /* xruns are errors, eof/hup buffer */
|
||||
|
||||
/*
|
||||
* device types
|
||||
* limits
|
||||
*/
|
||||
#define TYPE_AUDIO 0
|
||||
#define TYPE_MIDI 1
|
||||
#define NCHAN_MAX 16 /* max channel in a stream */
|
||||
#define RATE_MIN 4000 /* min sample rate */
|
||||
#define RATE_MAX 192000 /* max sample rate */
|
||||
#define BITS_MIN 1 /* min bits per sample */
|
||||
#define BITS_MAX 32 /* max bits per sample */
|
||||
|
||||
#endif /* !defined(DEFS_H) */
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
#define DEV_H
|
||||
|
||||
#include "abuf.h"
|
||||
#include "aparams.h"
|
||||
#include "dsp.h"
|
||||
|
||||
struct siofile;
|
||||
|
|
180
sndiod/dsp.c
180
sndiod/dsp.c
|
@ -15,11 +15,189 @@
|
|||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
#include <string.h>
|
||||
#include "aparams.h"
|
||||
#include "defs.h"
|
||||
#include "dsp.h"
|
||||
#include "utils.h"
|
||||
|
||||
int aparams_ctltovol[128] = {
|
||||
0,
|
||||
256, 266, 276, 287, 299, 310, 323, 335,
|
||||
348, 362, 376, 391, 406, 422, 439, 456,
|
||||
474, 493, 512, 532, 553, 575, 597, 621,
|
||||
645, 670, 697, 724, 753, 782, 813, 845,
|
||||
878, 912, 948, 985, 1024, 1064, 1106, 1149,
|
||||
1195, 1241, 1290, 1341, 1393, 1448, 1505, 1564,
|
||||
1625, 1689, 1756, 1825, 1896, 1971, 2048, 2128,
|
||||
2212, 2299, 2389, 2483, 2580, 2682, 2787, 2896,
|
||||
3010, 3128, 3251, 3379, 3511, 3649, 3792, 3941,
|
||||
4096, 4257, 4424, 4598, 4778, 4966, 5161, 5363,
|
||||
5574, 5793, 6020, 6256, 6502, 6757, 7023, 7298,
|
||||
7585, 7883, 8192, 8514, 8848, 9195, 9556, 9931,
|
||||
10321, 10726, 11148, 11585, 12040, 12513, 13004, 13515,
|
||||
14045, 14596, 15170, 15765, 16384, 17027, 17696, 18390,
|
||||
19112, 19863, 20643, 21453, 22295, 23170, 24080, 25025,
|
||||
26008, 27029, 28090, 29193, 30339, 31530, 32768
|
||||
};
|
||||
|
||||
/*
|
||||
* Generate a string corresponding to the encoding in par,
|
||||
* return the length of the resulting string.
|
||||
*/
|
||||
int
|
||||
aparams_enctostr(struct aparams *par, char *ostr)
|
||||
{
|
||||
char *p = ostr;
|
||||
|
||||
*p++ = par->sig ? 's' : 'u';
|
||||
if (par->bits > 9)
|
||||
*p++ = '0' + par->bits / 10;
|
||||
*p++ = '0' + par->bits % 10;
|
||||
if (par->bps > 1) {
|
||||
*p++ = par->le ? 'l' : 'b';
|
||||
*p++ = 'e';
|
||||
if (par->bps != APARAMS_BPS(par->bits) ||
|
||||
par->bits < par->bps * 8) {
|
||||
*p++ = par->bps + '0';
|
||||
if (par->bits < par->bps * 8) {
|
||||
*p++ = par->msb ? 'm' : 'l';
|
||||
*p++ = 's';
|
||||
*p++ = 'b';
|
||||
}
|
||||
}
|
||||
}
|
||||
*p++ = '\0';
|
||||
return p - ostr - 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Parse an encoding string, examples: s8, u8, s16, s16le, s24be ...
|
||||
* set *istr to the char following the encoding. Return the number
|
||||
* of bytes consumed.
|
||||
*/
|
||||
int
|
||||
aparams_strtoenc(struct aparams *par, char *istr)
|
||||
{
|
||||
char *p = istr;
|
||||
int i, sig, bits, le, bps, msb;
|
||||
|
||||
#define IS_SEP(c) \
|
||||
(((c) < 'a' || (c) > 'z') && \
|
||||
((c) < 'A' || (c) > 'Z') && \
|
||||
((c) < '0' || (c) > '9'))
|
||||
|
||||
/*
|
||||
* get signedness
|
||||
*/
|
||||
if (*p == 's') {
|
||||
sig = 1;
|
||||
} else if (*p == 'u') {
|
||||
sig = 0;
|
||||
} else
|
||||
return 0;
|
||||
p++;
|
||||
|
||||
/*
|
||||
* get number of bits per sample
|
||||
*/
|
||||
bits = 0;
|
||||
for (i = 0; i < 2; i++) {
|
||||
if (*p < '0' || *p > '9')
|
||||
break;
|
||||
bits = (bits * 10) + *p - '0';
|
||||
p++;
|
||||
}
|
||||
if (bits < BITS_MIN || bits > BITS_MAX)
|
||||
return 0;
|
||||
bps = APARAMS_BPS(bits);
|
||||
msb = 1;
|
||||
le = ADATA_LE;
|
||||
|
||||
/*
|
||||
* get (optional) endianness
|
||||
*/
|
||||
if (p[0] == 'l' && p[1] == 'e') {
|
||||
le = 1;
|
||||
p += 2;
|
||||
} else if (p[0] == 'b' && p[1] == 'e') {
|
||||
le = 0;
|
||||
p += 2;
|
||||
} else if (IS_SEP(*p)) {
|
||||
goto done;
|
||||
} else
|
||||
return 0;
|
||||
|
||||
/*
|
||||
* get (optional) number of bytes
|
||||
*/
|
||||
if (*p >= '0' && *p <= '9') {
|
||||
bps = *p - '0';
|
||||
if (bps < (bits + 7) / 8 ||
|
||||
bps > (BITS_MAX + 7) / 8)
|
||||
return 0;
|
||||
p++;
|
||||
|
||||
/*
|
||||
* get (optional) alignement
|
||||
*/
|
||||
if (p[0] == 'm' && p[1] == 's' && p[2] == 'b') {
|
||||
msb = 1;
|
||||
p += 3;
|
||||
} else if (p[0] == 'l' && p[1] == 's' && p[2] == 'b') {
|
||||
msb = 0;
|
||||
p += 3;
|
||||
} else if (IS_SEP(*p)) {
|
||||
goto done;
|
||||
} else
|
||||
return 0;
|
||||
} else if (!IS_SEP(*p))
|
||||
return 0;
|
||||
|
||||
done:
|
||||
par->msb = msb;
|
||||
par->sig = sig;
|
||||
par->bits = bits;
|
||||
par->bps = bps;
|
||||
par->le = le;
|
||||
return p - istr;
|
||||
}
|
||||
|
||||
/*
|
||||
* Initialise parameters structure with the defaults natively supported
|
||||
* by the machine.
|
||||
*/
|
||||
void
|
||||
aparams_init(struct aparams *par)
|
||||
{
|
||||
par->bps = sizeof(adata_t);
|
||||
par->bits = ADATA_BITS;
|
||||
par->le = ADATA_LE;
|
||||
par->sig = 1;
|
||||
par->msb = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Print the format/channels/encoding on stderr.
|
||||
*/
|
||||
void
|
||||
aparams_log(struct aparams *par)
|
||||
{
|
||||
char enc[ENCMAX];
|
||||
|
||||
aparams_enctostr(par, enc);
|
||||
log_puts(enc);
|
||||
}
|
||||
|
||||
/*
|
||||
* Return true if encoding can be represented as adata_t
|
||||
*/
|
||||
int
|
||||
aparams_native(struct aparams *par)
|
||||
{
|
||||
return par->bps == sizeof(adata_t) && par->bits == ADATA_BITS &&
|
||||
(par->bps > 1 || par->le == ADATA_LE) &&
|
||||
(par->bits < par->bps * 8 || !par->msb);
|
||||
}
|
||||
|
||||
int
|
||||
resamp_do(struct resamp *p, adata_t *in, adata_t *out, int todo)
|
||||
{
|
||||
|
|
117
sndiod/dsp.h
117
sndiod/dsp.h
|
@ -17,7 +17,98 @@
|
|||
#ifndef DSP_H
|
||||
#define DSP_H
|
||||
|
||||
#include "aparams.h"
|
||||
#include <sys/types.h>
|
||||
#include "defs.h"
|
||||
|
||||
/*
|
||||
* Samples are numbers in the interval [-1, 1[, note that 1, the upper
|
||||
* boundary is excluded. We represent them as signed fixed point numbers
|
||||
* of ADATA_BITS. We also assume that 2^(ADATA_BITS - 1) fits in a int.
|
||||
*/
|
||||
#ifndef ADATA_BITS
|
||||
#define ADATA_BITS 16
|
||||
#endif
|
||||
#define ADATA_LE (BYTE_ORDER == LITTLE_ENDIAN)
|
||||
#define ADATA_UNIT (1 << (ADATA_BITS - 1))
|
||||
|
||||
#if ADATA_BITS == 16
|
||||
|
||||
#define ADATA_MUL(x,y) (((int)(x) * (int)(y)) >> (ADATA_BITS - 1))
|
||||
#define ADATA_MULDIV(x,y,z) ((int)(x) * (int)(y) / (int)(z))
|
||||
|
||||
typedef short adata_t;
|
||||
|
||||
#elif ADATA_BITS == 24
|
||||
|
||||
#if defined(__i386__) && defined(__GNUC__)
|
||||
|
||||
static inline int
|
||||
fp24_mul(int x, int a)
|
||||
{
|
||||
int res;
|
||||
|
||||
asm volatile (
|
||||
"imull %2\n\t"
|
||||
"shrdl $23, %%edx, %%eax\n\t"
|
||||
: "=a" (res)
|
||||
: "a" (x), "r" (a)
|
||||
: "%edx"
|
||||
);
|
||||
return res;
|
||||
}
|
||||
|
||||
static inline int
|
||||
fp24_muldiv(int x, int a, int b)
|
||||
{
|
||||
int res;
|
||||
|
||||
asm volatile (
|
||||
"imull %2\n\t"
|
||||
"idivl %3\n\t"
|
||||
: "=a" (res)
|
||||
: "a" (x), "d" (a), "r" (b)
|
||||
);
|
||||
return res;
|
||||
}
|
||||
|
||||
#define ADATA_MUL(x,y) fp24_mul(x, y)
|
||||
#define ADATA_MULDIV(x,y,z) fp24_muldiv(x, y, z);
|
||||
|
||||
#elif defined(__amd64__) || defined(__sparc64__)
|
||||
|
||||
#define ADATA_MUL(x,y) \
|
||||
((int)(((long long)(x) * (long long)(y)) >> (ADATA_BITS - 1)))
|
||||
#define ADATA_MULDIV(x,y,z) \
|
||||
((int)((long long)(x) * (long long)(y) / (long long)(z)))
|
||||
|
||||
#else
|
||||
#error "no 24-bit code for this architecture"
|
||||
#endif
|
||||
|
||||
typedef int adata_t;
|
||||
|
||||
#else
|
||||
#error "only 16-bit and 24-bit precisions are supported"
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Maximum size of the encording string (the longest possible
|
||||
* encoding is ``s24le3msb'').
|
||||
*/
|
||||
#define ENCMAX 10
|
||||
|
||||
/*
|
||||
* Default bytes per sample for the given bits per sample.
|
||||
*/
|
||||
#define APARAMS_BPS(bits) (((bits) <= 8) ? 1 : (((bits) <= 16) ? 2 : 4))
|
||||
|
||||
struct aparams {
|
||||
unsigned int bps; /* bytes per sample */
|
||||
unsigned int bits; /* actually used bits */
|
||||
unsigned int le; /* 1 if little endian, 0 if big endian */
|
||||
unsigned int sig; /* 1 if signed, 0 if unsigned */
|
||||
unsigned int msb; /* 1 if msb justified, 0 if lsb justified */
|
||||
};
|
||||
|
||||
struct resamp {
|
||||
void *data;
|
||||
|
@ -26,18 +117,18 @@ struct resamp {
|
|||
adata_t ctx[NCHAN_MAX * RESAMP_NCTX];
|
||||
unsigned int iblksz, oblksz;
|
||||
int diff;
|
||||
int idelta, odelta; /* remainder of ipos/opos */
|
||||
int idelta, odelta; /* remainder of ipos/opos */
|
||||
int nch;
|
||||
};
|
||||
|
||||
struct conv {
|
||||
void *data;
|
||||
int bfirst; /* bytes to skip at startup */
|
||||
unsigned int bps; /* bytes per sample */
|
||||
unsigned int shift; /* shift to get 32bit MSB */
|
||||
int sigbit; /* sign bits to XOR */
|
||||
int bnext; /* to reach the next byte */
|
||||
int snext; /* to reach the next sample */
|
||||
int bfirst; /* bytes to skip at startup */
|
||||
unsigned int bps; /* bytes per sample */
|
||||
unsigned int shift; /* shift to get 32bit MSB */
|
||||
int sigbit; /* sign bits to XOR */
|
||||
int bnext; /* to reach the next byte */
|
||||
int snext; /* to reach the next sample */
|
||||
int nch;
|
||||
};
|
||||
|
||||
|
@ -49,6 +140,15 @@ struct cmap {
|
|||
int nch;
|
||||
};
|
||||
|
||||
#define MIDI_TO_ADATA(m) (aparams_ctltovol[m] << (ADATA_BITS - 16))
|
||||
extern int aparams_ctltovol[128];
|
||||
|
||||
void aparams_init(struct aparams *);
|
||||
void aparams_log(struct aparams *);
|
||||
int aparams_strtoenc(struct aparams *, char *);
|
||||
int aparams_enctostr(struct aparams *, char *);
|
||||
int aparams_native(struct aparams *);
|
||||
|
||||
int resamp_do(struct resamp *, adata_t *, adata_t *, int);
|
||||
void resamp_init(struct resamp *, unsigned int, unsigned int, int);
|
||||
void enc_do(struct conv *, unsigned char *, unsigned char *, int);
|
||||
|
@ -59,6 +159,5 @@ void dec_init(struct conv *, struct aparams *, int);
|
|||
void cmap_add(struct cmap *, void *, void *, int, int);
|
||||
void cmap_copy(struct cmap *, void *, void *, int, int);
|
||||
void cmap_init(struct cmap *, int, int, int, int, int, int, int, int);
|
||||
int sqrtone(int, adata_t *, int, int, int);
|
||||
|
||||
#endif /* !defined(DSP_H) */
|
||||
|
|
|
@ -42,6 +42,11 @@
|
|||
*/
|
||||
#define MIDI_CTL_VOL 7 /* volume */
|
||||
|
||||
/*
|
||||
* Max coarse value
|
||||
*/
|
||||
#define MIDI_MAXCTL 127
|
||||
|
||||
/*
|
||||
* midi stream state structure
|
||||
*/
|
||||
|
|
|
@ -17,9 +17,6 @@
|
|||
#ifndef OPT_H
|
||||
#define OPT_H
|
||||
|
||||
#include <sys/queue.h>
|
||||
#include "aparams.h"
|
||||
|
||||
struct dev;
|
||||
|
||||
struct opt {
|
||||
|
|
|
@ -24,10 +24,10 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "aparams.h"
|
||||
#include "abuf.h"
|
||||
#include "defs.h"
|
||||
#include "dev.h"
|
||||
#include "dsp.h"
|
||||
#include "file.h"
|
||||
#include "siofile.h"
|
||||
#include "utils.h"
|
||||
|
|
|
@ -33,7 +33,6 @@
|
|||
#include <unistd.h>
|
||||
|
||||
#include "amsg.h"
|
||||
#include "aparams.h"
|
||||
#include "defs.h"
|
||||
#include "dev.h"
|
||||
#include "file.h"
|
||||
|
|
Loading…
Reference in New Issue