[BACK]Return to aparams.h CVS log [TXT][DIR] Up to [local] / src / usr.bin / aucat

Annotation of src/usr.bin/aucat/aparams.h, Revision 1.13

1.13    ! deraadt     1: /*     $OpenBSD: aparams.h,v 1.12 2012/04/11 06:05:43 ratchov Exp $    */
1.1       ratchov     2: /*
                      3:  * Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
                      4:  *
                      5:  * Permission to use, copy, modify, and distribute this software for any
                      6:  * purpose with or without fee is hereby granted, provided that the above
                      7:  * copyright notice and this permission notice appear in all copies.
                      8:  *
                      9:  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
                     10:  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
                     11:  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
                     12:  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
                     13:  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
                     14:  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
                     15:  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
                     16:  */
                     17: #ifndef APARAMS_H
                     18: #define APARAMS_H
                     19:
1.2       ratchov    20: #define NCHAN_MAX      16              /* max channel in a stream */
                     21: #define RATE_MIN       4000            /* min sample rate */
                     22: #define RATE_MAX       192000          /* max sample rate */
                     23: #define BITS_MIN       1               /* min bits per sample */
1.1       ratchov    24: #define BITS_MAX       32              /* max bits per sample */
                     25:
1.2       ratchov    26: /*
1.6       ratchov    27:  * Maximum size of the encording string (the longest possible
                     28:  * encoding is ``s24le3msb'').
1.2       ratchov    29:  */
                     30: #define ENCMAX 10
                     31:
1.1       ratchov    32: /*
1.6       ratchov    33:  * Default bytes per sample for the given bits per sample.
1.2       ratchov    34:  */
                     35: #define APARAMS_BPS(bits) (((bits) <= 8) ? 1 : (((bits) <= 16) ? 2 : 4))
                     36:
                     37: /*
1.6       ratchov    38:  * Encoding specification.
1.1       ratchov    39:  */
                     40: struct aparams {
1.12      ratchov    41:        unsigned int bps;               /* bytes per sample */
                     42:        unsigned int bits;              /* actually used bits */
                     43:        unsigned int le;                /* 1 if little endian, 0 if big endian */
                     44:        unsigned int sig;               /* 1 if signed, 0 if unsigned */
                     45:        unsigned int msb;               /* 1 if msb justified, 0 if lsb justified */
                     46:        unsigned int cmin, cmax;        /* provided/consumed channels */
                     47:        unsigned int rate;              /* frames per second */
1.1       ratchov    48: };
                     49:
                     50: /*
                     51:  * Samples are numbers in the interval [-1, 1[, note that 1, the upper
1.10      ratchov    52:  * boundary is excluded. We represent them as signed fixed point numbers
                     53:  * of ADATA_BITS. We also assume that 2^(ADATA_BITS - 1) fits in a int.
1.1       ratchov    54:  */
1.11      ratchov    55: #ifndef ADATA_BITS
1.10      ratchov    56: #define ADATA_BITS                     16
1.11      ratchov    57: #endif
1.10      ratchov    58: #define ADATA_LE                       (BYTE_ORDER == LITTLE_ENDIAN)
                     59: #define ADATA_UNIT                     (1 << (ADATA_BITS - 1))
                     60:
1.11      ratchov    61: #if ADATA_BITS == 16
                     62:
1.9       ratchov    63: typedef short adata_t;
1.10      ratchov    64:
1.9       ratchov    65: #define ADATA_MUL(x,y)         (((int)(x) * (int)(y)) >> (ADATA_BITS - 1))
                     66: #define ADATA_MULDIV(x,y,z)    ((int)(x) * (int)(y) / (int)(z))
1.11      ratchov    67:
                     68: #elif ADATA_BITS == 24
                     69:
                     70: typedef int adata_t;
                     71:
                     72: #if defined(__i386__) && defined(__GNUC__)
                     73:
                     74: static inline int
                     75: fp24_mul(int x, int a)
                     76: {
                     77:        int res;
                     78:
                     79:        asm volatile (
                     80:                "imull  %2\n\t"
                     81:                "shrdl $23, %%edx, %%eax\n\t"
                     82:                : "=a" (res)
                     83:                : "a" (x), "r" (a)
                     84:                : "%edx"
                     85:                );
                     86:        return res;
                     87: }
                     88:
                     89: static inline int
                     90: fp24_muldiv(int x, int a, int b)
                     91: {
                     92:        int res;
                     93:
                     94:        asm volatile (
                     95:                "imull %2\n\t"
                     96:                "idivl %3\n\t"
                     97:                : "=a" (res)
                     98:                : "a" (x), "d" (a), "r" (b)
                     99:                );
                    100:        return res;
                    101: }
                    102:
                    103: #define ADATA_MUL(x,y)         fp24_mul(x, y)
                    104: #define ADATA_MULDIV(x,y,z)    fp24_muldiv(x, y, z);
                    105:
                    106: #elif defined(__amd64__) || defined(__sparc64__)
                    107:
                    108: #define ADATA_MUL(x,y)         \
                    109:        ((int)(((long long)(x) * (long long)(y)) >> (ADATA_BITS - 1)))
                    110: #define ADATA_MULDIV(x,y,z)    \
                    111:        ((int)((long long)(x) * (long long)(y) / (long long)(z)))
                    112:
                    113: #else
                    114: #error "no 24-bit code for this architecture"
                    115: #endif
                    116:
                    117: #else
                    118: #error "only 16-bit and 24-bit precisions are supported"
                    119: #endif
1.4       ratchov   120:
                    121: #define MIDI_MAXCTL            127
1.9       ratchov   122: #define MIDI_TO_ADATA(m)       (aparams_ctltovol[m] << (ADATA_BITS - 16))
1.4       ratchov   123:
                    124: extern int aparams_ctltovol[128];
1.7       ratchov   125: extern struct aparams aparams_none;
1.1       ratchov   126:
1.12      ratchov   127: void aparams_init(struct aparams *, unsigned int, unsigned int, unsigned int);
1.8       ratchov   128: void aparams_dbg(struct aparams *);
1.3       ratchov   129: int aparams_eqrate(struct aparams *, struct aparams *);
                    130: int aparams_eqenc(struct aparams *, struct aparams *);
1.1       ratchov   131: int aparams_eq(struct aparams *, struct aparams *);
1.3       ratchov   132: int aparams_subset(struct aparams *, struct aparams *);
1.5       ratchov   133: void aparams_grow(struct aparams *, struct aparams *);
1.12      ratchov   134: unsigned int aparams_bpf(struct aparams *);
1.2       ratchov   135: int aparams_strtoenc(struct aparams *, char *);
                    136: int aparams_enctostr(struct aparams *, char *);
                    137: void aparams_copyenc(struct aparams *, struct aparams *);
1.1       ratchov   138:
                    139: #endif /* !defined(APARAMS_H) */