mirror of
https://github.com/izzy2lost/xemu.git
synced 2026-07-06 00:20:22 -07:00
merged 15a_aqemu.patch audio patch (malc)
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@1584 c046a42c-6fe2-441c-8c8c-71466251a162
This commit is contained in:
@@ -1,3 +1,10 @@
|
|||||||
|
version 0.7.3:
|
||||||
|
|
||||||
|
- Mac OS X cocoa improvements (Mike Kronenberg)
|
||||||
|
- DirectSound driver (malc)
|
||||||
|
- new audio options: '-soundhw' and 'audio-help' (malc)
|
||||||
|
- ES1370 PCI audio device (malc)
|
||||||
|
|
||||||
version 0.7.2:
|
version 0.7.2:
|
||||||
|
|
||||||
- x86_64 fixes (Win2000 and Linux 2.6 boot in 32 bit)
|
- x86_64 fixes (Win2000 and Linux 2.6 boot in 32 bit)
|
||||||
|
|||||||
+33
-10
@@ -262,7 +262,7 @@ endif
|
|||||||
VL_OBJS=vl.o osdep.o block.o readline.o monitor.o pci.o console.o
|
VL_OBJS=vl.o osdep.o block.o readline.o monitor.o pci.o console.o
|
||||||
VL_OBJS+=block-cow.o block-qcow.o aes.o block-vmdk.o block-cloop.o block-dmg.o block-bochs.o block-vpc.o block-vvfat.o
|
VL_OBJS+=block-cow.o block-qcow.o aes.o block-vmdk.o block-cloop.o block-dmg.o block-bochs.o block-vpc.o block-vvfat.o
|
||||||
|
|
||||||
SOUND_HW = sb16.o
|
SOUND_HW = sb16.o es1370.o
|
||||||
AUDIODRV = audio.o noaudio.o wavaudio.o
|
AUDIODRV = audio.o noaudio.o wavaudio.o
|
||||||
ifdef CONFIG_SDL
|
ifdef CONFIG_SDL
|
||||||
AUDIODRV += sdlaudio.o
|
AUDIODRV += sdlaudio.o
|
||||||
@@ -270,29 +270,38 @@ endif
|
|||||||
ifdef CONFIG_OSS
|
ifdef CONFIG_OSS
|
||||||
AUDIODRV += ossaudio.o
|
AUDIODRV += ossaudio.o
|
||||||
endif
|
endif
|
||||||
|
ifdef CONFIG_COREAUDIO
|
||||||
pc.o: DEFINES := -DUSE_SB16 $(DEFINES)
|
AUDIODRV += coreaudio.o
|
||||||
|
endif
|
||||||
ifdef CONFIG_ADLIB
|
ifdef CONFIG_ALSA
|
||||||
SOUND_HW += fmopl.o adlib.o
|
AUDIODRV += alsaaudio.o
|
||||||
|
LIBS += -lasound
|
||||||
|
endif
|
||||||
|
ifdef CONFIG_DSOUND
|
||||||
|
AUDIODRV += dsoundaudio.o
|
||||||
|
LIBS += -lole32 -ldxguid
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifdef CONFIG_FMOD
|
ifdef CONFIG_FMOD
|
||||||
AUDIODRV += fmodaudio.o
|
AUDIODRV += fmodaudio.o
|
||||||
audio.o fmodaudio.o: DEFINES := -I$(CONFIG_FMOD_INC) $(DEFINES)
|
audio.o fmodaudio.o: DEFINES := -I$(CONFIG_FMOD_INC) $(DEFINES)
|
||||||
LIBS += $(CONFIG_FMOD_LIB)
|
LIBS += $(CONFIG_FMOD_LIB)
|
||||||
endif
|
endif
|
||||||
|
ifdef CONFIG_ADLIB
|
||||||
|
SOUND_HW += fmopl.o adlib.o
|
||||||
|
endif
|
||||||
|
|
||||||
ifeq ($(TARGET_BASE_ARCH), i386)
|
ifeq ($(TARGET_BASE_ARCH), i386)
|
||||||
# Hardware support
|
# Hardware support
|
||||||
VL_OBJS+= ide.o ne2000.o pckbd.o vga.o $(SOUND_HW) dma.o $(AUDIODRV)
|
VL_OBJS+= ide.o ne2000.o pckbd.o vga.o $(SOUND_HW) dma.o $(AUDIODRV)
|
||||||
VL_OBJS+= fdc.o mc146818rtc.o serial.o i8259.o i8254.o pc.o
|
VL_OBJS+= fdc.o mc146818rtc.o serial.o i8259.o i8254.o pc.o
|
||||||
VL_OBJS+= cirrus_vga.o mixeng.o apic.o parallel.o
|
VL_OBJS+= cirrus_vga.o mixeng.o apic.o parallel.o
|
||||||
|
DEFINES += -DHAS_AUDIO
|
||||||
endif
|
endif
|
||||||
ifeq ($(TARGET_BASE_ARCH), ppc)
|
ifeq ($(TARGET_BASE_ARCH), ppc)
|
||||||
VL_OBJS+= ppc.o ide.o ne2000.o pckbd.o vga.o $(SOUND_HW) dma.o $(AUDIODRV)
|
VL_OBJS+= ppc.o ide.o ne2000.o pckbd.o vga.o $(SOUND_HW) dma.o $(AUDIODRV)
|
||||||
VL_OBJS+= mc146818rtc.o serial.o i8259.o i8254.o fdc.o m48t59.o
|
VL_OBJS+= mc146818rtc.o serial.o i8259.o i8254.o fdc.o m48t59.o
|
||||||
VL_OBJS+= ppc_prep.o ppc_chrp.o cuda.o adb.o openpic.o heathrow_pic.o mixeng.o
|
VL_OBJS+= ppc_prep.o ppc_chrp.o cuda.o adb.o openpic.o heathrow_pic.o mixeng.o
|
||||||
|
DEFINES += -DHAS_AUDIO
|
||||||
endif
|
endif
|
||||||
ifeq ($(TARGET_ARCH), mips)
|
ifeq ($(TARGET_ARCH), mips)
|
||||||
VL_OBJS+= mips_r4k.o dma.o vga.o serial.o ne2000.o i8254.o i8259.o
|
VL_OBJS+= mips_r4k.o dma.o vga.o serial.o ne2000.o i8254.o i8259.o
|
||||||
@@ -317,7 +326,10 @@ VL_OBJS+=sdl.o
|
|||||||
endif
|
endif
|
||||||
ifdef CONFIG_COCOA
|
ifdef CONFIG_COCOA
|
||||||
VL_OBJS+=cocoa.o
|
VL_OBJS+=cocoa.o
|
||||||
COCOA_LIBS=-F/System/Library/Frameworks -framework Cocoa
|
COCOA_LIBS=-F/System/Library/Frameworks -framework Cocoa -framework IOKit
|
||||||
|
ifdef CONFIG_COREAUDIO
|
||||||
|
COCOA_LIBS+=-framework CoreAudio
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
ifdef CONFIG_SLIRP
|
ifdef CONFIG_SLIRP
|
||||||
DEFINES+=-I$(SRC_PATH)/slirp
|
DEFINES+=-I$(SRC_PATH)/slirp
|
||||||
@@ -349,6 +361,10 @@ ifeq ($(ARCH),ia64)
|
|||||||
VL_LDFLAGS+=-Wl,-G0 -Wl,-T,$(SRC_PATH)/ia64.ld
|
VL_LDFLAGS+=-Wl,-G0 -Wl,-T,$(SRC_PATH)/ia64.ld
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifdef CONFIG_WIN32
|
||||||
|
SDL_LIBS := $(filter-out -mwindows, $(SDL_LIBS)) -mconsole
|
||||||
|
endif
|
||||||
|
|
||||||
$(QEMU_SYSTEM): $(VL_OBJS) libqemu.a
|
$(QEMU_SYSTEM): $(VL_OBJS) libqemu.a
|
||||||
$(CC) $(VL_LDFLAGS) -o $@ $^ $(LIBS) $(SDL_LIBS) $(COCOA_LIBS) $(VL_LIBS)
|
$(CC) $(VL_LDFLAGS) -o $@ $^ $(LIBS) $(SDL_LIBS) $(COCOA_LIBS) $(VL_LIBS)
|
||||||
|
|
||||||
@@ -364,6 +380,9 @@ sdlaudio.o: sdlaudio.c
|
|||||||
depend: $(SRCS)
|
depend: $(SRCS)
|
||||||
$(CC) -MM $(CFLAGS) $(DEFINES) $^ 1>.depend
|
$(CC) -MM $(CFLAGS) $(DEFINES) $^ 1>.depend
|
||||||
|
|
||||||
|
vldepend: $(VL_OBJS:.o=.c)
|
||||||
|
$(CC) -MM $(CFLAGS) $(DEFINES) $^ 1>.depend
|
||||||
|
|
||||||
# libqemu
|
# libqemu
|
||||||
|
|
||||||
libqemu.a: $(LIBOBJS)
|
libqemu.a: $(LIBOBJS)
|
||||||
@@ -415,8 +434,6 @@ op.o: op.c op_template.c op_mem.c
|
|||||||
op_helper.o: op_helper_mem.c
|
op_helper.o: op_helper_mem.c
|
||||||
endif
|
endif
|
||||||
|
|
||||||
mixeng.o: mixeng.c mixeng.h mixeng_template.h
|
|
||||||
|
|
||||||
%.o: %.c
|
%.o: %.c
|
||||||
$(CC) $(CFLAGS) $(DEFINES) -c -o $@ $<
|
$(CC) $(CFLAGS) $(DEFINES) -c -o $@ $<
|
||||||
|
|
||||||
@@ -434,3 +451,9 @@ endif
|
|||||||
ifneq ($(wildcard .depend),)
|
ifneq ($(wildcard .depend),)
|
||||||
include .depend
|
include .depend
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifeq (0, 1)
|
||||||
|
audio.o sdlaudio.o dsoundaudio.o ossaudio.o wavaudio.o noaudio.o \
|
||||||
|
fmodaudio.o alsaaudio.o mixeng.o: \
|
||||||
|
CFLAGS := $(CFLAGS) -Wall -Werror -W -Wsign-compare
|
||||||
|
endif
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
+1370
-626
File diff suppressed because it is too large
Load Diff
+68
-16
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* QEMU Audio subsystem header
|
* QEMU Audio subsystem header
|
||||||
*
|
*
|
||||||
* Copyright (c) 2003-2004 Vassili Karpov (malc)
|
* Copyright (c) 2003-2005 Vassili Karpov (malc)
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -24,7 +24,7 @@
|
|||||||
#ifndef QEMU_AUDIO_H
|
#ifndef QEMU_AUDIO_H
|
||||||
#define QEMU_AUDIO_H
|
#define QEMU_AUDIO_H
|
||||||
|
|
||||||
#include "mixeng.h"
|
typedef void (*audio_callback_fn_t) (void *opaque, int avail);
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
AUD_FMT_U8,
|
AUD_FMT_U8,
|
||||||
@@ -33,22 +33,60 @@ typedef enum {
|
|||||||
AUD_FMT_S16
|
AUD_FMT_S16
|
||||||
} audfmt_e;
|
} audfmt_e;
|
||||||
|
|
||||||
typedef struct SWVoice SWVoice;
|
typedef struct SWVoiceOut SWVoiceOut;
|
||||||
|
typedef struct SWVoiceIn SWVoiceIn;
|
||||||
|
|
||||||
SWVoice * AUD_open (SWVoice *sw, const char *name, int freq,
|
typedef struct QEMUAudioTimeStamp {
|
||||||
int nchannels, audfmt_e fmt);
|
uint64_t old_ts;
|
||||||
void AUD_init (void);
|
} QEMUAudioTimeStamp;
|
||||||
|
|
||||||
|
void AUD_vlog (const char *cap, const char *fmt, va_list ap);
|
||||||
void AUD_log (const char *cap, const char *fmt, ...)
|
void AUD_log (const char *cap, const char *fmt, ...)
|
||||||
__attribute__ ((__format__ (__printf__, 2, 3)));;
|
#ifdef __GNUC__
|
||||||
void AUD_close (SWVoice *sw);
|
__attribute__ ((__format__ (__printf__, 2, 3)))
|
||||||
int AUD_write (SWVoice *sw, void *pcm_buf, int size);
|
#endif
|
||||||
void AUD_adjust (SWVoice *sw, int leftover);
|
;
|
||||||
void AUD_reset (SWVoice *sw);
|
|
||||||
int AUD_get_free (SWVoice *sw);
|
void AUD_init (void);
|
||||||
int AUD_get_buffer_size (SWVoice *sw);
|
void AUD_help (void);
|
||||||
void AUD_run (void);
|
|
||||||
void AUD_enable (SWVoice *sw, int on);
|
SWVoiceOut *AUD_open_out (
|
||||||
int AUD_calc_elapsed (SWVoice *sw);
|
SWVoiceOut *sw,
|
||||||
|
const char *name,
|
||||||
|
void *callback_opaque,
|
||||||
|
audio_callback_fn_t callback_fn,
|
||||||
|
int freq,
|
||||||
|
int nchannels,
|
||||||
|
audfmt_e fmt
|
||||||
|
);
|
||||||
|
void AUD_close_out (SWVoiceOut *sw);
|
||||||
|
int AUD_write (SWVoiceOut *sw, void *pcm_buf, int size);
|
||||||
|
int AUD_get_buffer_size_out (SWVoiceOut *sw);
|
||||||
|
void AUD_set_active_out (SWVoiceOut *sw, int on);
|
||||||
|
int AUD_is_active_out (SWVoiceOut *sw);
|
||||||
|
void AUD_init_time_stamp_out (SWVoiceOut *sw,
|
||||||
|
QEMUAudioTimeStamp *ts);
|
||||||
|
uint64_t AUD_time_stamp_get_elapsed_usec_out (SWVoiceOut *sw,
|
||||||
|
QEMUAudioTimeStamp *ts);
|
||||||
|
|
||||||
|
SWVoiceIn *AUD_open_in (
|
||||||
|
SWVoiceIn *sw,
|
||||||
|
const char *name,
|
||||||
|
void *callback_opaque,
|
||||||
|
audio_callback_fn_t callback_fn,
|
||||||
|
int freq,
|
||||||
|
int nchannels,
|
||||||
|
audfmt_e fmt
|
||||||
|
);
|
||||||
|
void AUD_close_in (SWVoiceIn *sw);
|
||||||
|
int AUD_read (SWVoiceIn *sw, void *pcm_buf, int size);
|
||||||
|
void AUD_adjust_in (SWVoiceIn *sw, int leftover);
|
||||||
|
void AUD_set_active_in (SWVoiceIn *sw, int on);
|
||||||
|
int AUD_is_active_in (SWVoiceIn *sw);
|
||||||
|
void AUD_init_time_stamp_in (SWVoiceIn *sw,
|
||||||
|
QEMUAudioTimeStamp *ts);
|
||||||
|
uint64_t AUD_time_stamp_get_elapsed_usec_in (SWVoiceIn *sw,
|
||||||
|
QEMUAudioTimeStamp *ts);
|
||||||
|
|
||||||
static inline void *advance (void *p, int incr)
|
static inline void *advance (void *p, int incr)
|
||||||
{
|
{
|
||||||
@@ -59,7 +97,21 @@ static inline void *advance (void *p, int incr)
|
|||||||
uint32_t popcount (uint32_t u);
|
uint32_t popcount (uint32_t u);
|
||||||
inline uint32_t lsbindex (uint32_t u);
|
inline uint32_t lsbindex (uint32_t u);
|
||||||
|
|
||||||
|
#ifdef __GNUC__
|
||||||
|
#define audio_MIN(a, b) ( __extension__ ({ \
|
||||||
|
__typeof (a) ta = a; \
|
||||||
|
__typeof (b) tb = b; \
|
||||||
|
((ta)>(tb)?(tb):(ta)); \
|
||||||
|
}))
|
||||||
|
|
||||||
|
#define audio_MAX(a, b) ( __extension__ ({ \
|
||||||
|
__typeof (a) ta = a; \
|
||||||
|
__typeof (b) tb = b; \
|
||||||
|
((ta)<(tb)?(tb):(ta)); \
|
||||||
|
}))
|
||||||
|
#else
|
||||||
#define audio_MIN(a, b) ((a)>(b)?(b):(a))
|
#define audio_MIN(a, b) ((a)>(b)?(b):(a))
|
||||||
#define audio_MAX(a, b) ((a)<(b)?(b):(a))
|
#define audio_MAX(a, b) ((a)<(b)?(b):(a))
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* audio.h */
|
#endif /* audio.h */
|
||||||
|
|||||||
+227
-101
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* QEMU Audio subsystem header
|
* QEMU Audio subsystem header
|
||||||
*
|
*
|
||||||
* Copyright (c) 2003-2004 Vassili Karpov (malc)
|
* Copyright (c) 2003-2005 Vassili Karpov (malc)
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -24,140 +24,266 @@
|
|||||||
#ifndef QEMU_AUDIO_INT_H
|
#ifndef QEMU_AUDIO_INT_H
|
||||||
#define QEMU_AUDIO_INT_H
|
#define QEMU_AUDIO_INT_H
|
||||||
|
|
||||||
#include "vl.h"
|
#include "sys-queue.h"
|
||||||
|
|
||||||
struct pcm_ops;
|
#ifdef CONFIG_COREAUDIO
|
||||||
|
#define FLOAT_MIXENG
|
||||||
|
/* #define RECIPROCAL */
|
||||||
|
#endif
|
||||||
|
#include "mixeng.h"
|
||||||
|
|
||||||
typedef struct HWVoice {
|
int audio_bug (const char *funcname, int cond);
|
||||||
|
|
||||||
|
struct audio_pcm_ops;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
AUD_OPT_INT,
|
||||||
|
AUD_OPT_FMT,
|
||||||
|
AUD_OPT_STR,
|
||||||
|
AUD_OPT_BOOL
|
||||||
|
} audio_option_tag_e;
|
||||||
|
|
||||||
|
struct audio_option {
|
||||||
|
const char *name;
|
||||||
|
audio_option_tag_e tag;
|
||||||
|
void *valp;
|
||||||
|
const char *descr;
|
||||||
|
int *overridenp;
|
||||||
|
int overriden;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct audio_callback {
|
||||||
|
void *opaque;
|
||||||
|
audio_callback_fn_t fn;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct audio_pcm_info {
|
||||||
|
int bits;
|
||||||
|
int sign;
|
||||||
|
int freq;
|
||||||
|
int nchannels;
|
||||||
|
int align;
|
||||||
|
int shift;
|
||||||
|
int bytes_per_second;
|
||||||
|
int swap_endian;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct HWVoiceOut {
|
||||||
int active;
|
int active;
|
||||||
int enabled;
|
int enabled;
|
||||||
int pending_disable;
|
int pending_disable;
|
||||||
int valid;
|
int valid;
|
||||||
int freq;
|
struct audio_pcm_info info;
|
||||||
|
|
||||||
f_sample *clip;
|
f_sample *clip;
|
||||||
audfmt_e fmt;
|
|
||||||
int nchannels;
|
|
||||||
|
|
||||||
int align;
|
|
||||||
int shift;
|
|
||||||
|
|
||||||
int rpos;
|
int rpos;
|
||||||
int bufsize;
|
int bufsize;
|
||||||
|
uint64_t ts_helper;
|
||||||
|
|
||||||
int bytes_per_second;
|
|
||||||
st_sample_t *mix_buf;
|
st_sample_t *mix_buf;
|
||||||
|
|
||||||
int samples;
|
int samples;
|
||||||
int64_t old_ticks;
|
LIST_HEAD (sw_out_listhead, SWVoiceOut) sw_head;
|
||||||
int nb_voices;
|
struct audio_pcm_ops *pcm_ops;
|
||||||
struct SWVoice **pvoice;
|
LIST_ENTRY (HWVoiceOut) entries;
|
||||||
struct pcm_ops *pcm_ops;
|
} HWVoiceOut;
|
||||||
} HWVoice;
|
|
||||||
|
|
||||||
extern struct pcm_ops no_pcm_ops;
|
typedef struct HWVoiceIn {
|
||||||
extern struct audio_output_driver no_output_driver;
|
int enabled;
|
||||||
|
int active;
|
||||||
extern struct pcm_ops oss_pcm_ops;
|
struct audio_pcm_info info;
|
||||||
extern struct audio_output_driver oss_output_driver;
|
|
||||||
|
|
||||||
extern struct pcm_ops sdl_pcm_ops;
|
|
||||||
extern struct audio_output_driver sdl_output_driver;
|
|
||||||
|
|
||||||
extern struct pcm_ops wav_pcm_ops;
|
|
||||||
extern struct audio_output_driver wav_output_driver;
|
|
||||||
|
|
||||||
extern struct pcm_ops fmod_pcm_ops;
|
|
||||||
extern struct audio_output_driver fmod_output_driver;
|
|
||||||
|
|
||||||
struct audio_output_driver {
|
|
||||||
const char *name;
|
|
||||||
void *(*init) (void);
|
|
||||||
void (*fini) (void *);
|
|
||||||
struct pcm_ops *pcm_ops;
|
|
||||||
int can_be_default;
|
|
||||||
int max_voices;
|
|
||||||
int voice_size;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct AudioState {
|
|
||||||
int fixed_format;
|
|
||||||
int fixed_freq;
|
|
||||||
int fixed_channels;
|
|
||||||
int fixed_fmt;
|
|
||||||
int nb_hw_voices;
|
|
||||||
int64_t ticks_threshold;
|
|
||||||
int freq_threshold;
|
|
||||||
void *opaque;
|
|
||||||
struct audio_output_driver *drv;
|
|
||||||
} AudioState;
|
|
||||||
extern AudioState audio_state;
|
|
||||||
|
|
||||||
struct SWVoice {
|
|
||||||
int freq;
|
|
||||||
audfmt_e fmt;
|
|
||||||
int nchannels;
|
|
||||||
|
|
||||||
int shift;
|
|
||||||
int align;
|
|
||||||
|
|
||||||
t_sample *conv;
|
t_sample *conv;
|
||||||
|
|
||||||
int left;
|
int wpos;
|
||||||
int pos;
|
int bufsize;
|
||||||
int bytes_per_second;
|
int total_samples_captured;
|
||||||
|
uint64_t ts_helper;
|
||||||
|
|
||||||
|
st_sample_t *conv_buf;
|
||||||
|
|
||||||
|
int samples;
|
||||||
|
LIST_HEAD (sw_in_listhead, SWVoiceIn) sw_head;
|
||||||
|
struct audio_pcm_ops *pcm_ops;
|
||||||
|
LIST_ENTRY (HWVoiceIn) entries;
|
||||||
|
} HWVoiceIn;
|
||||||
|
|
||||||
|
extern struct audio_driver no_audio_driver;
|
||||||
|
extern struct audio_driver oss_audio_driver;
|
||||||
|
extern struct audio_driver sdl_audio_driver;
|
||||||
|
extern struct audio_driver wav_audio_driver;
|
||||||
|
extern struct audio_driver fmod_audio_driver;
|
||||||
|
extern struct audio_driver alsa_audio_driver;
|
||||||
|
extern struct audio_driver coreaudio_audio_driver;
|
||||||
|
extern struct audio_driver dsound_audio_driver;
|
||||||
|
extern volume_t nominal_volume;
|
||||||
|
|
||||||
|
struct audio_driver {
|
||||||
|
const char *name;
|
||||||
|
const char *descr;
|
||||||
|
struct audio_option *options;
|
||||||
|
void *(*init) (void);
|
||||||
|
void (*fini) (void *);
|
||||||
|
struct audio_pcm_ops *pcm_ops;
|
||||||
|
int can_be_default;
|
||||||
|
int max_voices_out;
|
||||||
|
int max_voices_in;
|
||||||
|
int voice_size_out;
|
||||||
|
int voice_size_in;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct AudioState {
|
||||||
|
int fixed_settings_out;
|
||||||
|
int fixed_freq_out;
|
||||||
|
int fixed_channels_out;
|
||||||
|
int fixed_fmt_out;
|
||||||
|
int nb_hw_voices_out;
|
||||||
|
int greedy_out;
|
||||||
|
|
||||||
|
int fixed_settings_in;
|
||||||
|
int fixed_freq_in;
|
||||||
|
int fixed_channels_in;
|
||||||
|
int fixed_fmt_in;
|
||||||
|
int nb_hw_voices_in;
|
||||||
|
int greedy_in;
|
||||||
|
|
||||||
|
void *opaque;
|
||||||
|
struct audio_driver *drv;
|
||||||
|
|
||||||
|
QEMUTimer *ts;
|
||||||
|
union {
|
||||||
|
int usec;
|
||||||
|
int64_t ticks;
|
||||||
|
} period;
|
||||||
|
|
||||||
|
int plive;
|
||||||
|
} AudioState;
|
||||||
|
extern AudioState audio_state;
|
||||||
|
|
||||||
|
struct SWVoiceOut {
|
||||||
|
struct audio_pcm_info info;
|
||||||
|
t_sample *conv;
|
||||||
int64_t ratio;
|
int64_t ratio;
|
||||||
st_sample_t *buf;
|
st_sample_t *buf;
|
||||||
void *rate;
|
void *rate;
|
||||||
|
int total_hw_samples_mixed;
|
||||||
int wpos;
|
|
||||||
int live;
|
|
||||||
int active;
|
int active;
|
||||||
int64_t old_ticks;
|
int empty;
|
||||||
HWVoice *hw;
|
HWVoiceOut *hw;
|
||||||
char *name;
|
char *name;
|
||||||
|
volume_t vol;
|
||||||
|
struct audio_callback callback;
|
||||||
|
LIST_ENTRY (SWVoiceOut) entries;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct pcm_ops {
|
struct SWVoiceIn {
|
||||||
int (*init) (HWVoice *hw, int freq, int nchannels, audfmt_e fmt);
|
int active;
|
||||||
void (*fini) (HWVoice *hw);
|
struct audio_pcm_info info;
|
||||||
void (*run) (HWVoice *hw);
|
int64_t ratio;
|
||||||
int (*write) (SWVoice *sw, void *buf, int size);
|
void *rate;
|
||||||
int (*ctl) (HWVoice *hw, int cmd, ...);
|
int total_hw_samples_acquired;
|
||||||
|
st_sample_t *conv_buf;
|
||||||
|
f_sample *clip;
|
||||||
|
HWVoiceIn *hw;
|
||||||
|
char *name;
|
||||||
|
volume_t vol;
|
||||||
|
struct audio_callback callback;
|
||||||
|
LIST_ENTRY (SWVoiceIn) entries;
|
||||||
};
|
};
|
||||||
|
|
||||||
void pcm_sw_free_resources (SWVoice *sw);
|
struct audio_pcm_ops {
|
||||||
int pcm_sw_alloc_resources (SWVoice *sw);
|
int (*init_out)(HWVoiceOut *hw, int freq, int nchannels, audfmt_e fmt);
|
||||||
void pcm_sw_fini (SWVoice *sw);
|
void (*fini_out)(HWVoiceOut *hw);
|
||||||
int pcm_sw_init (SWVoice *sw, HWVoice *hw, int freq,
|
int (*run_out) (HWVoiceOut *hw);
|
||||||
int nchannels, audfmt_e fmt);
|
int (*write) (SWVoiceOut *sw, void *buf, int size);
|
||||||
|
int (*ctl_out) (HWVoiceOut *hw, int cmd, ...);
|
||||||
|
|
||||||
void pcm_hw_clear (HWVoice *hw, void *buf, int len);
|
int (*init_in) (HWVoiceIn *hw, int freq, int nchannels, audfmt_e fmt);
|
||||||
HWVoice * pcm_hw_find_any (HWVoice *hw);
|
void (*fini_in) (HWVoiceIn *hw);
|
||||||
HWVoice * pcm_hw_find_any_active (HWVoice *hw);
|
int (*run_in) (HWVoiceIn *hw);
|
||||||
HWVoice * pcm_hw_find_any_passive (HWVoice *hw);
|
int (*read) (SWVoiceIn *sw, void *buf, int size);
|
||||||
HWVoice * pcm_hw_find_specific (HWVoice *hw, int freq,
|
int (*ctl_in) (HWVoiceIn *hw, int cmd, ...);
|
||||||
int nchannels, audfmt_e fmt);
|
};
|
||||||
HWVoice * pcm_hw_add (int freq, int nchannels, audfmt_e fmt);
|
|
||||||
int pcm_hw_add_sw (HWVoice *hw, SWVoice *sw);
|
|
||||||
int pcm_hw_del_sw (HWVoice *hw, SWVoice *sw);
|
|
||||||
SWVoice * pcm_create_voice_pair (int freq, int nchannels, audfmt_e fmt);
|
|
||||||
|
|
||||||
void pcm_hw_free_resources (HWVoice *hw);
|
void audio_pcm_init_info (struct audio_pcm_info *info, int freq,
|
||||||
int pcm_hw_alloc_resources (HWVoice *hw);
|
int nchannels, audfmt_e fmt, int swap_endian);
|
||||||
void pcm_hw_fini (HWVoice *hw);
|
void audio_pcm_info_clear_buf (struct audio_pcm_info *info, void *buf, int len);
|
||||||
void pcm_hw_gc (HWVoice *hw);
|
|
||||||
int pcm_hw_get_live (HWVoice *hw);
|
|
||||||
int pcm_hw_get_live2 (HWVoice *hw, int *nb_active);
|
|
||||||
void pcm_hw_dec_live (HWVoice *hw, int decr);
|
|
||||||
int pcm_hw_write (SWVoice *sw, void *buf, int len);
|
|
||||||
|
|
||||||
int audio_get_conf_int (const char *key, int defval);
|
int audio_pcm_sw_write (SWVoiceOut *sw, void *buf, int len);
|
||||||
const char *audio_get_conf_str (const char *key, const char *defval);
|
int audio_pcm_hw_get_live_in (HWVoiceIn *hw);
|
||||||
|
|
||||||
struct audio_output_driver;
|
int audio_pcm_sw_read (SWVoiceIn *sw, void *buf, int len);
|
||||||
|
int audio_pcm_hw_get_live_out (HWVoiceOut *hw);
|
||||||
|
int audio_pcm_hw_get_live_out2 (HWVoiceOut *hw, int *nb_live);
|
||||||
|
|
||||||
#define VOICE_ENABLE 1
|
#define VOICE_ENABLE 1
|
||||||
#define VOICE_DISABLE 2
|
#define VOICE_DISABLE 2
|
||||||
|
|
||||||
|
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
|
||||||
|
#define GCC_FMT_ATTR(n, m) __attribute__ ((__format__ (printf, n, m)))
|
||||||
|
#else
|
||||||
|
#define GCC_ATTR /**/
|
||||||
|
#define INIT_FIELD(f) /**/
|
||||||
|
#define GCC_FMT_ATTR(n, m)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static void GCC_ATTR dolog (const char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
|
||||||
|
va_start (ap, fmt);
|
||||||
|
AUD_vlog (AUDIO_CAP, fmt, ap);
|
||||||
|
va_end (ap);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
static void GCC_ATTR ldebug (const char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
|
||||||
|
va_start (ap, fmt);
|
||||||
|
AUD_vlog (AUDIO_CAP, fmt, ap);
|
||||||
|
va_end (ap);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
#if defined NDEBUG && defined __GNUC__
|
||||||
|
#define ldebug(...)
|
||||||
|
#elif defined NDEBUG && defined _MSC_VER
|
||||||
|
#define ldebug __noop
|
||||||
|
#else
|
||||||
|
static void GCC_ATTR ldebug (const char *fmt, ...)
|
||||||
|
{
|
||||||
|
(void) fmt;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#undef GCC_ATTR
|
||||||
|
|
||||||
|
#define AUDIO_STRINGIFY_(n) #n
|
||||||
|
#define AUDIO_STRINGIFY(n) AUDIO_STRINGIFY_(n)
|
||||||
|
|
||||||
|
#if defined _MSC_VER || defined __GNUC__
|
||||||
|
#define AUDIO_FUNC __FUNCTION__
|
||||||
|
#else
|
||||||
|
#define AUDIO_FUNC __FILE__ ":" AUDIO_STRINGIFY (__LINE__)
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* audio_int.h */
|
#endif /* audio_int.h */
|
||||||
|
|||||||
@@ -0,0 +1,401 @@
|
|||||||
|
/*
|
||||||
|
* QEMU Audio subsystem header
|
||||||
|
*
|
||||||
|
* Copyright (c) 2005 Vassili Karpov (malc)
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||||
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef DAC
|
||||||
|
#define TYPE out
|
||||||
|
#define HW glue (HWVoice, Out)
|
||||||
|
#define SW glue (SWVoice, Out)
|
||||||
|
#else
|
||||||
|
#define TYPE in
|
||||||
|
#define HW glue (HWVoice, In)
|
||||||
|
#define SW glue (SWVoice, In)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static void glue (audio_pcm_sw_fini_, TYPE) (SW *sw)
|
||||||
|
{
|
||||||
|
glue (audio_pcm_sw_free_resources_, TYPE) (sw);
|
||||||
|
if (sw->name) {
|
||||||
|
qemu_free (sw->name);
|
||||||
|
sw->name = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void glue (audio_pcm_hw_add_sw_, TYPE) (HW *hw, SW *sw)
|
||||||
|
{
|
||||||
|
LIST_INSERT_HEAD (&hw->sw_head, sw, entries);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void glue (audio_pcm_hw_del_sw_, TYPE) (SW *sw)
|
||||||
|
{
|
||||||
|
LIST_REMOVE (sw, entries);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void glue (audio_pcm_hw_fini_, TYPE) (HW *hw)
|
||||||
|
{
|
||||||
|
if (hw->active) {
|
||||||
|
glue (audio_pcm_hw_free_resources_ ,TYPE) (hw);
|
||||||
|
glue (hw->pcm_ops->fini_, TYPE) (hw);
|
||||||
|
memset (hw, 0, glue (audio_state.drv->voice_size_, TYPE));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void glue (audio_pcm_hw_gc_, TYPE) (HW *hw)
|
||||||
|
{
|
||||||
|
if (!hw->sw_head.lh_first) {
|
||||||
|
glue (audio_pcm_hw_fini_, TYPE) (hw);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static HW *glue (audio_pcm_hw_find_any_, TYPE) (HW *hw)
|
||||||
|
{
|
||||||
|
return hw ? hw->entries.le_next : glue (hw_head_, TYPE).lh_first;
|
||||||
|
}
|
||||||
|
|
||||||
|
static HW *glue (audio_pcm_hw_find_any_active_, TYPE) (HW *hw)
|
||||||
|
{
|
||||||
|
while ((hw = glue (audio_pcm_hw_find_any_, TYPE) (hw))) {
|
||||||
|
if (hw->active) {
|
||||||
|
return hw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static HW *glue (audio_pcm_hw_find_any_active_enabled_, TYPE) (HW *hw)
|
||||||
|
{
|
||||||
|
while ((hw = glue (audio_pcm_hw_find_any_, TYPE) (hw))) {
|
||||||
|
if (hw->active && hw->enabled) {
|
||||||
|
return hw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static HW *glue (audio_pcm_hw_find_any_passive_, TYPE) (HW *hw)
|
||||||
|
{
|
||||||
|
while ((hw = glue (audio_pcm_hw_find_any_, TYPE) (hw))) {
|
||||||
|
if (!hw->active) {
|
||||||
|
return hw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static HW *glue (audio_pcm_hw_find_specific_, TYPE) (
|
||||||
|
HW *hw,
|
||||||
|
int freq,
|
||||||
|
int nchannels,
|
||||||
|
audfmt_e fmt
|
||||||
|
)
|
||||||
|
{
|
||||||
|
while ((hw = glue (audio_pcm_hw_find_any_active_, TYPE) (hw))) {
|
||||||
|
if (audio_pcm_info_eq (&hw->info, freq, nchannels, fmt)) {
|
||||||
|
return hw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static HW *glue (audio_pcm_hw_add_new_, TYPE) (
|
||||||
|
int freq,
|
||||||
|
int nchannels,
|
||||||
|
audfmt_e fmt
|
||||||
|
)
|
||||||
|
{
|
||||||
|
HW *hw;
|
||||||
|
|
||||||
|
hw = glue (audio_pcm_hw_find_any_passive_, TYPE) (NULL);
|
||||||
|
if (hw) {
|
||||||
|
hw->pcm_ops = audio_state.drv->pcm_ops;
|
||||||
|
if (!hw->pcm_ops) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (glue (audio_pcm_hw_init_, TYPE) (hw, freq, nchannels, fmt)) {
|
||||||
|
glue (audio_pcm_hw_gc_, TYPE) (hw);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return hw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static HW *glue (audio_pcm_hw_add_, TYPE) (
|
||||||
|
int freq,
|
||||||
|
int nchannels,
|
||||||
|
audfmt_e fmt
|
||||||
|
)
|
||||||
|
{
|
||||||
|
HW *hw;
|
||||||
|
|
||||||
|
if (glue (audio_state.greedy_, TYPE)) {
|
||||||
|
hw = glue (audio_pcm_hw_add_new_, TYPE) (freq, nchannels, fmt);
|
||||||
|
if (hw) {
|
||||||
|
return hw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
hw = glue (audio_pcm_hw_find_specific_, TYPE) (NULL, freq, nchannels, fmt);
|
||||||
|
if (hw) {
|
||||||
|
return hw;
|
||||||
|
}
|
||||||
|
|
||||||
|
hw = glue (audio_pcm_hw_add_new_, TYPE) (freq, nchannels, fmt);
|
||||||
|
if (hw) {
|
||||||
|
return hw;
|
||||||
|
}
|
||||||
|
|
||||||
|
return glue (audio_pcm_hw_find_any_active_, TYPE) (NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
static SW *glue (audio_pcm_create_voice_pair_, TYPE) (
|
||||||
|
const char *name,
|
||||||
|
int freq,
|
||||||
|
int nchannels,
|
||||||
|
audfmt_e fmt
|
||||||
|
)
|
||||||
|
{
|
||||||
|
SW *sw;
|
||||||
|
HW *hw;
|
||||||
|
int hw_freq = freq;
|
||||||
|
int hw_nchannels = nchannels;
|
||||||
|
int hw_fmt = fmt;
|
||||||
|
|
||||||
|
if (glue (audio_state.fixed_settings_, TYPE)) {
|
||||||
|
hw_freq = glue (audio_state.fixed_freq_, TYPE);
|
||||||
|
hw_nchannels = glue (audio_state.fixed_channels_, TYPE);
|
||||||
|
hw_fmt = glue (audio_state.fixed_fmt_, TYPE);
|
||||||
|
}
|
||||||
|
|
||||||
|
sw = qemu_mallocz (sizeof (*sw));
|
||||||
|
if (!sw) {
|
||||||
|
goto err1;
|
||||||
|
}
|
||||||
|
|
||||||
|
hw = glue (audio_pcm_hw_add_, TYPE) (hw_freq, hw_nchannels, hw_fmt);
|
||||||
|
if (!hw) {
|
||||||
|
goto err2;
|
||||||
|
}
|
||||||
|
|
||||||
|
glue (audio_pcm_hw_add_sw_, TYPE) (hw, sw);
|
||||||
|
|
||||||
|
if (glue (audio_pcm_sw_init_, TYPE) (sw, hw, name, freq, nchannels, fmt)) {
|
||||||
|
goto err3;
|
||||||
|
}
|
||||||
|
|
||||||
|
return sw;
|
||||||
|
|
||||||
|
err3:
|
||||||
|
glue (audio_pcm_hw_del_sw_, TYPE) (sw);
|
||||||
|
glue (audio_pcm_hw_gc_, TYPE) (hw);
|
||||||
|
err2:
|
||||||
|
qemu_free (sw);
|
||||||
|
err1:
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void glue (AUD_close_, TYPE) (SW *sw)
|
||||||
|
{
|
||||||
|
if (sw) {
|
||||||
|
glue (audio_pcm_sw_fini_, TYPE) (sw);
|
||||||
|
glue (audio_pcm_hw_del_sw_, TYPE) (sw);
|
||||||
|
glue (audio_pcm_hw_gc_, TYPE) (sw->hw);
|
||||||
|
qemu_free (sw);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SW *glue (AUD_open_, TYPE) (
|
||||||
|
SW *sw,
|
||||||
|
const char *name,
|
||||||
|
void *callback_opaque ,
|
||||||
|
audio_callback_fn_t callback_fn,
|
||||||
|
int freq,
|
||||||
|
int nchannels,
|
||||||
|
audfmt_e fmt
|
||||||
|
)
|
||||||
|
{
|
||||||
|
#ifdef DAC
|
||||||
|
int live = 0;
|
||||||
|
SW *old_sw = NULL;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (!callback_fn) {
|
||||||
|
dolog ("No callback specifed for voice `%s'\n", name);
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nchannels != 1 && nchannels != 2) {
|
||||||
|
dolog ("Bogus channel count %d for voice `%s'\n", nchannels, name);
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!audio_state.drv) {
|
||||||
|
dolog ("No audio driver defined\n");
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sw && audio_pcm_info_eq (&sw->info, freq, nchannels, fmt)) {
|
||||||
|
return sw;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef DAC
|
||||||
|
if (audio_state.plive && sw && (!sw->active && !sw->empty)) {
|
||||||
|
live = sw->total_hw_samples_mixed;
|
||||||
|
|
||||||
|
#ifdef DEBUG_PLIVE
|
||||||
|
dolog ("Replacing voice %s with %d live samples\n", sw->name, live);
|
||||||
|
dolog ("Old %s freq %d, bits %d, channels %d\n",
|
||||||
|
sw->name, sw->info.freq, sw->info.bits, sw->info.nchannels);
|
||||||
|
dolog ("New %s freq %d, bits %d, channels %d\n",
|
||||||
|
name, freq, (fmt == AUD_FMT_S16 || fmt == AUD_FMT_U16) ? 16 : 8,
|
||||||
|
nchannels);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (live) {
|
||||||
|
old_sw = sw;
|
||||||
|
old_sw->callback.fn = NULL;
|
||||||
|
sw = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (!glue (audio_state.fixed_settings_, TYPE) && sw) {
|
||||||
|
glue (AUD_close_, TYPE) (sw);
|
||||||
|
sw = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sw) {
|
||||||
|
HW *hw = sw->hw;
|
||||||
|
|
||||||
|
if (!hw) {
|
||||||
|
dolog ("Internal logic error voice %s has no hardware store\n",
|
||||||
|
name);
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (glue (audio_pcm_sw_init_, TYPE) (
|
||||||
|
sw,
|
||||||
|
hw,
|
||||||
|
name,
|
||||||
|
freq,
|
||||||
|
nchannels,
|
||||||
|
fmt
|
||||||
|
)) {
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
sw = glue (audio_pcm_create_voice_pair_, TYPE) (
|
||||||
|
name,
|
||||||
|
freq,
|
||||||
|
nchannels,
|
||||||
|
fmt);
|
||||||
|
if (!sw) {
|
||||||
|
dolog ("Failed to create voice %s\n", name);
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sw) {
|
||||||
|
sw->vol = nominal_volume;
|
||||||
|
sw->callback.fn = callback_fn;
|
||||||
|
sw->callback.opaque = callback_opaque;
|
||||||
|
|
||||||
|
#ifdef DAC
|
||||||
|
if (live) {
|
||||||
|
int mixed =
|
||||||
|
(live << old_sw->info.shift)
|
||||||
|
* old_sw->info.bytes_per_second
|
||||||
|
/ sw->info.bytes_per_second;
|
||||||
|
|
||||||
|
#ifdef DEBUG_PLIVE
|
||||||
|
dolog ("Silence will be mixed %d\n", mixed);
|
||||||
|
#endif
|
||||||
|
sw->total_hw_samples_mixed += mixed;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef DEBUG_AUDIO
|
||||||
|
dolog ("%s\n", name);
|
||||||
|
audio_pcm_print_info ("hw", &sw->hw->info);
|
||||||
|
audio_pcm_print_info ("sw", &sw->info);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
return sw;
|
||||||
|
|
||||||
|
fail:
|
||||||
|
glue (AUD_close_, TYPE) (sw);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
int glue (AUD_is_active_, TYPE) (SW *sw)
|
||||||
|
{
|
||||||
|
return sw ? sw->active : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void glue (AUD_init_time_stamp_, TYPE) (SW *sw, QEMUAudioTimeStamp *ts)
|
||||||
|
{
|
||||||
|
if (!sw) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ts->old_ts = sw->hw->ts_helper;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t glue (AUD_time_stamp_get_elapsed_usec_, TYPE) (
|
||||||
|
SW *sw,
|
||||||
|
QEMUAudioTimeStamp *ts
|
||||||
|
)
|
||||||
|
{
|
||||||
|
uint64_t delta, cur_ts, old_ts;
|
||||||
|
|
||||||
|
if (!sw) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
cur_ts = sw->hw->ts_helper;
|
||||||
|
old_ts = ts->old_ts;
|
||||||
|
/* dolog ("cur %lld old %lld\n", cur_ts, old_ts); */
|
||||||
|
|
||||||
|
if (cur_ts >= old_ts) {
|
||||||
|
delta = cur_ts - old_ts;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
delta = UINT64_MAX - old_ts + cur_ts;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!delta) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (delta * sw->hw->info.freq) / 1000000;
|
||||||
|
}
|
||||||
|
|
||||||
|
#undef TYPE
|
||||||
|
#undef HW
|
||||||
|
#undef SW
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,298 @@
|
|||||||
|
/*
|
||||||
|
* QEMU DirectSound audio driver header
|
||||||
|
*
|
||||||
|
* Copyright (c) 2005 Vassili Karpov (malc)
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||||
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
#ifdef DSBTYPE_IN
|
||||||
|
#define NAME "capture buffer"
|
||||||
|
#define TYPE in
|
||||||
|
#define IFACE IDirectSoundCaptureBuffer
|
||||||
|
#define BUFPTR LPDIRECTSOUNDCAPTUREBUFFER
|
||||||
|
#define FIELD dsound_capture_buffer
|
||||||
|
#else
|
||||||
|
#define NAME "playback buffer"
|
||||||
|
#define TYPE out
|
||||||
|
#define IFACE IDirectSoundBuffer
|
||||||
|
#define BUFPTR LPDIRECTSOUNDBUFFER
|
||||||
|
#define FIELD dsound_buffer
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static int glue (dsound_unlock_, TYPE) (
|
||||||
|
BUFPTR buf,
|
||||||
|
LPVOID p1,
|
||||||
|
LPVOID p2,
|
||||||
|
DWORD blen1,
|
||||||
|
DWORD blen2
|
||||||
|
)
|
||||||
|
{
|
||||||
|
HRESULT hr;
|
||||||
|
|
||||||
|
hr = glue (IFACE, _Unlock) (buf, p1, blen1, p2, blen2);
|
||||||
|
if (FAILED (hr)) {
|
||||||
|
dsound_logerr (hr, "Can not unlock " NAME "\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int glue (dsound_lock_, TYPE) (
|
||||||
|
BUFPTR buf,
|
||||||
|
struct audio_pcm_info *info,
|
||||||
|
DWORD pos,
|
||||||
|
DWORD len,
|
||||||
|
LPVOID *p1p,
|
||||||
|
LPVOID *p2p,
|
||||||
|
DWORD *blen1p,
|
||||||
|
DWORD *blen2p,
|
||||||
|
int entire
|
||||||
|
)
|
||||||
|
{
|
||||||
|
HRESULT hr;
|
||||||
|
int i;
|
||||||
|
LPVOID p1 = NULL, p2 = NULL;
|
||||||
|
DWORD blen1 = 0, blen2 = 0;
|
||||||
|
|
||||||
|
for (i = 0; i < conf.lock_retries; ++i) {
|
||||||
|
hr = glue (IFACE, _Lock) (
|
||||||
|
buf,
|
||||||
|
pos,
|
||||||
|
len,
|
||||||
|
&p1,
|
||||||
|
&blen1,
|
||||||
|
&p2,
|
||||||
|
&blen2,
|
||||||
|
(entire
|
||||||
|
#ifdef DSBTYPE_IN
|
||||||
|
? DSCBLOCK_ENTIREBUFFER
|
||||||
|
#else
|
||||||
|
? DSBLOCK_ENTIREBUFFER
|
||||||
|
#endif
|
||||||
|
: 0)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (FAILED (hr)) {
|
||||||
|
#ifndef DSBTYPE_IN
|
||||||
|
if (hr == DSERR_BUFFERLOST) {
|
||||||
|
if (glue (dsound_restore_, TYPE) (buf)) {
|
||||||
|
dsound_logerr (hr, "Can not lock " NAME "\n");
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
dsound_logerr (hr, "Can not lock " NAME "\n");
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i == conf.lock_retries) {
|
||||||
|
dolog ("%d attempts to lock " NAME " failed\n", i);
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((p1 && (blen1 & info->align)) || (p2 && (blen2 & info->align))) {
|
||||||
|
dolog ("DirectSound returned misaligned buffer %ld %ld\n",
|
||||||
|
blen1, blen2);
|
||||||
|
glue (dsound_unlock_, TYPE) (buf, p1, p2, blen1, blen2);
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!p1 && blen1) {
|
||||||
|
dolog ("warning: !p1 && blen1=%ld\n", blen1);
|
||||||
|
blen1 = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!p2 && blen2) {
|
||||||
|
dolog ("warning: !p2 && blen2=%ld\n", blen2);
|
||||||
|
blen2 = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
*p1p = p1;
|
||||||
|
*p2p = p2;
|
||||||
|
*blen1p = blen1;
|
||||||
|
*blen2p = blen2;
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
fail:
|
||||||
|
*p1p = NULL - 1;
|
||||||
|
*p2p = NULL - 1;
|
||||||
|
*blen1p = -1;
|
||||||
|
*blen2p = -1;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef DSBTYPE_IN
|
||||||
|
static void dsound_fini_in (HWVoiceIn *hw)
|
||||||
|
#else
|
||||||
|
static void dsound_fini_out (HWVoiceOut *hw)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
HRESULT hr;
|
||||||
|
#ifdef DSBTYPE_IN
|
||||||
|
DSoundVoiceIn *ds = (DSoundVoiceIn *) hw;
|
||||||
|
#else
|
||||||
|
DSoundVoiceOut *ds = (DSoundVoiceOut *) hw;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (ds->FIELD) {
|
||||||
|
hr = glue (IFACE, _Stop) (ds->FIELD);
|
||||||
|
if (FAILED (hr)) {
|
||||||
|
dsound_logerr (hr, "Can not stop " NAME "\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
hr = glue (IFACE, _Release) (ds->FIELD);
|
||||||
|
if (FAILED (hr)) {
|
||||||
|
dsound_logerr (hr, "Can not release " NAME "\n");
|
||||||
|
}
|
||||||
|
ds->FIELD = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef DSBTYPE_IN
|
||||||
|
static int dsound_init_in (
|
||||||
|
HWVoiceIn *hw,
|
||||||
|
int freq,
|
||||||
|
int nchannels,
|
||||||
|
audfmt_e fmt
|
||||||
|
)
|
||||||
|
#else
|
||||||
|
static int dsound_init_out (
|
||||||
|
HWVoiceOut *hw,
|
||||||
|
int freq,
|
||||||
|
int nchannels,
|
||||||
|
audfmt_e fmt
|
||||||
|
)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
int err;
|
||||||
|
HRESULT hr;
|
||||||
|
dsound *s = &glob_dsound;
|
||||||
|
WAVEFORMATEX wfx;
|
||||||
|
struct full_fmt full_fmt;
|
||||||
|
#ifdef DSBTYPE_IN
|
||||||
|
const char *typ = "ADC";
|
||||||
|
DSoundVoiceIn *ds = (DSoundVoiceIn *) hw;
|
||||||
|
DSCBUFFERDESC bd;
|
||||||
|
DSCBCAPS bc;
|
||||||
|
#else
|
||||||
|
const char *typ = "DAC";
|
||||||
|
DSoundVoiceOut *ds = (DSoundVoiceOut *) hw;
|
||||||
|
DSBUFFERDESC bd;
|
||||||
|
DSBCAPS bc;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
full_fmt.freq = freq;
|
||||||
|
full_fmt.nchannels = nchannels;
|
||||||
|
full_fmt.fmt = fmt;
|
||||||
|
err = waveformat_from_full_fmt (&wfx, &full_fmt);
|
||||||
|
if (err) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
memset (&bd, 0, sizeof (bd));
|
||||||
|
bd.dwSize = sizeof (bd);
|
||||||
|
bd.lpwfxFormat = &wfx;
|
||||||
|
#ifdef DSBTYPE_IN
|
||||||
|
bd.dwBufferBytes = conf.bufsize_in;
|
||||||
|
hr = IDirectSoundCapture_CreateCaptureBuffer (
|
||||||
|
s->dsound_capture,
|
||||||
|
&bd,
|
||||||
|
&ds->dsound_capture_buffer,
|
||||||
|
NULL
|
||||||
|
);
|
||||||
|
#else
|
||||||
|
bd.dwFlags = DSBCAPS_STICKYFOCUS | DSBCAPS_GETCURRENTPOSITION2;
|
||||||
|
bd.dwBufferBytes = conf.bufsize_out;
|
||||||
|
hr = IDirectSound_CreateSoundBuffer (
|
||||||
|
s->dsound,
|
||||||
|
&bd,
|
||||||
|
&ds->dsound_buffer,
|
||||||
|
NULL
|
||||||
|
);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (FAILED (hr)) {
|
||||||
|
dsound_logerr2 (hr, typ, "Can not create " NAME "\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
hr = glue (IFACE, _GetFormat) (
|
||||||
|
ds->FIELD,
|
||||||
|
&wfx,
|
||||||
|
sizeof (wfx),
|
||||||
|
NULL
|
||||||
|
);
|
||||||
|
if (FAILED (hr)) {
|
||||||
|
dsound_logerr2 (hr, typ, "Can not get " NAME " format\n");
|
||||||
|
goto fail0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef DEBUG_DSOUND
|
||||||
|
dolog (NAME "\n");
|
||||||
|
print_wave_format (&wfx);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
memset (&bc, 0, sizeof (bc));
|
||||||
|
bc.dwSize = sizeof (bc);
|
||||||
|
|
||||||
|
hr = glue (IFACE, _GetCaps) (ds->FIELD, &bc);
|
||||||
|
if (FAILED (hr)) {
|
||||||
|
dsound_logerr2 (hr, typ, "Can not get " NAME " format\n");
|
||||||
|
goto fail0;
|
||||||
|
}
|
||||||
|
|
||||||
|
err = waveformat_to_full_fmt (&wfx, &full_fmt);
|
||||||
|
if (err) {
|
||||||
|
goto fail0;
|
||||||
|
}
|
||||||
|
|
||||||
|
ds->first_time = 1;
|
||||||
|
hw->bufsize = bc.dwBufferBytes;
|
||||||
|
audio_pcm_init_info (
|
||||||
|
&hw->info,
|
||||||
|
full_fmt.freq,
|
||||||
|
full_fmt.nchannels,
|
||||||
|
full_fmt.fmt,
|
||||||
|
audio_need_to_swap_endian (0)
|
||||||
|
);
|
||||||
|
|
||||||
|
#ifdef DEBUG_DSOUND
|
||||||
|
dolog ("caps %ld, desc %ld\n",
|
||||||
|
bc.dwBufferBytes, bd.dwBufferBytes);
|
||||||
|
|
||||||
|
dolog ("bufsize %d, freq %d, chan %d, fmt %d\n",
|
||||||
|
hw->bufsize, full_fmt.freq, full_fmt.nchannels, full_fmt.fmt);
|
||||||
|
#endif
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
fail0:
|
||||||
|
glue (dsound_fini_, TYPE) (hw);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#undef NAME
|
||||||
|
#undef TYPE
|
||||||
|
#undef IFACE
|
||||||
|
#undef BUFPTR
|
||||||
|
#undef FIELD
|
||||||
+1082
File diff suppressed because it is too large
Load Diff
+374
-158
File diff suppressed because it is too large
Load Diff
+123
-102
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* QEMU Mixing engine
|
* QEMU Mixing engine
|
||||||
*
|
*
|
||||||
* Copyright (c) 2004 Vassili Karpov (malc)
|
* Copyright (c) 2004-2005 Vassili Karpov (malc)
|
||||||
* Copyright (c) 1998 Fabrice Bellard
|
* Copyright (c) 1998 Fabrice Bellard
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
@@ -23,87 +23,174 @@
|
|||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
#include "vl.h"
|
#include "vl.h"
|
||||||
//#define DEBUG_FP
|
|
||||||
#include "audio/mixeng.h"
|
|
||||||
|
|
||||||
|
#define AUDIO_CAP "mixeng"
|
||||||
|
#include "audio_int.h"
|
||||||
|
|
||||||
|
#define NOVOL
|
||||||
|
|
||||||
|
/* 8 bit */
|
||||||
|
#define ENDIAN_CONVERSION natural
|
||||||
|
#define ENDIAN_CONVERT(v) (v)
|
||||||
|
|
||||||
|
/* Signed 8 bit */
|
||||||
#define IN_T int8_t
|
#define IN_T int8_t
|
||||||
#define IN_MIN CHAR_MIN
|
#define IN_MIN SCHAR_MIN
|
||||||
#define IN_MAX CHAR_MAX
|
#define IN_MAX SCHAR_MAX
|
||||||
#define SIGNED
|
#define SIGNED
|
||||||
|
#define SHIFT 8
|
||||||
#include "mixeng_template.h"
|
#include "mixeng_template.h"
|
||||||
#undef SIGNED
|
#undef SIGNED
|
||||||
#undef IN_MAX
|
#undef IN_MAX
|
||||||
#undef IN_MIN
|
#undef IN_MIN
|
||||||
#undef IN_T
|
#undef IN_T
|
||||||
|
#undef SHIFT
|
||||||
|
|
||||||
|
/* Unsigned 8 bit */
|
||||||
#define IN_T uint8_t
|
#define IN_T uint8_t
|
||||||
#define IN_MIN 0
|
#define IN_MIN 0
|
||||||
#define IN_MAX UCHAR_MAX
|
#define IN_MAX UCHAR_MAX
|
||||||
|
#define SHIFT 8
|
||||||
#include "mixeng_template.h"
|
#include "mixeng_template.h"
|
||||||
#undef IN_MAX
|
#undef IN_MAX
|
||||||
#undef IN_MIN
|
#undef IN_MIN
|
||||||
#undef IN_T
|
#undef IN_T
|
||||||
|
#undef SHIFT
|
||||||
|
|
||||||
|
#undef ENDIAN_CONVERT
|
||||||
|
#undef ENDIAN_CONVERSION
|
||||||
|
|
||||||
|
/* Signed 16 bit */
|
||||||
#define IN_T int16_t
|
#define IN_T int16_t
|
||||||
#define IN_MIN SHRT_MIN
|
#define IN_MIN SHRT_MIN
|
||||||
#define IN_MAX SHRT_MAX
|
#define IN_MAX SHRT_MAX
|
||||||
#define SIGNED
|
#define SIGNED
|
||||||
|
#define SHIFT 16
|
||||||
|
#define ENDIAN_CONVERSION natural
|
||||||
|
#define ENDIAN_CONVERT(v) (v)
|
||||||
#include "mixeng_template.h"
|
#include "mixeng_template.h"
|
||||||
|
#undef ENDIAN_CONVERT
|
||||||
|
#undef ENDIAN_CONVERSION
|
||||||
|
#define ENDIAN_CONVERSION swap
|
||||||
|
#define ENDIAN_CONVERT(v) bswap16 (v)
|
||||||
|
#include "mixeng_template.h"
|
||||||
|
#undef ENDIAN_CONVERT
|
||||||
|
#undef ENDIAN_CONVERSION
|
||||||
#undef SIGNED
|
#undef SIGNED
|
||||||
#undef IN_MAX
|
#undef IN_MAX
|
||||||
#undef IN_MIN
|
#undef IN_MIN
|
||||||
#undef IN_T
|
#undef IN_T
|
||||||
|
#undef SHIFT
|
||||||
|
|
||||||
#define IN_T uint16_t
|
#define IN_T uint16_t
|
||||||
#define IN_MIN 0
|
#define IN_MIN 0
|
||||||
#define IN_MAX USHRT_MAX
|
#define IN_MAX USHRT_MAX
|
||||||
|
#define SHIFT 16
|
||||||
|
#define ENDIAN_CONVERSION natural
|
||||||
|
#define ENDIAN_CONVERT(v) (v)
|
||||||
#include "mixeng_template.h"
|
#include "mixeng_template.h"
|
||||||
|
#undef ENDIAN_CONVERT
|
||||||
|
#undef ENDIAN_CONVERSION
|
||||||
|
#define ENDIAN_CONVERSION swap
|
||||||
|
#define ENDIAN_CONVERT(v) bswap16 (v)
|
||||||
|
#include "mixeng_template.h"
|
||||||
|
#undef ENDIAN_CONVERT
|
||||||
|
#undef ENDIAN_CONVERSION
|
||||||
#undef IN_MAX
|
#undef IN_MAX
|
||||||
#undef IN_MIN
|
#undef IN_MIN
|
||||||
#undef IN_T
|
#undef IN_T
|
||||||
|
#undef SHIFT
|
||||||
|
|
||||||
t_sample *mixeng_conv[2][2][2] = {
|
t_sample *mixeng_conv[2][2][2][2] = {
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
conv_uint8_t_to_mono,
|
{
|
||||||
conv_uint16_t_to_mono
|
conv_natural_uint8_t_to_mono,
|
||||||
|
conv_natural_uint16_t_to_mono
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
conv_int8_t_to_mono,
|
conv_natural_uint8_t_to_mono,
|
||||||
conv_int16_t_to_mono
|
conv_swap_uint16_t_to_mono
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
conv_uint8_t_to_stereo,
|
conv_natural_int8_t_to_mono,
|
||||||
conv_uint16_t_to_stereo
|
conv_natural_int16_t_to_mono
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
conv_int8_t_to_stereo,
|
conv_natural_int8_t_to_mono,
|
||||||
conv_int16_t_to_stereo
|
conv_swap_int16_t_to_mono
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
{
|
||||||
|
{
|
||||||
|
conv_natural_uint8_t_to_stereo,
|
||||||
|
conv_natural_uint16_t_to_stereo
|
||||||
|
},
|
||||||
|
{
|
||||||
|
conv_natural_uint8_t_to_stereo,
|
||||||
|
conv_swap_uint16_t_to_stereo
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
{
|
||||||
|
conv_natural_int8_t_to_stereo,
|
||||||
|
conv_natural_int16_t_to_stereo
|
||||||
|
},
|
||||||
|
{
|
||||||
|
conv_natural_int8_t_to_stereo,
|
||||||
|
conv_swap_int16_t_to_stereo
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
f_sample *mixeng_clip[2][2][2] = {
|
f_sample *mixeng_clip[2][2][2][2] = {
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
clip_uint8_t_from_mono,
|
{
|
||||||
clip_uint16_t_from_mono
|
clip_natural_uint8_t_from_mono,
|
||||||
|
clip_natural_uint16_t_from_mono
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
clip_int8_t_from_mono,
|
clip_natural_uint8_t_from_mono,
|
||||||
clip_int16_t_from_mono
|
clip_swap_uint16_t_from_mono
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
clip_uint8_t_from_stereo,
|
clip_natural_int8_t_from_mono,
|
||||||
clip_uint16_t_from_stereo
|
clip_natural_int16_t_from_mono
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
clip_int8_t_from_stereo,
|
clip_natural_int8_t_from_mono,
|
||||||
clip_int16_t_from_stereo
|
clip_swap_int16_t_from_mono
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
{
|
||||||
|
{
|
||||||
|
clip_natural_uint8_t_from_stereo,
|
||||||
|
clip_natural_uint16_t_from_stereo
|
||||||
|
},
|
||||||
|
{
|
||||||
|
clip_natural_uint8_t_from_stereo,
|
||||||
|
clip_swap_uint16_t_from_stereo
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
{
|
||||||
|
clip_natural_int8_t_from_stereo,
|
||||||
|
clip_natural_int16_t_from_stereo
|
||||||
|
},
|
||||||
|
{
|
||||||
|
clip_natural_int8_t_from_stereo,
|
||||||
|
clip_swap_int16_t_from_stereo
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -156,21 +243,13 @@ void *st_rate_start (int inrate, int outrate)
|
|||||||
rate_t rate = (rate_t) qemu_mallocz (sizeof (struct ratestuff));
|
rate_t rate = (rate_t) qemu_mallocz (sizeof (struct ratestuff));
|
||||||
|
|
||||||
if (!rate) {
|
if (!rate) {
|
||||||
exit (EXIT_FAILURE);
|
return NULL;
|
||||||
}
|
|
||||||
|
|
||||||
if (inrate == outrate) {
|
|
||||||
// exit (EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (inrate >= 65535 || outrate >= 65535) {
|
|
||||||
// exit (EXIT_FAILURE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rate->opos = 0;
|
rate->opos = 0;
|
||||||
|
|
||||||
/* increment */
|
/* increment */
|
||||||
rate->opos_inc = (inrate * ((int64_t) UINT_MAX)) / outrate;
|
rate->opos_inc = ((uint64_t) inrate << 32) / outrate;
|
||||||
|
|
||||||
rate->ipos = 0;
|
rate->ipos = 0;
|
||||||
rate->ilast.l = 0;
|
rate->ilast.l = 0;
|
||||||
@@ -178,78 +257,20 @@ void *st_rate_start (int inrate, int outrate)
|
|||||||
return rate;
|
return rate;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
#define NAME st_rate_flow_mix
|
||||||
* Processed signed long samples from ibuf to obuf.
|
#define OP(a, b) a += b
|
||||||
* Return number of samples processed.
|
#include "rate_template.h"
|
||||||
*/
|
|
||||||
void st_rate_flow (void *opaque, st_sample_t *ibuf, st_sample_t *obuf,
|
|
||||||
int *isamp, int *osamp)
|
|
||||||
{
|
|
||||||
rate_t rate = (rate_t) opaque;
|
|
||||||
st_sample_t *istart, *iend;
|
|
||||||
st_sample_t *ostart, *oend;
|
|
||||||
st_sample_t ilast, icur, out;
|
|
||||||
int64_t t;
|
|
||||||
|
|
||||||
ilast = rate->ilast;
|
#define NAME st_rate_flow
|
||||||
|
#define OP(a, b) a = b
|
||||||
istart = ibuf;
|
#include "rate_template.h"
|
||||||
iend = ibuf + *isamp;
|
|
||||||
|
|
||||||
ostart = obuf;
|
|
||||||
oend = obuf + *osamp;
|
|
||||||
|
|
||||||
if (rate->opos_inc == 1ULL << 32) {
|
|
||||||
int i, n = *isamp > *osamp ? *osamp : *isamp;
|
|
||||||
for (i = 0; i < n; i++) {
|
|
||||||
obuf[i].l += ibuf[i].r;
|
|
||||||
obuf[i].r += ibuf[i].r;
|
|
||||||
}
|
|
||||||
*isamp = n;
|
|
||||||
*osamp = n;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (obuf < oend) {
|
|
||||||
|
|
||||||
/* Safety catch to make sure we have input samples. */
|
|
||||||
if (ibuf >= iend)
|
|
||||||
break;
|
|
||||||
|
|
||||||
/* read as many input samples so that ipos > opos */
|
|
||||||
|
|
||||||
while (rate->ipos <= (rate->opos >> 32)) {
|
|
||||||
ilast = *ibuf++;
|
|
||||||
rate->ipos++;
|
|
||||||
/* See if we finished the input buffer yet */
|
|
||||||
if (ibuf >= iend) goto the_end;
|
|
||||||
}
|
|
||||||
|
|
||||||
icur = *ibuf;
|
|
||||||
|
|
||||||
/* interpolate */
|
|
||||||
t = rate->opos & 0xffffffff;
|
|
||||||
out.l = (ilast.l * (INT_MAX - t) + icur.l * t) / INT_MAX;
|
|
||||||
out.r = (ilast.r * (INT_MAX - t) + icur.r * t) / INT_MAX;
|
|
||||||
|
|
||||||
/* output sample & increment position */
|
|
||||||
#if 0
|
|
||||||
*obuf++ = out;
|
|
||||||
#else
|
|
||||||
obuf->l += out.l;
|
|
||||||
obuf->r += out.r;
|
|
||||||
obuf += 1;
|
|
||||||
#endif
|
|
||||||
rate->opos += rate->opos_inc;
|
|
||||||
}
|
|
||||||
|
|
||||||
the_end:
|
|
||||||
*isamp = ibuf - istart;
|
|
||||||
*osamp = obuf - ostart;
|
|
||||||
rate->ilast = ilast;
|
|
||||||
}
|
|
||||||
|
|
||||||
void st_rate_stop (void *opaque)
|
void st_rate_stop (void *opaque)
|
||||||
{
|
{
|
||||||
qemu_free (opaque);
|
qemu_free (opaque);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void mixeng_clear (st_sample_t *buf, int len)
|
||||||
|
{
|
||||||
|
memset (buf, 0, len * sizeof (st_sample_t));
|
||||||
|
}
|
||||||
|
|||||||
+17
-5
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* QEMU Mixing engine header
|
* QEMU Mixing engine header
|
||||||
*
|
*
|
||||||
* Copyright (c) 2004 Vassili Karpov (malc)
|
* Copyright (c) 2004-2005 Vassili Karpov (malc)
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -24,16 +24,28 @@
|
|||||||
#ifndef QEMU_MIXENG_H
|
#ifndef QEMU_MIXENG_H
|
||||||
#define QEMU_MIXENG_H
|
#define QEMU_MIXENG_H
|
||||||
|
|
||||||
typedef void (t_sample) (void *dst, const void *src, int samples);
|
#ifdef FLOAT_MIXENG
|
||||||
typedef void (f_sample) (void *dst, const void *src, int samples);
|
typedef float real_t;
|
||||||
|
typedef struct { int mute; real_t r; real_t l; } volume_t;
|
||||||
|
typedef struct { real_t l; real_t r; } st_sample_t;
|
||||||
|
#else
|
||||||
|
typedef struct { int mute; int64_t r; int64_t l; } volume_t;
|
||||||
typedef struct { int64_t l; int64_t r; } st_sample_t;
|
typedef struct { int64_t l; int64_t r; } st_sample_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
extern t_sample *mixeng_conv[2][2][2];
|
typedef void (t_sample) (st_sample_t *dst, const void *src,
|
||||||
extern f_sample *mixeng_clip[2][2][2];
|
int samples, volume_t *vol);
|
||||||
|
typedef void (f_sample) (void *dst, const st_sample_t *src, int samples);
|
||||||
|
|
||||||
|
extern t_sample *mixeng_conv[2][2][2][2];
|
||||||
|
extern f_sample *mixeng_clip[2][2][2][2];
|
||||||
|
|
||||||
void *st_rate_start (int inrate, int outrate);
|
void *st_rate_start (int inrate, int outrate);
|
||||||
void st_rate_flow (void *opaque, st_sample_t *ibuf, st_sample_t *obuf,
|
void st_rate_flow (void *opaque, st_sample_t *ibuf, st_sample_t *obuf,
|
||||||
int *isamp, int *osamp);
|
int *isamp, int *osamp);
|
||||||
|
void st_rate_flow_mix (void *opaque, st_sample_t *ibuf, st_sample_t *obuf,
|
||||||
|
int *isamp, int *osamp);
|
||||||
void st_rate_stop (void *opaque);
|
void st_rate_stop (void *opaque);
|
||||||
|
void mixeng_clear (st_sample_t *buf, int len);
|
||||||
|
|
||||||
#endif /* mixeng.h */
|
#endif /* mixeng.h */
|
||||||
|
|||||||
+103
-37
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* QEMU Mixing engine
|
* QEMU Mixing engine
|
||||||
*
|
*
|
||||||
* Copyright (c) 2004 Vassili Karpov (malc)
|
* Copyright (c) 2004-2005 Vassili Karpov (malc)
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -27,85 +27,151 @@
|
|||||||
* dec++'ified by Dscho
|
* dec++'ified by Dscho
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef SIGNED
|
#ifndef SIGNED
|
||||||
#define HALFT IN_MAX
|
#define HALF (IN_MAX >> 1)
|
||||||
#define HALF IN_MAX
|
|
||||||
#else
|
|
||||||
#define HALFT ((IN_MAX)>>1)
|
|
||||||
#define HALF HALFT
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static int64_t inline glue(conv_,IN_T) (IN_T v)
|
#ifdef NOVOL
|
||||||
{
|
#define VOL(a, b) a
|
||||||
#ifdef SIGNED
|
|
||||||
return (INT_MAX*(int64_t)v)/HALF;
|
|
||||||
#else
|
#else
|
||||||
return (INT_MAX*((int64_t)v-HALFT))/HALF;
|
#ifdef FLOAT_MIXENG
|
||||||
|
#define VOL(a, b) ((a) * (b))
|
||||||
|
#else
|
||||||
|
#define VOL(a, b) ((a) * (b)) >> 32
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define ET glue (ENDIAN_CONVERSION, glue (_, IN_T))
|
||||||
|
|
||||||
|
#ifdef FLOAT_MIXENG
|
||||||
|
static real_t inline glue (conv_, ET) (IN_T v)
|
||||||
|
{
|
||||||
|
IN_T nv = ENDIAN_CONVERT (v);
|
||||||
|
|
||||||
|
#ifdef RECIPROCAL
|
||||||
|
#ifdef SIGNED
|
||||||
|
return nv * (1.f / (real_t) (IN_MAX - IN_MIN));
|
||||||
|
#else
|
||||||
|
return (nv - HALF) * (1.f / (real_t) IN_MAX);
|
||||||
|
#endif
|
||||||
|
#else /* !RECIPROCAL */
|
||||||
|
#ifdef SIGNED
|
||||||
|
return nv / (real_t) (IN_MAX - IN_MIN);
|
||||||
|
#else
|
||||||
|
return (nv - HALF) / (real_t) IN_MAX;
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static IN_T inline glue(clip_,IN_T) (int64_t v)
|
static IN_T inline glue (clip_, ET) (real_t v)
|
||||||
{
|
{
|
||||||
if (v >= INT_MAX)
|
if (v >= 0.5) {
|
||||||
return IN_MAX;
|
return IN_MAX;
|
||||||
else if (v < -INT_MAX)
|
}
|
||||||
|
else if (v < -0.5) {
|
||||||
return IN_MIN;
|
return IN_MIN;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef SIGNED
|
#ifdef SIGNED
|
||||||
return (IN_T) (v*HALF/INT_MAX);
|
return ENDIAN_CONVERT ((IN_T) (v * (IN_MAX - IN_MIN)));
|
||||||
#else
|
#else
|
||||||
return (IN_T) (v+INT_MAX/2)*HALF/INT_MAX;
|
return ENDIAN_CONVERT ((IN_T) ((v * IN_MAX) + HALF));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void glue(glue(conv_,IN_T),_to_stereo) (void *dst, const void *src,
|
#else /* !FLOAT_MIXENG */
|
||||||
int samples)
|
|
||||||
|
static inline int64_t glue (conv_, ET) (IN_T v)
|
||||||
{
|
{
|
||||||
st_sample_t *out = (st_sample_t *) dst;
|
IN_T nv = ENDIAN_CONVERT (v);
|
||||||
|
#ifdef SIGNED
|
||||||
|
return ((int64_t) nv) << (32 - SHIFT);
|
||||||
|
#else
|
||||||
|
return ((int64_t) nv - HALF) << (32 - SHIFT);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline IN_T glue (clip_, ET) (int64_t v)
|
||||||
|
{
|
||||||
|
if (v >= 0x7f000000) {
|
||||||
|
return IN_MAX;
|
||||||
|
}
|
||||||
|
else if (v < -2147483648LL) {
|
||||||
|
return IN_MIN;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef SIGNED
|
||||||
|
return ENDIAN_CONVERT ((IN_T) (v >> (32 - SHIFT)));
|
||||||
|
#else
|
||||||
|
return ENDIAN_CONVERT ((IN_T) ((v >> (32 - SHIFT)) + HALF));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static void glue (glue (conv_, ET), _to_stereo)
|
||||||
|
(st_sample_t *dst, const void *src, int samples, volume_t *vol)
|
||||||
|
{
|
||||||
|
st_sample_t *out = dst;
|
||||||
IN_T *in = (IN_T *) src;
|
IN_T *in = (IN_T *) src;
|
||||||
|
#ifndef NOVOL
|
||||||
|
if (vol->mute) {
|
||||||
|
mixeng_clear (dst, samples);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
(void) vol;
|
||||||
|
#endif
|
||||||
while (samples--) {
|
while (samples--) {
|
||||||
out->l = glue(conv_,IN_T) (*in++);
|
out->l = VOL (glue (conv_, ET) (*in++), vol->l);
|
||||||
out->r = glue(conv_,IN_T) (*in++);
|
out->r = VOL (glue (conv_, ET) (*in++), vol->r);
|
||||||
out += 1;
|
out += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void glue(glue(conv_,IN_T),_to_mono) (void *dst, const void *src,
|
static void glue (glue (conv_, ET), _to_mono)
|
||||||
int samples)
|
(st_sample_t *dst, const void *src, int samples, volume_t *vol)
|
||||||
{
|
{
|
||||||
st_sample_t *out = (st_sample_t *) dst;
|
st_sample_t *out = dst;
|
||||||
IN_T *in = (IN_T *) src;
|
IN_T *in = (IN_T *) src;
|
||||||
|
#ifndef NOVOL
|
||||||
|
if (vol->mute) {
|
||||||
|
mixeng_clear (dst, samples);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
(void) vol;
|
||||||
|
#endif
|
||||||
while (samples--) {
|
while (samples--) {
|
||||||
out->l = glue(conv_,IN_T) (in[0]);
|
out->l = VOL (glue (conv_, ET) (in[0]), vol->l);
|
||||||
out->r = out->l;
|
out->r = out->l;
|
||||||
out += 1;
|
out += 1;
|
||||||
in += 1;
|
in += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void glue(glue(clip_,IN_T),_from_stereo) (void *dst, const void *src,
|
static void glue (glue (clip_, ET), _from_stereo)
|
||||||
int samples)
|
(void *dst, const st_sample_t *src, int samples)
|
||||||
{
|
{
|
||||||
st_sample_t *in = (st_sample_t *) src;
|
const st_sample_t *in = src;
|
||||||
IN_T *out = (IN_T *) dst;
|
IN_T *out = (IN_T *) dst;
|
||||||
while (samples--) {
|
while (samples--) {
|
||||||
*out++ = glue(clip_,IN_T) (in->l);
|
*out++ = glue (clip_, ET) (in->l);
|
||||||
*out++ = glue(clip_,IN_T) (in->r);
|
*out++ = glue (clip_, ET) (in->r);
|
||||||
in += 1;
|
in += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void glue(glue(clip_,IN_T),_from_mono) (void *dst, const void *src,
|
static void glue (glue (clip_, ET), _from_mono)
|
||||||
int samples)
|
(void *dst, const st_sample_t *src, int samples)
|
||||||
{
|
{
|
||||||
st_sample_t *in = (st_sample_t *) src;
|
const st_sample_t *in = src;
|
||||||
IN_T *out = (IN_T *) dst;
|
IN_T *out = (IN_T *) dst;
|
||||||
while (samples--) {
|
while (samples--) {
|
||||||
*out++ = glue(clip_,IN_T) (in->l + in->r);
|
*out++ = glue (clip_, ET) (in->l + in->r);
|
||||||
in += 1;
|
in += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#undef ET
|
||||||
#undef HALF
|
#undef HALF
|
||||||
#undef HALFT
|
#undef VOL
|
||||||
|
|
||||||
|
|||||||
+105
-61
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* QEMU NULL audio output driver
|
* QEMU Timer based audio emulation
|
||||||
*
|
*
|
||||||
* Copyright (c) 2004 Vassili Karpov (malc)
|
* Copyright (c) 2004-2005 Vassili Karpov (malc)
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -23,77 +23,110 @@
|
|||||||
*/
|
*/
|
||||||
#include "vl.h"
|
#include "vl.h"
|
||||||
|
|
||||||
#include "audio/audio_int.h"
|
#define AUDIO_CAP "noaudio"
|
||||||
|
#include "audio_int.h"
|
||||||
|
|
||||||
typedef struct NoVoice {
|
typedef struct NoVoiceOut {
|
||||||
HWVoice hw;
|
HWVoiceOut hw;
|
||||||
int64_t old_ticks;
|
int64_t old_ticks;
|
||||||
} NoVoice;
|
} NoVoiceOut;
|
||||||
|
|
||||||
#define dolog(...) AUD_log ("noaudio", __VA_ARGS__)
|
typedef struct NoVoiceIn {
|
||||||
#ifdef DEBUG
|
HWVoiceIn hw;
|
||||||
#define ldebug(...) dolog (__VA_ARGS__)
|
int64_t old_ticks;
|
||||||
#else
|
} NoVoiceIn;
|
||||||
#define ldebug(...)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static void no_hw_run (HWVoice *hw)
|
static int no_run_out (HWVoiceOut *hw)
|
||||||
{
|
{
|
||||||
NoVoice *no = (NoVoice *) hw;
|
NoVoiceOut *no = (NoVoiceOut *) hw;
|
||||||
int rpos, live, decr, samples;
|
int live, decr, samples;
|
||||||
st_sample_t *src;
|
|
||||||
int64_t now = qemu_get_clock (vm_clock);
|
int64_t now = qemu_get_clock (vm_clock);
|
||||||
int64_t ticks = now - no->old_ticks;
|
int64_t ticks = now - no->old_ticks;
|
||||||
int64_t bytes = (ticks * hw->bytes_per_second) / ticks_per_sec;
|
int64_t bytes = (ticks * hw->info.bytes_per_second) / ticks_per_sec;
|
||||||
|
|
||||||
if (bytes > INT_MAX)
|
if (bytes > INT_MAX) {
|
||||||
samples = INT_MAX >> hw->shift;
|
samples = INT_MAX >> hw->info.shift;
|
||||||
else
|
}
|
||||||
samples = bytes >> hw->shift;
|
else {
|
||||||
|
samples = bytes >> hw->info.shift;
|
||||||
|
}
|
||||||
|
|
||||||
live = pcm_hw_get_live (hw);
|
live = audio_pcm_hw_get_live_out (&no->hw);
|
||||||
if (live <= 0)
|
if (!live) {
|
||||||
return;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
no->old_ticks = now;
|
no->old_ticks = now;
|
||||||
decr = audio_MIN (live, samples);
|
decr = audio_MIN (live, samples);
|
||||||
samples = decr;
|
hw->rpos = (hw->rpos + decr) % hw->samples;
|
||||||
rpos = hw->rpos;
|
return decr;
|
||||||
while (samples) {
|
|
||||||
int left_till_end_samples = hw->samples - rpos;
|
|
||||||
int convert_samples = audio_MIN (samples, left_till_end_samples);
|
|
||||||
|
|
||||||
src = advance (hw->mix_buf, rpos * sizeof (st_sample_t));
|
|
||||||
memset (src, 0, convert_samples * sizeof (st_sample_t));
|
|
||||||
|
|
||||||
rpos = (rpos + convert_samples) % hw->samples;
|
|
||||||
samples -= convert_samples;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pcm_hw_dec_live (hw, decr);
|
static int no_write (SWVoiceOut *sw, void *buf, int len)
|
||||||
hw->rpos = rpos;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int no_hw_write (SWVoice *sw, void *buf, int len)
|
|
||||||
{
|
{
|
||||||
return pcm_hw_write (sw, buf, len);
|
return audio_pcm_sw_write (sw, buf, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int no_hw_init (HWVoice *hw, int freq, int nchannels, audfmt_e fmt)
|
static int no_init_out (HWVoiceOut *hw, int freq,
|
||||||
|
int nchannels, audfmt_e fmt)
|
||||||
{
|
{
|
||||||
hw->freq = freq;
|
audio_pcm_init_info (&hw->info, freq, nchannels, fmt, 0);
|
||||||
hw->nchannels = nchannels;
|
|
||||||
hw->fmt = fmt;
|
|
||||||
hw->bufsize = 4096;
|
hw->bufsize = 4096;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void no_hw_fini (HWVoice *hw)
|
static void no_fini_out (HWVoiceOut *hw)
|
||||||
{
|
{
|
||||||
(void) hw;
|
(void) hw;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int no_hw_ctl (HWVoice *hw, int cmd, ...)
|
static int no_ctl_out (HWVoiceOut *hw, int cmd, ...)
|
||||||
|
{
|
||||||
|
(void) hw;
|
||||||
|
(void) cmd;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int no_init_in (HWVoiceIn *hw, int freq,
|
||||||
|
int nchannels, audfmt_e fmt)
|
||||||
|
{
|
||||||
|
audio_pcm_init_info (&hw->info, freq, nchannels, fmt, 0);
|
||||||
|
hw->bufsize = 4096;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void no_fini_in (HWVoiceIn *hw)
|
||||||
|
{
|
||||||
|
(void) hw;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int no_run_in (HWVoiceIn *hw)
|
||||||
|
{
|
||||||
|
NoVoiceIn *no = (NoVoiceIn *) hw;
|
||||||
|
int64_t now = qemu_get_clock (vm_clock);
|
||||||
|
int64_t ticks = now - no->old_ticks;
|
||||||
|
int64_t bytes = (ticks * hw->info.bytes_per_second) / ticks_per_sec;
|
||||||
|
int live = audio_pcm_hw_get_live_in (hw);
|
||||||
|
int dead = hw->samples - live;
|
||||||
|
int samples;
|
||||||
|
|
||||||
|
bytes = audio_MIN (bytes, INT_MAX);
|
||||||
|
samples = bytes >> hw->info.shift;
|
||||||
|
samples = audio_MIN (samples, dead);
|
||||||
|
|
||||||
|
return samples;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int no_read (SWVoiceIn *sw, void *buf, int size)
|
||||||
|
{
|
||||||
|
int samples = size >> sw->info.shift;
|
||||||
|
int total = sw->hw->total_samples_captured - sw->total_hw_samples_acquired;
|
||||||
|
int to_clear = audio_MIN (samples, total);
|
||||||
|
audio_pcm_info_clear_buf (&sw->info, buf, to_clear);
|
||||||
|
return to_clear;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int no_ctl_in (HWVoiceIn *hw, int cmd, ...)
|
||||||
{
|
{
|
||||||
(void) hw;
|
(void) hw;
|
||||||
(void) cmd;
|
(void) cmd;
|
||||||
@@ -107,22 +140,33 @@ static void *no_audio_init (void)
|
|||||||
|
|
||||||
static void no_audio_fini (void *opaque)
|
static void no_audio_fini (void *opaque)
|
||||||
{
|
{
|
||||||
|
(void) opaque;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct pcm_ops no_pcm_ops = {
|
static struct audio_pcm_ops no_pcm_ops = {
|
||||||
no_hw_init,
|
no_init_out,
|
||||||
no_hw_fini,
|
no_fini_out,
|
||||||
no_hw_run,
|
no_run_out,
|
||||||
no_hw_write,
|
no_write,
|
||||||
no_hw_ctl
|
no_ctl_out,
|
||||||
|
|
||||||
|
no_init_in,
|
||||||
|
no_fini_in,
|
||||||
|
no_run_in,
|
||||||
|
no_read,
|
||||||
|
no_ctl_in
|
||||||
};
|
};
|
||||||
|
|
||||||
struct audio_output_driver no_output_driver = {
|
struct audio_driver no_audio_driver = {
|
||||||
"none",
|
INIT_FIELD (name = ) "none",
|
||||||
no_audio_init,
|
INIT_FIELD (descr = ) "Timer based audio emulation",
|
||||||
no_audio_fini,
|
INIT_FIELD (options = ) NULL,
|
||||||
&no_pcm_ops,
|
INIT_FIELD (init = ) no_audio_init,
|
||||||
1,
|
INIT_FIELD (fini = ) no_audio_fini,
|
||||||
1,
|
INIT_FIELD (pcm_ops = ) &no_pcm_ops,
|
||||||
sizeof (NoVoice)
|
INIT_FIELD (can_be_default = ) 1,
|
||||||
|
INIT_FIELD (max_voices_out = ) INT_MAX,
|
||||||
|
INIT_FIELD (max_voices_in = ) INT_MAX,
|
||||||
|
INIT_FIELD (voice_size_out = ) sizeof (NoVoiceOut),
|
||||||
|
INIT_FIELD (voice_size_in = ) sizeof (NoVoiceIn)
|
||||||
};
|
};
|
||||||
|
|||||||
+415
-169
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,111 @@
|
|||||||
|
/*
|
||||||
|
* QEMU Mixing engine
|
||||||
|
*
|
||||||
|
* Copyright (c) 2004-2005 Vassili Karpov (malc)
|
||||||
|
* Copyright (c) 1998 Fabrice Bellard
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||||
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Processed signed long samples from ibuf to obuf.
|
||||||
|
* Return number of samples processed.
|
||||||
|
*/
|
||||||
|
void NAME (void *opaque, st_sample_t *ibuf, st_sample_t *obuf,
|
||||||
|
int *isamp, int *osamp)
|
||||||
|
{
|
||||||
|
rate_t rate = (rate_t) opaque;
|
||||||
|
st_sample_t *istart, *iend;
|
||||||
|
st_sample_t *ostart, *oend;
|
||||||
|
st_sample_t ilast, icur, out;
|
||||||
|
#ifdef FLOAT_MIXENG
|
||||||
|
real_t t;
|
||||||
|
#else
|
||||||
|
int64_t t;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
ilast = rate->ilast;
|
||||||
|
|
||||||
|
istart = ibuf;
|
||||||
|
iend = ibuf + *isamp;
|
||||||
|
|
||||||
|
ostart = obuf;
|
||||||
|
oend = obuf + *osamp;
|
||||||
|
|
||||||
|
if (rate->opos_inc == (1ULL + UINT_MAX)) {
|
||||||
|
int i, n = *isamp > *osamp ? *osamp : *isamp;
|
||||||
|
for (i = 0; i < n; i++) {
|
||||||
|
OP (obuf[i].l, ibuf[i].r);
|
||||||
|
OP (obuf[i].r, ibuf[i].r);
|
||||||
|
}
|
||||||
|
*isamp = n;
|
||||||
|
*osamp = n;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (obuf < oend) {
|
||||||
|
|
||||||
|
/* Safety catch to make sure we have input samples. */
|
||||||
|
if (ibuf >= iend) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* read as many input samples so that ipos > opos */
|
||||||
|
|
||||||
|
while (rate->ipos <= (rate->opos >> 32)) {
|
||||||
|
ilast = *ibuf++;
|
||||||
|
rate->ipos++;
|
||||||
|
/* See if we finished the input buffer yet */
|
||||||
|
if (ibuf >= iend) {
|
||||||
|
goto the_end;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
icur = *ibuf;
|
||||||
|
|
||||||
|
/* interpolate */
|
||||||
|
#ifdef FLOAT_MIXENG
|
||||||
|
#ifdef RECIPROCAL
|
||||||
|
t = (rate->opos & UINT_MAX) * (1.f / UINT_MAX);
|
||||||
|
#else
|
||||||
|
t = (rate->opos & UINT_MAX) / (real_t) UINT_MAX;
|
||||||
|
#endif
|
||||||
|
out.l = (ilast.l * (1.0 - t)) + icur.l * t;
|
||||||
|
out.r = (ilast.r * (1.0 - t)) + icur.r * t;
|
||||||
|
#else
|
||||||
|
t = rate->opos & 0xffffffff;
|
||||||
|
out.l = (ilast.l * ((int64_t) UINT_MAX - t) + icur.l * t) >> 32;
|
||||||
|
out.r = (ilast.r * ((int64_t) UINT_MAX - t) + icur.r * t) >> 32;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* output sample & increment position */
|
||||||
|
OP (obuf->l, out.l);
|
||||||
|
OP (obuf->r, out.r);
|
||||||
|
obuf += 1;
|
||||||
|
rate->opos += rate->opos_inc;
|
||||||
|
}
|
||||||
|
|
||||||
|
the_end:
|
||||||
|
*isamp = ibuf - istart;
|
||||||
|
*osamp = obuf - ostart;
|
||||||
|
rate->ilast = ilast;
|
||||||
|
}
|
||||||
|
|
||||||
|
#undef NAME
|
||||||
|
#undef OP
|
||||||
+214
-107
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* QEMU SDL audio output driver
|
* QEMU SDL audio driver
|
||||||
*
|
*
|
||||||
* Copyright (c) 2004 Vassili Karpov (malc)
|
* Copyright (c) 2004-2005 Vassili Karpov (malc)
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -25,22 +25,15 @@
|
|||||||
#include <SDL_thread.h>
|
#include <SDL_thread.h>
|
||||||
#include "vl.h"
|
#include "vl.h"
|
||||||
|
|
||||||
#include "audio/audio_int.h"
|
#define AUDIO_CAP "sdl"
|
||||||
|
#include "audio_int.h"
|
||||||
|
|
||||||
typedef struct SDLVoice {
|
typedef struct SDLVoiceOut {
|
||||||
HWVoice hw;
|
HWVoiceOut hw;
|
||||||
} SDLVoice;
|
int live;
|
||||||
|
int rpos;
|
||||||
#define dolog(...) AUD_log ("sdl", __VA_ARGS__)
|
int decr;
|
||||||
#ifdef DEBUG
|
} SDLVoiceOut;
|
||||||
#define ldebug(...) dolog (__VA_ARGS__)
|
|
||||||
#else
|
|
||||||
#define ldebug(...)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define QC_SDL_SAMPLES "QEMU_SDL_SAMPLES"
|
|
||||||
|
|
||||||
#define errstr() SDL_GetError ()
|
|
||||||
|
|
||||||
static struct {
|
static struct {
|
||||||
int nb_samples;
|
int nb_samples;
|
||||||
@@ -56,91 +49,129 @@ struct SDLAudioState {
|
|||||||
} glob_sdl;
|
} glob_sdl;
|
||||||
typedef struct SDLAudioState SDLAudioState;
|
typedef struct SDLAudioState SDLAudioState;
|
||||||
|
|
||||||
static void sdl_hw_run (HWVoice *hw)
|
static void GCC_FMT_ATTR (1, 2) sdl_logerr (const char *fmt, ...)
|
||||||
{
|
{
|
||||||
(void) hw;
|
va_list ap;
|
||||||
|
|
||||||
|
va_start (ap, fmt);
|
||||||
|
AUD_vlog (AUDIO_CAP, fmt, ap);
|
||||||
|
va_end (ap);
|
||||||
|
|
||||||
|
AUD_log (AUDIO_CAP, "Reason: %s\n", SDL_GetError ());
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sdl_lock (SDLAudioState *s)
|
static int sdl_lock (SDLAudioState *s, const char *forfn)
|
||||||
{
|
{
|
||||||
if (SDL_LockMutex (s->mutex)) {
|
if (SDL_LockMutex (s->mutex)) {
|
||||||
dolog ("SDL_LockMutex failed\nReason: %s\n", errstr ());
|
sdl_logerr ("SDL_LockMutex for %s failed\n", forfn);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sdl_unlock (SDLAudioState *s)
|
static int sdl_unlock (SDLAudioState *s, const char *forfn)
|
||||||
{
|
{
|
||||||
if (SDL_UnlockMutex (s->mutex)) {
|
if (SDL_UnlockMutex (s->mutex)) {
|
||||||
dolog ("SDL_UnlockMutex failed\nReason: %s\n", errstr ());
|
sdl_logerr ("SDL_UnlockMutex for %s failed\n", forfn);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sdl_post (SDLAudioState *s)
|
static int sdl_post (SDLAudioState *s, const char *forfn)
|
||||||
{
|
{
|
||||||
if (SDL_SemPost (s->sem)) {
|
if (SDL_SemPost (s->sem)) {
|
||||||
dolog ("SDL_SemPost failed\nReason: %s\n", errstr ());
|
sdl_logerr ("SDL_SemPost for %s failed\n", forfn);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sdl_wait (SDLAudioState *s)
|
static int sdl_wait (SDLAudioState *s, const char *forfn)
|
||||||
{
|
{
|
||||||
if (SDL_SemWait (s->sem)) {
|
if (SDL_SemWait (s->sem)) {
|
||||||
dolog ("SDL_SemWait failed\nReason: %s\n", errstr ());
|
sdl_logerr ("SDL_SemWait for %s failed\n", forfn);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sdl_unlock_and_post (SDLAudioState *s)
|
static int sdl_unlock_and_post (SDLAudioState *s, const char *forfn)
|
||||||
{
|
{
|
||||||
if (sdl_unlock (s))
|
if (sdl_unlock (s, forfn)) {
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return sdl_post (s);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sdl_hw_write (SWVoice *sw, void *buf, int len)
|
return sdl_post (s, forfn);
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
SDLAudioState *s = &glob_sdl;
|
|
||||||
sdl_lock (s);
|
|
||||||
ret = pcm_hw_write (sw, buf, len);
|
|
||||||
sdl_unlock_and_post (s);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int AUD_to_sdlfmt (audfmt_e fmt, int *shift)
|
static int aud_to_sdlfmt (audfmt_e fmt, int *shift)
|
||||||
{
|
{
|
||||||
|
switch (fmt) {
|
||||||
|
case AUD_FMT_S8:
|
||||||
*shift = 0;
|
*shift = 0;
|
||||||
switch (fmt) {
|
return AUDIO_S8;
|
||||||
case AUD_FMT_S8: return AUDIO_S8;
|
|
||||||
case AUD_FMT_U8: return AUDIO_U8;
|
case AUD_FMT_U8:
|
||||||
case AUD_FMT_S16: *shift = 1; return AUDIO_S16LSB;
|
*shift = 0;
|
||||||
case AUD_FMT_U16: *shift = 1; return AUDIO_U16LSB;
|
return AUDIO_U8;
|
||||||
|
|
||||||
|
case AUD_FMT_S16:
|
||||||
|
*shift = 1;
|
||||||
|
return AUDIO_S16LSB;
|
||||||
|
|
||||||
|
case AUD_FMT_U16:
|
||||||
|
*shift = 1;
|
||||||
|
return AUDIO_U16LSB;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
dolog ("Internal logic error: Bad audio format %d\nAborting\n", fmt);
|
dolog ("Internal logic error: Bad audio format %d\n", fmt);
|
||||||
exit (EXIT_FAILURE);
|
#ifdef DEBUG_AUDIO
|
||||||
|
abort ();
|
||||||
|
#endif
|
||||||
|
return AUDIO_U8;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sdl_to_audfmt (int fmt)
|
static int sdl_to_audfmt (int sdlfmt, audfmt_e *fmt, int *endianess)
|
||||||
{
|
{
|
||||||
switch (fmt) {
|
switch (sdlfmt) {
|
||||||
case AUDIO_S8: return AUD_FMT_S8;
|
case AUDIO_S8:
|
||||||
case AUDIO_U8: return AUD_FMT_U8;
|
*endianess = 0;
|
||||||
case AUDIO_S16LSB: return AUD_FMT_S16;
|
*fmt = AUD_FMT_S8;
|
||||||
case AUDIO_U16LSB: return AUD_FMT_U16;
|
break;
|
||||||
|
|
||||||
|
case AUDIO_U8:
|
||||||
|
*endianess = 0;
|
||||||
|
*fmt = AUD_FMT_U8;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case AUDIO_S16LSB:
|
||||||
|
*endianess = 0;
|
||||||
|
*fmt = AUD_FMT_S16;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case AUDIO_U16LSB:
|
||||||
|
*endianess = 0;
|
||||||
|
*fmt = AUD_FMT_U16;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case AUDIO_S16MSB:
|
||||||
|
*endianess = 1;
|
||||||
|
*fmt = AUD_FMT_S16;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case AUDIO_U16MSB:
|
||||||
|
*endianess = 1;
|
||||||
|
*fmt = AUD_FMT_U16;
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
dolog ("Internal logic error: Unrecognized SDL audio format %d\n"
|
dolog ("Unrecognized SDL audio format %d\n", sdlfmt);
|
||||||
"Aborting\n", fmt);
|
return -1;
|
||||||
exit (EXIT_FAILURE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sdl_open (SDL_AudioSpec *req, SDL_AudioSpec *obt)
|
static int sdl_open (SDL_AudioSpec *req, SDL_AudioSpec *obt)
|
||||||
@@ -149,7 +180,7 @@ static int sdl_open (SDL_AudioSpec *req, SDL_AudioSpec *obt)
|
|||||||
|
|
||||||
status = SDL_OpenAudio (req, obt);
|
status = SDL_OpenAudio (req, obt);
|
||||||
if (status) {
|
if (status) {
|
||||||
dolog ("SDL_OpenAudio failed\nReason: %s\n", errstr ());
|
sdl_logerr ("SDL_OpenAudio failed\n");
|
||||||
}
|
}
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
@@ -157,9 +188,9 @@ static int sdl_open (SDL_AudioSpec *req, SDL_AudioSpec *obt)
|
|||||||
static void sdl_close (SDLAudioState *s)
|
static void sdl_close (SDLAudioState *s)
|
||||||
{
|
{
|
||||||
if (s->initialized) {
|
if (s->initialized) {
|
||||||
sdl_lock (s);
|
sdl_lock (s, "sdl_close");
|
||||||
s->exit = 1;
|
s->exit = 1;
|
||||||
sdl_unlock_and_post (s);
|
sdl_unlock_and_post (s, "sdl_close");
|
||||||
SDL_PauseAudio (1);
|
SDL_PauseAudio (1);
|
||||||
SDL_CloseAudio ();
|
SDL_CloseAudio ();
|
||||||
s->initialized = 0;
|
s->initialized = 0;
|
||||||
@@ -168,31 +199,40 @@ static void sdl_close (SDLAudioState *s)
|
|||||||
|
|
||||||
static void sdl_callback (void *opaque, Uint8 *buf, int len)
|
static void sdl_callback (void *opaque, Uint8 *buf, int len)
|
||||||
{
|
{
|
||||||
SDLVoice *sdl = opaque;
|
SDLVoiceOut *sdl = opaque;
|
||||||
SDLAudioState *s = &glob_sdl;
|
SDLAudioState *s = &glob_sdl;
|
||||||
HWVoice *hw = &sdl->hw;
|
HWVoiceOut *hw = &sdl->hw;
|
||||||
int samples = len >> hw->shift;
|
int samples = len >> hw->info.shift;
|
||||||
|
|
||||||
if (s->exit) {
|
if (s->exit) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (samples) {
|
while (samples) {
|
||||||
int to_mix, live, decr;
|
int to_mix, decr;
|
||||||
|
|
||||||
/* dolog ("in callback samples=%d\n", samples); */
|
/* dolog ("in callback samples=%d\n", samples); */
|
||||||
sdl_wait (s);
|
sdl_wait (s, "sdl_callback");
|
||||||
if (s->exit) {
|
if (s->exit) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
sdl_lock (s);
|
if (sdl_lock (s, "sdl_callback")) {
|
||||||
live = pcm_hw_get_live (hw);
|
return;
|
||||||
if (live <= 0)
|
}
|
||||||
|
|
||||||
|
if (audio_bug (AUDIO_FUNC, sdl->live < 0 || sdl->live > hw->samples)) {
|
||||||
|
dolog ("sdl->live=%d hw->samples=%d\n",
|
||||||
|
sdl->live, hw->samples);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!sdl->live) {
|
||||||
goto again;
|
goto again;
|
||||||
|
}
|
||||||
|
|
||||||
/* dolog ("in callback live=%d\n", live); */
|
/* dolog ("in callback live=%d\n", live); */
|
||||||
to_mix = audio_MIN (samples, live);
|
to_mix = audio_MIN (samples, sdl->live);
|
||||||
decr = to_mix;
|
decr = to_mix;
|
||||||
while (to_mix) {
|
while (to_mix) {
|
||||||
int chunk = audio_MIN (to_mix, hw->samples - hw->rpos);
|
int chunk = audio_MIN (to_mix, hw->samples - hw->rpos);
|
||||||
@@ -200,44 +240,86 @@ static void sdl_callback (void *opaque, Uint8 *buf, int len)
|
|||||||
|
|
||||||
/* dolog ("in callback to_mix %d, chunk %d\n", to_mix, chunk); */
|
/* dolog ("in callback to_mix %d, chunk %d\n", to_mix, chunk); */
|
||||||
hw->clip (buf, src, chunk);
|
hw->clip (buf, src, chunk);
|
||||||
memset (src, 0, chunk * sizeof (st_sample_t));
|
mixeng_clear (src, chunk);
|
||||||
hw->rpos = (hw->rpos + chunk) % hw->samples;
|
sdl->rpos = (sdl->rpos + chunk) % hw->samples;
|
||||||
to_mix -= chunk;
|
to_mix -= chunk;
|
||||||
buf += chunk << hw->shift;
|
buf += chunk << hw->info.shift;
|
||||||
}
|
}
|
||||||
samples -= decr;
|
samples -= decr;
|
||||||
pcm_hw_dec_live (hw, decr);
|
sdl->live -= decr;
|
||||||
|
sdl->decr += decr;
|
||||||
|
|
||||||
again:
|
again:
|
||||||
sdl_unlock (s);
|
if (sdl_unlock (s, "sdl_callback")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/* dolog ("done len=%d\n", len); */
|
/* dolog ("done len=%d\n", len); */
|
||||||
}
|
}
|
||||||
|
|
||||||
static void sdl_hw_fini (HWVoice *hw)
|
static int sdl_write_out (SWVoiceOut *sw, void *buf, int len)
|
||||||
{
|
{
|
||||||
ldebug ("sdl_hw_fini %d fixed=%d\n",
|
return audio_pcm_sw_write (sw, buf, len);
|
||||||
glob_sdl.initialized, audio_state.fixed_format);
|
}
|
||||||
|
|
||||||
|
static int sdl_run_out (HWVoiceOut *hw)
|
||||||
|
{
|
||||||
|
int decr, live;
|
||||||
|
SDLVoiceOut *sdl = (SDLVoiceOut *) hw;
|
||||||
|
SDLAudioState *s = &glob_sdl;
|
||||||
|
|
||||||
|
if (sdl_lock (s, "sdl_callback")) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
live = audio_pcm_hw_get_live_out (hw);
|
||||||
|
|
||||||
|
if (sdl->decr > live) {
|
||||||
|
ldebug ("sdl->decr %d live %d sdl->live %d\n",
|
||||||
|
sdl->decr,
|
||||||
|
live,
|
||||||
|
sdl->live);
|
||||||
|
}
|
||||||
|
|
||||||
|
decr = audio_MIN (sdl->decr, live);
|
||||||
|
sdl->decr -= decr;
|
||||||
|
|
||||||
|
sdl->live = live - decr;
|
||||||
|
hw->rpos = sdl->rpos;
|
||||||
|
|
||||||
|
if (sdl->live > 0) {
|
||||||
|
sdl_unlock_and_post (s, "sdl_callback");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
sdl_unlock (s, "sdl_callback");
|
||||||
|
}
|
||||||
|
return decr;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void sdl_fini_out (HWVoiceOut *hw)
|
||||||
|
{
|
||||||
|
(void) hw;
|
||||||
|
|
||||||
sdl_close (&glob_sdl);
|
sdl_close (&glob_sdl);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sdl_hw_init (HWVoice *hw, int freq, int nchannels, audfmt_e fmt)
|
static int sdl_init_out (HWVoiceOut *hw, int freq, int nchannels, audfmt_e fmt)
|
||||||
{
|
{
|
||||||
SDLVoice *sdl = (SDLVoice *) hw;
|
SDLVoiceOut *sdl = (SDLVoiceOut *) hw;
|
||||||
SDLAudioState *s = &glob_sdl;
|
SDLAudioState *s = &glob_sdl;
|
||||||
SDL_AudioSpec req, obt;
|
SDL_AudioSpec req, obt;
|
||||||
int shift;
|
int shift;
|
||||||
|
int endianess;
|
||||||
ldebug ("sdl_hw_init %d freq=%d fixed=%d\n",
|
int err;
|
||||||
s->initialized, freq, audio_state.fixed_format);
|
audfmt_e effective_fmt;
|
||||||
|
|
||||||
if (nchannels != 2) {
|
if (nchannels != 2) {
|
||||||
dolog ("Bogus channel count %d\n", nchannels);
|
dolog ("Can not init DAC. Bogus channel count %d\n", nchannels);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
req.freq = freq;
|
req.freq = freq;
|
||||||
req.format = AUD_to_sdlfmt (fmt, &shift);
|
req.format = aud_to_sdlfmt (fmt, &shift);
|
||||||
req.channels = nchannels;
|
req.channels = nchannels;
|
||||||
req.samples = conf.nb_samples;
|
req.samples = conf.nb_samples;
|
||||||
shift <<= nchannels == 2;
|
shift <<= nchannels == 2;
|
||||||
@@ -245,12 +327,23 @@ static int sdl_hw_init (HWVoice *hw, int freq, int nchannels, audfmt_e fmt)
|
|||||||
req.callback = sdl_callback;
|
req.callback = sdl_callback;
|
||||||
req.userdata = sdl;
|
req.userdata = sdl;
|
||||||
|
|
||||||
if (sdl_open (&req, &obt))
|
if (sdl_open (&req, &obt)) {
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
hw->freq = obt.freq;
|
err = sdl_to_audfmt (obt.format, &effective_fmt, &endianess);
|
||||||
hw->fmt = sdl_to_audfmt (obt.format);
|
if (err) {
|
||||||
hw->nchannels = obt.channels;
|
sdl_close (s);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
audio_pcm_init_info (
|
||||||
|
&hw->info,
|
||||||
|
obt.freq,
|
||||||
|
obt.channels,
|
||||||
|
effective_fmt,
|
||||||
|
audio_need_to_swap_endian (endianess)
|
||||||
|
);
|
||||||
hw->bufsize = obt.samples << shift;
|
hw->bufsize = obt.samples << shift;
|
||||||
|
|
||||||
s->initialized = 1;
|
s->initialized = 1;
|
||||||
@@ -259,7 +352,7 @@ static int sdl_hw_init (HWVoice *hw, int freq, int nchannels, audfmt_e fmt)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sdl_hw_ctl (HWVoice *hw, int cmd, ...)
|
static int sdl_ctl_out (HWVoiceOut *hw, int cmd, ...)
|
||||||
{
|
{
|
||||||
(void) hw;
|
(void) hw;
|
||||||
|
|
||||||
@@ -278,24 +371,22 @@ static int sdl_hw_ctl (HWVoice *hw, int cmd, ...)
|
|||||||
static void *sdl_audio_init (void)
|
static void *sdl_audio_init (void)
|
||||||
{
|
{
|
||||||
SDLAudioState *s = &glob_sdl;
|
SDLAudioState *s = &glob_sdl;
|
||||||
conf.nb_samples = audio_get_conf_int (QC_SDL_SAMPLES, conf.nb_samples);
|
|
||||||
|
|
||||||
if (SDL_InitSubSystem (SDL_INIT_AUDIO)) {
|
if (SDL_InitSubSystem (SDL_INIT_AUDIO)) {
|
||||||
dolog ("SDL failed to initialize audio subsystem\nReason: %s\n",
|
sdl_logerr ("SDL failed to initialize audio subsystem\n");
|
||||||
errstr ());
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
s->mutex = SDL_CreateMutex ();
|
s->mutex = SDL_CreateMutex ();
|
||||||
if (!s->mutex) {
|
if (!s->mutex) {
|
||||||
dolog ("Failed to create SDL mutex\nReason: %s\n", errstr ());
|
sdl_logerr ("Failed to create SDL mutex\n");
|
||||||
SDL_QuitSubSystem (SDL_INIT_AUDIO);
|
SDL_QuitSubSystem (SDL_INIT_AUDIO);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
s->sem = SDL_CreateSemaphore (0);
|
s->sem = SDL_CreateSemaphore (0);
|
||||||
if (!s->sem) {
|
if (!s->sem) {
|
||||||
dolog ("Failed to create SDL semaphore\nReason: %s\n", errstr ());
|
sdl_logerr ("Failed to create SDL semaphore\n");
|
||||||
SDL_DestroyMutex (s->mutex);
|
SDL_DestroyMutex (s->mutex);
|
||||||
SDL_QuitSubSystem (SDL_INIT_AUDIO);
|
SDL_QuitSubSystem (SDL_INIT_AUDIO);
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -313,20 +404,36 @@ static void sdl_audio_fini (void *opaque)
|
|||||||
SDL_QuitSubSystem (SDL_INIT_AUDIO);
|
SDL_QuitSubSystem (SDL_INIT_AUDIO);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct pcm_ops sdl_pcm_ops = {
|
static struct audio_option sdl_options[] = {
|
||||||
sdl_hw_init,
|
{"SAMPLES", AUD_OPT_INT, &conf.nb_samples,
|
||||||
sdl_hw_fini,
|
"Size of SDL buffer in samples", NULL, 0},
|
||||||
sdl_hw_run,
|
{NULL, 0, NULL, NULL, NULL, 0}
|
||||||
sdl_hw_write,
|
|
||||||
sdl_hw_ctl
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct audio_output_driver sdl_output_driver = {
|
static struct audio_pcm_ops sdl_pcm_ops = {
|
||||||
"sdl",
|
sdl_init_out,
|
||||||
sdl_audio_init,
|
sdl_fini_out,
|
||||||
sdl_audio_fini,
|
sdl_run_out,
|
||||||
&sdl_pcm_ops,
|
sdl_write_out,
|
||||||
1,
|
sdl_ctl_out,
|
||||||
1,
|
|
||||||
sizeof (SDLVoice)
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
struct audio_driver sdl_audio_driver = {
|
||||||
|
INIT_FIELD (name = ) "sdl",
|
||||||
|
INIT_FIELD (descr = ) "SDL http://www.libsdl.org",
|
||||||
|
INIT_FIELD (options = ) sdl_options,
|
||||||
|
INIT_FIELD (init = ) sdl_audio_init,
|
||||||
|
INIT_FIELD (fini = ) sdl_audio_fini,
|
||||||
|
INIT_FIELD (pcm_ops = ) &sdl_pcm_ops,
|
||||||
|
INIT_FIELD (can_be_default = ) 1,
|
||||||
|
INIT_FIELD (max_voices_out = ) 1,
|
||||||
|
INIT_FIELD (max_voices_in = ) 0,
|
||||||
|
INIT_FIELD (voice_size_out = ) sizeof (SDLVoiceOut),
|
||||||
|
INIT_FIELD (voice_size_in = ) 0
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,241 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 1991, 1993
|
||||||
|
* The Regents of the University of California. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 4. Neither the name of the University nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
* @(#)queue.h 8.3 (Berkeley) 12/13/93
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _SYS_QUEUE_H
|
||||||
|
#define _SYS_QUEUE_H 1
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file defines three types of data structures: lists, tail queues,
|
||||||
|
* and circular queues.
|
||||||
|
*
|
||||||
|
* A list is headed by a single forward pointer (or an array of forward
|
||||||
|
* pointers for a hash table header). The elements are doubly linked
|
||||||
|
* so that an arbitrary element can be removed without a need to
|
||||||
|
* traverse the list. New elements can be added to the list after
|
||||||
|
* an existing element or at the head of the list. A list may only be
|
||||||
|
* traversed in the forward direction.
|
||||||
|
*
|
||||||
|
* A tail queue is headed by a pair of pointers, one to the head of the
|
||||||
|
* list and the other to the tail of the list. The elements are doubly
|
||||||
|
* linked so that an arbitrary element can be removed without a need to
|
||||||
|
* traverse the list. New elements can be added to the list after
|
||||||
|
* an existing element, at the head of the list, or at the end of the
|
||||||
|
* list. A tail queue may only be traversed in the forward direction.
|
||||||
|
*
|
||||||
|
* A circle queue is headed by a pair of pointers, one to the head of the
|
||||||
|
* list and the other to the tail of the list. The elements are doubly
|
||||||
|
* linked so that an arbitrary element can be removed without a need to
|
||||||
|
* traverse the list. New elements can be added to the list before or after
|
||||||
|
* an existing element, at the head of the list, or at the end of the list.
|
||||||
|
* A circle queue may be traversed in either direction, but has a more
|
||||||
|
* complex end of list detection.
|
||||||
|
*
|
||||||
|
* For details on the use of these macros, see the queue(3) manual page.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* List definitions.
|
||||||
|
*/
|
||||||
|
#define LIST_HEAD(name, type) \
|
||||||
|
struct name { \
|
||||||
|
struct type *lh_first; /* first element */ \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define LIST_ENTRY(type) \
|
||||||
|
struct { \
|
||||||
|
struct type *le_next; /* next element */ \
|
||||||
|
struct type **le_prev; /* address of previous next element */ \
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* List functions.
|
||||||
|
*/
|
||||||
|
#define LIST_INIT(head) { \
|
||||||
|
(head)->lh_first = NULL; \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define LIST_INSERT_AFTER(listelm, elm, field) { \
|
||||||
|
if (((elm)->field.le_next = (listelm)->field.le_next) != NULL) \
|
||||||
|
(listelm)->field.le_next->field.le_prev = \
|
||||||
|
&(elm)->field.le_next; \
|
||||||
|
(listelm)->field.le_next = (elm); \
|
||||||
|
(elm)->field.le_prev = &(listelm)->field.le_next; \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define LIST_INSERT_HEAD(head, elm, field) { \
|
||||||
|
if (((elm)->field.le_next = (head)->lh_first) != NULL) \
|
||||||
|
(head)->lh_first->field.le_prev = &(elm)->field.le_next;\
|
||||||
|
(head)->lh_first = (elm); \
|
||||||
|
(elm)->field.le_prev = &(head)->lh_first; \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define LIST_REMOVE(elm, field) { \
|
||||||
|
if ((elm)->field.le_next != NULL) \
|
||||||
|
(elm)->field.le_next->field.le_prev = \
|
||||||
|
(elm)->field.le_prev; \
|
||||||
|
*(elm)->field.le_prev = (elm)->field.le_next; \
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Tail queue definitions.
|
||||||
|
*/
|
||||||
|
#define TAILQ_HEAD(name, type) \
|
||||||
|
struct name { \
|
||||||
|
struct type *tqh_first; /* first element */ \
|
||||||
|
struct type **tqh_last; /* addr of last next element */ \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define TAILQ_ENTRY(type) \
|
||||||
|
struct { \
|
||||||
|
struct type *tqe_next; /* next element */ \
|
||||||
|
struct type **tqe_prev; /* address of previous next element */ \
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Tail queue functions.
|
||||||
|
*/
|
||||||
|
#define TAILQ_INIT(head) { \
|
||||||
|
(head)->tqh_first = NULL; \
|
||||||
|
(head)->tqh_last = &(head)->tqh_first; \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define TAILQ_INSERT_HEAD(head, elm, field) { \
|
||||||
|
if (((elm)->field.tqe_next = (head)->tqh_first) != NULL) \
|
||||||
|
(elm)->field.tqe_next->field.tqe_prev = \
|
||||||
|
&(elm)->field.tqe_next; \
|
||||||
|
else \
|
||||||
|
(head)->tqh_last = &(elm)->field.tqe_next; \
|
||||||
|
(head)->tqh_first = (elm); \
|
||||||
|
(elm)->field.tqe_prev = &(head)->tqh_first; \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define TAILQ_INSERT_TAIL(head, elm, field) { \
|
||||||
|
(elm)->field.tqe_next = NULL; \
|
||||||
|
(elm)->field.tqe_prev = (head)->tqh_last; \
|
||||||
|
*(head)->tqh_last = (elm); \
|
||||||
|
(head)->tqh_last = &(elm)->field.tqe_next; \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define TAILQ_INSERT_AFTER(head, listelm, elm, field) { \
|
||||||
|
if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)\
|
||||||
|
(elm)->field.tqe_next->field.tqe_prev = \
|
||||||
|
&(elm)->field.tqe_next; \
|
||||||
|
else \
|
||||||
|
(head)->tqh_last = &(elm)->field.tqe_next; \
|
||||||
|
(listelm)->field.tqe_next = (elm); \
|
||||||
|
(elm)->field.tqe_prev = &(listelm)->field.tqe_next; \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define TAILQ_REMOVE(head, elm, field) { \
|
||||||
|
if (((elm)->field.tqe_next) != NULL) \
|
||||||
|
(elm)->field.tqe_next->field.tqe_prev = \
|
||||||
|
(elm)->field.tqe_prev; \
|
||||||
|
else \
|
||||||
|
(head)->tqh_last = (elm)->field.tqe_prev; \
|
||||||
|
*(elm)->field.tqe_prev = (elm)->field.tqe_next; \
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Circular queue definitions.
|
||||||
|
*/
|
||||||
|
#define CIRCLEQ_HEAD(name, type) \
|
||||||
|
struct name { \
|
||||||
|
struct type *cqh_first; /* first element */ \
|
||||||
|
struct type *cqh_last; /* last element */ \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define CIRCLEQ_ENTRY(type) \
|
||||||
|
struct { \
|
||||||
|
struct type *cqe_next; /* next element */ \
|
||||||
|
struct type *cqe_prev; /* previous element */ \
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Circular queue functions.
|
||||||
|
*/
|
||||||
|
#define CIRCLEQ_INIT(head) { \
|
||||||
|
(head)->cqh_first = (void *)(head); \
|
||||||
|
(head)->cqh_last = (void *)(head); \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define CIRCLEQ_INSERT_AFTER(head, listelm, elm, field) { \
|
||||||
|
(elm)->field.cqe_next = (listelm)->field.cqe_next; \
|
||||||
|
(elm)->field.cqe_prev = (listelm); \
|
||||||
|
if ((listelm)->field.cqe_next == (void *)(head)) \
|
||||||
|
(head)->cqh_last = (elm); \
|
||||||
|
else \
|
||||||
|
(listelm)->field.cqe_next->field.cqe_prev = (elm); \
|
||||||
|
(listelm)->field.cqe_next = (elm); \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define CIRCLEQ_INSERT_BEFORE(head, listelm, elm, field) { \
|
||||||
|
(elm)->field.cqe_next = (listelm); \
|
||||||
|
(elm)->field.cqe_prev = (listelm)->field.cqe_prev; \
|
||||||
|
if ((listelm)->field.cqe_prev == (void *)(head)) \
|
||||||
|
(head)->cqh_first = (elm); \
|
||||||
|
else \
|
||||||
|
(listelm)->field.cqe_prev->field.cqe_next = (elm); \
|
||||||
|
(listelm)->field.cqe_prev = (elm); \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define CIRCLEQ_INSERT_HEAD(head, elm, field) { \
|
||||||
|
(elm)->field.cqe_next = (head)->cqh_first; \
|
||||||
|
(elm)->field.cqe_prev = (void *)(head); \
|
||||||
|
if ((head)->cqh_last == (void *)(head)) \
|
||||||
|
(head)->cqh_last = (elm); \
|
||||||
|
else \
|
||||||
|
(head)->cqh_first->field.cqe_prev = (elm); \
|
||||||
|
(head)->cqh_first = (elm); \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define CIRCLEQ_INSERT_TAIL(head, elm, field) { \
|
||||||
|
(elm)->field.cqe_next = (void *)(head); \
|
||||||
|
(elm)->field.cqe_prev = (head)->cqh_last; \
|
||||||
|
if ((head)->cqh_first == (void *)(head)) \
|
||||||
|
(head)->cqh_first = (elm); \
|
||||||
|
else \
|
||||||
|
(head)->cqh_last->field.cqe_next = (elm); \
|
||||||
|
(head)->cqh_last = (elm); \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define CIRCLEQ_REMOVE(head, elm, field) { \
|
||||||
|
if ((elm)->field.cqe_next == (void *)(head)) \
|
||||||
|
(head)->cqh_last = (elm)->field.cqe_prev; \
|
||||||
|
else \
|
||||||
|
(elm)->field.cqe_next->field.cqe_prev = \
|
||||||
|
(elm)->field.cqe_prev; \
|
||||||
|
if ((elm)->field.cqe_prev == (void *)(head)) \
|
||||||
|
(head)->cqh_first = (elm)->field.cqe_next; \
|
||||||
|
else \
|
||||||
|
(elm)->field.cqe_prev->field.cqe_next = \
|
||||||
|
(elm)->field.cqe_next; \
|
||||||
|
}
|
||||||
|
#endif /* sys/queue.h */
|
||||||
+94
-62
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* QEMU WAV audio output driver
|
* QEMU WAV audio driver
|
||||||
*
|
*
|
||||||
* Copyright (c) 2004 Vassili Karpov (malc)
|
* Copyright (c) 2004-2005 Vassili Karpov (malc)
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -23,22 +23,16 @@
|
|||||||
*/
|
*/
|
||||||
#include "vl.h"
|
#include "vl.h"
|
||||||
|
|
||||||
#include "audio/audio_int.h"
|
#define AUDIO_CAP "wav"
|
||||||
|
#include "audio_int.h"
|
||||||
|
|
||||||
typedef struct WAVVoice {
|
typedef struct WAVVoiceOut {
|
||||||
HWVoice hw;
|
HWVoiceOut hw;
|
||||||
QEMUFile *f;
|
QEMUFile *f;
|
||||||
int64_t old_ticks;
|
int64_t old_ticks;
|
||||||
void *pcm_buf;
|
void *pcm_buf;
|
||||||
int total_samples;
|
int total_samples;
|
||||||
} WAVVoice;
|
} WAVVoiceOut;
|
||||||
|
|
||||||
#define dolog(...) AUD_log ("wav", __VA_ARGS__)
|
|
||||||
#ifdef DEBUG
|
|
||||||
#define ldebug(...) dolog (__VA_ARGS__)
|
|
||||||
#else
|
|
||||||
#define ldebug(...)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static struct {
|
static struct {
|
||||||
const char *wav_path;
|
const char *wav_path;
|
||||||
@@ -46,24 +40,27 @@ static struct {
|
|||||||
.wav_path = "qemu.wav"
|
.wav_path = "qemu.wav"
|
||||||
};
|
};
|
||||||
|
|
||||||
static void wav_hw_run (HWVoice *hw)
|
static int wav_run_out (HWVoiceOut *hw)
|
||||||
{
|
{
|
||||||
WAVVoice *wav = (WAVVoice *) hw;
|
WAVVoiceOut *wav = (WAVVoiceOut *) hw;
|
||||||
int rpos, live, decr, samples;
|
int rpos, live, decr, samples;
|
||||||
uint8_t *dst;
|
uint8_t *dst;
|
||||||
st_sample_t *src;
|
st_sample_t *src;
|
||||||
int64_t now = qemu_get_clock (vm_clock);
|
int64_t now = qemu_get_clock (vm_clock);
|
||||||
int64_t ticks = now - wav->old_ticks;
|
int64_t ticks = now - wav->old_ticks;
|
||||||
int64_t bytes = (ticks * hw->bytes_per_second) / ticks_per_sec;
|
int64_t bytes = (ticks * hw->info.bytes_per_second) / ticks_per_sec;
|
||||||
|
|
||||||
if (bytes > INT_MAX)
|
if (bytes > INT_MAX) {
|
||||||
samples = INT_MAX >> hw->shift;
|
samples = INT_MAX >> hw->info.shift;
|
||||||
else
|
}
|
||||||
samples = bytes >> hw->shift;
|
else {
|
||||||
|
samples = bytes >> hw->info.shift;
|
||||||
|
}
|
||||||
|
|
||||||
live = pcm_hw_get_live (hw);
|
live = audio_pcm_hw_get_live_out (hw);
|
||||||
if (live <= 0)
|
if (!live) {
|
||||||
return;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
wav->old_ticks = now;
|
wav->old_ticks = now;
|
||||||
decr = audio_MIN (live, samples);
|
decr = audio_MIN (live, samples);
|
||||||
@@ -73,25 +70,25 @@ static void wav_hw_run (HWVoice *hw)
|
|||||||
int left_till_end_samples = hw->samples - rpos;
|
int left_till_end_samples = hw->samples - rpos;
|
||||||
int convert_samples = audio_MIN (samples, left_till_end_samples);
|
int convert_samples = audio_MIN (samples, left_till_end_samples);
|
||||||
|
|
||||||
src = advance (hw->mix_buf, rpos * sizeof (st_sample_t));
|
src = hw->mix_buf + rpos;
|
||||||
dst = advance (wav->pcm_buf, rpos << hw->shift);
|
dst = advance (wav->pcm_buf, rpos << hw->info.shift);
|
||||||
|
|
||||||
hw->clip (dst, src, convert_samples);
|
hw->clip (dst, src, convert_samples);
|
||||||
qemu_put_buffer (wav->f, dst, convert_samples << hw->shift);
|
qemu_put_buffer (wav->f, dst, convert_samples << hw->info.shift);
|
||||||
memset (src, 0, convert_samples * sizeof (st_sample_t));
|
mixeng_clear (src, convert_samples);
|
||||||
|
|
||||||
rpos = (rpos + convert_samples) % hw->samples;
|
rpos = (rpos + convert_samples) % hw->samples;
|
||||||
samples -= convert_samples;
|
samples -= convert_samples;
|
||||||
wav->total_samples += convert_samples;
|
wav->total_samples += convert_samples;
|
||||||
}
|
}
|
||||||
|
|
||||||
pcm_hw_dec_live (hw, decr);
|
|
||||||
hw->rpos = rpos;
|
hw->rpos = rpos;
|
||||||
|
return decr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int wav_hw_write (SWVoice *sw, void *buf, int len)
|
static int wav_write_out (SWVoiceOut *sw, void *buf, int len)
|
||||||
{
|
{
|
||||||
return pcm_hw_write (sw, buf, len);
|
return audio_pcm_sw_write (sw, buf, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* VICE code: Store number as little endian. */
|
/* VICE code: Store number as little endian. */
|
||||||
@@ -104,10 +101,10 @@ static void le_store (uint8_t *buf, uint32_t val, int len)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int wav_hw_init (HWVoice *hw, int freq, int nchannels, audfmt_e fmt)
|
static int wav_init_out (HWVoiceOut *hw, int freq, int nchannels, audfmt_e fmt)
|
||||||
{
|
{
|
||||||
WAVVoice *wav = (WAVVoice *) hw;
|
WAVVoiceOut *wav = (WAVVoiceOut *) hw;
|
||||||
int bits16 = 0, stereo = audio_state.fixed_channels == 2;
|
int bits16;
|
||||||
uint8_t hdr[] = {
|
uint8_t hdr[] = {
|
||||||
0x52, 0x49, 0x46, 0x46, 0x00, 0x00, 0x00, 0x00, 0x57, 0x41, 0x56,
|
0x52, 0x49, 0x46, 0x46, 0x00, 0x00, 0x00, 0x00, 0x57, 0x41, 0x56,
|
||||||
0x45, 0x66, 0x6d, 0x74, 0x20, 0x10, 0x00, 0x00, 0x00, 0x01, 0x00,
|
0x45, 0x66, 0x6d, 0x74, 0x20, 0x10, 0x00, 0x00, 0x00, 0x01, 0x00,
|
||||||
@@ -115,34 +112,50 @@ static int wav_hw_init (HWVoice *hw, int freq, int nchannels, audfmt_e fmt)
|
|||||||
0x00, 0x10, 0x00, 0x64, 0x61, 0x74, 0x61, 0x00, 0x00, 0x00, 0x00
|
0x00, 0x10, 0x00, 0x64, 0x61, 0x74, 0x61, 0x00, 0x00, 0x00, 0x00
|
||||||
};
|
};
|
||||||
|
|
||||||
switch (audio_state.fixed_fmt) {
|
freq = audio_state.fixed_freq_out;
|
||||||
|
fmt = audio_state.fixed_fmt_out;
|
||||||
|
nchannels = audio_state.fixed_channels_out;
|
||||||
|
|
||||||
|
switch (fmt) {
|
||||||
case AUD_FMT_S8:
|
case AUD_FMT_S8:
|
||||||
case AUD_FMT_U8:
|
case AUD_FMT_U8:
|
||||||
|
bits16 = 0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AUD_FMT_S16:
|
case AUD_FMT_S16:
|
||||||
case AUD_FMT_U16:
|
case AUD_FMT_U16:
|
||||||
bits16 = 1;
|
bits16 = 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
dolog ("Internal logic error bad format %d\n", fmt);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
hdr[34] = bits16 ? 0x10 : 0x08;
|
hdr[34] = bits16 ? 0x10 : 0x08;
|
||||||
hw->freq = 44100;
|
audio_pcm_init_info (
|
||||||
hw->nchannels = stereo ? 2 : 1;
|
&hw->info,
|
||||||
hw->fmt = bits16 ? AUD_FMT_S16 : AUD_FMT_U8;
|
freq,
|
||||||
|
nchannels,
|
||||||
|
bits16 ? AUD_FMT_S16 : AUD_FMT_U8,
|
||||||
|
audio_need_to_swap_endian (0)
|
||||||
|
);
|
||||||
hw->bufsize = 4096;
|
hw->bufsize = 4096;
|
||||||
wav->pcm_buf = qemu_mallocz (hw->bufsize);
|
wav->pcm_buf = qemu_mallocz (hw->bufsize);
|
||||||
if (!wav->pcm_buf)
|
if (!wav->pcm_buf) {
|
||||||
|
dolog ("Can not initialize WAV buffer of %d bytes\n",
|
||||||
|
hw->bufsize);
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
le_store (hdr + 22, hw->nchannels, 2);
|
le_store (hdr + 22, hw->info.nchannels, 2);
|
||||||
le_store (hdr + 24, hw->freq, 4);
|
le_store (hdr + 24, hw->info.freq, 4);
|
||||||
le_store (hdr + 28, hw->freq << (bits16 + stereo), 4);
|
le_store (hdr + 28, hw->info.freq << (bits16 + (nchannels == 2)), 4);
|
||||||
le_store (hdr + 32, 1 << (bits16 + stereo), 2);
|
le_store (hdr + 32, 1 << (bits16 + (nchannels == 2)), 2);
|
||||||
|
|
||||||
wav->f = fopen (conf.wav_path, "wb");
|
wav->f = fopen (conf.wav_path, "wb");
|
||||||
if (!wav->f) {
|
if (!wav->f) {
|
||||||
dolog ("failed to open wave file `%s'\nReason: %s\n",
|
dolog ("Failed to open wave file `%s'\nReason: %s\n",
|
||||||
conf.wav_path, strerror (errno));
|
conf.wav_path, strerror (errno));
|
||||||
qemu_free (wav->pcm_buf);
|
qemu_free (wav->pcm_buf);
|
||||||
wav->pcm_buf = NULL;
|
wav->pcm_buf = NULL;
|
||||||
@@ -153,17 +166,18 @@ static int wav_hw_init (HWVoice *hw, int freq, int nchannels, audfmt_e fmt)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void wav_hw_fini (HWVoice *hw)
|
static void wav_fini_out (HWVoiceOut *hw)
|
||||||
{
|
{
|
||||||
WAVVoice *wav = (WAVVoice *) hw;
|
WAVVoiceOut *wav = (WAVVoiceOut *) hw;
|
||||||
int stereo = hw->nchannels == 2;
|
int stereo = hw->info.nchannels == 2;
|
||||||
uint8_t rlen[4];
|
uint8_t rlen[4];
|
||||||
uint8_t dlen[4];
|
uint8_t dlen[4];
|
||||||
uint32_t rifflen = (wav->total_samples << stereo) + 36;
|
uint32_t rifflen = (wav->total_samples << stereo) + 36;
|
||||||
uint32_t datalen = wav->total_samples << stereo;
|
uint32_t datalen = wav->total_samples << stereo;
|
||||||
|
|
||||||
if (!wav->f || !hw->active)
|
if (!wav->f || !hw->active) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
le_store (rlen, rifflen, 4);
|
le_store (rlen, rifflen, 4);
|
||||||
le_store (dlen, datalen, 4);
|
le_store (dlen, datalen, 4);
|
||||||
@@ -181,7 +195,7 @@ static void wav_hw_fini (HWVoice *hw)
|
|||||||
wav->pcm_buf = NULL;
|
wav->pcm_buf = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int wav_hw_ctl (HWVoice *hw, int cmd, ...)
|
static int wav_ctl_out (HWVoiceOut *hw, int cmd, ...)
|
||||||
{
|
{
|
||||||
(void) hw;
|
(void) hw;
|
||||||
(void) cmd;
|
(void) cmd;
|
||||||
@@ -195,23 +209,41 @@ static void *wav_audio_init (void)
|
|||||||
|
|
||||||
static void wav_audio_fini (void *opaque)
|
static void wav_audio_fini (void *opaque)
|
||||||
{
|
{
|
||||||
|
(void) opaque;
|
||||||
ldebug ("wav_fini");
|
ldebug ("wav_fini");
|
||||||
}
|
}
|
||||||
|
|
||||||
struct pcm_ops wav_pcm_ops = {
|
struct audio_option wav_options[] = {
|
||||||
wav_hw_init,
|
{"PATH", AUD_OPT_STR, &conf.wav_path,
|
||||||
wav_hw_fini,
|
"Path to wave file", NULL, 0},
|
||||||
wav_hw_run,
|
{NULL, 0, NULL, NULL, NULL, 0}
|
||||||
wav_hw_write,
|
|
||||||
wav_hw_ctl
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct audio_output_driver wav_output_driver = {
|
struct audio_pcm_ops wav_pcm_ops = {
|
||||||
"wav",
|
wav_init_out,
|
||||||
wav_audio_init,
|
wav_fini_out,
|
||||||
wav_audio_fini,
|
wav_run_out,
|
||||||
&wav_pcm_ops,
|
wav_write_out,
|
||||||
1,
|
wav_ctl_out,
|
||||||
1,
|
|
||||||
sizeof (WAVVoice)
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
struct audio_driver wav_audio_driver = {
|
||||||
|
INIT_FIELD (name = ) "wav",
|
||||||
|
INIT_FIELD (descr = )
|
||||||
|
"WAV renderer http://wikipedia.org/wiki/WAV",
|
||||||
|
INIT_FIELD (options = ) wav_options,
|
||||||
|
INIT_FIELD (init = ) wav_audio_init,
|
||||||
|
INIT_FIELD (fini = ) wav_audio_fini,
|
||||||
|
INIT_FIELD (pcm_ops = ) &wav_pcm_ops,
|
||||||
|
INIT_FIELD (can_be_default = ) 0,
|
||||||
|
INIT_FIELD (max_voices_out = ) 1,
|
||||||
|
INIT_FIELD (max_voices_in = ) 0,
|
||||||
|
INIT_FIELD (voice_size_out = ) sizeof (WAVVoiceOut),
|
||||||
|
INIT_FIELD (voice_size_in = ) 0
|
||||||
};
|
};
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user