[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 09/12] wavaudio: do not use global variables
From: |
Kővágó, Zoltán |
Subject: |
[Qemu-devel] [PATCH 09/12] wavaudio: do not use global variables |
Date: |
Mon, 1 Jun 2015 15:23:47 +0200 |
Signed-off-by: Kővágó, Zoltán <address@hidden>
---
audio/wavaudio.c | 37 +++++++++++++++++++++----------------
1 file changed, 21 insertions(+), 16 deletions(-)
diff --git a/audio/wavaudio.c b/audio/wavaudio.c
index 5132aed..8acea8f 100644
--- a/audio/wavaudio.c
+++ b/audio/wavaudio.c
@@ -36,15 +36,10 @@ typedef struct WAVVoiceOut {
int total_samples;
} WAVVoiceOut;
-static struct {
+typedef struct {
struct audsettings settings;
const char *wav_path;
-} conf = {
- .settings.freq = 44100,
- .settings.nchannels = 2,
- .settings.fmt = AUD_FMT_S16,
- .wav_path = "qemu.wav"
-};
+} WAVConf;
static int wav_run_out (HWVoiceOut *hw, int live)
{
@@ -116,7 +111,8 @@ static int wav_init_out(HWVoiceOut *hw, struct audsettings
*as,
0x02, 0x00, 0x44, 0xac, 0x00, 0x00, 0x10, 0xb1, 0x02, 0x00, 0x04,
0x00, 0x10, 0x00, 0x64, 0x61, 0x74, 0x61, 0x00, 0x00, 0x00, 0x00
};
- struct audsettings wav_as = conf.settings;
+ WAVConf *conf = drv_opaque;
+ struct audsettings wav_as = conf->settings;
(void) as;
(void) drv_opaque;
@@ -157,10 +153,10 @@ static int wav_init_out(HWVoiceOut *hw, struct
audsettings *as,
le_store (hdr + 28, hw->info.freq << (bits16 + stereo), 4);
le_store (hdr + 32, 1 << (bits16 + stereo), 2);
- wav->f = fopen (conf.wav_path, "wb");
+ wav->f = fopen (conf->wav_path, "wb");
if (!wav->f) {
dolog ("Failed to open wave file `%s'\nReason: %s\n",
- conf.wav_path, strerror (errno));
+ conf->wav_path, strerror (errno));
g_free (wav->pcm_buf);
wav->pcm_buf = NULL;
return -1;
@@ -228,40 +224,49 @@ static int wav_ctl_out (HWVoiceOut *hw, int cmd, ...)
return 0;
}
+static WAVConf glob_conf = {
+ .settings.freq = 44100,
+ .settings.nchannels = 2,
+ .settings.fmt = AUD_FMT_S16,
+ .wav_path = "qemu.wav"
+};
+
static void *wav_audio_init (void)
{
- return &conf;
+ WAVConf *conf = g_malloc(sizeof(WAVConf));
+ *conf = glob_conf;
+ return conf;
}
static void wav_audio_fini (void *opaque)
{
- (void) opaque;
ldebug ("wav_fini");
+ g_free(opaque);
}
static struct audio_option wav_options[] = {
{
.name = "FREQUENCY",
.tag = AUD_OPT_INT,
- .valp = &conf.settings.freq,
+ .valp = &glob_conf.settings.freq,
.descr = "Frequency"
},
{
.name = "FORMAT",
.tag = AUD_OPT_FMT,
- .valp = &conf.settings.fmt,
+ .valp = &glob_conf.settings.fmt,
.descr = "Format"
},
{
.name = "DAC_FIXED_CHANNELS",
.tag = AUD_OPT_INT,
- .valp = &conf.settings.nchannels,
+ .valp = &glob_conf.settings.nchannels,
.descr = "Number of channels (1 - mono, 2 - stereo)"
},
{
.name = "PATH",
.tag = AUD_OPT_STR,
- .valp = &conf.wav_path,
+ .valp = &glob_conf.wav_path,
.descr = "Path to wave file"
},
{ /* End of list */ }
--
2.4.2
- [Qemu-devel] [PATCH 05/12] audio: expose drv_opaque to init_out and init_in, (continued)
- [Qemu-devel] [PATCH 03/12] audio: remove sdl backend, Kővágó, Zoltán, 2015/06/01
- [Qemu-devel] [PATCH 06/12] alsaaudio: do not use global variables, Kővágó, Zoltán, 2015/06/01
- [Qemu-devel] [PATCH 07/12] paaudio: do not use global variables, Kővágó, Zoltán, 2015/06/01
- [Qemu-devel] [PATCH 02/12] audio: remove fmod backend, Kővágó, Zoltán, 2015/06/01
- [Qemu-devel] [PATCH 08/12] ossaudio: do not use global variables, Kővágó, Zoltán, 2015/06/01
- [Qemu-devel] [PATCH 04/12] audio: remove winwave audio driver, Kővágó, Zoltán, 2015/06/01
- [Qemu-devel] [PATCH 09/12] wavaudio: do not use global variables,
Kővágó, Zoltán <=
- [Qemu-devel] [PATCH 11/12] paaudio: fix possible resource leak, Kővágó, Zoltán, 2015/06/01
- [Qemu-devel] [PATCH 10/12] dsoundaudio: do not use global variables, Kővágó, Zoltán, 2015/06/01
- [Qemu-devel] [PATCH 12/12] coreaudio: do not use global variables where possible, Kővágó, Zoltán, 2015/06/01
- Re: [Qemu-devel] [PATCH 00/12] Audio backend cleanup, Michael Tokarev, 2015/06/01