diff options
Diffstat (limited to 'audio')
-rw-r--r-- | audio/alsaaudio.c | 14 | ||||
-rw-r--r-- | audio/audio.c | 46 | ||||
-rw-r--r-- | audio/audio.h | 15 | ||||
-rw-r--r-- | audio/audio_int.h | 14 | ||||
-rw-r--r-- | audio/audio_template.h | 21 | ||||
-rw-r--r-- | audio/coreaudio.c | 10 | ||||
-rw-r--r-- | audio/dsound_template.h | 4 | ||||
-rw-r--r-- | audio/fmodaudio.c | 8 | ||||
-rw-r--r-- | audio/noaudio.c | 4 | ||||
-rw-r--r-- | audio/ossaudio.c | 14 | ||||
-rw-r--r-- | audio/sdlaudio.c | 7 | ||||
-rw-r--r-- | audio/wavaudio.c | 3 | ||||
-rw-r--r-- | audio/wavcapture.c | 3 |
13 files changed, 70 insertions, 93 deletions
diff --git a/audio/alsaaudio.c b/audio/alsaaudio.c index 2cac396b26..71e5235664 100644 --- a/audio/alsaaudio.c +++ b/audio/alsaaudio.c @@ -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); diff --git a/audio/audio.c b/audio/audio.c index 0de728cc5f..dd86c4d7a7 100644 --- a/audio/audio.c +++ b/audio/audio.c @@ -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); diff --git a/audio/audio.h b/audio/audio.h index 4e1a694d07..14fa3bce96 100644 --- a/audio/audio.h +++ b/audio/audio.h @@ -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); diff --git a/audio/audio_int.h b/audio/audio_int.h index c01c16add6..f5dcb2c705 100644 --- a/audio/audio_int.h +++ b/audio/audio_int.h @@ -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 diff --git a/audio/audio_template.h b/audio/audio_template.h index 04b30239db..04b47befee 100644 --- a/audio/audio_template.h +++ b/audio/audio_template.h @@ -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; diff --git a/audio/coreaudio.c b/audio/coreaudio.c index 34e416d93a..8512f122b0 100644 --- a/audio/coreaudio.c +++ b/audio/coreaudio.c @@ -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); diff --git a/audio/dsound_template.h b/audio/dsound_template.h index 96f7cc7fa1..0896b04a03 100644 --- a/audio/dsound_template.h +++ b/audio/dsound_template.h @@ -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 ( diff --git a/audio/fmodaudio.c b/audio/fmodaudio.c index 23f267753f..5875ba15e1 100644 --- a/audio/fmodaudio.c +++ b/audio/fmodaudio.c @@ -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; diff --git a/audio/noaudio.c b/audio/noaudio.c index 314f6177ad..8fb15a224d 100644 --- a/audio/noaudio.c +++ b/audio/noaudio.c @@ -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; } diff --git a/audio/ossaudio.c b/audio/ossaudio.c index 0bdc8eaab1..125e4c8ff7 100644 --- a/audio/ossaudio.c +++ b/audio/ossaudio.c @@ -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; diff --git a/audio/sdlaudio.c b/audio/sdlaudio.c index 9fe212833f..f2a6896a52 100644 --- a/audio/sdlaudio.c +++ b/audio/sdlaudio.c @@ -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; diff --git a/audio/wavaudio.c b/audio/wavaudio.c index ca1e99f4ce..c359fc4f2b 100644 --- a/audio/wavaudio.c +++ b/audio/wavaudio.c @@ -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); diff --git a/audio/wavcapture.c b/audio/wavcapture.c index 33f04c50b3..7458a5e3e6 100644 --- a/audio/wavcapture.c +++ b/audio/wavcapture.c @@ -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); } |