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