blob: 84a6bfbb1c87d2913b113530e070cb00d4bf1a7c [file] [log] [blame]
bellard7372f882004-11-11 16:55:09 +00001/*
bellard1d14ffa2005-10-30 18:58:22 +00002 * QEMU Timer based audio emulation
3 *
4 * Copyright (c) 2004-2005 Vassili Karpov (malc)
5 *
bellard7372f882004-11-11 16:55:09 +00006 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
Markus Armbruster0b8fa322019-05-23 16:35:07 +020024
Peter Maydell6086a562016-01-18 17:33:52 +000025#include "qemu/osdep.h"
Paolo Bonzini87776ab2016-03-15 15:36:13 +010026#include "qemu/host-utils.h"
Markus Armbruster0b8fa322019-05-23 16:35:07 +020027#include "qemu/module.h"
pbrook87ecb682007-11-17 17:14:51 +000028#include "audio.h"
Paolo Bonzini1de7afc2012-12-17 18:20:00 +010029#include "qemu/timer.h"
bellard7372f882004-11-11 16:55:09 +000030
bellard1d14ffa2005-10-30 18:58:22 +000031#define AUDIO_CAP "noaudio"
32#include "audio_int.h"
bellard7372f882004-11-11 16:55:09 +000033
bellard1d14ffa2005-10-30 18:58:22 +000034typedef struct NoVoiceOut {
35 HWVoiceOut hw;
Kővágó, Zoltán857271a2019-09-19 23:24:21 +020036 RateCtl rate;
bellard1d14ffa2005-10-30 18:58:22 +000037} NoVoiceOut;
bellard7372f882004-11-11 16:55:09 +000038
bellard1d14ffa2005-10-30 18:58:22 +000039typedef struct NoVoiceIn {
40 HWVoiceIn hw;
Kővágó, Zoltán857271a2019-09-19 23:24:21 +020041 RateCtl rate;
bellard1d14ffa2005-10-30 18:58:22 +000042} NoVoiceIn;
bellard7372f882004-11-11 16:55:09 +000043
Kővágó, Zoltánaffc6912019-09-19 23:24:13 +020044static size_t no_write(HWVoiceOut *hw, void *buf, size_t len)
bellard7372f882004-11-11 16:55:09 +000045{
bellard1d14ffa2005-10-30 18:58:22 +000046 NoVoiceOut *no = (NoVoiceOut *) hw;
Kővágó, Zoltán857271a2019-09-19 23:24:21 +020047 return audio_rate_get_bytes(&hw->info, &no->rate, len);
bellard7372f882004-11-11 16:55:09 +000048}
49
Kővágó, Zoltán5706db12015-06-03 23:03:47 +020050static int no_init_out(HWVoiceOut *hw, struct audsettings *as, void *drv_opaque)
bellard7372f882004-11-11 16:55:09 +000051{
Kővágó, Zoltán857271a2019-09-19 23:24:21 +020052 NoVoiceOut *no = (NoVoiceOut *) hw;
53
bellardd929eba2006-07-04 21:47:22 +000054 audio_pcm_init_info (&hw->info, as);
bellardc0fe3822005-11-05 18:55:28 +000055 hw->samples = 1024;
Kővágó, Zoltán857271a2019-09-19 23:24:21 +020056 audio_rate_start(&no->rate);
bellard7372f882004-11-11 16:55:09 +000057 return 0;
58}
59
bellard1d14ffa2005-10-30 18:58:22 +000060static void no_fini_out (HWVoiceOut *hw)
bellard7372f882004-11-11 16:55:09 +000061{
62 (void) hw;
63}
64
Kővágó, Zoltán571a8c52019-09-19 23:24:22 +020065static void no_enable_out(HWVoiceOut *hw, bool enable)
bellard1d14ffa2005-10-30 18:58:22 +000066{
Kővágó, Zoltán857271a2019-09-19 23:24:21 +020067 NoVoiceOut *no = (NoVoiceOut *) hw;
68
Kővágó, Zoltán571a8c52019-09-19 23:24:22 +020069 if (enable) {
Kővágó, Zoltán857271a2019-09-19 23:24:21 +020070 audio_rate_start(&no->rate);
71 }
bellard1d14ffa2005-10-30 18:58:22 +000072}
73
Kővágó, Zoltán5706db12015-06-03 23:03:47 +020074static int no_init_in(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque)
bellard1d14ffa2005-10-30 18:58:22 +000075{
Kővágó, Zoltán857271a2019-09-19 23:24:21 +020076 NoVoiceIn *no = (NoVoiceIn *) hw;
77
bellardd929eba2006-07-04 21:47:22 +000078 audio_pcm_init_info (&hw->info, as);
bellardc0fe3822005-11-05 18:55:28 +000079 hw->samples = 1024;
Kővágó, Zoltán857271a2019-09-19 23:24:21 +020080 audio_rate_start(&no->rate);
bellard1d14ffa2005-10-30 18:58:22 +000081 return 0;
82}
83
84static void no_fini_in (HWVoiceIn *hw)
85{
86 (void) hw;
87}
88
Kővágó, Zoltánaffc6912019-09-19 23:24:13 +020089static size_t no_read(HWVoiceIn *hw, void *buf, size_t size)
bellard1d14ffa2005-10-30 18:58:22 +000090{
91 NoVoiceIn *no = (NoVoiceIn *) hw;
Kővágó, Zoltán857271a2019-09-19 23:24:21 +020092 int64_t bytes = audio_rate_get_bytes(&hw->info, &no->rate, size);
bellard1d14ffa2005-10-30 18:58:22 +000093
Kővágó, Zoltán2b9cce82019-10-13 21:58:02 +020094 audio_pcm_info_clear_buf(&hw->info, buf, bytes / hw->info.bytes_per_frame);
Kővágó, Zoltán857271a2019-09-19 23:24:21 +020095 return bytes;
bellard1d14ffa2005-10-30 18:58:22 +000096}
97
Kővágó, Zoltán571a8c52019-09-19 23:24:22 +020098static void no_enable_in(HWVoiceIn *hw, bool enable)
bellard7372f882004-11-11 16:55:09 +000099{
Kővágó, Zoltán857271a2019-09-19 23:24:21 +0200100 NoVoiceIn *no = (NoVoiceIn *) hw;
101
Kővágó, Zoltán571a8c52019-09-19 23:24:22 +0200102 if (enable) {
Kővágó, Zoltán857271a2019-09-19 23:24:21 +0200103 audio_rate_start(&no->rate);
104 }
bellard7372f882004-11-11 16:55:09 +0000105}
106
Kővágó, Zoltán71830222019-03-08 23:34:15 +0100107static void *no_audio_init(Audiodev *dev)
bellard7372f882004-11-11 16:55:09 +0000108{
109 return &no_audio_init;
110}
111
112static void no_audio_fini (void *opaque)
113{
bellard1d14ffa2005-10-30 18:58:22 +0000114 (void) opaque;
bellard7372f882004-11-11 16:55:09 +0000115}
116
blueswir135f4b582008-10-06 18:08:30 +0000117static struct audio_pcm_ops no_pcm_ops = {
Juan Quintela1dd3e4d2009-08-11 02:31:15 +0200118 .init_out = no_init_out,
119 .fini_out = no_fini_out,
Kővágó, Zoltánaffc6912019-09-19 23:24:13 +0200120 .write = no_write,
Volker Rümelin98334382022-03-01 20:13:06 +0100121 .buffer_get_free = audio_generic_buffer_get_free,
Volker Rümelinfdc8c5f2020-01-23 08:49:39 +0100122 .run_buffer_out = audio_generic_run_buffer_out,
Kővágó, Zoltán571a8c52019-09-19 23:24:22 +0200123 .enable_out = no_enable_out,
bellard1d14ffa2005-10-30 18:58:22 +0000124
Juan Quintela1dd3e4d2009-08-11 02:31:15 +0200125 .init_in = no_init_in,
126 .fini_in = no_fini_in,
Kővágó, Zoltánaffc6912019-09-19 23:24:13 +0200127 .read = no_read,
Volker Rümelina2893c82021-01-10 11:02:24 +0100128 .run_buffer_in = audio_generic_run_buffer_in,
Kővágó, Zoltán571a8c52019-09-19 23:24:22 +0200129 .enable_in = no_enable_in
bellard7372f882004-11-11 16:55:09 +0000130};
131
Gerd Hoffmannd3893a32018-03-06 08:40:47 +0100132static struct audio_driver no_audio_driver = {
Juan Quintelabee37f32009-08-11 02:31:14 +0200133 .name = "none",
134 .descr = "Timer based audio emulation",
Juan Quintelabee37f32009-08-11 02:31:14 +0200135 .init = no_audio_init,
136 .fini = no_audio_fini,
137 .pcm_ops = &no_pcm_ops,
138 .can_be_default = 1,
139 .max_voices_out = INT_MAX,
140 .max_voices_in = INT_MAX,
141 .voice_size_out = sizeof (NoVoiceOut),
142 .voice_size_in = sizeof (NoVoiceIn)
bellard7372f882004-11-11 16:55:09 +0000143};
Gerd Hoffmannd3893a32018-03-06 08:40:47 +0100144
145static void register_audio_none(void)
146{
147 audio_driver_register(&no_audio_driver);
148}
149type_init(register_audio_none);