VirtualBox

Changeset 6521 in vbox


Ignore:
Timestamp:
Jan 28, 2008 8:13:46 AM (17 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
27540
Message:

audio: fixed mixing of 8 bit unsigned; 32-bit updates from qemu

Location:
trunk/src/VBox/Devices/Audio
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Audio/audio.c

    r6140 r6521  
    238238#endif
    239239
     240static inline int audio_bits_to_index (int bits)
     241{
     242    switch (bits) {
     243    case 8:
     244        return 0;
     245
     246    case 16:
     247        return 1;
     248
     249    case 32:
     250        return 2;
     251
     252    default:
     253        audio_bug ("bits_to_index", 1);
     254        AUD_log (NULL, "invalid bits %d\n", bits);
     255        return 0;
     256    }
     257}
     258
    240259void *audio_calloc (const char *funcname, int nmemb, size_t size)
    241260{
     
    571590void audio_pcm_init_info (struct audio_pcm_info *info, audsettings_t *as)
    572591{
    573     int bits = 8, sign = 0;
     592    int bits = 8, sign = 0, shift = 0;
    574593
    575594    switch (as->fmt) {
     
    583602    case AUD_FMT_U16:
    584603        bits = 16;
     604        shift = 1;
    585605        break;
    586606
     
    589609    case AUD_FMT_U32:
    590610        bits = 32;
     611        shift = 2;
    591612        break;
    592613    }
     
    596617    info->sign = sign;
    597618    info->nchannels = as->nchannels;
    598     info->shift = (as->nchannels == 2) + (bits == 16);
     619    info->shift = (as->nchannels == 2) + shift;
    599620    info->align = (1 << info->shift) - 1;
    600621    info->bytes_per_second = info->freq << info->shift;
     
    612633    }
    613634    else {
    614         if (info->bits == 8) {
     635        switch (info->bits) {
     636        case 8:
    615637            memset (buf, 0x80, len << info->shift);
    616         }
    617         else {
    618             int i;
    619             uint16_t *p = buf;
    620             int shift = info->nchannels - 1;
    621             short s = INT16_MAX;
    622 
    623             if (info->swap_endianness) {
    624                 s = bswap16 (s);
    625             }
    626 
    627             for (i = 0; i < len << shift; i++) {
    628                 p[i] = s;
    629             }
     638            break;
     639
     640        case 16:
     641            {
     642                int i;
     643                uint16_t *p = buf;
     644                int shift = info->nchannels - 1;
     645                short s = INT16_MAX;
     646
     647                if (info->swap_endianness) {
     648                    s = bswap16 (s);
     649                }
     650
     651                for (i = 0; i < len << shift; i++) {
     652                    p[i] = s;
     653                }
     654            }
     655            break;
     656
     657        case 32:
     658            {
     659                int i;
     660                uint32_t *p = buf;
     661                int shift = info->nchannels - 1;
     662                int32_t s = INT32_MAX;
     663
     664                if (info->swap_endianness) {
     665                    s = bswap32 (s);
     666                }
     667
     668                for (i = 0; i < len << shift; i++) {
     669                    p[i] = s;
     670                }
     671            }
     672            break;
     673
     674        default:
     675            AUD_log (NULL, "audio_pcm_info_clear_buf: invalid bits %d\n",
     676                     info->bits);
     677            break;
    630678        }
    631679    }
     
    17401788            [hw->info.sign]
    17411789            [hw->info.swap_endianness]
    1742             [hw->info.bits == 16];
     1790            [audio_bits_to_index (hw->info.bits)];
    17431791
    17441792        LIST_INSERT_HEAD (&s->cap_head, cap, entries);
  • trunk/src/VBox/Devices/Audio/audio_template.h

    r1 r6521  
    165165        [sw->info.sign]
    166166        [sw->info.swap_endianness]
    167         [sw->info.bits == 16];
     167        [audio_bits_to_index (sw->info.bits)];
    168168
    169169    sw->name = qemu_strdup (name);
     
    290290        [hw->info.sign]
    291291        [hw->info.swap_endianness]
    292         [hw->info.bits == 16];
     292        [audio_bits_to_index (hw->info.bits)];
    293293
    294294    if (glue (audio_pcm_hw_alloc_resources_, TYPE) (hw)) {
     
    353353    sw = audio_calloc (AUDIO_FUNC, 1, sizeof (*sw));
    354354    if (!sw) {
    355 #if defined __STDC_VERSION__ && __STDC_VERSION__ > 199901L
    356355        dolog ("Could not allocate soft voice `%s' (%zu bytes)\n",
    357356               sw_name ? sw_name : "unknown", sizeof (*sw));
    358 #else
    359         dolog ("Could not allocate soft voice `%s' (%u bytes)\n",
    360                sw_name ? sw_name : "unknown", sizeof (*sw));
    361 #endif
    362357        goto err1;
    363358    }
  • trunk/src/VBox/Devices/Audio/mixeng.c

    r355 r6521  
    9292#undef SHIFT
    9393
     94/* Unsigned 16 bit */
    9495#define IN_T uint16_t
    9596#define IN_MIN 0
     
    111112#undef SHIFT
    112113
    113 t_sample *mixeng_conv[2][2][2][2] = {
     114/* Signed 32 bit */
     115#define IN_T int32_t
     116#define IN_MIN INT32_MIN
     117#define IN_MAX INT32_MAX
     118#define SIGNED
     119#define SHIFT 32
     120#define ENDIAN_CONVERSION natural
     121#define ENDIAN_CONVERT(v) (v)
     122#include "mixeng_template.h"
     123#undef ENDIAN_CONVERT
     124#undef ENDIAN_CONVERSION
     125#define ENDIAN_CONVERSION swap
     126#define ENDIAN_CONVERT(v) bswap32 (v)
     127#include "mixeng_template.h"
     128#undef ENDIAN_CONVERT
     129#undef ENDIAN_CONVERSION
     130#undef SIGNED
     131#undef IN_MAX
     132#undef IN_MIN
     133#undef IN_T
     134#undef SHIFT
     135
     136/* Unsigned 32 bit */
     137#define IN_T uint32_t
     138#define IN_MIN 0
     139#define IN_MAX UINT32_MAX
     140#define SHIFT 32
     141#define ENDIAN_CONVERSION natural
     142#define ENDIAN_CONVERT(v) (v)
     143#include "mixeng_template.h"
     144#undef ENDIAN_CONVERT
     145#undef ENDIAN_CONVERSION
     146#define ENDIAN_CONVERSION swap
     147#define ENDIAN_CONVERT(v) bswap32 (v)
     148#include "mixeng_template.h"
     149#undef ENDIAN_CONVERT
     150#undef ENDIAN_CONVERSION
     151#undef IN_MAX
     152#undef IN_MIN
     153#undef IN_T
     154#undef SHIFT
     155
     156t_sample *mixeng_conv[2][2][2][3] = {
    114157    {
    115158        {
    116159            {
    117160                conv_natural_uint8_t_to_mono,
    118                 conv_natural_uint16_t_to_mono
     161                conv_natural_uint16_t_to_mono,
     162                conv_natural_uint32_t_to_mono
    119163            },
    120164            {
    121165                conv_natural_uint8_t_to_mono,
    122                 conv_swap_uint16_t_to_mono
     166                conv_swap_uint16_t_to_mono,
     167                conv_swap_uint32_t_to_mono,
    123168            }
    124169        },
     
    126171            {
    127172                conv_natural_int8_t_to_mono,
    128                 conv_natural_int16_t_to_mono
     173                conv_natural_int16_t_to_mono,
     174                conv_natural_int32_t_to_mono
    129175            },
    130176            {
    131177                conv_natural_int8_t_to_mono,
    132                 conv_swap_int16_t_to_mono
     178                conv_swap_int16_t_to_mono,
     179                conv_swap_int32_t_to_mono
    133180            }
    134181        }
     
    138185            {
    139186                conv_natural_uint8_t_to_stereo,
    140                 conv_natural_uint16_t_to_stereo
     187                conv_natural_uint16_t_to_stereo,
     188                conv_natural_uint32_t_to_stereo
    141189            },
    142190            {
    143191                conv_natural_uint8_t_to_stereo,
    144                 conv_swap_uint16_t_to_stereo
     192                conv_swap_uint16_t_to_stereo,
     193                conv_swap_uint32_t_to_stereo
    145194            }
    146195        },
     
    148197            {
    149198                conv_natural_int8_t_to_stereo,
    150                 conv_natural_int16_t_to_stereo
     199                conv_natural_int16_t_to_stereo,
     200                conv_natural_int32_t_to_stereo
    151201            },
    152202            {
    153203                conv_natural_int8_t_to_stereo,
    154                 conv_swap_int16_t_to_stereo
     204                conv_swap_int16_t_to_stereo,
     205                conv_swap_int32_t_to_stereo,
    155206            }
    156207        }
     
    158209};
    159210
    160 f_sample *mixeng_clip[2][2][2][2] = {
     211f_sample *mixeng_clip[2][2][2][3] = {
    161212    {
    162213        {
    163214            {
    164215                clip_natural_uint8_t_from_mono,
    165                 clip_natural_uint16_t_from_mono
     216                clip_natural_uint16_t_from_mono,
     217                clip_natural_uint32_t_from_mono
    166218            },
    167219            {
    168220                clip_natural_uint8_t_from_mono,
    169                 clip_swap_uint16_t_from_mono
     221                clip_swap_uint16_t_from_mono,
     222                clip_swap_uint32_t_from_mono
    170223            }
    171224        },
     
    173226            {
    174227                clip_natural_int8_t_from_mono,
    175                 clip_natural_int16_t_from_mono
     228                clip_natural_int16_t_from_mono,
     229                clip_natural_int32_t_from_mono
    176230            },
    177231            {
    178232                clip_natural_int8_t_from_mono,
    179                 clip_swap_int16_t_from_mono
     233                clip_swap_int16_t_from_mono,
     234                clip_swap_int32_t_from_mono
    180235            }
    181236        }
     
    185240            {
    186241                clip_natural_uint8_t_from_stereo,
    187                 clip_natural_uint16_t_from_stereo
     242                clip_natural_uint16_t_from_stereo,
     243                clip_natural_uint32_t_from_stereo
    188244            },
    189245            {
    190246                clip_natural_uint8_t_from_stereo,
    191                 clip_swap_uint16_t_from_stereo
     247                clip_swap_uint16_t_from_stereo,
     248                clip_swap_uint32_t_from_stereo
    192249            }
    193250        },
     
    195252            {
    196253                clip_natural_int8_t_from_stereo,
    197                 clip_natural_int16_t_from_stereo
     254                clip_natural_int16_t_from_stereo,
     255                clip_natural_int32_t_from_stereo
    198256            },
    199257            {
    200258                clip_natural_int8_t_from_stereo,
    201                 clip_swap_int16_t_from_stereo
     259                clip_swap_int16_t_from_stereo,
     260                clip_swap_int32_t_from_stereo
    202261            }
    203262        }
  • trunk/src/VBox/Devices/Audio/mixeng.h

    r355 r6521  
    4646typedef void (f_sample) (void *dst, const st_sample_t *src, int samples);
    4747
    48 extern t_sample *mixeng_conv[2][2][2][2];
    49 extern f_sample *mixeng_clip[2][2][2][2];
     48extern t_sample *mixeng_conv[2][2][2][3];
     49extern f_sample *mixeng_clip[2][2][2][3];
    5050
    5151void *st_rate_start (int inrate, int outrate);
  • trunk/src/VBox/Devices/Audio/mixeng_template.h

    r355 r6521  
    3636#else
    3737#ifdef VBOX
    38 #ifdef SIGNED
    3938#define VOL(a, b) ((ASMMult2xS32RetS64(a, b) >> 31))
    40 #else
    41 #define VOL(a, b) ((ASMMult2xU32RetU64(a, b) >> 31))
    42 #endif
    4339#else /* !VBOX */
    4440#ifdef FLOAT_MIXENG
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette