bellard | 7372f88 | 2004-11-11 16:55:09 +0000 | [diff] [blame] | 1 | /* |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 2 | * QEMU Timer based audio emulation |
| 3 | * |
| 4 | * Copyright (c) 2004-2005 Vassili Karpov (malc) |
| 5 | * |
bellard | 7372f88 | 2004-11-11 16:55:09 +0000 | [diff] [blame] | 6 | * 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 Armbruster | 0b8fa32 | 2019-05-23 16:35:07 +0200 | [diff] [blame] | 24 | |
Peter Maydell | 6086a56 | 2016-01-18 17:33:52 +0000 | [diff] [blame] | 25 | #include "qemu/osdep.h" |
Paolo Bonzini | 87776ab | 2016-03-15 15:36:13 +0100 | [diff] [blame] | 26 | #include "qemu/host-utils.h" |
Markus Armbruster | 0b8fa32 | 2019-05-23 16:35:07 +0200 | [diff] [blame] | 27 | #include "qemu/module.h" |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 28 | #include "audio.h" |
Paolo Bonzini | 1de7afc | 2012-12-17 18:20:00 +0100 | [diff] [blame] | 29 | #include "qemu/timer.h" |
bellard | 7372f88 | 2004-11-11 16:55:09 +0000 | [diff] [blame] | 30 | |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 31 | #define AUDIO_CAP "noaudio" |
| 32 | #include "audio_int.h" |
bellard | 7372f88 | 2004-11-11 16:55:09 +0000 | [diff] [blame] | 33 | |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 34 | typedef struct NoVoiceOut { |
| 35 | HWVoiceOut hw; |
Kővágó, Zoltán | 857271a | 2019-09-19 23:24:21 +0200 | [diff] [blame] | 36 | RateCtl rate; |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 37 | } NoVoiceOut; |
bellard | 7372f88 | 2004-11-11 16:55:09 +0000 | [diff] [blame] | 38 | |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 39 | typedef struct NoVoiceIn { |
| 40 | HWVoiceIn hw; |
Kővágó, Zoltán | 857271a | 2019-09-19 23:24:21 +0200 | [diff] [blame] | 41 | RateCtl rate; |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 42 | } NoVoiceIn; |
bellard | 7372f88 | 2004-11-11 16:55:09 +0000 | [diff] [blame] | 43 | |
Kővágó, Zoltán | affc691 | 2019-09-19 23:24:13 +0200 | [diff] [blame] | 44 | static size_t no_write(HWVoiceOut *hw, void *buf, size_t len) |
bellard | 7372f88 | 2004-11-11 16:55:09 +0000 | [diff] [blame] | 45 | { |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 46 | NoVoiceOut *no = (NoVoiceOut *) hw; |
Kővágó, Zoltán | 857271a | 2019-09-19 23:24:21 +0200 | [diff] [blame] | 47 | return audio_rate_get_bytes(&hw->info, &no->rate, len); |
bellard | 7372f88 | 2004-11-11 16:55:09 +0000 | [diff] [blame] | 48 | } |
| 49 | |
Kővágó, Zoltán | 5706db1 | 2015-06-03 23:03:47 +0200 | [diff] [blame] | 50 | static int no_init_out(HWVoiceOut *hw, struct audsettings *as, void *drv_opaque) |
bellard | 7372f88 | 2004-11-11 16:55:09 +0000 | [diff] [blame] | 51 | { |
Kővágó, Zoltán | 857271a | 2019-09-19 23:24:21 +0200 | [diff] [blame] | 52 | NoVoiceOut *no = (NoVoiceOut *) hw; |
| 53 | |
bellard | d929eba | 2006-07-04 21:47:22 +0000 | [diff] [blame] | 54 | audio_pcm_init_info (&hw->info, as); |
bellard | c0fe382 | 2005-11-05 18:55:28 +0000 | [diff] [blame] | 55 | hw->samples = 1024; |
Kővágó, Zoltán | 857271a | 2019-09-19 23:24:21 +0200 | [diff] [blame] | 56 | audio_rate_start(&no->rate); |
bellard | 7372f88 | 2004-11-11 16:55:09 +0000 | [diff] [blame] | 57 | return 0; |
| 58 | } |
| 59 | |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 60 | static void no_fini_out (HWVoiceOut *hw) |
bellard | 7372f88 | 2004-11-11 16:55:09 +0000 | [diff] [blame] | 61 | { |
| 62 | (void) hw; |
| 63 | } |
| 64 | |
Kővágó, Zoltán | 571a8c5 | 2019-09-19 23:24:22 +0200 | [diff] [blame] | 65 | static void no_enable_out(HWVoiceOut *hw, bool enable) |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 66 | { |
Kővágó, Zoltán | 857271a | 2019-09-19 23:24:21 +0200 | [diff] [blame] | 67 | NoVoiceOut *no = (NoVoiceOut *) hw; |
| 68 | |
Kővágó, Zoltán | 571a8c5 | 2019-09-19 23:24:22 +0200 | [diff] [blame] | 69 | if (enable) { |
Kővágó, Zoltán | 857271a | 2019-09-19 23:24:21 +0200 | [diff] [blame] | 70 | audio_rate_start(&no->rate); |
| 71 | } |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 72 | } |
| 73 | |
Kővágó, Zoltán | 5706db1 | 2015-06-03 23:03:47 +0200 | [diff] [blame] | 74 | static int no_init_in(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque) |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 75 | { |
Kővágó, Zoltán | 857271a | 2019-09-19 23:24:21 +0200 | [diff] [blame] | 76 | NoVoiceIn *no = (NoVoiceIn *) hw; |
| 77 | |
bellard | d929eba | 2006-07-04 21:47:22 +0000 | [diff] [blame] | 78 | audio_pcm_init_info (&hw->info, as); |
bellard | c0fe382 | 2005-11-05 18:55:28 +0000 | [diff] [blame] | 79 | hw->samples = 1024; |
Kővágó, Zoltán | 857271a | 2019-09-19 23:24:21 +0200 | [diff] [blame] | 80 | audio_rate_start(&no->rate); |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 81 | return 0; |
| 82 | } |
| 83 | |
| 84 | static void no_fini_in (HWVoiceIn *hw) |
| 85 | { |
| 86 | (void) hw; |
| 87 | } |
| 88 | |
Kővágó, Zoltán | affc691 | 2019-09-19 23:24:13 +0200 | [diff] [blame] | 89 | static size_t no_read(HWVoiceIn *hw, void *buf, size_t size) |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 90 | { |
| 91 | NoVoiceIn *no = (NoVoiceIn *) hw; |
Kővágó, Zoltán | 857271a | 2019-09-19 23:24:21 +0200 | [diff] [blame] | 92 | int64_t bytes = audio_rate_get_bytes(&hw->info, &no->rate, size); |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 93 | |
Kővágó, Zoltán | 2b9cce8 | 2019-10-13 21:58:02 +0200 | [diff] [blame] | 94 | audio_pcm_info_clear_buf(&hw->info, buf, bytes / hw->info.bytes_per_frame); |
Kővágó, Zoltán | 857271a | 2019-09-19 23:24:21 +0200 | [diff] [blame] | 95 | return bytes; |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 96 | } |
| 97 | |
Kővágó, Zoltán | 571a8c5 | 2019-09-19 23:24:22 +0200 | [diff] [blame] | 98 | static void no_enable_in(HWVoiceIn *hw, bool enable) |
bellard | 7372f88 | 2004-11-11 16:55:09 +0000 | [diff] [blame] | 99 | { |
Kővágó, Zoltán | 857271a | 2019-09-19 23:24:21 +0200 | [diff] [blame] | 100 | NoVoiceIn *no = (NoVoiceIn *) hw; |
| 101 | |
Kővágó, Zoltán | 571a8c5 | 2019-09-19 23:24:22 +0200 | [diff] [blame] | 102 | if (enable) { |
Kővágó, Zoltán | 857271a | 2019-09-19 23:24:21 +0200 | [diff] [blame] | 103 | audio_rate_start(&no->rate); |
| 104 | } |
bellard | 7372f88 | 2004-11-11 16:55:09 +0000 | [diff] [blame] | 105 | } |
| 106 | |
Kővágó, Zoltán | 7183022 | 2019-03-08 23:34:15 +0100 | [diff] [blame] | 107 | static void *no_audio_init(Audiodev *dev) |
bellard | 7372f88 | 2004-11-11 16:55:09 +0000 | [diff] [blame] | 108 | { |
| 109 | return &no_audio_init; |
| 110 | } |
| 111 | |
| 112 | static void no_audio_fini (void *opaque) |
| 113 | { |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 114 | (void) opaque; |
bellard | 7372f88 | 2004-11-11 16:55:09 +0000 | [diff] [blame] | 115 | } |
| 116 | |
blueswir1 | 35f4b58 | 2008-10-06 18:08:30 +0000 | [diff] [blame] | 117 | static struct audio_pcm_ops no_pcm_ops = { |
Juan Quintela | 1dd3e4d | 2009-08-11 02:31:15 +0200 | [diff] [blame] | 118 | .init_out = no_init_out, |
| 119 | .fini_out = no_fini_out, |
Kővágó, Zoltán | affc691 | 2019-09-19 23:24:13 +0200 | [diff] [blame] | 120 | .write = no_write, |
Volker Rümelin | 9833438 | 2022-03-01 20:13:06 +0100 | [diff] [blame] | 121 | .buffer_get_free = audio_generic_buffer_get_free, |
Volker Rümelin | fdc8c5f | 2020-01-23 08:49:39 +0100 | [diff] [blame] | 122 | .run_buffer_out = audio_generic_run_buffer_out, |
Kővágó, Zoltán | 571a8c5 | 2019-09-19 23:24:22 +0200 | [diff] [blame] | 123 | .enable_out = no_enable_out, |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 124 | |
Juan Quintela | 1dd3e4d | 2009-08-11 02:31:15 +0200 | [diff] [blame] | 125 | .init_in = no_init_in, |
| 126 | .fini_in = no_fini_in, |
Kővágó, Zoltán | affc691 | 2019-09-19 23:24:13 +0200 | [diff] [blame] | 127 | .read = no_read, |
Volker Rümelin | a2893c8 | 2021-01-10 11:02:24 +0100 | [diff] [blame] | 128 | .run_buffer_in = audio_generic_run_buffer_in, |
Kővágó, Zoltán | 571a8c5 | 2019-09-19 23:24:22 +0200 | [diff] [blame] | 129 | .enable_in = no_enable_in |
bellard | 7372f88 | 2004-11-11 16:55:09 +0000 | [diff] [blame] | 130 | }; |
| 131 | |
Gerd Hoffmann | d3893a3 | 2018-03-06 08:40:47 +0100 | [diff] [blame] | 132 | static struct audio_driver no_audio_driver = { |
Juan Quintela | bee37f3 | 2009-08-11 02:31:14 +0200 | [diff] [blame] | 133 | .name = "none", |
| 134 | .descr = "Timer based audio emulation", |
Juan Quintela | bee37f3 | 2009-08-11 02:31:14 +0200 | [diff] [blame] | 135 | .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) |
bellard | 7372f88 | 2004-11-11 16:55:09 +0000 | [diff] [blame] | 143 | }; |
Gerd Hoffmann | d3893a3 | 2018-03-06 08:40:47 +0100 | [diff] [blame] | 144 | |
| 145 | static void register_audio_none(void) |
| 146 | { |
| 147 | audio_driver_register(&no_audio_driver); |
| 148 | } |
| 149 | type_init(register_audio_none); |