Annotation of qemu/audio/mixeng_template.h, revision 1.1.1.6

1.1       root        1: /*
                      2:  * QEMU Mixing engine
1.1.1.2   root        3:  *
                      4:  * Copyright (c) 2004-2005 Vassili Karpov (malc)
                      5:  *
1.1       root        6:  * Permission is hereby granted, free of charge, to any person obtaining a copy
                      7:  * of this software and associated documentation files (the "Software"), to deal
                      8:  * in the Software without restriction, including without limitation the rights
                      9:  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
                     10:  * copies of the Software, and to permit persons to whom the Software is
                     11:  * furnished to do so, subject to the following conditions:
                     12:  *
                     13:  * The above copyright notice and this permission notice shall be included in
                     14:  * all copies or substantial portions of the Software.
                     15:  *
                     16:  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
                     17:  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
                     18:  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
                     19:  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
                     20:  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
                     21:  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
                     22:  * THE SOFTWARE.
                     23:  */
                     24: 
                     25: /*
                     26:  * Tusen tack till Mike Nordell
                     27:  * dec++'ified by Dscho
                     28:  */
                     29: 
1.1.1.2   root       30: #ifndef SIGNED
                     31: #define HALF (IN_MAX >> 1)
                     32: #endif
                     33: 
1.1.1.6 ! root       34: #define ET glue (ENDIAN_CONVERSION, glue (glue (glue (_, ITYPE), BSIZE), _t))
        !            35: #define IN_T glue (glue (ITYPE, BSIZE), _t)
1.1.1.2   root       36: 
                     37: #ifdef FLOAT_MIXENG
1.1.1.3   root       38: static mixeng_real inline glue (conv_, ET) (IN_T v)
1.1.1.2   root       39: {
                     40:     IN_T nv = ENDIAN_CONVERT (v);
                     41: 
                     42: #ifdef RECIPROCAL
                     43: #ifdef SIGNED
1.1.1.3   root       44:     return nv * (1.f / (mixeng_real) (IN_MAX - IN_MIN));
1.1.1.2   root       45: #else
1.1.1.3   root       46:     return (nv - HALF) * (1.f / (mixeng_real) IN_MAX);
1.1.1.2   root       47: #endif
                     48: #else  /* !RECIPROCAL */
1.1       root       49: #ifdef SIGNED
1.1.1.5   root       50:     return nv / (mixeng_real) ((mixeng_real) IN_MAX - IN_MIN);
1.1       root       51: #else
1.1.1.3   root       52:     return (nv - HALF) / (mixeng_real) IN_MAX;
1.1       root       53: #endif
1.1.1.2   root       54: #endif
                     55: }
1.1       root       56: 
1.1.1.3   root       57: static IN_T inline glue (clip_, ET) (mixeng_real v)
1.1       root       58: {
1.1.1.2   root       59:     if (v >= 0.5) {
                     60:         return IN_MAX;
                     61:     }
                     62:     else if (v < -0.5) {
                     63:         return IN_MIN;
                     64:     }
                     65: 
                     66: #ifdef SIGNED
1.1.1.5   root       67:     return ENDIAN_CONVERT ((IN_T) (v * ((mixeng_real) IN_MAX - IN_MIN)));
1.1.1.2   root       68: #else
                     69:     return ENDIAN_CONVERT ((IN_T) ((v * IN_MAX) + HALF));
                     70: #endif
                     71: }
                     72: 
                     73: #else  /* !FLOAT_MIXENG */
                     74: 
                     75: static inline int64_t glue (conv_, ET) (IN_T v)
                     76: {
                     77:     IN_T nv = ENDIAN_CONVERT (v);
1.1       root       78: #ifdef SIGNED
1.1.1.2   root       79:     return ((int64_t) nv) << (32 - SHIFT);
1.1       root       80: #else
1.1.1.2   root       81:     return ((int64_t) nv - HALF) << (32 - SHIFT);
1.1       root       82: #endif
                     83: }
                     84: 
1.1.1.2   root       85: static inline IN_T glue (clip_, ET) (int64_t v)
1.1       root       86: {
1.1.1.2   root       87:     if (v >= 0x7f000000) {
1.1       root       88:         return IN_MAX;
1.1.1.2   root       89:     }
                     90:     else if (v < -2147483648LL) {
1.1       root       91:         return IN_MIN;
1.1.1.2   root       92:     }
1.1       root       93: 
                     94: #ifdef SIGNED
1.1.1.2   root       95:     return ENDIAN_CONVERT ((IN_T) (v >> (32 - SHIFT)));
1.1       root       96: #else
1.1.1.2   root       97:     return ENDIAN_CONVERT ((IN_T) ((v >> (32 - SHIFT)) + HALF));
1.1       root       98: #endif
                     99: }
1.1.1.2   root      100: #endif
1.1       root      101: 
1.1.1.2   root      102: static void glue (glue (conv_, ET), _to_stereo)
1.1.1.4   root      103:     (struct st_sample *dst, const void *src, int samples)
1.1       root      104: {
1.1.1.3   root      105:     struct st_sample *out = dst;
1.1       root      106:     IN_T *in = (IN_T *) src;
1.1.1.4   root      107: 
1.1       root      108:     while (samples--) {
1.1.1.4   root      109:         out->l = glue (conv_, ET) (*in++);
                    110:         out->r = glue (conv_, ET) (*in++);
1.1       root      111:         out += 1;
                    112:     }
                    113: }
                    114: 
1.1.1.2   root      115: static void glue (glue (conv_, ET), _to_mono)
1.1.1.4   root      116:     (struct st_sample *dst, const void *src, int samples)
1.1       root      117: {
1.1.1.3   root      118:     struct st_sample *out = dst;
1.1       root      119:     IN_T *in = (IN_T *) src;
1.1.1.4   root      120: 
1.1       root      121:     while (samples--) {
1.1.1.4   root      122:         out->l = glue (conv_, ET) (in[0]);
1.1       root      123:         out->r = out->l;
                    124:         out += 1;
                    125:         in += 1;
                    126:     }
                    127: }
                    128: 
1.1.1.2   root      129: static void glue (glue (clip_, ET), _from_stereo)
1.1.1.3   root      130:     (void *dst, const struct st_sample *src, int samples)
1.1       root      131: {
1.1.1.3   root      132:     const struct st_sample *in = src;
1.1       root      133:     IN_T *out = (IN_T *) dst;
                    134:     while (samples--) {
1.1.1.2   root      135:         *out++ = glue (clip_, ET) (in->l);
                    136:         *out++ = glue (clip_, ET) (in->r);
1.1       root      137:         in += 1;
                    138:     }
                    139: }
                    140: 
1.1.1.2   root      141: static void glue (glue (clip_, ET), _from_mono)
1.1.1.3   root      142:     (void *dst, const struct st_sample *src, int samples)
1.1       root      143: {
1.1.1.3   root      144:     const struct st_sample *in = src;
1.1       root      145:     IN_T *out = (IN_T *) dst;
                    146:     while (samples--) {
1.1.1.2   root      147:         *out++ = glue (clip_, ET) (in->l + in->r);
1.1       root      148:         in += 1;
                    149:     }
                    150: }
                    151: 
1.1.1.2   root      152: #undef ET
1.1       root      153: #undef HALF
1.1.1.6 ! root      154: #undef IN_T

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.