Commit 85bc5852 authored by Kővágó, Zoltán's avatar Kővágó, Zoltán Committed by Gerd Hoffmann
Browse files

audio: use qapi AudioFormat instead of audfmt_e



I had to include an enum for audio sampling formats into qapi, but that
meant duplicating the audfmt_e enum.  This patch replaces audfmt_e and
associated values with the qapi generated AudioFormat enum.

This patch is mostly a search-and-replace, except for switches where the
qapi generated AUDIO_FORMAT_MAX caused problems.

Signed-off-by: default avatarKővágó, Zoltán <DirtY.iCE.hu@gmail.com>
Reviewed-by: default avatarThomas Huth <thuth@redhat.com>
Message-id: 01251b2758a1679c66842120b77c0fb46d7d0eaf.1552083282.git.DirtY.iCE.hu@gmail.com
Signed-off-by: default avatarGerd Hoffmann <kraxel@redhat.com>
parent 8c3a7d00
Loading
Loading
Loading
Loading
+28 −25
Original line number Diff line number Diff line
@@ -87,7 +87,7 @@ struct alsa_params_req {

struct alsa_params_obt {
    int freq;
    audfmt_e fmt;
    AudioFormat fmt;
    int endianness;
    int nchannels;
    snd_pcm_uframes_t samples;
@@ -294,16 +294,16 @@ static int alsa_write (SWVoiceOut *sw, void *buf, int len)
    return audio_pcm_sw_write (sw, buf, len);
}

static snd_pcm_format_t aud_to_alsafmt (audfmt_e fmt, int endianness)
static snd_pcm_format_t aud_to_alsafmt (AudioFormat fmt, int endianness)
{
    switch (fmt) {
    case AUD_FMT_S8:
    case AUDIO_FORMAT_S8:
        return SND_PCM_FORMAT_S8;

    case AUD_FMT_U8:
    case AUDIO_FORMAT_U8:
        return SND_PCM_FORMAT_U8;

    case AUD_FMT_S16:
    case AUDIO_FORMAT_S16:
        if (endianness) {
            return SND_PCM_FORMAT_S16_BE;
        }
@@ -311,7 +311,7 @@ static snd_pcm_format_t aud_to_alsafmt (audfmt_e fmt, int endianness)
            return SND_PCM_FORMAT_S16_LE;
        }

    case AUD_FMT_U16:
    case AUDIO_FORMAT_U16:
        if (endianness) {
            return SND_PCM_FORMAT_U16_BE;
        }
@@ -319,7 +319,7 @@ static snd_pcm_format_t aud_to_alsafmt (audfmt_e fmt, int endianness)
            return SND_PCM_FORMAT_U16_LE;
        }

    case AUD_FMT_S32:
    case AUDIO_FORMAT_S32:
        if (endianness) {
            return SND_PCM_FORMAT_S32_BE;
        }
@@ -327,7 +327,7 @@ static snd_pcm_format_t aud_to_alsafmt (audfmt_e fmt, int endianness)
            return SND_PCM_FORMAT_S32_LE;
        }

    case AUD_FMT_U32:
    case AUDIO_FORMAT_U32:
        if (endianness) {
            return SND_PCM_FORMAT_U32_BE;
        }
@@ -344,58 +344,58 @@ static snd_pcm_format_t aud_to_alsafmt (audfmt_e fmt, int endianness)
    }
}

static int alsa_to_audfmt (snd_pcm_format_t alsafmt, audfmt_e *fmt,
static int alsa_to_audfmt (snd_pcm_format_t alsafmt, AudioFormat *fmt,
                           int *endianness)
{
    switch (alsafmt) {
    case SND_PCM_FORMAT_S8:
        *endianness = 0;
        *fmt = AUD_FMT_S8;
        *fmt = AUDIO_FORMAT_S8;
        break;

    case SND_PCM_FORMAT_U8:
        *endianness = 0;
        *fmt = AUD_FMT_U8;
        *fmt = AUDIO_FORMAT_U8;
        break;

    case SND_PCM_FORMAT_S16_LE:
        *endianness = 0;
        *fmt = AUD_FMT_S16;
        *fmt = AUDIO_FORMAT_S16;
        break;

    case SND_PCM_FORMAT_U16_LE:
        *endianness = 0;
        *fmt = AUD_FMT_U16;
        *fmt = AUDIO_FORMAT_U16;
        break;

    case SND_PCM_FORMAT_S16_BE:
        *endianness = 1;
        *fmt = AUD_FMT_S16;
        *fmt = AUDIO_FORMAT_S16;
        break;

    case SND_PCM_FORMAT_U16_BE:
        *endianness = 1;
        *fmt = AUD_FMT_U16;
        *fmt = AUDIO_FORMAT_U16;
        break;

    case SND_PCM_FORMAT_S32_LE:
        *endianness = 0;
        *fmt = AUD_FMT_S32;
        *fmt = AUDIO_FORMAT_S32;
        break;

    case SND_PCM_FORMAT_U32_LE:
        *endianness = 0;
        *fmt = AUD_FMT_U32;
        *fmt = AUDIO_FORMAT_U32;
        break;

    case SND_PCM_FORMAT_S32_BE:
        *endianness = 1;
        *fmt = AUD_FMT_S32;
        *fmt = AUDIO_FORMAT_S32;
        break;

    case SND_PCM_FORMAT_U32_BE:
        *endianness = 1;
        *fmt = AUD_FMT_U32;
        *fmt = AUDIO_FORMAT_U32;
        break;

    default:
@@ -638,19 +638,22 @@ static int alsa_open (int in, struct alsa_params_req *req,
        bytes_per_sec = freq << (nchannels == 2);

        switch (obt->fmt) {
        case AUD_FMT_S8:
        case AUD_FMT_U8:
        case AUDIO_FORMAT_S8:
        case AUDIO_FORMAT_U8:
            break;

        case AUD_FMT_S16:
        case AUD_FMT_U16:
        case AUDIO_FORMAT_S16:
        case AUDIO_FORMAT_U16:
            bytes_per_sec <<= 1;
            break;

        case AUD_FMT_S32:
        case AUD_FMT_U32:
        case AUDIO_FORMAT_S32:
        case AUDIO_FORMAT_U32:
            bytes_per_sec <<= 2;
            break;

        default:
            abort();
        }

        threshold = (conf->threshold * bytes_per_sec) / 1000;
+53 −44
Original line number Diff line number Diff line
@@ -113,7 +113,7 @@ static struct {
        .settings = {
            .freq = 44100,
            .nchannels = 2,
            .fmt = AUD_FMT_S16,
            .fmt = AUDIO_FORMAT_S16,
            .endianness =  AUDIO_HOST_ENDIANNESS,
        }
    },
@@ -125,7 +125,7 @@ static struct {
        .settings = {
            .freq = 44100,
            .nchannels = 2,
            .fmt = AUD_FMT_S16,
            .fmt = AUDIO_FORMAT_S16,
            .endianness = AUDIO_HOST_ENDIANNESS,
        }
    },
@@ -257,58 +257,61 @@ static char *audio_alloc_prefix (const char *s)
    return r;
}

static const char *audio_audfmt_to_string (audfmt_e fmt)
static const char *audio_audfmt_to_string (AudioFormat fmt)
{
    switch (fmt) {
    case AUD_FMT_U8:
    case AUDIO_FORMAT_U8:
        return "U8";

    case AUD_FMT_U16:
    case AUDIO_FORMAT_U16:
        return "U16";

    case AUD_FMT_S8:
    case AUDIO_FORMAT_S8:
        return "S8";

    case AUD_FMT_S16:
    case AUDIO_FORMAT_S16:
        return "S16";

    case AUD_FMT_U32:
    case AUDIO_FORMAT_U32:
        return "U32";

    case AUD_FMT_S32:
    case AUDIO_FORMAT_S32:
        return "S32";

    default:
        abort();
    }

    dolog ("Bogus audfmt %d returning S16\n", fmt);
    return "S16";
}

static audfmt_e audio_string_to_audfmt (const char *s, audfmt_e defval,
static AudioFormat audio_string_to_audfmt (const char *s, AudioFormat defval,
                                        int *defaultp)
{
    if (!strcasecmp (s, "u8")) {
        *defaultp = 0;
        return AUD_FMT_U8;
        return AUDIO_FORMAT_U8;
    }
    else if (!strcasecmp (s, "u16")) {
        *defaultp = 0;
        return AUD_FMT_U16;
        return AUDIO_FORMAT_U16;
    }
    else if (!strcasecmp (s, "u32")) {
        *defaultp = 0;
        return AUD_FMT_U32;
        return AUDIO_FORMAT_U32;
    }
    else if (!strcasecmp (s, "s8")) {
        *defaultp = 0;
        return AUD_FMT_S8;
        return AUDIO_FORMAT_S8;
    }
    else if (!strcasecmp (s, "s16")) {
        *defaultp = 0;
        return AUD_FMT_S16;
        return AUDIO_FORMAT_S16;
    }
    else if (!strcasecmp (s, "s32")) {
        *defaultp = 0;
        return AUD_FMT_S32;
        return AUDIO_FORMAT_S32;
    }
    else {
        dolog ("Bogus audio format `%s' using %s\n",
@@ -318,8 +321,8 @@ static audfmt_e audio_string_to_audfmt (const char *s, audfmt_e defval,
    }
}

static audfmt_e audio_get_conf_fmt (const char *envname,
                                    audfmt_e defval,
static AudioFormat audio_get_conf_fmt (const char *envname,
                                    AudioFormat defval,
                                    int *defaultp)
{
    const char *var = getenv (envname);
@@ -421,7 +424,7 @@ static void audio_print_options (const char *prefix,

        case AUD_OPT_FMT:
            {
                audfmt_e *fmtp = opt->valp;
                AudioFormat *fmtp = opt->valp;
                printf (
                    "format, %s = %s, (one of: U8 S8 U16 S16 U32 S32)\n",
                    state,
@@ -492,7 +495,7 @@ static void audio_process_options (const char *prefix,

        case AUD_OPT_FMT:
            {
                audfmt_e *fmtp = opt->valp;
                AudioFormat *fmtp = opt->valp;
                *fmtp = audio_get_conf_fmt (optname, *fmtp, &def);
            }
            break;
@@ -524,22 +527,22 @@ static void audio_print_settings (struct audsettings *as)
    dolog ("frequency=%d nchannels=%d fmt=", as->freq, as->nchannels);

    switch (as->fmt) {
    case AUD_FMT_S8:
    case AUDIO_FORMAT_S8:
        AUD_log (NULL, "S8");
        break;
    case AUD_FMT_U8:
    case AUDIO_FORMAT_U8:
        AUD_log (NULL, "U8");
        break;
    case AUD_FMT_S16:
    case AUDIO_FORMAT_S16:
        AUD_log (NULL, "S16");
        break;
    case AUD_FMT_U16:
    case AUDIO_FORMAT_U16:
        AUD_log (NULL, "U16");
        break;
    case AUD_FMT_S32:
    case AUDIO_FORMAT_S32:
        AUD_log (NULL, "S32");
        break;
    case AUD_FMT_U32:
    case AUDIO_FORMAT_U32:
        AUD_log (NULL, "U32");
        break;
    default:
@@ -570,12 +573,12 @@ static int audio_validate_settings (struct audsettings *as)
    invalid |= as->endianness != 0 && as->endianness != 1;

    switch (as->fmt) {
    case AUD_FMT_S8:
    case AUD_FMT_U8:
    case AUD_FMT_S16:
    case AUD_FMT_U16:
    case AUD_FMT_S32:
    case AUD_FMT_U32:
    case AUDIO_FORMAT_S8:
    case AUDIO_FORMAT_U8:
    case AUDIO_FORMAT_S16:
    case AUDIO_FORMAT_U16:
    case AUDIO_FORMAT_S32:
    case AUDIO_FORMAT_U32:
        break;
    default:
        invalid = 1;
@@ -591,25 +594,28 @@ static int audio_pcm_info_eq (struct audio_pcm_info *info, struct audsettings *a
    int bits = 8, sign = 0;

    switch (as->fmt) {
    case AUD_FMT_S8:
    case AUDIO_FORMAT_S8:
        sign = 1;
        /* fall through */
    case AUD_FMT_U8:
    case AUDIO_FORMAT_U8:
        break;

    case AUD_FMT_S16:
    case AUDIO_FORMAT_S16:
        sign = 1;
        /* fall through */
    case AUD_FMT_U16:
    case AUDIO_FORMAT_U16:
        bits = 16;
        break;

    case AUD_FMT_S32:
    case AUDIO_FORMAT_S32:
        sign = 1;
        /* fall through */
    case AUD_FMT_U32:
    case AUDIO_FORMAT_U32:
        bits = 32;
        break;

    default:
        abort();
    }
    return info->freq == as->freq
        && info->nchannels == as->nchannels
@@ -623,24 +629,27 @@ void audio_pcm_init_info (struct audio_pcm_info *info, struct audsettings *as)
    int bits = 8, sign = 0, shift = 0;

    switch (as->fmt) {
    case AUD_FMT_S8:
    case AUDIO_FORMAT_S8:
        sign = 1;
    case AUD_FMT_U8:
    case AUDIO_FORMAT_U8:
        break;

    case AUD_FMT_S16:
    case AUDIO_FORMAT_S16:
        sign = 1;
    case AUD_FMT_U16:
    case AUDIO_FORMAT_U16:
        bits = 16;
        shift = 1;
        break;

    case AUD_FMT_S32:
    case AUDIO_FORMAT_S32:
        sign = 1;
    case AUD_FMT_U32:
    case AUDIO_FORMAT_U32:
        bits = 32;
        shift = 2;
        break;

    default:
        abort();
    }

    info->freq = as->freq;
+2 −10
Original line number Diff line number Diff line
@@ -26,18 +26,10 @@
#define QEMU_AUDIO_H

#include "qemu/queue.h"
#include "qapi/qapi-types-audio.h"

typedef void (*audio_callback_fn) (void *opaque, int avail);

typedef enum {
    AUD_FMT_U8,
    AUD_FMT_S8,
    AUD_FMT_U16,
    AUD_FMT_S16,
    AUD_FMT_U32,
    AUD_FMT_S32
} audfmt_e;

#ifdef HOST_WORDS_BIGENDIAN
#define AUDIO_HOST_ENDIANNESS 1
#else
@@ -47,7 +39,7 @@ typedef enum {
struct audsettings {
    int freq;
    int nchannels;
    audfmt_e fmt;
    AudioFormat fmt;
    int endianness;
};

+9 −9
Original line number Diff line number Diff line
@@ -24,20 +24,20 @@ int waveformat_from_audio_settings (WAVEFORMATEX *wfx,
    wfx->cbSize = 0;

    switch (as->fmt) {
    case AUD_FMT_S8:
    case AUD_FMT_U8:
    case AUDIO_FORMAT_S8:
    case AUDIO_FORMAT_U8:
        wfx->wBitsPerSample = 8;
        break;

    case AUD_FMT_S16:
    case AUD_FMT_U16:
    case AUDIO_FORMAT_S16:
    case AUDIO_FORMAT_U16:
        wfx->wBitsPerSample = 16;
        wfx->nAvgBytesPerSec <<= 1;
        wfx->nBlockAlign <<= 1;
        break;

    case AUD_FMT_S32:
    case AUD_FMT_U32:
    case AUDIO_FORMAT_S32:
    case AUDIO_FORMAT_U32:
        wfx->wBitsPerSample = 32;
        wfx->nAvgBytesPerSec <<= 2;
        wfx->nBlockAlign <<= 2;
@@ -85,15 +85,15 @@ int waveformat_to_audio_settings (WAVEFORMATEX *wfx,

    switch (wfx->wBitsPerSample) {
    case 8:
        as->fmt = AUD_FMT_U8;
        as->fmt = AUDIO_FORMAT_U8;
        break;

    case 16:
        as->fmt = AUD_FMT_S16;
        as->fmt = AUDIO_FORMAT_S16;
        break;

    case 32:
        as->fmt = AUD_FMT_S32;
        as->fmt = AUDIO_FORMAT_S32;
        break;

    default:
+15 −15
Original line number Diff line number Diff line
@@ -70,7 +70,7 @@ typedef struct OSSVoiceIn {

struct oss_params {
    int freq;
    audfmt_e fmt;
    AudioFormat fmt;
    int nchannels;
    int nfrags;
    int fragsize;
@@ -148,16 +148,16 @@ static int oss_write (SWVoiceOut *sw, void *buf, int len)
    return audio_pcm_sw_write (sw, buf, len);
}

static int aud_to_ossfmt (audfmt_e fmt, int endianness)
static int aud_to_ossfmt (AudioFormat fmt, int endianness)
{
    switch (fmt) {
    case AUD_FMT_S8:
    case AUDIO_FORMAT_S8:
        return AFMT_S8;

    case AUD_FMT_U8:
    case AUDIO_FORMAT_U8:
        return AFMT_U8;

    case AUD_FMT_S16:
    case AUDIO_FORMAT_S16:
        if (endianness) {
            return AFMT_S16_BE;
        }
@@ -165,7 +165,7 @@ static int aud_to_ossfmt (audfmt_e fmt, int endianness)
            return AFMT_S16_LE;
        }

    case AUD_FMT_U16:
    case AUDIO_FORMAT_U16:
        if (endianness) {
            return AFMT_U16_BE;
        }
@@ -182,37 +182,37 @@ static int aud_to_ossfmt (audfmt_e fmt, int endianness)
    }
}

static int oss_to_audfmt (int ossfmt, audfmt_e *fmt, int *endianness)
static int oss_to_audfmt (int ossfmt, AudioFormat *fmt, int *endianness)
{
    switch (ossfmt) {
    case AFMT_S8:
        *endianness = 0;
        *fmt = AUD_FMT_S8;
        *fmt = AUDIO_FORMAT_S8;
        break;

    case AFMT_U8:
        *endianness = 0;
        *fmt = AUD_FMT_U8;
        *fmt = AUDIO_FORMAT_U8;
        break;

    case AFMT_S16_LE:
        *endianness = 0;
        *fmt = AUD_FMT_S16;
        *fmt = AUDIO_FORMAT_S16;
        break;

    case AFMT_U16_LE:
        *endianness = 0;
        *fmt = AUD_FMT_U16;
        *fmt = AUDIO_FORMAT_U16;
        break;

    case AFMT_S16_BE:
        *endianness = 1;
        *fmt = AUD_FMT_S16;
        *fmt = AUDIO_FORMAT_S16;
        break;

    case AFMT_U16_BE:
        *endianness = 1;
        *fmt = AUD_FMT_U16;
        *fmt = AUDIO_FORMAT_U16;
        break;

    default:
@@ -500,7 +500,7 @@ static int oss_init_out(HWVoiceOut *hw, struct audsettings *as,
    int endianness;
    int err;
    int fd;
    audfmt_e effective_fmt;
    AudioFormat effective_fmt;
    struct audsettings obt_as;
    OSSConf *conf = drv_opaque;

@@ -667,7 +667,7 @@ static int oss_init_in(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque)
    int endianness;
    int err;
    int fd;
    audfmt_e effective_fmt;
    AudioFormat effective_fmt;
    struct audsettings obt_as;
    OSSConf *conf = drv_opaque;

Loading