2004-11-12 00:55:09 +08:00
|
|
|
/*
|
2005-10-31 02:58:22 +08:00
|
|
|
* QEMU Timer based audio emulation
|
|
|
|
*
|
|
|
|
* Copyright (c) 2004-2005 Vassili Karpov (malc)
|
|
|
|
*
|
2004-11-12 00:55:09 +08:00
|
|
|
* 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.
|
|
|
|
*/
|
2019-05-23 22:35:07 +08:00
|
|
|
|
2016-01-19 01:33:52 +08:00
|
|
|
#include "qemu/osdep.h"
|
2016-03-15 22:36:13 +08:00
|
|
|
#include "qemu/host-utils.h"
|
2019-05-23 22:35:07 +08:00
|
|
|
#include "qemu/module.h"
|
2007-11-18 01:14:51 +08:00
|
|
|
#include "audio.h"
|
2012-12-18 01:20:00 +08:00
|
|
|
#include "qemu/timer.h"
|
2004-11-12 00:55:09 +08:00
|
|
|
|
2005-10-31 02:58:22 +08:00
|
|
|
#define AUDIO_CAP "noaudio"
|
|
|
|
#include "audio_int.h"
|
2004-11-12 00:55:09 +08:00
|
|
|
|
2005-10-31 02:58:22 +08:00
|
|
|
typedef struct NoVoiceOut {
|
|
|
|
HWVoiceOut hw;
|
2019-09-20 05:24:21 +08:00
|
|
|
RateCtl rate;
|
2005-10-31 02:58:22 +08:00
|
|
|
} NoVoiceOut;
|
2004-11-12 00:55:09 +08:00
|
|
|
|
2005-10-31 02:58:22 +08:00
|
|
|
typedef struct NoVoiceIn {
|
|
|
|
HWVoiceIn hw;
|
2019-09-20 05:24:21 +08:00
|
|
|
RateCtl rate;
|
2005-10-31 02:58:22 +08:00
|
|
|
} NoVoiceIn;
|
2004-11-12 00:55:09 +08:00
|
|
|
|
2019-09-20 05:24:13 +08:00
|
|
|
static size_t no_write(HWVoiceOut *hw, void *buf, size_t len)
|
2004-11-12 00:55:09 +08:00
|
|
|
{
|
2005-10-31 02:58:22 +08:00
|
|
|
NoVoiceOut *no = (NoVoiceOut *) hw;
|
2019-09-20 05:24:21 +08:00
|
|
|
return audio_rate_get_bytes(&hw->info, &no->rate, len);
|
2005-10-31 02:58:22 +08:00
|
|
|
}
|
2004-11-12 00:55:09 +08:00
|
|
|
|
2015-06-04 05:03:47 +08:00
|
|
|
static int no_init_out(HWVoiceOut *hw, struct audsettings *as, void *drv_opaque)
|
2005-10-31 02:58:22 +08:00
|
|
|
{
|
2019-09-20 05:24:21 +08:00
|
|
|
NoVoiceOut *no = (NoVoiceOut *) hw;
|
|
|
|
|
2006-07-05 05:47:22 +08:00
|
|
|
audio_pcm_init_info (&hw->info, as);
|
2005-11-06 02:55:28 +08:00
|
|
|
hw->samples = 1024;
|
2019-09-20 05:24:21 +08:00
|
|
|
audio_rate_start(&no->rate);
|
2005-10-31 02:58:22 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2004-11-12 00:55:09 +08:00
|
|
|
|
2005-10-31 02:58:22 +08:00
|
|
|
static void no_fini_out (HWVoiceOut *hw)
|
|
|
|
{
|
|
|
|
(void) hw;
|
2004-11-12 00:55:09 +08:00
|
|
|
}
|
|
|
|
|
2019-09-20 05:24:22 +08:00
|
|
|
static void no_enable_out(HWVoiceOut *hw, bool enable)
|
2004-11-12 00:55:09 +08:00
|
|
|
{
|
2019-09-20 05:24:21 +08:00
|
|
|
NoVoiceOut *no = (NoVoiceOut *) hw;
|
|
|
|
|
2019-09-20 05:24:22 +08:00
|
|
|
if (enable) {
|
2019-09-20 05:24:21 +08:00
|
|
|
audio_rate_start(&no->rate);
|
|
|
|
}
|
2004-11-12 00:55:09 +08:00
|
|
|
}
|
|
|
|
|
2015-06-04 05:03:47 +08:00
|
|
|
static int no_init_in(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque)
|
2004-11-12 00:55:09 +08:00
|
|
|
{
|
2019-09-20 05:24:21 +08:00
|
|
|
NoVoiceIn *no = (NoVoiceIn *) hw;
|
|
|
|
|
2006-07-05 05:47:22 +08:00
|
|
|
audio_pcm_init_info (&hw->info, as);
|
2005-11-06 02:55:28 +08:00
|
|
|
hw->samples = 1024;
|
2019-09-20 05:24:21 +08:00
|
|
|
audio_rate_start(&no->rate);
|
2004-11-12 00:55:09 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-10-31 02:58:22 +08:00
|
|
|
static void no_fini_in (HWVoiceIn *hw)
|
2004-11-12 00:55:09 +08:00
|
|
|
{
|
|
|
|
(void) hw;
|
|
|
|
}
|
|
|
|
|
2019-09-20 05:24:13 +08:00
|
|
|
static size_t no_read(HWVoiceIn *hw, void *buf, size_t size)
|
2005-10-31 02:58:22 +08:00
|
|
|
{
|
|
|
|
NoVoiceIn *no = (NoVoiceIn *) hw;
|
2019-09-20 05:24:21 +08:00
|
|
|
int64_t bytes = audio_rate_get_bytes(&hw->info, &no->rate, size);
|
2019-09-20 05:24:13 +08:00
|
|
|
|
2019-10-14 03:58:02 +08:00
|
|
|
audio_pcm_info_clear_buf(&hw->info, buf, bytes / hw->info.bytes_per_frame);
|
2019-09-20 05:24:21 +08:00
|
|
|
return bytes;
|
2005-10-31 02:58:22 +08:00
|
|
|
}
|
|
|
|
|
2019-09-20 05:24:22 +08:00
|
|
|
static void no_enable_in(HWVoiceIn *hw, bool enable)
|
2004-11-12 00:55:09 +08:00
|
|
|
{
|
2019-09-20 05:24:21 +08:00
|
|
|
NoVoiceIn *no = (NoVoiceIn *) hw;
|
|
|
|
|
2019-09-20 05:24:22 +08:00
|
|
|
if (enable) {
|
2019-09-20 05:24:21 +08:00
|
|
|
audio_rate_start(&no->rate);
|
|
|
|
}
|
2004-11-12 00:55:09 +08:00
|
|
|
}
|
|
|
|
|
2019-03-09 06:34:15 +08:00
|
|
|
static void *no_audio_init(Audiodev *dev)
|
2004-11-12 00:55:09 +08:00
|
|
|
{
|
|
|
|
return &no_audio_init;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void no_audio_fini (void *opaque)
|
|
|
|
{
|
2005-10-31 02:58:22 +08:00
|
|
|
(void) opaque;
|
2004-11-12 00:55:09 +08:00
|
|
|
}
|
|
|
|
|
2008-10-07 02:08:30 +08:00
|
|
|
static struct audio_pcm_ops no_pcm_ops = {
|
2009-08-11 08:31:15 +08:00
|
|
|
.init_out = no_init_out,
|
|
|
|
.fini_out = no_fini_out,
|
2019-09-20 05:24:13 +08:00
|
|
|
.write = no_write,
|
2022-03-02 03:13:06 +08:00
|
|
|
.buffer_get_free = audio_generic_buffer_get_free,
|
2020-01-23 15:49:39 +08:00
|
|
|
.run_buffer_out = audio_generic_run_buffer_out,
|
2019-09-20 05:24:22 +08:00
|
|
|
.enable_out = no_enable_out,
|
2009-08-11 08:31:15 +08:00
|
|
|
|
|
|
|
.init_in = no_init_in,
|
|
|
|
.fini_in = no_fini_in,
|
2019-09-20 05:24:13 +08:00
|
|
|
.read = no_read,
|
2021-01-10 18:02:24 +08:00
|
|
|
.run_buffer_in = audio_generic_run_buffer_in,
|
2019-09-20 05:24:22 +08:00
|
|
|
.enable_in = no_enable_in
|
2004-11-12 00:55:09 +08:00
|
|
|
};
|
|
|
|
|
2018-03-06 15:40:47 +08:00
|
|
|
static struct audio_driver no_audio_driver = {
|
2009-08-11 08:31:14 +08:00
|
|
|
.name = "none",
|
|
|
|
.descr = "Timer based audio emulation",
|
|
|
|
.init = no_audio_init,
|
|
|
|
.fini = no_audio_fini,
|
|
|
|
.pcm_ops = &no_pcm_ops,
|
|
|
|
.can_be_default = 1,
|
|
|
|
.max_voices_out = INT_MAX,
|
|
|
|
.max_voices_in = INT_MAX,
|
|
|
|
.voice_size_out = sizeof (NoVoiceOut),
|
|
|
|
.voice_size_in = sizeof (NoVoiceIn)
|
2004-11-12 00:55:09 +08:00
|
|
|
};
|
2018-03-06 15:40:47 +08:00
|
|
|
|
|
|
|
static void register_audio_none(void)
|
|
|
|
{
|
|
|
|
audio_driver_register(&no_audio_driver);
|
|
|
|
}
|
|
|
|
type_init(register_audio_none);
|