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