Commit d929eba5 authored by bellard's avatar bellard

audio endianness API changes (malc)


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@2042 c046a42c-6fe2-441c-8c8c-71466251a162
parent 219fb125
......@@ -662,12 +662,9 @@ static int alsa_init_out (HWVoiceOut *hw, audsettings_t *as)
obt_as.freq = obt.freq;
obt_as.nchannels = obt.nchannels;
obt_as.fmt = effective_fmt;
obt_as.endianness = endianness;
audio_pcm_init_info (
&hw->info,
&obt_as,
audio_need_to_swap_endian (endianness)
);
audio_pcm_init_info (&hw->info, &obt_as);
hw->samples = obt.samples;
alsa->pcm_buf = audio_calloc (AUDIO_FUNC, obt.samples, 1 << hw->info.shift);
......@@ -751,12 +748,9 @@ static int alsa_init_in (HWVoiceIn *hw, audsettings_t *as)
obt_as.freq = obt.freq;
obt_as.nchannels = obt.nchannels;
obt_as.fmt = effective_fmt;
obt_as.endianness = endianness;
audio_pcm_init_info (
&hw->info,
&obt_as,
audio_need_to_swap_endian (endianness)
);
audio_pcm_init_info (&hw->info, &obt_as);
hw->samples = obt.samples;
alsa->pcm_buf = audio_calloc (AUDIO_FUNC, hw->samples, 1 << hw->info.shift);
......
......@@ -510,6 +510,18 @@ static void audio_print_settings (audsettings_t *as)
AUD_log (NULL, "invalid(%d)", as->fmt);
break;
}
AUD_log (NULL, "endianness=");
switch (as->endianness) {
case 0:
AUD_log (NULL, "little");
break;
case 1:
AUD_log (NULL, "big");
break;
default:
AUD_log (NULL, "invalid");
break;
}
AUD_log (NULL, "\n");
}
......@@ -518,6 +530,7 @@ static int audio_validate_settigs (audsettings_t *as)
int invalid;
invalid = as->nchannels != 1 && as->nchannels != 2;
invalid |= as->endianness != 0 && as->endianness != 1;
switch (as->fmt) {
case AUD_FMT_S8:
......@@ -531,11 +544,7 @@ static int audio_validate_settigs (audsettings_t *as)
}
invalid |= as->freq <= 0;
if (invalid) {
return -1;
}
return 0;
return invalid ? -1 : 0;
}
static int audio_pcm_info_eq (struct audio_pcm_info *info, audsettings_t *as)
......@@ -557,14 +566,11 @@ static int audio_pcm_info_eq (struct audio_pcm_info *info, audsettings_t *as)
return info->freq == as->freq
&& info->nchannels == as->nchannels
&& info->sign == sign
&& info->bits == bits;
&& info->bits == bits
&& info->swap_endianness == (as->endianness != AUDIO_HOST_ENDIANNESS);
}
void audio_pcm_init_info (
struct audio_pcm_info *info,
audsettings_t *as,
int swap_endian
)
void audio_pcm_init_info (struct audio_pcm_info *info, audsettings_t *as)
{
int bits = 8, sign = 0;
......@@ -588,7 +594,7 @@ void audio_pcm_init_info (
info->shift = (as->nchannels == 2) + (bits == 16);
info->align = (1 << info->shift) - 1;
info->bytes_per_second = info->freq << info->shift;
info->swap_endian = swap_endian;
info->swap_endianness = (as->endianness != AUDIO_HOST_ENDIANNESS);
}
void audio_pcm_info_clear_buf (struct audio_pcm_info *info, void *buf, int len)
......@@ -610,7 +616,7 @@ void audio_pcm_info_clear_buf (struct audio_pcm_info *info, void *buf, int len)
int shift = info->nchannels - 1;
short s = INT16_MAX;
if (info->swap_endian) {
if (info->swap_endianness) {
s = bswap16 (s);
}
......@@ -635,16 +641,13 @@ static void noop_conv (st_sample_t *dst, const void *src,
static CaptureVoiceOut *audio_pcm_capture_find_specific (
AudioState *s,
audsettings_t *as,
int endian
audsettings_t *as
)
{
CaptureVoiceOut *cap;
int swap_endian = audio_need_to_swap_endian (endian);
for (cap = s->cap_head.lh_first; cap; cap = cap->entries.le_next) {
if ((cap->hw.info.swap_endian == swap_endian)
&& audio_pcm_info_eq (&cap->hw.info, as)) {
if (audio_pcm_info_eq (&cap->hw.info, as)) {
return cap;
}
}
......@@ -1697,7 +1700,6 @@ AudioState *AUD_init (void)
int AUD_add_capture (
AudioState *s,
audsettings_t *as,
int endian,
struct audio_capture_ops *ops,
void *cb_opaque
)
......@@ -1725,7 +1727,7 @@ int AUD_add_capture (
cb->ops = *ops;
cb->opaque = cb_opaque;
cap = audio_pcm_capture_find_specific (s, as, endian);
cap = audio_pcm_capture_find_specific (s, as);
if (cap) {
LIST_INSERT_HEAD (&cap->cb_head, cb, entries);
return 0;
......@@ -1755,7 +1757,7 @@ int AUD_add_capture (
goto err2;
}
audio_pcm_init_info (&hw->info, as, endian);
audio_pcm_init_info (&hw->info, as);
cap->buf = audio_calloc (AUDIO_FUNC, hw->samples, 1 << hw->info.shift);
if (!cap->buf) {
......@@ -1768,7 +1770,7 @@ int AUD_add_capture (
hw->clip = mixeng_clip
[hw->info.nchannels == 2]
[hw->info.sign]
[hw->info.swap_endian]
[hw->info.swap_endianness]
[hw->info.bits == 16];
LIST_INSERT_HEAD (&s->cap_head, cap, entries);
......
......@@ -24,6 +24,7 @@
#ifndef QEMU_AUDIO_H
#define QEMU_AUDIO_H
#include "config.h"
#include "sys-queue.h"
typedef void (*audio_callback_fn_t) (void *opaque, int avail);
......@@ -35,10 +36,17 @@ typedef enum {
AUD_FMT_S16
} audfmt_e;
#ifdef WORDS_BIGENDIAN
#define AUDIO_HOST_ENDIANNESS 1
#else
#define AUDIO_HOST_ENDIANNESS 0
#endif
typedef struct {
int freq;
int nchannels;
audfmt_e fmt;
int endianness;
} audsettings_t;
struct audio_capture_ops {
......@@ -74,7 +82,6 @@ void AUD_remove_card (QEMUSoundCard *card);
int AUD_add_capture (
AudioState *s,
audsettings_t *as,
int endian,
struct audio_capture_ops *ops,
void *opaque
);
......@@ -85,8 +92,7 @@ SWVoiceOut *AUD_open_out (
const char *name,
void *callback_opaque,
audio_callback_fn_t callback_fn,
audsettings_t *settings,
int sw_endian
audsettings_t *settings
);
void AUD_close_out (QEMUSoundCard *card, SWVoiceOut *sw);
......@@ -104,8 +110,7 @@ SWVoiceIn *AUD_open_in (
const char *name,
void *callback_opaque,
audio_callback_fn_t callback_fn,
audsettings_t *settings,
int sw_endian
audsettings_t *settings
);
void AUD_close_in (QEMUSoundCard *card, SWVoiceIn *sw);
......
......@@ -61,7 +61,7 @@ struct audio_pcm_info {
int align;
int shift;
int bytes_per_second;
int swap_endian;
int swap_endianness;
};
typedef struct HWVoiceOut {
......@@ -198,8 +198,7 @@ extern struct audio_driver coreaudio_audio_driver;
extern struct audio_driver dsound_audio_driver;
extern volume_t nominal_volume;
void audio_pcm_init_info (struct audio_pcm_info *info, audsettings_t *as,
int swap_endian);
void audio_pcm_init_info (struct audio_pcm_info *info, audsettings_t *as);
void audio_pcm_info_clear_buf (struct audio_pcm_info *info, void *buf, int len);
int audio_pcm_sw_write (SWVoiceOut *sw, void *buf, int len);
......@@ -220,15 +219,6 @@ static inline int audio_ring_dist (int dst, int src, int len)
return (dst >= src) ? (dst - src) : (len - src + dst);
}
static inline int audio_need_to_swap_endian (int endianness)
{
#ifdef WORDS_BIGENDIAN
return endianness != 1;
#else
return endianness != 0;
#endif
}
#if defined __GNUC__
#define GCC_ATTR __attribute__ ((__unused__, __format__ (__printf__, 1, 2)))
#define INIT_FIELD(f) . f
......
......@@ -140,13 +140,12 @@ static int glue (audio_pcm_sw_init_, TYPE) (
SW *sw,
HW *hw,
const char *name,
audsettings_t *as,
int endian
audsettings_t *as
)
{
int err;
audio_pcm_init_info (&sw->info, as, audio_need_to_swap_endian (endian));
audio_pcm_init_info (&sw->info, as);
sw->hw = hw;
sw->active = 0;
#ifdef DAC
......@@ -164,7 +163,7 @@ static int glue (audio_pcm_sw_init_, TYPE) (
#endif
[sw->info.nchannels == 2]
[sw->info.sign]
[sw->info.swap_endian]
[sw->info.swap_endianness]
[sw->info.bits == 16];
sw->name = qemu_strdup (name);
......@@ -288,7 +287,7 @@ static HW *glue (audio_pcm_hw_add_new_, TYPE) (AudioState *s, audsettings_t *as)
#endif
[hw->info.nchannels == 2]
[hw->info.sign]
[hw->info.swap_endian]
[hw->info.swap_endianness]
[hw->info.bits == 16];
if (glue (audio_pcm_hw_alloc_resources_, TYPE) (hw)) {
......@@ -336,8 +335,7 @@ static HW *glue (audio_pcm_hw_add_, TYPE) (AudioState *s, audsettings_t *as)
static SW *glue (audio_pcm_create_voice_pair_, TYPE) (
AudioState *s,
const char *sw_name,
audsettings_t *as,
int sw_endian
audsettings_t *as
)
{
SW *sw;
......@@ -365,7 +363,7 @@ static SW *glue (audio_pcm_create_voice_pair_, TYPE) (
glue (audio_pcm_hw_add_sw_, TYPE) (hw, sw);
if (glue (audio_pcm_sw_init_, TYPE) (sw, hw, sw_name, as, sw_endian)) {
if (glue (audio_pcm_sw_init_, TYPE) (sw, hw, sw_name, as)) {
goto err3;
}
......@@ -407,8 +405,7 @@ SW *glue (AUD_open_, TYPE) (
const char *name,
void *callback_opaque ,
audio_callback_fn_t callback_fn,
audsettings_t *as,
int sw_endian
audsettings_t *as
)
{
AudioState *s;
......@@ -481,12 +478,12 @@ SW *glue (AUD_open_, TYPE) (
}
glue (audio_pcm_sw_fini_, TYPE) (sw);
if (glue (audio_pcm_sw_init_, TYPE) (sw, hw, name, as, sw_endian)) {
if (glue (audio_pcm_sw_init_, TYPE) (sw, hw, name, as)) {
goto fail;
}
}
else {
sw = glue (audio_pcm_create_voice_pair_, TYPE) (s, name, as, sw_endian);
sw = glue (audio_pcm_create_voice_pair_, TYPE) (s, name, as);
if (!sw) {
dolog ("Failed to create voice `%s'\n", name);
return NULL;
......
......@@ -295,7 +295,6 @@ static int coreaudio_init_out (HWVoiceOut *hw, audsettings_t *as)
UInt32 propertySize;
int err;
int bits = 8;
int endianess = 0;
const char *typ = "playback";
AudioValueRange frameRange;
......@@ -308,16 +307,9 @@ static int coreaudio_init_out (HWVoiceOut *hw, audsettings_t *as)
if (as->fmt == AUD_FMT_S16 || as->fmt == AUD_FMT_U16) {
bits = 16;
endianess = 1;
}
audio_pcm_init_info (
&hw->info,
as,
/* Following is irrelevant actually since we do not use
mixengs clipping routines */
audio_need_to_swap_endian (endianess)
);
audio_pcm_init_info (&hw->info, as);
/* open default output device */
propertySize = sizeof(core->outputDeviceID);
......
......@@ -250,8 +250,8 @@ static int dsound_init_out (HWVoiceOut *hw, audsettings_t *as)
}
ds->first_time = 1;
audio_pcm_init_info (&hw->info, &obt_as, audio_need_to_swap_endian (0));
obt_as.endianness = 0;
audio_pcm_init_info (&hw->info, &obt_as);
if (bc.dwBufferBytes & hw->info.align) {
dolog (
......
......@@ -358,6 +358,7 @@ static int fmod_init_out (HWVoiceOut *hw, audsettings_t *as)
{
int bits16, mode, channel;
FMODVoiceOut *fmd = (FMODVoiceOut *) hw;
audsettings_t obt_as = *as;
mode = aud_to_fmodfmt (as->fmt, as->nchannels == 2 ? 1 : 0);
fmd->fmod_sample = FSOUND_Sample_Alloc (
......@@ -384,7 +385,8 @@ static int fmod_init_out (HWVoiceOut *hw, audsettings_t *as)
fmd->channel = channel;
/* FMOD always operates on little endian frames? */
audio_pcm_init_info (&hw->info, as, audio_need_to_swap_endian (0));
obt_as.endianness = 0;
audio_pcm_init_info (&hw->info, &obt_as);
bits16 = (mode & FSOUND_16BITS) != 0;
hw->samples = conf.nb_samples;
return 0;
......@@ -418,6 +420,7 @@ static int fmod_init_in (HWVoiceIn *hw, audsettings_t *as)
{
int bits16, mode;
FMODVoiceIn *fmd = (FMODVoiceIn *) hw;
audsettings_t obt_as = *as;
if (conf.broken_adc) {
return -1;
......@@ -440,7 +443,8 @@ static int fmod_init_in (HWVoiceIn *hw, audsettings_t *as)
}
/* FMOD always operates on little endian frames? */
audio_pcm_init_info (&hw->info, as, audio_need_to_swap_endian (0));
obt_as.endianness = 0;
audio_pcm_init_info (&hw->info, &obt_as);
bits16 = (mode & FSOUND_16BITS) != 0;
hw->samples = conf.nb_samples;
return 0;
......
......@@ -68,7 +68,7 @@ static int no_write (SWVoiceOut *sw, void *buf, int len)
static int no_init_out (HWVoiceOut *hw, audsettings_t *as)
{
audio_pcm_init_info (&hw->info, as, 0);
audio_pcm_init_info (&hw->info, as);
hw->samples = 1024;
return 0;
}
......@@ -87,7 +87,7 @@ static int no_ctl_out (HWVoiceOut *hw, int cmd, ...)
static int no_init_in (HWVoiceIn *hw, audsettings_t *as)
{
audio_pcm_init_info (&hw->info, as, 0);
audio_pcm_init_info (&hw->info, as);
hw->samples = 1024;
return 0;
}
......
......@@ -453,12 +453,9 @@ static int oss_init_out (HWVoiceOut *hw, audsettings_t *as)
obt_as.freq = obt.freq;
obt_as.nchannels = obt.nchannels;
obt_as.fmt = effective_fmt;
obt_as.endianness = endianness;
audio_pcm_init_info (
&hw->info,
&obt_as,
audio_need_to_swap_endian (endianness)
);
audio_pcm_init_info (&hw->info, &obt_as);
oss->nfrags = obt.nfrags;
oss->fragsize = obt.fragsize;
......@@ -597,12 +594,9 @@ static int oss_init_in (HWVoiceIn *hw, audsettings_t *as)
obt_as.freq = obt.freq;
obt_as.nchannels = obt.nchannels;
obt_as.fmt = effective_fmt;
obt_as.endianness = endianness;
audio_pcm_init_info (
&hw->info,
&obt_as,
audio_need_to_swap_endian (endianness)
);
audio_pcm_init_info (&hw->info, &obt_as);
oss->nfrags = obt.nfrags;
oss->fragsize = obt.fragsize;
......
......@@ -335,12 +335,9 @@ static int sdl_init_out (HWVoiceOut *hw, audsettings_t *as)
obt_as.freq = obt.freq;
obt_as.nchannels = obt.channels;
obt_as.fmt = effective_fmt;
obt_as.endianness = endianess;
audio_pcm_init_info (
&hw->info,
&obt_as,
audio_need_to_swap_endian (endianess)
);
audio_pcm_init_info (&hw->info, &obt_as);
hw->samples = obt.samples;
s->initialized = 1;
......
......@@ -135,7 +135,8 @@ static int wav_init_out (HWVoiceOut *hw, audsettings_t *as)
hdr[34] = bits16 ? 0x10 : 0x08;
audio_pcm_init_info (&hw->info, &wav_as, audio_need_to_swap_endian (0));
wav_as.endianness = 0;
audio_pcm_init_info (&hw->info, &wav_as);
hw->samples = 1024;
wav->pcm_buf = audio_calloc (AUDIO_FUNC, hw->samples, 1 << hw->info.shift);
......
......@@ -70,6 +70,7 @@ void wav_capture (const char *path, int freq, int bits16, int stereo)
as.freq = freq;
as.nchannels = 1 << stereo;
as.fmt = bits16 ? AUD_FMT_S16 : AUD_FMT_U8;
as.endianness = 0;
ops.state = wav_state_cb;
ops.capture = wav_capture_cb;
......@@ -97,5 +98,5 @@ void wav_capture (const char *path, int freq, int bits16, int stereo)
}
qemu_put_buffer (wav->f, hdr, sizeof (hdr));
AUD_add_capture (NULL, &as, 0, &ops, wav);
AUD_add_capture (NULL, &as, &ops, wav);
}
......@@ -301,6 +301,7 @@ int Adlib_init (AudioState *audio)
as.freq = conf.freq;
as.nchannels = SHIFT;
as.fmt = AUD_FMT_S16;
as.endianness = AUDIO_HOST_ENDIANNESS;
AUD_register_card (audio, "adlib", &s->card);
......@@ -310,8 +311,7 @@ int Adlib_init (AudioState *audio)
"adlib",
s,
adlib_callback,
&as,
0 /* XXX: little endian? */
&as
);
if (!s->voice) {
Adlib_fini (s);
......
......@@ -423,6 +423,7 @@ static void es1370_update_voices (ES1370State *s, uint32_t ctl, uint32_t sctl)
as.freq = new_freq;
as.nchannels = 1 << (new_fmt & 1);
as.fmt = (new_fmt & 2) ? AUD_FMT_S16 : AUD_FMT_U8;
as.endianness = 0;
if (i == ADC_CHANNEL) {
s->adc_voice =
......@@ -432,8 +433,7 @@ static void es1370_update_voices (ES1370State *s, uint32_t ctl, uint32_t sctl)
"es1370.adc",
s,
es1370_adc_callback,
&as,
0 /* little endian */
&as
);
}
else {
......@@ -444,8 +444,7 @@ static void es1370_update_voices (ES1370State *s, uint32_t ctl, uint32_t sctl)
i ? "es1370.dac2" : "es1370.dac1",
s,
i ? es1370_dac2_callback : es1370_dac1_callback,
&as,
0 /* litle endian */
&as
);
}
}
......
......@@ -95,7 +95,7 @@ static void pcspk_callback(void *opaque, int free)
int pcspk_audio_init(AudioState *audio)
{
PCSpkState *s = &pcspk_state;
audsettings_t as = {PCSPK_SAMPLE_RATE, 1, AUD_FMT_U8};
audsettings_t as = {PCSPK_SAMPLE_RATE, 1, AUD_FMT_U8, 0};
if (!audio) {
AUD_log(s_spk, "No audio state\n");
......@@ -103,7 +103,7 @@ int pcspk_audio_init(AudioState *audio)
}
AUD_register_card(audio, s_spk, &s->card);
s->voice = AUD_open_out(&s->card, s->voice, s_spk, s, pcspk_callback, &as, 0);
s->voice = AUD_open_out(&s->card, s->voice, s_spk, s, pcspk_callback, &as);
if (!s->voice) {
AUD_log(s_spk, "Could not open voice\n");
return -1;
......
......@@ -203,6 +203,7 @@ static void continue_dma8 (SB16State *s)
as.freq = s->freq;
as.nchannels = 1 << s->fmt_stereo;
as.fmt = s->fmt;
as.endianness = 0;
s->voice = AUD_open_out (
&s->card,
......@@ -210,8 +211,7 @@ static void continue_dma8 (SB16State *s)
"sb16",
s,
SB_audio_callback,
&as,
0 /* little endian */
&as
);
}
......@@ -348,6 +348,7 @@ static void dma_cmd (SB16State *s, uint8_t cmd, uint8_t d0, int dma_len)
as.freq = s->freq;
as.nchannels = 1 << s->fmt_stereo;
as.fmt = s->fmt;
as.endianness = 0;
s->voice = AUD_open_out (
&s->card,
......@@ -355,8 +356,7 @@ static void dma_cmd (SB16State *s, uint8_t cmd, uint8_t d0, int dma_len)
"sb16",
s,
SB_audio_callback,
&as,
0 /* little endian */
&as
);
}
......@@ -838,6 +838,7 @@ static void legacy_reset (SB16State *s)
as.freq = s->freq;
as.nchannels = 1;
as.fmt = AUD_FMT_U8;
as.endianness = 0;
s->voice = AUD_open_out (
&s->card,
......@@ -845,8 +846,7 @@ static void legacy_reset (SB16State *s)
"sb16",
s,
SB_audio_callback,
&as,
0 /* little endian */
&as
);
/* Not sure about that... */
......@@ -1371,6 +1371,7 @@ static int SB_load (QEMUFile *f, void *opaque, int version_id)
as.freq = s->freq;
as.nchannels = 1 << s->fmt_stereo;
as.fmt = s->fmt;
as.endianness = 0;
s->voice = AUD_open_out (
&s->card,
......@@ -1378,8 +1379,7 @@ static int SB_load (QEMUFile *f, void *opaque, int version_id)
"sb16",
s,
SB_audio_callback,
&as,
0 /* little endian */
&as
);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment