]>
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 | |
affc691a | 44 | static size_t no_write(HWVoiceOut *hw, void *buf, size_t len) |
7372f88d | 45 | { |
1d14ffa9 | 46 | NoVoiceOut *no = (NoVoiceOut *) hw; |
8ead62cf FB |
47 | int64_t now; |
48 | int64_t ticks; | |
49 | int64_t bytes; | |
7372f88d | 50 | |
bc72ad67 | 51 | now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); |
8ead62cf | 52 | ticks = now - no->old_ticks; |
73bcb24d | 53 | bytes = muldiv64(ticks, hw->info.bytes_per_second, NANOSECONDS_PER_SECOND); |
8ead62cf | 54 | |
7372f88d | 55 | no->old_ticks = now; |
affc691a | 56 | return MIN(len, bytes); |
1d14ffa9 | 57 | } |
7372f88d | 58 | |
5706db1d | 59 | static int no_init_out(HWVoiceOut *hw, struct audsettings *as, void *drv_opaque) |
1d14ffa9 | 60 | { |
d929eba5 | 61 | audio_pcm_init_info (&hw->info, as); |
c0fe3827 | 62 | hw->samples = 1024; |
1d14ffa9 FB |
63 | return 0; |
64 | } | |
7372f88d | 65 | |
1d14ffa9 FB |
66 | static void no_fini_out (HWVoiceOut *hw) |
67 | { | |
68 | (void) hw; | |
7372f88d FB |
69 | } |
70 | ||
1d14ffa9 | 71 | static int no_ctl_out (HWVoiceOut *hw, int cmd, ...) |
7372f88d | 72 | { |
1d14ffa9 FB |
73 | (void) hw; |
74 | (void) cmd; | |
75 | return 0; | |
7372f88d FB |
76 | } |
77 | ||
5706db1d | 78 | static int no_init_in(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque) |
7372f88d | 79 | { |
d929eba5 | 80 | audio_pcm_init_info (&hw->info, as); |
c0fe3827 | 81 | hw->samples = 1024; |
7372f88d FB |
82 | return 0; |
83 | } | |
84 | ||
1d14ffa9 | 85 | static void no_fini_in (HWVoiceIn *hw) |
7372f88d FB |
86 | { |
87 | (void) hw; | |
88 | } | |
89 | ||
affc691a | 90 | static size_t no_read(HWVoiceIn *hw, void *buf, size_t size) |
1d14ffa9 | 91 | { |
affc691a | 92 | size_t to_clear; |
1d14ffa9 | 93 | NoVoiceIn *no = (NoVoiceIn *) hw; |
affc691a KZ |
94 | |
95 | int64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); | |
96 | int64_t ticks = now - no->old_ticks; | |
97 | int64_t bytes = | |
98 | muldiv64(ticks, hw->info.bytes_per_second, NANOSECONDS_PER_SECOND); | |
99 | ||
100 | no->old_ticks = now; | |
101 | to_clear = MIN(bytes, size); | |
102 | ||
103 | audio_pcm_info_clear_buf(&hw->info, buf, to_clear >> hw->info.shift); | |
104 | return to_clear; | |
1d14ffa9 FB |
105 | } |
106 | ||
1d14ffa9 | 107 | static int no_ctl_in (HWVoiceIn *hw, int cmd, ...) |
7372f88d FB |
108 | { |
109 | (void) hw; | |
110 | (void) cmd; | |
111 | return 0; | |
112 | } | |
113 | ||
71830221 | 114 | static void *no_audio_init(Audiodev *dev) |
7372f88d FB |
115 | { |
116 | return &no_audio_init; | |
117 | } | |
118 | ||
119 | static void no_audio_fini (void *opaque) | |
120 | { | |
1d14ffa9 | 121 | (void) opaque; |
7372f88d FB |
122 | } |
123 | ||
35f4b58c | 124 | static struct audio_pcm_ops no_pcm_ops = { |
1dd3e4d1 JQ |
125 | .init_out = no_init_out, |
126 | .fini_out = no_fini_out, | |
affc691a | 127 | .write = no_write, |
1dd3e4d1 JQ |
128 | .ctl_out = no_ctl_out, |
129 | ||
130 | .init_in = no_init_in, | |
131 | .fini_in = no_fini_in, | |
affc691a | 132 | .read = no_read, |
1dd3e4d1 | 133 | .ctl_in = no_ctl_in |
7372f88d FB |
134 | }; |
135 | ||
d3893a39 | 136 | static struct audio_driver no_audio_driver = { |
bee37f32 JQ |
137 | .name = "none", |
138 | .descr = "Timer based audio emulation", | |
bee37f32 JQ |
139 | .init = no_audio_init, |
140 | .fini = no_audio_fini, | |
141 | .pcm_ops = &no_pcm_ops, | |
142 | .can_be_default = 1, | |
143 | .max_voices_out = INT_MAX, | |
144 | .max_voices_in = INT_MAX, | |
145 | .voice_size_out = sizeof (NoVoiceOut), | |
146 | .voice_size_in = sizeof (NoVoiceIn) | |
7372f88d | 147 | }; |
d3893a39 GH |
148 | |
149 | static void register_audio_none(void) | |
150 | { | |
151 | audio_driver_register(&no_audio_driver); | |
152 | } | |
153 | type_init(register_audio_none); |