]>
Commit | Line | Data |
---|---|---|
7372f88d | 1 | /* |
1d14ffa9 FB |
2 | * QEMU Timer based audio emulation |
3 | * | |
4 | * Copyright (c) 2004-2005 Vassili Karpov (malc) | |
5 | * | |
7372f88d FB |
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 | */ | |
0b8fa32f | 24 | |
6086a565 | 25 | #include "qemu/osdep.h" |
87776ab7 | 26 | #include "qemu/host-utils.h" |
0b8fa32f | 27 | #include "qemu/module.h" |
87ecb68b | 28 | #include "audio.h" |
1de7afc9 | 29 | #include "qemu/timer.h" |
7372f88d | 30 | |
1d14ffa9 FB |
31 | #define AUDIO_CAP "noaudio" |
32 | #include "audio_int.h" | |
7372f88d | 33 | |
1d14ffa9 FB |
34 | typedef struct NoVoiceOut { |
35 | HWVoiceOut hw; | |
7372f88d | 36 | int64_t old_ticks; |
1d14ffa9 | 37 | } NoVoiceOut; |
7372f88d | 38 | |
1d14ffa9 FB |
39 | typedef struct NoVoiceIn { |
40 | HWVoiceIn hw; | |
41 | int64_t old_ticks; | |
42 | } NoVoiceIn; | |
7372f88d | 43 | |
7520462b | 44 | static size_t no_run_out(HWVoiceOut *hw, size_t live) |
7372f88d | 45 | { |
1d14ffa9 | 46 | NoVoiceOut *no = (NoVoiceOut *) hw; |
7520462b | 47 | size_t decr, samples; |
8ead62cf FB |
48 | int64_t now; |
49 | int64_t ticks; | |
50 | int64_t bytes; | |
7372f88d | 51 | |
bc72ad67 | 52 | now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); |
8ead62cf | 53 | ticks = now - no->old_ticks; |
73bcb24d | 54 | bytes = muldiv64(ticks, hw->info.bytes_per_second, NANOSECONDS_PER_SECOND); |
7520462b | 55 | bytes = MIN(bytes, SIZE_MAX); |
8ead62cf FB |
56 | samples = bytes >> hw->info.shift; |
57 | ||
7372f88d | 58 | no->old_ticks = now; |
58935915 | 59 | decr = MIN (live, samples); |
1d14ffa9 FB |
60 | hw->rpos = (hw->rpos + decr) % hw->samples; |
61 | return decr; | |
62 | } | |
7372f88d | 63 | |
5706db1d | 64 | static int no_init_out(HWVoiceOut *hw, struct audsettings *as, void *drv_opaque) |
1d14ffa9 | 65 | { |
d929eba5 | 66 | audio_pcm_init_info (&hw->info, as); |
c0fe3827 | 67 | hw->samples = 1024; |
1d14ffa9 FB |
68 | return 0; |
69 | } | |
7372f88d | 70 | |
1d14ffa9 FB |
71 | static void no_fini_out (HWVoiceOut *hw) |
72 | { | |
73 | (void) hw; | |
7372f88d FB |
74 | } |
75 | ||
1d14ffa9 | 76 | static int no_ctl_out (HWVoiceOut *hw, int cmd, ...) |
7372f88d | 77 | { |
1d14ffa9 FB |
78 | (void) hw; |
79 | (void) cmd; | |
80 | return 0; | |
7372f88d FB |
81 | } |
82 | ||
5706db1d | 83 | static int no_init_in(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque) |
7372f88d | 84 | { |
d929eba5 | 85 | audio_pcm_init_info (&hw->info, as); |
c0fe3827 | 86 | hw->samples = 1024; |
7372f88d FB |
87 | return 0; |
88 | } | |
89 | ||
1d14ffa9 | 90 | static void no_fini_in (HWVoiceIn *hw) |
7372f88d FB |
91 | { |
92 | (void) hw; | |
93 | } | |
94 | ||
7520462b | 95 | static size_t no_run_in(HWVoiceIn *hw) |
1d14ffa9 FB |
96 | { |
97 | NoVoiceIn *no = (NoVoiceIn *) hw; | |
7520462b KZ |
98 | size_t live = audio_pcm_hw_get_live_in(hw); |
99 | size_t dead = hw->samples - live; | |
100 | size_t samples = 0; | |
1d14ffa9 | 101 | |
8ead62cf | 102 | if (dead) { |
bc72ad67 | 103 | int64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); |
8ead62cf | 104 | int64_t ticks = now - no->old_ticks; |
4f4cc0ef | 105 | int64_t bytes = |
73bcb24d | 106 | muldiv64(ticks, hw->info.bytes_per_second, NANOSECONDS_PER_SECOND); |
1d14ffa9 | 107 | |
8ead62cf | 108 | no->old_ticks = now; |
7520462b | 109 | bytes = MIN (bytes, SIZE_MAX); |
8ead62cf | 110 | samples = bytes >> hw->info.shift; |
58935915 | 111 | samples = MIN (samples, dead); |
8ead62cf | 112 | } |
1d14ffa9 FB |
113 | return samples; |
114 | } | |
115 | ||
1d14ffa9 | 116 | static int no_ctl_in (HWVoiceIn *hw, int cmd, ...) |
7372f88d FB |
117 | { |
118 | (void) hw; | |
119 | (void) cmd; | |
120 | return 0; | |
121 | } | |
122 | ||
71830221 | 123 | static void *no_audio_init(Audiodev *dev) |
7372f88d FB |
124 | { |
125 | return &no_audio_init; | |
126 | } | |
127 | ||
128 | static void no_audio_fini (void *opaque) | |
129 | { | |
1d14ffa9 | 130 | (void) opaque; |
7372f88d FB |
131 | } |
132 | ||
35f4b58c | 133 | static struct audio_pcm_ops no_pcm_ops = { |
1dd3e4d1 JQ |
134 | .init_out = no_init_out, |
135 | .fini_out = no_fini_out, | |
136 | .run_out = no_run_out, | |
1dd3e4d1 JQ |
137 | .ctl_out = no_ctl_out, |
138 | ||
139 | .init_in = no_init_in, | |
140 | .fini_in = no_fini_in, | |
141 | .run_in = no_run_in, | |
1dd3e4d1 | 142 | .ctl_in = no_ctl_in |
7372f88d FB |
143 | }; |
144 | ||
d3893a39 | 145 | static struct audio_driver no_audio_driver = { |
bee37f32 JQ |
146 | .name = "none", |
147 | .descr = "Timer based audio emulation", | |
bee37f32 JQ |
148 | .init = no_audio_init, |
149 | .fini = no_audio_fini, | |
150 | .pcm_ops = &no_pcm_ops, | |
151 | .can_be_default = 1, | |
152 | .max_voices_out = INT_MAX, | |
153 | .max_voices_in = INT_MAX, | |
154 | .voice_size_out = sizeof (NoVoiceOut), | |
155 | .voice_size_in = sizeof (NoVoiceIn) | |
7372f88d | 156 | }; |
d3893a39 GH |
157 | |
158 | static void register_audio_none(void) | |
159 | { | |
160 | audio_driver_register(&no_audio_driver); | |
161 | } | |
162 | type_init(register_audio_none); |